Files
LCUI/test/test_string_render.c
T

44 lines
1.2 KiB
C
Raw Normal View History

2021-05-05 14:50:01 +08:00
#include <LCUI.h>
#include <LCUI/image.h>
2016-11-20 18:27:11 +08:00
#include <LCUI/font.h>
2021-09-28 10:58:30 +08:00
#include <LCUI/graph.h>
2016-11-20 18:27:11 +08:00
int main(void)
2016-11-20 18:27:11 +08:00
{
int ret;
pd_canvas_t img;
pd_pos_t pos = { 0, 80 };
pd_rect_t area = { 0, 0, 320, 240 };
2016-11-20 18:27:11 +08:00
LCUI_TextLayer txt = TextLayer_New();
2017-11-28 23:06:20 +08:00
LCUI_TextStyleRec txtstyle;
2016-11-20 18:27:11 +08:00
/* 初始化字体处理功能 */
LCUI_InitFontLibrary();
2016-11-20 18:27:11 +08:00
/* 创建一个图像,并使用灰色填充 */
pd_canvas_init(&img);
pd_canvas_create(&img, 320, 240);
pd_canvas_fill_rect(&img, RGB(240, 240, 240), NULL, FALSE);
2016-11-20 18:27:11 +08:00
/* 设置文本的字体大小 */
TextStyle_Init(&txtstyle);
2016-11-20 18:27:11 +08:00
txtstyle.pixel_size = 24;
txtstyle.has_pixel_size = TRUE;
/* 设置文本图层的固定尺寸、文本样式、文本内容、对齐方式 */
TextLayer_SetFixedSize(txt, 320, 240);
TextLayer_SetTextStyle(txt, &txtstyle);
2022-01-27 22:46:21 +08:00
TextLayer_SetTextAlign(txt, CSS_KEYWORD_CENTER);
TextLayer_SetTextW(txt, L"这是一段测试文本\nHello, World!", NULL);
TextLayer_Update(txt, NULL);
2016-11-20 18:27:11 +08:00
/* 将文本图层绘制到图像中,然后将图像写入至 png 文件中 */
TextLayer_RenderTo(txt, area, pos, &img);
ret = LCUI_WritePNGFile("test_string_render.png", &img);
pd_canvas_free(&img);
2016-11-20 18:27:11 +08:00
2017-07-03 22:42:05 +08:00
/* 释放字体处理功能相关资源 */
LCUI_FreeFontLibrary();
2016-11-20 18:27:11 +08:00
return ret;
}