diff options
| author | bernard.xiong <[email protected]> | 2009-11-15 14:47:26 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2009-11-15 14:47:26 +0000 |
| commit | 2ea68440811d431d0e0ab1910d0d1b4a2c4285d7 (patch) | |
| tree | d192a61e99b302706db68c1e93795457c317f71c /rtgui/common | |
| parent | 3344963e4b343950d46217b36bdc6760f06d805f (diff) | |
add rt_memory_info function in kernel; cleanup code in dfs_posix.c; add Chinese Font(file cached) support in RTGUI;
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@166 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui/common')
| -rw-r--r-- | rtgui/common/font.c | 19 | ||||
| -rw-r--r-- | rtgui/common/font_hz_file.c | 47 | ||||
| -rw-r--r-- | rtgui/common/hz12font.c | 4 | ||||
| -rw-r--r-- | rtgui/common/hz16font.c | 28 | ||||
| -rw-r--r-- | rtgui/common/image_xpm.c | 3 |
5 files changed, 50 insertions, 51 deletions
diff --git a/rtgui/common/font.c b/rtgui/common/font.c index 65a64705cc..4979348c22 100644 --- a/rtgui/common/font.c +++ b/rtgui/common/font.c @@ -29,26 +29,41 @@ void rtgui_font_system_init() rtgui_list_init(&(_rtgui_font_list)); /* set default font to NULL */ - rtgui_default_font = RT_NULL;
+ rtgui_default_font = RT_NULL; #ifdef RTGUI_USING_FONT16 rtgui_font_system_add_font(&rtgui_font_asc16); #ifdef RTGUI_USING_FONTHZ rtgui_font_system_add_font(&rtgui_font_hz16); #endif -#endif
+#endif + +#ifdef RTGUI_USING_FONT12 rtgui_font_system_add_font(&rtgui_font_asc12); #ifdef RTGUI_USING_FONTHZ rtgui_font_system_add_font(&rtgui_font_hz12); #endif +#endif +#ifdef RTGUI_USING_FONT12 rtgui_font_set_defaut(&rtgui_font_asc12); +#elif defined(RTGUI_USING_FONT16) + rtgui_font_set_defaut(&rtgui_font_asc16); +#endif } void rtgui_font_system_add_font(struct rtgui_font* font) { rtgui_list_init(&(font->list)); rtgui_list_append(&_rtgui_font_list, &(font->list)); + + /* init font */ + if (font->engine->font_init != RT_NULL) + font->engine->font_init(font); + + /* first refer, load it */ + if (font->engine->font_load != RT_NULL) + font->engine->font_load(font); } void rtgui_font_system_remove_font(struct rtgui_font* font) diff --git a/rtgui/common/font_hz_file.c b/rtgui/common/font_hz_file.c index ac4372e50b..6c2967317d 100644 --- a/rtgui/common/font_hz_file.c +++ b/rtgui/common/font_hz_file.c @@ -7,30 +7,7 @@ #include <rtgui/rtgui_system.h> #include <dfs_posix.h> -#define HZ_DATA_SIZE (2 * 16) #define HZ_CACHE_MAX 64 -SPLAY_HEAD(cache_tree, hz_cache); -struct hz_cache -{ - SPLAY_ENTRY(hz_cache) hz_node; - - rt_uint16_t hz_id; -}; - -struct rtgui_hz_file_font -{ - struct cache_tree cache_root; - rt_uint16_t cache_size; - - /* font size */ - rt_uint16_t font_size; - - /* file descriptor */ - int fd; - - /* font file name */ - const char* font_fn; -}; static int _font_cache_compare(struct hz_cache* node1, struct hz_cache* node2); @@ -70,24 +47,25 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t } /* can not find it, load to cache */ - cache = (struct hz_cache*) rtgui_malloc(sizeof(struct hz_cache) + HZ_DATA_SIZE); + cache = (struct hz_cache*) rtgui_malloc(sizeof(struct hz_cache) + font->font_data_size); if (cache == RT_NULL) return RT_NULL; /* no memory yet */ cache->hz_id = hz_id; - seek = 94 * ((hz_id & 0xff - 0xA0) - 1) + ((hz_id >> 8) - 0xA0); - seek = seek * HZ_DATA_SIZE; + seek = 94 * (((hz_id & 0xff) - 0xA0) - 1) + ((hz_id >> 8) - 0xA0) - 1; + seek *= font->font_data_size; /* read hz font data */ if ((lseek(font->fd, seek, SEEK_SET) < 0) || - read(font->fd, (char*)(cache + 1), HZ_DATA_SIZE) != - HZ_DATA_SIZE) + read(font->fd, (char*)(cache + 1), font->font_data_size) != + font->font_data_size) { rtgui_free(cache); return RT_NULL; } /* insert to cache */ - SPLAY_INSERT(cache_tree, &(font->cache_root), cache); + SPLAY_INSERT(cache_tree, &(font->cache_root), cache);
+ font->cache_size ++; if (font->cache_size > HZ_CACHE_MAX) { @@ -97,7 +75,8 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t while (SPLAY_LEFT(left, hz_node) != RT_NULL) left = SPLAY_LEFT(left, hz_node); /* remove the left node */ - SPLAY_REMOVE(cache_tree, &(font->cache_root), left); + SPLAY_REMOVE(cache_tree, &(font->cache_root), left);
+ font->cache_size --; } return (rt_uint8_t*)(cache + 1); @@ -105,7 +84,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t static void rtgui_hz_file_font_load(struct rtgui_font* font) { - struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font; + struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data; RT_ASSERT(hz_file_font != RT_NULL); hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0); @@ -115,7 +94,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d { rt_base_t h; rt_uint8_t* str; - struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font; + struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data; RT_ASSERT(hz_file_font != RT_NULL); /* drawing height */ @@ -130,7 +109,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d register rt_base_t i, j, k; /* get font pixel data */ - font_ptr = _font_cache_get(hz_file_font, *(rt_uint16_t*)str); + font_ptr = _font_cache_get(hz_file_font, *str | (*(str+1) << 8)); /* draw word */ for (i=0; i < h; i ++) @@ -155,7 +134,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) { - struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font; + struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data; RT_ASSERT(hz_file_font != RT_NULL); /* set metrics rect */ diff --git a/rtgui/common/hz12font.c b/rtgui/common/hz12font.c index 0c2e697505..e51ed16e47 100644 --- a/rtgui/common/hz12font.c +++ b/rtgui/common/hz12font.c @@ -1,5 +1,6 @@ #include <rtgui/font.h> - +
+#ifdef RTGUI_USING_FONT12 #ifndef RTGUI_USING_HZ_FILE const unsigned char hz12_font[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -12311,3 +12312,4 @@ struct rtgui_font rtgui_font_hz12 = (void*)&hz12, /* font private data */ }; #endif +#endif
diff --git a/rtgui/common/hz16font.c b/rtgui/common/hz16font.c index 01adb78534..8f316f13fd 100644 --- a/rtgui/common/hz16font.c +++ b/rtgui/common/hz16font.c @@ -1,5 +1,6 @@ -#include <rtgui/font.h> +#include <rtgui/font.h>
+#ifdef RTGUI_USING_FONT16 #ifndef RTGUI_USING_HZ_FILE const unsigned char hz16_font[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -16752,20 +16753,21 @@ const struct rtgui_font rtgui_font_hz16 = #else struct rtgui_hz_file_font hz16 = { - {RT_NULL}, /* cache root */ - 0, /* cache_size */ - 16, /* font_size */ - -1, /* fd */ - "/resource/hz16" /* font_fn */ + {RT_NULL}, /* cache root */ + 0, /* cache size */ + 16, /* font size */
+ 32, /* font data size */ + -1, /* fd */ + "/resource/hzk16.fnt" /* font_fn */ }; -extern struct rtgui_hz_file_font_engine hz_file_font_engine; -const struct rtgui_font rtgui_font_hz16 = +struct rtgui_font rtgui_font_hz16 = { - "hz", /* family */ - 16, /* height */ - 1, /* refer count */ - &hz_file_font_engine,/* font engine */ - (void*)&hz16, /* font private data */ + "hz", /* family */ + 16, /* height */ + 1, /* refer count */ + &rtgui_hz_file_font_engine,/* font engine */ + (void*)&hz16, /* font private data */ }; #endif +#endif
diff --git a/rtgui/common/image_xpm.c b/rtgui/common/image_xpm.c index bb7ce057f5..4b171fd674 100644 --- a/rtgui/common/image_xpm.c +++ b/rtgui/common/image_xpm.c @@ -565,7 +565,8 @@ color_none: } } - free_colorhash(colors_table); + free_colorhash(colors_table);
+ rtgui_filerw_close(file); return RT_TRUE; } |
