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