Files
LCUI/test/test_string_render.c
T
GregoryLiand李刚毅 c44562b45b refactor(paint): migrate to new naming style (#265)
* ib/paint 目录内代码及相关调用代码的重命名

* Revert "ib/paint 目录内代码及相关调用代码的重命名"

This reverts commit 6369a3b7bc.

* lib/paint 目录内代码及相关调用代码的重命名

* 添加 PandaGL 优化文档

* 修改部分命名规范

* - 将paint 中的LCUI_BOOL 更改为 pd_bool 其他地方保持 LCUI_BOOL
- 将 .h 文件中 PandaGL 函数更改为以 pd_ 前缀
- 将 paint 中 graph 更改为 canvas

* 退回 LCUI_StyleValue 与 LCUI_StyleType 的修改

* - 根据使用范围修改 types.h 中 LCUI_BOOL 与 pd_bool
- 回退LCUI_Style、LCUI_StyleRec
- 回退LCUI_Background

* 将 pd_paint_context 修改为 pd_paint_context_t *

* 替换 PDASSIGN

* 修改logger_debug

* 更改logger_error

Co-authored-by: 李刚毅 <gregoryli@foxmail.com>
2023-04-01 22:34:33 +08:00

44 lines
1.2 KiB
C

#include <LCUI.h>
#include <LCUI/image.h>
#include <LCUI/font.h>
#include <LCUI/graph.h>
int main(void)
{
int ret;
pd_canvas_t img;
pd_pos_t pos = { 0, 80 };
pd_rect_t area = { 0, 0, 320, 240 };
LCUI_TextLayer txt = TextLayer_New();
LCUI_TextStyleRec txtstyle;
/* 初始化字体处理功能 */
LCUI_InitFontLibrary();
/* 创建一个图像,并使用灰色填充 */
pd_canvas_init(&img);
pd_canvas_create(&img, 320, 240);
pd_canvas_fill_rect(&img, RGB(240, 240, 240), NULL, FALSE);
/* 设置文本的字体大小 */
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);
/* 将文本图层绘制到图像中,然后将图像写入至 png 文件中 */
TextLayer_RenderTo(txt, area, pos, &img);
ret = LCUI_WritePNGFile("test_string_render.png", &img);
pd_canvas_free(&img);
/* 释放字体处理功能相关资源 */
LCUI_FreeFontLibrary();
return ret;
}