mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-12 02:19:10 +08:00
gui 引擎 font_freetype.c 代码功能优化;
This commit is contained in:
parent
fd234eafdc
commit
2c145743cb
@ -393,7 +393,7 @@ static void _get_metrics(struct rtgui_ttf_font *ttf_font, const rt_uint16_t *tex
|
|||||||
static void _draw_bitmap(struct rtgui_dc *dc,
|
static void _draw_bitmap(struct rtgui_dc *dc,
|
||||||
FTC_SBit bitmap,
|
FTC_SBit bitmap,
|
||||||
rt_int16_t ox, rt_int16_t btm_y,
|
rt_int16_t ox, rt_int16_t btm_y,
|
||||||
rt_uint8_t a, rt_uint8_t r, rt_uint8_t g, rt_uint8_t b)
|
rtgui_color_t fgc, rt_uint16_t right, rt_uint16_t bottom)
|
||||||
{
|
{
|
||||||
rt_int16_t x_start, y_start;
|
rt_int16_t x_start, y_start;
|
||||||
struct rtgui_blit_info info = { 0 };
|
struct rtgui_blit_info info = { 0 };
|
||||||
@ -403,10 +403,12 @@ static void _draw_bitmap(struct rtgui_dc *dc,
|
|||||||
x_start = ox + bitmap->left;
|
x_start = ox + bitmap->left;
|
||||||
y_start = btm_y - bitmap->top;
|
y_start = btm_y - bitmap->top;
|
||||||
|
|
||||||
info.a = a;
|
PINFO(" draw bitmap (x, y) -> (%d, %d)\n", x_start, y_start);
|
||||||
info.r = r;
|
|
||||||
info.g = g;
|
info.a = RTGUI_RGB_A(fgc);
|
||||||
info.b = b;
|
info.r = RTGUI_RGB_R(fgc);
|
||||||
|
info.g = RTGUI_RGB_G(fgc);
|
||||||
|
info.b = RTGUI_RGB_B(fgc);
|
||||||
|
|
||||||
if (dc->type == RTGUI_DC_HW)
|
if (dc->type == RTGUI_DC_HW)
|
||||||
{
|
{
|
||||||
@ -444,18 +446,22 @@ static void _draw_bitmap(struct rtgui_dc *dc,
|
|||||||
}
|
}
|
||||||
else if (dc->type == RTGUI_DC_BUFFER)
|
else if (dc->type == RTGUI_DC_BUFFER)
|
||||||
{
|
{
|
||||||
|
int max_right, max_bottom;
|
||||||
|
|
||||||
dest_buf = (struct rtgui_dc_buffer*)dc;
|
dest_buf = (struct rtgui_dc_buffer*)dc;
|
||||||
|
max_right = right > dest_buf->width ? dest_buf->width : right;
|
||||||
|
max_bottom = bottom > dest_buf->height ? dest_buf->height : bottom;
|
||||||
|
|
||||||
if (x_start + bitmap->width < 0 || y_start + bitmap->height < 0
|
if (x_start + bitmap->width < 0 || y_start + bitmap->height < 0
|
||||||
|| x_start > dest_buf->width || y_start > dest_buf->height)
|
|| x_start > max_right || y_start > max_bottom)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* blit source */
|
/* blit source */
|
||||||
info.src = (rt_uint8_t *)bitmap->buffer;
|
info.src = (rt_uint8_t *)bitmap->buffer;
|
||||||
info.src = info.src + (y_start > 0 ? 0 : -y_start) * bitmap->width + (x_start > 0 ? 0 : -x_start);
|
info.src = info.src + (y_start > 0 ? 0 : -y_start) * bitmap->width + (x_start > 0 ? 0 : -x_start);
|
||||||
info.src_fmt = RTGRAPHIC_PIXEL_FORMAT_ALPHA;
|
info.src_fmt = RTGRAPHIC_PIXEL_FORMAT_ALPHA;
|
||||||
info.src_w = bitmap->width - (x_start > 0 ? 0 : -x_start) - (x_start + bitmap->width < dest_buf->width ? 0 : x_start + bitmap->width - dest_buf->width);
|
info.src_w = bitmap->width - (x_start > 0 ? 0 : -x_start) - (x_start + bitmap->width < max_right ? 0 : x_start + bitmap->width - max_right);
|
||||||
info.src_h = bitmap->height - (y_start > 0 ? 0 : -y_start) - (y_start + bitmap->height < dest_buf->height ? 0 : y_start + bitmap->height - dest_buf->height);
|
info.src_h = bitmap->height - (y_start > 0 ? 0 : -y_start) - (y_start + bitmap->height < max_bottom ? 0 : y_start + bitmap->height - max_bottom);
|
||||||
info.src_pitch = bitmap->width;
|
info.src_pitch = bitmap->width;
|
||||||
info.src_skip = info.src_pitch - info.src_w;
|
info.src_skip = info.src_pitch - info.src_w;
|
||||||
|
|
||||||
@ -473,7 +479,13 @@ static void _draw_bitmap(struct rtgui_dc *dc,
|
|||||||
{
|
{
|
||||||
struct rtgui_rect text_rect;
|
struct rtgui_rect text_rect;
|
||||||
struct rtgui_point dc_point = { 0, 0 };
|
struct rtgui_point dc_point = { 0, 0 };
|
||||||
struct rtgui_dc *text_dc = rtgui_dc_buffer_create_pixformat(RTGRAPHIC_PIXEL_FORMAT_ARGB888, bitmap->width, bitmap->height);
|
struct rtgui_dc *text_dc;
|
||||||
|
|
||||||
|
if (x_start + bitmap->width < 0 || y_start + bitmap->height < 0
|
||||||
|
|| x_start > right || y_start > bottom)
|
||||||
|
return;
|
||||||
|
|
||||||
|
text_dc = rtgui_dc_buffer_create_pixformat(RTGRAPHIC_PIXEL_FORMAT_ARGB888, bitmap->width, bitmap->height);
|
||||||
if (text_dc)
|
if (text_dc)
|
||||||
{
|
{
|
||||||
dest_buf = (struct rtgui_dc_buffer*)text_dc;
|
dest_buf = (struct rtgui_dc_buffer*)text_dc;
|
||||||
@ -503,7 +515,7 @@ static void _draw_bitmap(struct rtgui_dc *dc,
|
|||||||
text_rect.y1 = y_start;
|
text_rect.y1 = y_start;
|
||||||
text_rect.y2 = text_rect.y1 + bitmap->height;
|
text_rect.y2 = text_rect.y1 + bitmap->height;
|
||||||
|
|
||||||
rtgui_dc_buffer_set_alpha(text_dc, a);
|
rtgui_dc_buffer_set_alpha(text_dc, RTGUI_RGB_A(fgc));
|
||||||
rtgui_dc_blit(text_dc, &dc_point, dc, &text_rect);
|
rtgui_dc_blit(text_dc, &dc_point, dc, &text_rect);
|
||||||
|
|
||||||
rtgui_dc_destory(text_dc);
|
rtgui_dc_destory(text_dc);
|
||||||
@ -515,7 +527,7 @@ static void _draw_text(struct rtgui_dc *dc,
|
|||||||
struct rtgui_ttf_font *ttf_font,
|
struct rtgui_ttf_font *ttf_font,
|
||||||
rt_uint16_t *text_short,
|
rt_uint16_t *text_short,
|
||||||
rt_int16_t begin_x, rt_int16_t btm_y,
|
rt_int16_t begin_x, rt_int16_t btm_y,
|
||||||
rt_uint8_t a, rt_uint8_t r, rt_uint8_t g, rt_uint8_t b)
|
rtgui_color_t fgc, rt_uint16_t right, rt_uint16_t bottom)
|
||||||
{
|
{
|
||||||
int glyphIndex;
|
int glyphIndex;
|
||||||
FTC_SBit ftcSBit = RT_NULL;
|
FTC_SBit ftcSBit = RT_NULL;
|
||||||
@ -531,7 +543,7 @@ static void _draw_text(struct rtgui_dc *dc,
|
|||||||
/* render font */
|
/* render font */
|
||||||
begin_x -= (ftcSBit->left - (abs(ftcSBit->left) + 2) / 2);
|
begin_x -= (ftcSBit->left - (abs(ftcSBit->left) + 2) / 2);
|
||||||
|
|
||||||
_draw_bitmap(dc, ftcSBit, begin_x, btm_y, a, r, g, b);
|
_draw_bitmap(dc, ftcSBit, begin_x, btm_y, fgc, right, bottom);
|
||||||
|
|
||||||
begin_x += ftcSBit->width + ftcSBit->left;
|
begin_x += ftcSBit->width + ftcSBit->left;
|
||||||
|
|
||||||
@ -594,10 +606,6 @@ static void ftc_draw_text(struct rtgui_font *font,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
fgc = RTGUI_DC_FC(dc);
|
fgc = RTGUI_DC_FC(dc);
|
||||||
a = RTGUI_RGB_A(fgc);
|
|
||||||
r = RTGUI_RGB_R(fgc);
|
|
||||||
g = RTGUI_RGB_G(fgc);
|
|
||||||
b = RTGUI_RGB_B(fgc);
|
|
||||||
|
|
||||||
/* text align */
|
/* text align */
|
||||||
_get_metrics(ttf_font, text_short, &text_rect);
|
_get_metrics(ttf_font, text_short, &text_rect);
|
||||||
@ -633,7 +641,7 @@ static void ftc_draw_text(struct rtgui_font *font,
|
|||||||
goto _out;
|
goto _out;
|
||||||
}
|
}
|
||||||
|
|
||||||
_draw_text(dc, ttf_font, text_short, begin_x, btm_y, a, r, g, b);
|
_draw_text(dc, ttf_font, text_short, begin_x, btm_y, fgc, rect->x2, rect->y2);
|
||||||
|
|
||||||
_out:
|
_out:
|
||||||
/* release unicode buffer */
|
/* release unicode buffer */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user