version 2.8
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.org/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  uint16_t first_char;
25 
26  /* The total count of characters in this range. */
27  uint16_t 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  uint8_t offset_x;
32  uint8_t offset_y;
33 
34  /* Column height for glyphs in this range, in bytes and pixels. */
35  uint8_t height_bytes;
36  uint8_t 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  uint8_t width;
41 
42  /* Lookup table for the character widths. NULL if width is specified. */
43  const uint8_t *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 uint16_t *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 uint8_t *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 uint8_t version;
64 
65  /* Number of character ranges. */
66  const uint16_t 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 uint8_t mf_bwfont_render_character(const struct mf_font_s *font,
75  int16_t x0, int16_t y0,
76  uint16_t character,
77  mf_pixel_callback_t callback,
78  void *state);
79 
80 MF_EXTERN uint8_t mf_bwfont_character_width(const struct mf_font_s *font,
81  uint16_t character);
82 #endif
83 
84 #endif