]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/font.h
Merge llvm-project release/17.x llvmorg-17.0.1-25-g098e653a5bed
[FreeBSD/FreeBSD.git] / sys / sys / font.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2009, 2013 The FreeBSD Foundation
5  *
6  * This software was developed by Ed Schouten under sponsorship from the
7  * FreeBSD Foundation.
8  *
9  * Portions of this software were developed by Oleksandr Rybalko
10  * under sponsorship from the FreeBSD Foundation.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #ifndef _SYS_FONT_H_
35 #define _SYS_FONT_H_
36
37 #include <sys/queue.h>
38
39 /*
40  * Fonts.
41  *
42  * Fonts support normal and bold weights, and single and double width glyphs.
43  * Mapping tables are used to map Unicode points to glyphs.  They are sorted by
44  * code point, and vtfont_lookup() uses this to perform a binary search.  Each
45  * font has four mapping tables: two weights times two halves (left/single,
46  * right).  When a character is not present in a bold map the glyph from the
47  * normal map is used.  When no glyph is available, it uses glyph 0, which is
48  * normally equal to U+FFFD.
49  */
50
51 enum vfnt_map_type {
52         VFNT_MAP_NORMAL = 0,    /* Normal font. */
53         VFNT_MAP_NORMAL_RIGHT,  /* Normal font right hand. */
54         VFNT_MAP_BOLD,          /* Bold font. */
55         VFNT_MAP_BOLD_RIGHT,    /* Bold font right hand. */
56         VFNT_MAPS               /* Number of maps. */
57 };
58
59 struct font_info {
60         int32_t fi_checksum;
61         uint32_t fi_width;
62         uint32_t fi_height;
63         uint32_t fi_bitmap_size;
64         uint32_t fi_map_count[VFNT_MAPS];
65 };
66
67 struct vfnt_map {
68         uint32_t         vfm_src;
69         uint16_t         vfm_dst;
70         uint16_t         vfm_len;
71 } __packed;
72 typedef struct vfnt_map vfnt_map_t;
73
74 struct vt_font {
75         vfnt_map_t      *vf_map[VFNT_MAPS];
76         uint8_t         *vf_bytes;
77         uint32_t         vf_height;
78         uint32_t         vf_width;
79         uint32_t         vf_map_count[VFNT_MAPS];
80         uint32_t         vf_refcount;
81 };
82
83 typedef struct vt_font_bitmap_data {
84         uint32_t        vfbd_width;
85         uint32_t        vfbd_height;
86         uint32_t        vfbd_compressed_size;
87         uint32_t        vfbd_uncompressed_size;
88         uint8_t         *vfbd_compressed_data;
89         struct vt_font  *vfbd_font;
90 } vt_font_bitmap_data_t;
91
92 typedef enum {
93         FONT_AUTO,      /* This font is loaded by software */
94         FONT_MANUAL,    /* This font is loaded manually by user */
95         FONT_BUILTIN,   /* This font was built in at compile time */
96         FONT_RELOAD     /* This font is marked to be re-read from file */
97 } FONT_FLAGS;
98
99 struct fontlist {
100         char                    *font_name;
101         FONT_FLAGS              font_flags;
102         vt_font_bitmap_data_t   *font_data;
103         vt_font_bitmap_data_t   *(*font_load)(char *);
104         STAILQ_ENTRY(fontlist)  font_next;
105 };
106
107 typedef STAILQ_HEAD(font_list, fontlist) font_list_t;
108
109 #define FONT_HEADER_MAGIC       "VFNT0002"
110 struct font_header {
111         uint8_t         fh_magic[8];
112         uint8_t         fh_width;
113         uint8_t         fh_height;
114         uint16_t        fh_pad;
115         uint32_t        fh_glyph_count;
116         uint32_t        fh_map_count[VFNT_MAPS];
117 } __packed;
118
119 #endif /* !_SYS_FONT_H_ */