add none-fixed font support.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@961 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com
2010-09-26 14:30:42 +00:00
parent 03072ba689
commit 74a97349d2
8 changed files with 141 additions and 86 deletions

View File

@@ -156,75 +156,3 @@ void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rec
rt_memset(rect, 0, sizeof(rtgui_rect_t));
}
}
static void rtgui_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_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect);
struct rtgui_font_engine bmp_font_engine =
{
RT_NULL,
RT_NULL,
rtgui_bitmap_font_draw_text,
rtgui_bitmap_font_get_metrics
};
void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap* font, struct rtgui_dc* dc, const char ch,
rtgui_rect_t* rect)
{
const rt_uint8_t* font_ptr;
rt_uint16_t x, y, h;
register rt_base_t i, j, k, word_bytes;
/* check first and last char */
if (ch < font->first_char || ch > font->last_char) return;
x = rect->x1;
y = rect->y1;
word_bytes = (((font->width - 1) / 8) + 1);
font_ptr = font->bmp + (ch - font->first_char) * word_bytes * font->height;
h = (font->height + y > rect->y2) ? rect->y2 - rect->y1 : font->height;
for (i = 0; i < h; i++)
{
for (j = 0; j < word_bytes; j++)
{
for (k = 0; k < 8; k++)
{
if (((font_ptr[i * word_bytes + j] >> (7 - k)) & 0x01) != 0)
{
/* draw a pixel */
rtgui_dc_draw_point(dc, k + 8 * j + x, i + y);
}
}
}
}
}
static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect)
{
struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data);
RT_ASSERT(bmp_font != RT_NULL);
while (len-- && rect->x1 < rect->x2)
{
rtgui_bitmap_font_draw_char(bmp_font, dc, *text, rect);
/* move x to next character */
rect->x1 += bmp_font->width;
text ++;
}
}
static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect)
{
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;
rect->x2 = bmp_font->width * (rt_int16_t)rt_strlen((const char*)text);
rect->y2 = bmp_font->height;
}