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