mf_rlefont.h 2.6 KB

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