xref: /illumos-gate/usr/src/uts/common/sys/font.h (revision dd72704bd9e794056c558153663c739e2012d721)
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,	/* This font is loaded by software */
88 	FONT_MANUAL,	/* This font is loaded manually by user */
89 	FONT_BOOT,	/* This font was passed to kernel by bootloader */
90 	FONT_BUILTIN,	/* This font was built in at compile time */
91 	FONT_RELOAD	/* This font is marked to be re-read from file */
92 } FONT_FLAGS;
93 
94 struct fontlist {
95 	char		*font_name;
96 	FONT_FLAGS	font_flags;
97 	bitmap_data_t	*font_data;
98 	bitmap_data_t   *(*font_load)(char *);
99 	STAILQ_ENTRY(fontlist) font_next;
100 };
101 
102 #define	FONT_HEADER_MAGIC	"VFNT0002"
103 struct font_header {
104 	uint8_t		fh_magic[8];
105 	uint8_t		fh_width;
106 	uint8_t		fh_height;
107 	uint16_t	fh_pad;
108 	uint32_t	fh_glyph_count;
109 	uint32_t	fh_map_count[4];
110 } __attribute__((__packed__));
111 
112 typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
113 extern font_list_t fonts;
114 
115 /*
116  * Built in fonts. We are using Gallant as default on sparc to keep
117  * smooth transition from prom and 8x16 on x86, for vga text mode.
118  */
119 #ifdef sparc
120 #define	DEFAULT_FONT_DATA	font_data_12x22
121 extern bitmap_data_t font_data_12x22;
122 #else
123 #define	DEFAULT_FONT_DATA	font_data_8x16
124 extern bitmap_data_t font_data_8x16;
125 #endif
126 #define	BORDER_PIXELS		10	/* space from screen border */
127 
128 void reset_font_flags(void);
129 bitmap_data_t *set_font(short *, short *, short, short);
130 const uint8_t *font_lookup(const struct font *, uint32_t);
131 void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
132 void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
133 void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint32_t, uint32_t);
134 void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
135 void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* !_SYS_FONT_H */
142