Skip to content

Commit

Permalink
fix(textlayer): incorrect text line height calculation (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 17, 2019
1 parent e53b42c commit a4d2f0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/font/textlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static void TextLayer_UpdateRowSize(LCUI_TextLayer layer, LCUI_TextRow txtrow)
if (layer->line_height > -1) {
txtrow->height = layer->line_height;
} else {
txtrow->height = GetDefaultLineHeight(txtrow->height);
txtrow->height = GetDefaultLineHeight(txtrow->text_height);
}
}

Expand Down
30 changes: 15 additions & 15 deletions test/test_string_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
#include <LCUI/image.h>
#include <LCUI/font.h>

int main( void )
int main(void)
{
int ret;
LCUI_Graph img;
LCUI_Pos pos = {0, 80};
LCUI_Rect area = {0, 0, 320, 240};
LCUI_Pos pos = { 0, 80 };
LCUI_Rect area = { 0, 0, 320, 240 };
LCUI_TextLayer txt = TextLayer_New();
LCUI_TextStyleRec txtstyle;

/* 初始化字体处理功能 */
LCUI_InitFontLibrary();

/* 创建一个图像,并使用灰色填充 */
Graph_Init( &img );
Graph_Create( &img, 320, 240 );
Graph_FillRect( &img, RGB( 240, 240, 240 ), NULL, FALSE );
Graph_Init(&img);
Graph_Create(&img, 320, 240);
Graph_FillRect(&img, RGB(240, 240, 240), NULL, FALSE);

/* 设置文本的字体大小 */
TextStyle_Init( &txtstyle );
TextStyle_Init(&txtstyle);
txtstyle.pixel_size = 24;
txtstyle.has_pixel_size = TRUE;

/* 设置文本图层的固定尺寸、文本样式、文本内容、对齐方式 */
TextLayer_SetFixedSize( txt, 320, 240 );
TextLayer_SetTextStyle( txt, &txtstyle );
TextLayer_SetTextAlign( txt, SV_CENTER );
TextLayer_SetTextW( txt, L"这是一段测试文本\nHello, World!", NULL );
TextLayer_Update( txt, NULL );
TextLayer_SetFixedSize(txt, 320, 240);
TextLayer_SetTextStyle(txt, &txtstyle);
TextLayer_SetTextAlign(txt, SV_CENTER);
TextLayer_SetTextW(txt, L"这是一段测试文本\nHello, World!", NULL);
TextLayer_Update(txt, NULL);

/* 将文本图层绘制到图像中,然后将图像写入至 png 文件中 */
TextLayer_RenderTo( txt, area, pos, &img );
ret = LCUI_WritePNGFile( "test_string_render.png", &img );
Graph_Free( &img );
TextLayer_RenderTo(txt, area, pos, &img);
ret = LCUI_WritePNGFile("test_string_render.png", &img);
Graph_Free(&img);

/* 释放字体处理功能相关资源 */
LCUI_FreeFontLibrary();
Expand Down

0 comments on commit a4d2f0a

Please sign in to comment.