| 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 | * Returns: the number of bytes per glyph
|
| 54 |
|
| 55 | static inline unsigned int font_glyph_size(unsigned int width, unsigned int vpitch)
|
| 56 | {
|
| 57 | return font_glyph_pitch(width) * vpitch;
|
| 58 | }
|
| 59 |
|
| 60 | |
| 61 | * font_data_t and helpers
|
| 62 |
|
| 63 |
|
| 64 | |
| 65 | * typedef font_data_t - Raw font data
|
| 66 | *
|
| 67 | * Values of type font_data_t store a pointer to raw font data. The format
|
| 68 | * is monochrome. Each bit sets a pixel of a stored glyph. Font data does
|
| 69 | * not store geometry information for the individual glyphs. Users of the
|
| 70 | * font have to store glyph size, pitch and character count separately.
|
| 71 | *
|
| 72 | * Font data in font_data_t is not equivalent to raw u8. Each pointer stores
|
| 73 | * an additional hidden header before the font data. The layout is
|
| 74 | *
|
| 75 | * +------+-----------------------------+
|
| 76 | * | -16 | CRC32 Checksum (optional) |
|
| 77 | * | -12 | <Unused> |
|
| 78 | * | -8 | Number of data bytes |
|
| 79 | * | -4 | Reference count |
|
| 80 | * +------+-----------------------------+
|
| 81 | * | 0 | Data buffer |
|
| 82 | * | ... | |
|
| 83 | * +------+-----------------------------+
|
| 84 | *
|
| 85 | * Use helpers to access font_data_t. Use font_data_buf() to get the stored data.
|
| 86 |
|
| 87 | typedef const unsigned char font_data_t;
|
| 88 |
|
| 89 | |
| 90 | * font_data_buf() - Returns the font data as raw bytes
|
| 91 | * @fd: The font data
|
| 92 | *
|
| 93 | * Returns:
|
| 94 | * The raw font data. The provided buffer is read-only.
|
| 95 |
|
| 96 | static inline const unsigned char *font_data_buf(font_data_t *fd)
|
| 97 | {
|
| 98 | return (const unsigned char *)fd;
|
| 99 | }
|
| 100 |
|
| 101 | font_data_t *font_data_import(const struct console_font *font, unsigned int vpitch,
|
| 102 | u32 (*calc_csum)(u32, const void *, size_t));
|
| 103 | void font_data_get(font_data_t *fd);
|
| 104 | bool font_data_put(font_data_t *fd);
|
| 105 | unsigned int font_data_size(font_data_t *fd);
|
| 106 | const unsigned char *font_data_glyph_buf(font_data_t *fd,
|
| 107 | unsigned int width, unsigned int vpitch,
|
| 108 | unsigned int c);
|
| 109 | bool font_data_is_equal(font_data_t *lhs, font_data_t *rhs);
|
| 110 | int font_data_export(font_data_t *fd, struct console_font *font, unsigned int vpitch);
|
| 111 |
|
| 112 |
|
| 113 | void font_glyph_rotate_90(const unsigned char *glyph, unsigned int width, unsigned int height,
|
| 114 | unsigned char *out);
|
| 115 | void font_glyph_rotate_180(const unsigned char *glyph, unsigned int width, unsigned int height,
|
| 116 | unsigned char *out);
|
| 117 | void font_glyph_rotate_270(const unsigned char *glyph, unsigned int width, unsigned int height,
|
| 118 | unsigned char *out);
|
| 119 | unsigned char *font_data_rotate(font_data_t *fd, unsigned int width, unsigned int height,
|
| 120 | unsigned int charcount, unsigned int steps,
|
| 121 | unsigned char *buf, size_t *bufsize);
|
| 122 |
|
| 123 | |
| 124 | * Font description
|
| 125 |
|
| 126 |
|
| 127 | struct font_desc {
|
| 128 | int idx;
|
| 129 | const char *name;
|
| 130 | unsigned int width, height;
|
| 131 | unsigned int charcount;
|
| 132 | font_data_t *data;
|
| 133 | int pref;
|
| 134 | };
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 | extern const struct font_desc *find_font(const char *name);
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 | extern const struct font_desc *get_default_font(int xres, int yres,
|
| 143 | unsigned long *font_w,
|
| 144 | unsigned long *font_h);
|
| 145 |
|
| 146 |
|
| 147 | #define MAX_FONT_NAME 32
|
| 148 |
|
| 149 | |
| 150 | * Built-in fonts
|
| 151 |
|
| 152 |
|
| 153 | extern const struct font_desc font_10x18;
|
| 154 | extern const struct font_desc font_6x10;
|
| 155 | extern const struct font_desc font_6x8;
|
| 156 | extern const struct font_desc font_7x14;
|
| 157 | extern const struct font_desc font_acorn_8x8;
|
| 158 | extern const struct font_desc font_mini_4x6;
|
| 159 | extern const struct font_desc font_pearl_8x8;
|
| 160 | extern const struct font_desc font_sun_12x22;
|
| 161 | extern const struct font_desc font_sun_8x16;
|
| 162 | extern const struct font_desc font_ter_10x18;
|
| 163 | extern const struct font_desc font_ter_16x32;
|
| 164 | extern const struct font_desc font_vga_6x11;
|
| 165 | extern const struct font_desc font_vga_8x16;
|
| 166 | extern const struct font_desc font_vga_8x8;
|
| 167 |
|
| 168 | #endif
|