summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/font.h
blob: 5733686bf302f3c17d4caa4e3cedce1205771591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 * Copyright 2019 Toomas Soome <tsoome@me.com>
 */

#ifndef _SYS_FONT_H
#define	_SYS_FONT_H

#include <sys/queue.h>

#ifdef __cplusplus
extern "C" {
#endif

enum vfnt_map {
	VFNT_MAP_NORMAL = 0,	/* Normal font. */
	VFNT_MAP_NORMAL_RH,	/* Normal font right hand. */
	VFNT_MAP_BOLD,		/* Bold font. */
	VFNT_MAP_BOLD_RH,	/* Bold font right hand. */
	VFNT_MAPS		/* Number of maps. */
};

/*
 * If the custom console font was loaded, pass it for kernel as a module.
 * We do not just load the font file, as the font file needs to be processed,
 * and the early boot has very little resources. So we just set up the
 * needed structures and make a copy of the byte arrays.
 *
 * Note we cannot copy the structures one to one due to the pointer size,
 * so we record the data by using fixed size structure.
 */
struct font_info {
	int32_t fi_checksum;
	uint32_t fi_width;
	uint32_t fi_height;
	uint32_t fi_bitmap_size;
	uint32_t fi_map_count[VFNT_MAPS];
};

struct font_map {
	uint32_t font_src;	/* Source glyph. */
	uint16_t font_dst;	/* Target glyph. */
	uint16_t font_len;	/* The number of glyphs in sequence. */
};

/* Any unknown glyph is mapped as first (offset 0) glyph in bitmap. */
struct font {
	struct font_map	*vf_map[VFNT_MAPS];	/* Mapping tables. */
	uint8_t		*vf_bytes;		/* Font bitmap data. */
	uint32_t	vf_width;		/* Glyph width. */
	uint32_t	vf_height;		/* Glyph height. */
	uint32_t	vf_map_count[VFNT_MAPS];	/* Entries in map */
};

typedef	struct  bitmap_data {
	uint32_t	width;
	uint32_t	height;
	uint32_t	compressed_size;
	uint32_t	uncompressed_size;
	uint8_t		*compressed_data;
	struct font	*font;
} bitmap_data_t;

typedef enum {
	FONT_AUTO,
	FONT_MANUAL,
	FONT_BOOT
} FONT_FLAGS;

struct fontlist {
	char		*font_name;
	FONT_FLAGS	font_flags;
	bitmap_data_t	*font_data;
	bitmap_data_t   *(*font_load)(char *);
	STAILQ_ENTRY(fontlist) font_next;
};

#define	FONT_HEADER_MAGIC	"VFNT0002"
struct font_header {
	uint8_t		fh_magic[8];
	uint8_t		fh_width;
	uint8_t		fh_height;
	uint16_t	fh_pad;
	uint32_t	fh_glyph_count;
	uint32_t	fh_map_count[4];
} __attribute__((__packed__));

typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
extern font_list_t fonts;

/*
 * Built in fonts. We are using Gallant as default on sparc to keep
 * smooth transition from prom and 8x16 on x86, for vga text mode.
 */
#ifdef sparc
#define	DEFAULT_FONT_DATA	font_data_12x22
extern bitmap_data_t font_data_12x22;
#else
#define	DEFAULT_FONT_DATA	font_data_8x16
extern bitmap_data_t font_data_8x16;
#endif
#define	BORDER_PIXELS		10	/* space from screen border */

void reset_font_flags(void);
bitmap_data_t *set_font(short *, short *, short, short);
const uint8_t *font_lookup(const struct font *, uint32_t);
void font_bit_to_pix4(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
void font_bit_to_pix8(struct font *, uint8_t *, uint32_t, uint8_t, uint8_t);
void font_bit_to_pix16(struct font *, uint16_t *, uint32_t, uint16_t, uint16_t);
void font_bit_to_pix24(struct font *, uint8_t *, uint32_t, uint32_t, uint32_t);
void font_bit_to_pix32(struct font *, uint32_t *, uint32_t, uint32_t, uint32_t);

#ifdef __cplusplus
}
#endif

#endif /* !_SYS_FONT_H */