font.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * File : font.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #ifndef __RTGUI_FONT_H__
  15. #define __RTGUI_FONT_H__
  16. #include <rtgui/rtgui.h>
  17. #include <rtgui/list.h>
  18. struct rtgui_font;
  19. struct rtgui_dc;
  20. struct rtgui_rect;
  21. struct rtgui_font_engine
  22. {
  23. /* font engine function */
  24. void (*font_init)(struct rtgui_font* font);
  25. void (*font_load)(struct rtgui_font* font);
  26. void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const char* text,
  27. rt_ubase_t len, struct rtgui_rect* rect);
  28. void (*font_get_metrics)(struct rtgui_font* font, const char* text, struct rtgui_rect* rect);
  29. };
  30. /*
  31. * bitmap font engine
  32. */
  33. struct rtgui_font_bitmap
  34. {
  35. const rt_uint8_t* bmp; /* bitmap font data */
  36. const rt_uint8_t* char_width; /* each character width, NULL for fixed font */
  37. const rt_uint32_t* offset; /* offset for each character */
  38. rt_uint16_t width; /* font width */
  39. rt_uint16_t height; /* font height */
  40. rt_uint8_t first_char;
  41. rt_uint8_t last_char;
  42. };
  43. extern const struct rtgui_font_engine bmp_font_engine;
  44. #include <rtgui/tree.h>
  45. SPLAY_HEAD(cache_tree, hz_cache);
  46. struct hz_cache
  47. {
  48. SPLAY_ENTRY(hz_cache) hz_node;
  49. rt_uint16_t hz_id;
  50. };
  51. struct rtgui_hz_file_font
  52. {
  53. struct cache_tree cache_root;
  54. rt_uint16_t cache_size;
  55. /* font size */
  56. rt_uint16_t font_size;
  57. rt_uint16_t font_data_size;
  58. /* file descriptor */
  59. int fd;
  60. /* font file name */
  61. const char* font_fn;
  62. };
  63. extern const struct rtgui_font_engine rtgui_hz_file_font_engine;
  64. struct rtgui_font
  65. {
  66. /* font name */
  67. char* family;
  68. /* font height */
  69. rt_uint16_t height;
  70. /* refer count */
  71. rt_uint32_t refer_count;
  72. /* font engine */
  73. const struct rtgui_font_engine* engine;
  74. /* font private data */
  75. void* data;
  76. /* the font list */
  77. rtgui_list_t list;
  78. };
  79. typedef struct rtgui_font rtgui_font_t;
  80. void rtgui_font_system_init(void);
  81. void rtgui_font_system_add_font(struct rtgui_font* font);
  82. void rtgui_font_system_remove_font(struct rtgui_font* font);
  83. struct rtgui_font* rtgui_font_default(void);
  84. void rtgui_font_set_defaut(struct rtgui_font* font);
  85. struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height);
  86. void rtgui_font_derefer(struct rtgui_font* font);
  87. /* draw a text */
  88. void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
  89. int rtgui_font_get_string_width(struct rtgui_font* font, const char* text);
  90. void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, struct rtgui_rect* rect);
  91. #endif