version 2.8
src/gdisp/mcufont/mf_rlefont.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 /* A compressed font format based on run length encoding and dictionary
9  * compression.
10  */
11 
12 #ifndef _MF_RLEFONT_H_
13 #define _MF_RLEFONT_H_
14 
15 #include "mf_font.h"
16 
17 /* Versions of the RLE font format that are supported. */
18 #define MF_RLEFONT_VERSION_4_SUPPORTED 1
19 
20 /* Structure for a range of characters. This implements a sparse storage of
21  * character indices, so that you can e.g. pick a 100 characters in the middle
22  * of the UTF16 range and just store them. */
23 struct mf_rlefont_char_range_s
24 {
25  /* The number of the first character in this range. */
26  uint16_t first_char;
27 
28  /* The total count of characters in this range. */
29  uint16_t char_count;
30 
31  /* Lookup table with the start indices into glyph_data. */
32  const uint16_t *glyph_offsets;
33 
34  /* The encoded glyph data for glyphs in this range. */
35  const uint8_t *glyph_data;
36 };
37 
38 /* Structure for a single encoded font. */
39 struct mf_rlefont_s
40 {
41  struct mf_font_s font;
42 
43  /* Version of the font definition used. */
44  const uint8_t version;
45 
46  /* Big array of the data for all the dictionary entries. */
47  const uint8_t *dictionary_data;
48 
49  /* Lookup table with the start indices into dictionary_data.
50  * Contains N+1 entries, so that the length of the entry can
51  * be determined by subtracting from the next offset. */
52  const uint16_t *dictionary_offsets;
53 
54  /* Number of dictionary entries using the RLE encoding.
55  * Entries starting at this index use the dictionary encoding. */
56  const uint8_t rle_entry_count;
57 
58  /* Total number of dictionary entries.
59  * Entries after this are nonexistent. */
60  const uint8_t dict_entry_count;
61 
62  /* Number of discontinuous character ranges */
63  const uint16_t char_range_count;
64 
65  /* Array of the character ranges */
66  const struct mf_rlefont_char_range_s *char_ranges;
67 };
68 
69 #ifdef MF_RLEFONT_INTERNALS
70 /* Internal functions, don't use these directly. */
71 MF_EXTERN uint8_t mf_rlefont_render_character(const struct mf_font_s *font,
72  int16_t x0, int16_t y0,
73  uint16_t character,
74  mf_pixel_callback_t callback,
75  void *state);
76 
77 MF_EXTERN uint8_t mf_rlefont_character_width(const struct mf_font_s *font,
78  uint16_t character);
79 #endif
80 
81 #endif