mf_bwfont.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Uncompressed font format for storing black & white fonts. Very efficient
  2. * to decode and works well for small font sizes.
  3. */
  4. #ifndef _MF_BWFONT_H_
  5. #define _MF_BWFONT_H_
  6. #include "mf_font.h"
  7. /* Versions of the BW font format that are supported. */
  8. #define MF_BWFONT_VERSION_4_SUPPORTED 1
  9. /* Structure for a range of characters. */
  10. struct mf_bwfont_char_range_s
  11. {
  12. /* The number of the first character in this range. */
  13. uint16_t first_char;
  14. /* The total count of characters in this range. */
  15. uint16_t char_count;
  16. /* The left and top skips of the characters in this range.
  17. * This is the number of empty rows at left and at top. */
  18. uint8_t offset_x;
  19. uint8_t offset_y;
  20. /* Column height for glyphs in this range, in bytes and pixels. */
  21. uint8_t height_bytes;
  22. uint8_t height_pixels;
  23. /* Positive value if the width of all glyphs in this range is the
  24. * same, or zero if it is not. */
  25. uint8_t width;
  26. /* Lookup table for the character widths. NULL if width is specified. */
  27. uint8_t *glyph_widths;
  28. /* Lookup table for the character offsets. Multiply by height_bytes
  29. * to get the byte offset. Also allows lookup of the number of columns.
  30. * NULL if width is specified. */
  31. uint16_t *glyph_offsets;
  32. /* Table for the glyph data.
  33. * The data for each glyph is column-by-column, with N bytes per each
  34. * column. The LSB of the first byte is the top left pixel.
  35. */
  36. uint8_t *glyph_data;
  37. };
  38. /* Structure for the font */
  39. struct mf_bwfont_s
  40. {
  41. struct mf_font_s font;
  42. /* Version of the font format. */
  43. uint8_t version;
  44. /* Number of character ranges. */
  45. uint8_t char_range_count;
  46. /* Array of the character ranges */
  47. struct mf_bwfont_char_range_s *char_ranges;
  48. };
  49. #ifdef MF_BWFONT_INTERNALS
  50. /* Internal functions, don't use these directly. */
  51. MF_EXTERN uint8_t mf_bwfont_render_character(const struct mf_font_s *font,
  52. int16_t x0, int16_t y0,
  53. mf_char character,
  54. mf_pixel_callback_t callback,
  55. void *state);
  56. MF_EXTERN uint8_t mf_bwfont_character_width(const struct mf_font_s *font,
  57. mf_char character);
  58. #endif
  59. #endif