xref: /linux/include/linux/font.h (revision cfa72955a029cd79433694cac6b5630788609cd4)
1 /*
2  *  font.h -- `Soft' font definitions
3  *
4  *  Created 1995 by Geert Uytterhoeven
5  *
6  *  This file is subject to the terms and conditions of the GNU General Public
7  *  License.  See the file COPYING in the main directory of this archive
8  *  for more details.
9  */
10 
11 #ifndef _VIDEO_FONT_H
12 #define _VIDEO_FONT_H
13 
14 #include <linux/math.h>
15 #include <linux/types.h>
16 
17 struct console_font;
18 
19 /*
20  * Glyphs
21  */
22 
23 /**
24  * font_glyph_pitch - Calculates the number of bytes per scanline
25  * @width: The glyph width in bits per scanline
26  *
27  * A glyph's pitch is the number of bytes in a single scanline, rounded
28  * up to the next full byte. The parameter @width receives the number
29  * of visible bits per scanline. For example, if width is 14 bytes per
30  * scanline, the pitch is 2 bytes per scanline. If width is 8 bits per
31  * scanline, the pitch is 1 byte per scanline.
32  *
33  * Returns:
34  * The number of bytes in a single scanline of the glyph
35  */
36 static inline unsigned int font_glyph_pitch(unsigned int width)
37 {
38 	return DIV_ROUND_UP(width, 8);
39 }
40 
41 /**
42  * font_glyph_size - Calculates the number of bytes per glyph
43  * @width: The glyph width in bits per scanline
44  * @vpitch: The number of scanlines in the glyph
45  *
46  * The number of bytes in a glyph depends on the pitch and the number
47  * of scanlines. font_glyph_size automatically calculates the pitch
48  * from the given width. The parameter @vpitch gives the number of
49  * scanlines, which is usually the glyph's height in scanlines. Fonts
50  * coming from user space can sometimes have a different vertical pitch
51  * with empty scanlines between two adjacent glyphs.
52  */
53 static inline unsigned int font_glyph_size(unsigned int width, unsigned int vpitch)
54 {
55 	return font_glyph_pitch(width) * vpitch;
56 }
57 
58 /*
59  * font_data_t and helpers
60  */
61 
62 /**
63  * font_data_t - Raw font data
64  *
65  * Values of type font_data_t store a pointer to raw font data. The format
66  * is monochrome. Each bit sets a pixel of a stored glyph. Font data does
67  * not store geometry information for the individual glyphs. Users of the
68  * font have to store glyph size, pitch and character count separately.
69  *
70  * Font data in font_data_t is not equivalent to raw u8. Each pointer stores
71  * an additional hidden header before the font data. The layout is
72  *
73  * +------+-----------------------------+
74  * | -16  |  CRC32 Checksum (optional)  |
75  * | -12  |  <Unused>                   |
76  * |  -8  |  Number of data bytes       |
77  * |  -4  |  Reference count            |
78  * +------+-----------------------------+
79  * |   0  |  Data buffer                |
80  * |  ... |                             |
81  * +------+-----------------------------+
82  *
83  * Use helpers to access font_data_t. Use font_data_buf() to get the stored data.
84  */
85 typedef const unsigned char font_data_t;
86 
87 /**
88  * font_data_buf() - Returns the font data as raw bytes
89  * @fd: The font data
90  *
91  * Returns:
92  * The raw font data. The provided buffer is read-only.
93  */
94 static inline const unsigned char *font_data_buf(font_data_t *fd)
95 {
96 	return (const unsigned char *)fd;
97 }
98 
99 font_data_t *font_data_import(const struct console_font *font, unsigned int vpitch,
100 			      u32 (*calc_csum)(u32, const void *, size_t));
101 void font_data_get(font_data_t *fd);
102 bool font_data_put(font_data_t *fd);
103 unsigned int font_data_size(font_data_t *fd);
104 bool font_data_is_equal(font_data_t *lhs, font_data_t *rhs);
105 int font_data_export(font_data_t *fd, struct console_font *font, unsigned int vpitch);
106 
107 /* font_rotate.c */
108 void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, unsigned int height,
109 			  unsigned char *out);
110 void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width, unsigned int height,
111 			   unsigned char *out);
112 void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width, unsigned int height,
113 			   unsigned char *out);
114 unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsigned int height,
115 				unsigned int charcount, unsigned int steps,
116 				unsigned char *buf, size_t *bufsize);
117 
118 /*
119  * Font description
120  */
121 
122 struct font_desc {
123     int idx;
124     const char *name;
125     unsigned int width, height;
126     unsigned int charcount;
127     font_data_t *data;
128     int pref;
129 };
130 
131 /* Find a font with a specific name */
132 
133 extern const struct font_desc *find_font(const char *name);
134 
135 /* Get the default font for a specific screen size */
136 
137 extern const struct font_desc *get_default_font(int xres, int yres,
138 						unsigned long *font_w,
139 						unsigned long *font_h);
140 
141 /* Max. length for the name of a predefined font */
142 #define MAX_FONT_NAME	32
143 
144 /*
145  * Built-in fonts
146  */
147 
148 extern const struct font_desc font_10x18;
149 extern const struct font_desc font_6x10;
150 extern const struct font_desc font_6x8;
151 extern const struct font_desc font_7x14;
152 extern const struct font_desc font_acorn_8x8;
153 extern const struct font_desc font_mini_4x6;
154 extern const struct font_desc font_pearl_8x8;
155 extern const struct font_desc font_sun_12x22;
156 extern const struct font_desc font_sun_8x16;
157 extern const struct font_desc font_ter_10x18;
158 extern const struct font_desc font_ter_16x32;
159 extern const struct font_desc font_vga_6x11;
160 extern const struct font_desc font_vga_8x16;
161 extern const struct font_desc font_vga_8x8;
162 
163 #endif /* _VIDEO_FONT_H */
164