2010-02-04 22:46:09 +08:00
|
|
|
|
2009-11-11 07:49:33 +08:00
|
|
|
#include <rtgui/dc.h>
|
|
|
|
#include <rtgui/font.h>
|
|
|
|
|
2010-02-04 22:46:09 +08:00
|
|
|
#ifdef RTGUI_USING_HZ_BMP
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect);
|
|
|
|
static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
|
2010-09-24 12:31:20 +08:00
|
|
|
const struct rtgui_font_engine hz_bmp_font_engine =
|
2009-11-11 07:49:33 +08:00
|
|
|
{
|
|
|
|
RT_NULL,
|
|
|
|
RT_NULL,
|
|
|
|
rtgui_hz_bitmap_font_draw_text,
|
|
|
|
rtgui_hz_bitmap_font_get_metrics
|
|
|
|
};
|
|
|
|
|
2010-09-27 23:36:03 +08:00
|
|
|
static void _rtgui_hz_bitmap_font_draw_text(struct rtgui_font_bitmap* bmp_font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
|
2009-11-11 07:49:33 +08:00
|
|
|
{
|
|
|
|
rt_uint8_t* str;
|
2011-01-20 17:59:45 +08:00
|
|
|
rtgui_color_t bc;
|
|
|
|
rt_uint16_t style;
|
2011-08-17 16:23:59 +08:00
|
|
|
register rt_base_t h, word_bytes, font_bytes;
|
2009-11-11 07:49:33 +08:00
|
|
|
|
|
|
|
RT_ASSERT(bmp_font != RT_NULL);
|
|
|
|
|
2011-01-20 17:59:45 +08:00
|
|
|
/* get text style */
|
|
|
|
style = rtgui_dc_get_gc(dc)->textstyle;
|
|
|
|
bc = rtgui_dc_get_gc(dc)->background;
|
|
|
|
|
2009-11-11 07:49:33 +08:00
|
|
|
/* drawing height */
|
|
|
|
h = (bmp_font->height + rect->y1 > rect->y2)? rect->y2 - rect->y1 : bmp_font->height;
|
2010-05-15 22:36:02 +08:00
|
|
|
word_bytes = (bmp_font->width + 7)/8;
|
2011-08-17 16:23:59 +08:00
|
|
|
font_bytes = word_bytes * bmp_font->height;
|
2009-11-11 07:49:33 +08:00
|
|
|
|
|
|
|
str = (rt_uint8_t*)text;
|
|
|
|
|
|
|
|
while (len > 0 && rect->x1 < rect->x2)
|
|
|
|
{
|
|
|
|
const rt_uint8_t* font_ptr;
|
|
|
|
rt_ubase_t sect, index;
|
|
|
|
register rt_base_t i, j, k;
|
|
|
|
|
|
|
|
/* calculate section and index */
|
|
|
|
sect = *str - 0xA0;
|
|
|
|
index = *(str+1) - 0xA0;
|
|
|
|
|
|
|
|
/* get font pixel data */
|
2011-08-17 16:23:59 +08:00
|
|
|
font_ptr = bmp_font->bmp + (94 * (sect - 1) + (index - 1)) * font_bytes;
|
2009-11-11 07:49:33 +08:00
|
|
|
/* draw word */
|
|
|
|
for (i=0; i < h; i ++)
|
|
|
|
{
|
2010-05-15 22:36:02 +08:00
|
|
|
for (j=0; j < word_bytes; j++)
|
2009-11-11 07:49:33 +08:00
|
|
|
for (k=0; k < 8; k++)
|
|
|
|
{
|
2011-08-17 16:23:59 +08:00
|
|
|
if ( ((font_ptr[i*word_bytes + j] >> (7-k)) & 0x01) != 0 &&
|
2009-11-11 07:49:33 +08:00
|
|
|
(rect->x1 + 8 * j + k < rect->x2))
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_point(dc, rect->x1 + 8*j + k, rect->y1 + i);
|
|
|
|
}
|
2011-01-20 17:59:45 +08:00
|
|
|
else if (style & RTGUI_TEXTSTYLE_DRAW_BACKGROUND)
|
|
|
|
{
|
|
|
|
rtgui_dc_draw_color_point(dc, rect->x1 + 8*j + k, rect->y1 + i, bc);
|
|
|
|
}
|
2009-11-11 07:49:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move x to next character */
|
|
|
|
rect->x1 += bmp_font->width;
|
|
|
|
str += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 21:41:34 +08:00
|
|
|
static void rtgui_hz_bitmap_font_draw_text (struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t length, struct rtgui_rect* rect)
|
|
|
|
{
|
|
|
|
rt_uint32_t len;
|
|
|
|
struct rtgui_font *efont;
|
2010-09-27 23:36:03 +08:00
|
|
|
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);
|
2011-01-23 21:41:34 +08:00
|
|
|
|
|
|
|
RT_ASSERT(dc != RT_NULL);
|
|
|
|
|
|
|
|
/* get English font */
|
|
|
|
efont = rtgui_font_refer("asc", bmp_font->height);
|
|
|
|
if (efont == RT_NULL) efont = rtgui_font_default(); /* use system default font */
|
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len)) len ++;
|
|
|
|
/* draw text with English font */
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
rtgui_font_draw(efont, dc, text, len, rect);
|
|
|
|
|
|
|
|
text += len;
|
|
|
|
length -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
while (((rt_uint8_t)*(text + len)) >= 0x80) len ++;
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
_rtgui_hz_bitmap_font_draw_text(bmp_font, dc, text, len, rect);
|
|
|
|
|
|
|
|
text += len;
|
|
|
|
length -= len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rtgui_font_derefer(efont);
|
2010-09-27 23:36:03 +08:00
|
|
|
}
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
|
2009-11-11 07:49:33 +08:00
|
|
|
{
|
|
|
|
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);
|
|
|
|
|
|
|
|
RT_ASSERT(bmp_font != RT_NULL);
|
|
|
|
|
|
|
|
/* set metrics rect */
|
|
|
|
rect->x1 = rect->y1 = 0;
|
2010-09-27 23:36:03 +08:00
|
|
|
/* Chinese font is always fixed font */
|
2009-11-11 07:49:33 +08:00
|
|
|
rect->x2 = (rt_int16_t)(bmp_font->width * rt_strlen((const char*)text));
|
|
|
|
rect->y2 = bmp_font->height;
|
|
|
|
}
|
2010-02-04 22:46:09 +08:00
|
|
|
|
|
|
|
#endif
|