diff options
Diffstat (limited to 'components/gui/src/font_bmp.c')
| -rw-r--r-- | components/gui/src/font_bmp.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/components/gui/src/font_bmp.c b/components/gui/src/font_bmp.c index f6aa34a11f..1aba5c34b4 100644 --- a/components/gui/src/font_bmp.c +++ b/components/gui/src/font_bmp.c @@ -95,6 +95,7 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc const char *text, rt_ubase_t len, struct rtgui_rect *rect) { rt_uint32_t length; + struct rtgui_rect text_rect; struct rtgui_font_bitmap *bmp_font = (struct rtgui_font_bitmap *)(font->data); #ifdef RTGUI_USING_FONTHZ struct rtgui_font *hz_font; @@ -102,18 +103,21 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc RT_ASSERT(bmp_font != RT_NULL); + rtgui_font_get_metrics(rtgui_dc_get_gc(dc)->font, text, &text_rect); + rtgui_rect_move_to_align(rect, &text_rect, RTGUI_DC_TEXTALIGN(dc)); + /* parameter check */ - if (rect->y1 > rect->y2) return; + if (text_rect.y1 > text_rect.y2) return; #ifdef RTGUI_USING_FONTHZ hz_font = rtgui_font_refer("hz", font->height); - while ((rect->x1 < rect->x2) && len) + while ((text_rect.x1 < text_rect.x2) && len) { length = 0; while ((rt_uint8_t) * (text + length) >= 0x80) length ++; /* it's not a ascii character */ if (length > 0) { - if (hz_font != RT_NULL) rtgui_font_draw(hz_font, dc, text, length, rect); + if (hz_font != RT_NULL) rtgui_font_draw(hz_font, dc, text, length, &text_rect); text += length; len -= length; } @@ -123,15 +127,15 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc if (length > 0) { len -= length; - while (length-- && rect->x1 < rect->x2) + while (length-- && text_rect.x1 < text_rect.x2) { - rtgui_bitmap_font_draw_char(bmp_font, dc, *text, rect); + rtgui_bitmap_font_draw_char(bmp_font, dc, *text, &text_rect); /* move x to next character */ if (bmp_font->char_width == RT_NULL) - rect->x1 += bmp_font->width; + text_rect.x1 += bmp_font->width; else - rect->x1 += bmp_font->char_width[*text - bmp_font->first_char]; + text_rect.x1 += bmp_font->char_width[*text - bmp_font->first_char]; text ++; } } @@ -140,22 +144,22 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font *font, struct rtgui_dc if (hz_font != RT_NULL) rtgui_font_derefer(hz_font); #else - while ((rect->x1 < rect->x2) && len) + while ((text_rect.x1 < text_rect.x2) && len) { length = 0; while (((rt_uint8_t) * (text + length) < 0x80) && *(text + length)) length ++; if (length > 0) { len -= length; - while (length-- && rect->x1 < rect->x2) + while (length-- && text_rect.x1 < text_rect.x2) { - rtgui_bitmap_font_draw_char(bmp_font, dc, *text, rect); + rtgui_bitmap_font_draw_char(bmp_font, dc, *text, &text_rect); /* move x to next character */ if (bmp_font->char_width == RT_NULL) - rect->x1 += bmp_font->width; + text_rect.x1 += bmp_font->width; else - rect->x1 += bmp_font->char_width[*text - bmp_font->first_char]; + text_rect.x1 += bmp_font->char_width[*text - bmp_font->first_char]; text ++; } } |
