xref: /illumos-gate/usr/src/uts/common/sys/font.h (revision 337411fcf93041fb98fbfba6506e4128cd3e1933)
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  * Copyright 2019 Toomas Soome <tsoome@me.com>
26  */
27 
28 #ifndef _SYS_FONT_H
29 #define	_SYS_FONT_H
30 
31 #include <sys/queue.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 enum vfnt_map {
38 	VFNT_MAP_NORMAL = 0,	/* Normal font. */
39 	VFNT_MAP_NORMAL_RH,	/* Normal font right hand. */
40 	VFNT_MAP_BOLD,		/* Bold font. */
41 	VFNT_MAP_BOLD_RH,	/* Bold font right hand. */
42 	VFNT_MAPS		/* Number of maps. */
43 };
44 
45 /*
46  * If the custom console font was loaded, pass it for kernel as a module.
47  * We do not just load the font file, as the font file needs to be processed,
48  * and the early boot has very little resources. So we just set up the
49  * needed structures and make a copy of the byte arrays.
50  *
51  * Note we cannot copy the structures one to one due to the pointer size,
52  * so we record the data by using fixed size structure.
53  */
54 struct font_info {
55 	int32_t fi_checksum;
56 	uint32_t fi_width;
57 	uint32_t fi_height;
58 	uint32_t fi_bitmap_size;
59 	uint32_t fi_map_count[VFNT_MAPS];
60 };
61 
62 struct font_map {
63 	uint32_t font_src;	/* Source glyph. */
64 	uint16_t font_dst;	/* Target glyph. */
65 	uint16_t font_len;	/* The number of glyphs in sequence. */
66 };
67 
68 /* Any unknown glyph is mapped as first (offset 0) glyph in bitmap. */
69 struct font {
70 	struct font_map	*vf_map[VFNT_MAPS];	/* Mapping tables. */
71 	uint8_t		*vf_bytes;		/* Font bitmap data. */
72 	uint32_t	vf_width;		/* Glyph width. */
73 	uint32_t	vf_height;		/* Glyph height. */
74 	uint32_t	vf_map_count[VFNT_MAPS];	/* Entries in map */
75 };
76 
77 typedef	struct  bitmap_data {
78 	uint32_t	width;
79 	uint32_t	height;
80 	uint32_t	compressed_size;
81 	uint32_t	uncompressed_size;
82 	uint8_t		*compressed_data;
83 	struct font	*font;
84 } bitmap_data_t;
85 
86 typedef enum {
87 	FONT_AUTO,
88 	FONT_MANUAL,
89 	FONT_BOOT
90 } FONT_FLAGS;
91 
92 struct fontlist {
93 	char		*font_name;
94 	FONT_FLAGS	font_flags;
95 	bitmap_data_t	*font_data;
96 	bitmap_data_t   *(*font_load)(char *);
97 	STAILQ_ENTRY(fontlist) font_next;
98 };
99 
100 #define	FONT_HEADER_MAGIC	"VFNT0002"
101 struct font_header {
102 	uint8_t		fh_magic[8];
103 	uint8_t		fh_width;
104 	uint8_t		fh_height;
105 	uint16_t	fh_pad;
106 	uint32_t	fh_glyph_count;
107 	uint32_t	fh_map_count[4];
108 } __attribute__((__packed__));
109 
110 typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
111 extern font_list_t fonts;
112 
113 /*
114  * Built in fonts. We are using Gallant as default on sparc to keep
115  * smooth transition from prom and 8x16 on x86, for vga text mode.
116  */
117 #ifdef sparc
118 #define	DEFAULT_FONT_DATA	font_data_12x22
119 extern bitmap_data_t font_data_12x22;
120 #else
121 #define	DEFAULT_FONT_DATA	font_data_8x16
122 extern bitmap_data_t font_data_8x16;
123 #endif
124 #define	BORDER_PIXELS		10	/* space from screen border */
125 
126 void reset_font_flags(void);
127 bitmap_data_t *set_font(short *, short *, short, short);
128 const uint8_t *font_lookup(const struct font *, uint32_t);
129 void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
130 void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
131 void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint16_t, uint16_t);
132 void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
133 void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /* !_SYS_FONT_H */
140