µGFX  2.9
version 2.9
src/gdisp/mcufont/mf_bwfont.h
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /* Uncompressed font format for storing black & white fonts. Very efficient
9  * to decode and works well for small font sizes.
10  */
11 
12 #ifndef _MF_BWFONT_H_
13 #define _MF_BWFONT_H_
14 
15 #include "mf_font.h"
16 
17 /* Versions of the BW font format that are supported. */
18 #define MF_BWFONT_VERSION_4_SUPPORTED 1
19 
20 /* Structure for a range of characters. */
21 struct mf_bwfont_char_range_s
22 {
23  /* The number of the first character in this range. */
24  gU16 first_char;
25 
26  /* The total count of characters in this range. */
27  gU16 char_count;
28 
29  /* The left and top skips of the characters in this range.
30  * This is the number of empty rows at left and at top. */
31  gU8 offset_x;
32  gU8 offset_y;
33 
34  /* Column height for glyphs in this range, in bytes and pixels. */
35  gU8 height_bytes;
36  gU8 height_pixels;
37 
38  /* Positive value if the width of all glyphs in this range is the
39  * same, or zero if it is not. */
40  gU8 width;
41 
42  /* Lookup table for the character widths. NULL if width is specified. */
43  const gU8 *glyph_widths;
44 
45  /* Lookup table for the character offsets. Multiply by height_bytes
46  * to get the byte offset. Also allows lookup of the number of columns.
47  * NULL if width is specified. */
48  const gU16 *glyph_offsets;
49 
50  /* Table for the glyph data.
51  * The data for each glyph is column-by-column, with N bytes per each
52  * column. The LSB of the first byte is the top left pixel.
53  */
54  const gU8 *glyph_data;
55 };
56 
57 /* Structure for the font */
58 struct mf_bwfont_s
59 {
60  struct mf_font_s font;
61 
62  /* Version of the font format. */
63  const gU8 version;
64 
65  /* Number of character ranges. */
66  const gU16 char_range_count;
67 
68  /* Array of the character ranges */
69  const struct mf_bwfont_char_range_s *char_ranges;
70 };
71 
72 #ifdef MF_BWFONT_INTERNALS
73 /* Internal functions, don't use these directly. */
74 MF_EXTERN gU8 mf_bwfont_render_character(const struct mf_font_s *font,
75  gI16 x0, gI16 y0,
76  gU16 character,
77  mf_pixel_callback_t callback,
78  void *state);
79 
80 MF_EXTERN gU8 mf_bwfont_character_width(const struct mf_font_s *font,
81  gU16 character);
82 #endif
83 
84 #endif