psf.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-02-25 GuEe-GUI the first version
  9. */
  10. #ifndef __PSF_H__
  11. #define __PSF_H__
  12. #include <rtthread.h>
  13. #define PSF1_MAGIC0 0x36
  14. #define PSF1_MAGIC1 0x04
  15. #define PSF1_MODE512 0x01
  16. #define PSF1_MODEHASTAB 0x02
  17. #define PSF1_MODEHASSEQ 0x04
  18. #define PSF1_MAXMODE 0x05
  19. #define PSF1_SEPARATOR 0xffff
  20. #define PSF1_STARTSEQ 0xfffe
  21. struct psf1_header
  22. {
  23. rt_uint8_t magic[2]; /* Magic number */
  24. rt_uint8_t mode; /* PSF font mode */
  25. rt_uint8_t charsize; /* Character size */
  26. };
  27. #define PSF2_MAGIC0 0x72
  28. #define PSF2_MAGIC1 0xb5
  29. #define PSF2_MAGIC2 0x4a
  30. #define PSF2_MAGIC3 0x86
  31. /* bits used in flags */
  32. #define PSF2_HAS_UNICODE_TABLE 0x01
  33. /* max version recognized so far */
  34. #define PSF2_MAXVERSION 0
  35. /* UTF8 separators */
  36. #define PSF2_SEPARATOR 0xff
  37. #define PSF2_STARTSEQ 0xfe
  38. struct psf2_header
  39. {
  40. rt_uint8_t magic[4];
  41. rt_uint32_t version;
  42. rt_uint32_t headersize; /* offset of bitmaps in file */
  43. rt_uint32_t flags;
  44. rt_uint32_t length; /* number of glyphs */
  45. rt_uint32_t charsize; /* number of bytes for each character, charsize = height * ((width + 7) / 8) */
  46. rt_uint32_t height, width; /* max dimensions of glyphs */
  47. };
  48. enum psf_type
  49. {
  50. PSF_TYPE_1,
  51. PSF_TYPE_2,
  52. PSF_TYPE_UNKNOW,
  53. };
  54. struct psf_font
  55. {
  56. union
  57. {
  58. const rt_uint8_t *raw_data;
  59. struct psf1_header *header1;
  60. struct psf2_header *header2;
  61. };
  62. const rt_uint8_t *font_map;
  63. const rt_uint8_t *font_data;
  64. enum psf_type type;
  65. rt_uint32_t count; /* fonts count */
  66. rt_uint32_t size;
  67. rt_uint32_t height;
  68. rt_uint32_t width;
  69. rt_uint32_t glyph; /* height * width */
  70. };
  71. rt_err_t psf_initialize(const void *psf_data, struct psf_font *out_psf);
  72. rt_err_t psf_parse(struct psf_font *psf, const rt_uint8_t *font_data,
  73. rt_uint8_t *tmpglyph, rt_uint32_t color_size,
  74. rt_uint32_t foreground, rt_uint32_t background);
  75. #endif /* __PSF_H__ */