font.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. extern rtgui_font_t rtgui_font_asc12,rtgui_font_asc16,font_dotum;
  19. struct rtgui_font_engine
  20. {
  21. /* font engine function */
  22. void (*font_init)(rtgui_font_t* font);
  23. void (*font_load)(rtgui_font_t* font);
  24. void (*font_draw_text)(rtgui_font_t* font, rtgui_dc_t *dc, const char* text, rt_uint32_t len, rtgui_rect_t* rect);
  25. void (*font_get_metrics)(rtgui_font_t* font, const char* text, rtgui_rect_t* rect);
  26. };
  27. /*
  28. * bitmap font engine
  29. */
  30. /* bitmap font private data */
  31. struct rtgui_font_bitmap
  32. {
  33. /* bitmap data */
  34. const rt_uint8_t* bmp;
  35. const rt_uint8_t* char_width; /* each character width, NULL for fixed font */
  36. const rt_uint32_t* offset; /* offset for each character */
  37. rt_uint16_t width;
  38. rt_uint16_t height;
  39. rt_uint8_t first_char;
  40. rt_uint8_t last_char;
  41. };
  42. extern const struct rtgui_font_engine bmp_font_engine;
  43. #include <rtgui/tree.h>
  44. SPLAY_HEAD(cache_tree, hz_cache);
  45. struct hz_cache
  46. {
  47. SPLAY_ENTRY(hz_cache) hz_node;
  48. rt_uint16_t hz_id;
  49. };
  50. struct rtgui_hz_file_font
  51. {
  52. struct cache_tree cache_root;
  53. rt_uint16_t cache_size;
  54. /* font size */
  55. rt_uint16_t font_size;
  56. rt_uint16_t font_data_size;
  57. /* file descriptor */
  58. int fd;
  59. /* font file name */
  60. const char* font_fn;
  61. };
  62. extern struct rtgui_font_engine rtgui_hz_file_font_engine;
  63. struct rtgui_font
  64. {
  65. /* font name */
  66. char* family;
  67. /* font height */
  68. rt_uint16_t height;
  69. /* refer count */
  70. rt_uint32_t refer_count;
  71. /* font engine */
  72. const struct rtgui_font_engine* engine;
  73. /* font private data */
  74. void* data;
  75. /* the font list */
  76. rtgui_list_t list;
  77. };
  78. typedef struct rtgui_font rtgui_font_t;
  79. void rtgui_font_system_init(void);
  80. void rtgui_font_system_add_font(rtgui_font_t* font);
  81. void rtgui_font_system_remove_font(rtgui_font_t* font);
  82. rtgui_font_t* rtgui_font_default(void);
  83. void rtgui_font_set_defaut(rtgui_font_t* font);
  84. rtgui_font_t* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height);
  85. void rtgui_font_derefer(rtgui_font_t* font);
  86. /* draw a text */
  87. void rtgui_font_draw(rtgui_font_t* font, rtgui_dc_t *dc, const char* text, rt_uint32_t len, rtgui_rect_t* rect);
  88. int rtgui_font_get_string_width(rtgui_font_t* font, const char* text);//取得字符串的宽度
  89. int rtgui_font_get_font_width(rtgui_font_t* font); //取得字体的宽度
  90. int rtgui_font_get_font_height(rtgui_font_t* font);//取得字体的高度
  91. void rtgui_font_get_string_rect(rtgui_font_t* font, const char* text, rtgui_rect_t* rect);//取得字符串的矩形区域
  92. void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
  93. #endif