1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #ifndef _SYS_FONT_H
  28 #define _SYS_FONT_H
  29 
  30 #include <sys/queue.h>
  31 
  32 #ifdef __cplusplus
  33 extern "C" {
  34 #endif
  35 
  36 enum vfnt_map {
  37         VFNT_MAP_NORMAL = 0,    /* Normal font. */
  38         VFNT_MAP_NORMAL_RH,     /* Normal font right hand. */
  39         VFNT_MAP_BOLD,          /* Bold font. */
  40         VFNT_MAP_BOLD_RH,       /* Bold font right hand. */
  41         VFNT_MAPS               /* Number of maps. */
  42 };
  43 
  44 struct font_map {
  45         uint32_t font_src;      /* Source glyph. */
  46         uint16_t font_dst;      /* Target glyph. */
  47         uint16_t font_len;      /* The number of glyphs in sequence. */
  48 };
  49 
  50 /* Any unknown glyph is mapped as first (offset 0) glyph in bitmap. */
  51 struct font {
  52         struct font_map *vf_map[VFNT_MAPS];     /* Mapping tables. */
  53         uint8_t         *vf_bytes;              /* Font bitmap data. */
  54         uint32_t        vf_width;               /* Glyph width. */
  55         uint32_t        vf_height;              /* Glyph height. */
  56         uint32_t        vf_map_count[VFNT_MAPS];        /* Entries in map */
  57 };
  58 
  59 typedef struct  bitmap_data {
  60         short           width;
  61         short           height;
  62         uint32_t        compressed_size;
  63         uint32_t        uncompressed_size;
  64         uint8_t         *compressed_data;
  65         struct font     *font;
  66 } bitmap_data_t;
  67 
  68 typedef bitmap_data_t   *font_load_cb_t(char *);
  69 typedef enum {
  70         FONT_AUTO,
  71         FONT_MANUAL,
  72         FONT_BOOT
  73 } FONT_FLAGS;
  74 
  75 struct fontlist {
  76         char            *font_name;
  77         FONT_FLAGS      font_flags;
  78         bitmap_data_t   *font_data;
  79         font_load_cb_t  *font_load;
  80         STAILQ_ENTRY(fontlist) font_next;
  81 };
  82 
  83 #define FONT_HEADER_MAGIC       "VFNT0002"
  84 struct font_header {
  85         uint8_t         fh_magic[8];
  86         uint8_t         fh_width;
  87         uint8_t         fh_height;
  88         uint16_t        fh_pad;
  89         uint32_t        fh_glyph_count;
  90         uint32_t        fh_map_count[4];
  91 } __attribute__((__packed__));
  92 
  93 typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
  94 extern font_list_t fonts;
  95 
  96 /*
  97  * Built in fonts. We are using Gallant as default on sparc to keep
  98  * smooth transition from prom and 8x16 on x86, for vga text mode.
  99  */
 100 #ifdef sparc
 101 #define DEFAULT_FONT_DATA       font_data_12x22
 102 extern bitmap_data_t font_data_12x22;
 103 #else
 104 #define DEFAULT_FONT_DATA       font_data_8x16
 105 extern bitmap_data_t font_data_8x16;
 106 #endif
 107 #define BORDER_PIXELS           10      /* space from screen border */
 108 
 109 bitmap_data_t *set_font(short *, short *, short, short);
 110 const uint8_t *font_lookup(const struct font *, uint32_t);
 111 void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
 112 void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
 113 void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint16_t, uint16_t);
 114 void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
 115 void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);
 116 
 117 #ifdef __cplusplus
 118 }
 119 #endif
 120 
 121 #endif /* !_SYS_FONT_H */