add tinyttf

This commit is contained in:
huchao
2023-03-20 07:55:30 +00:00
parent 779444f998
commit cf1d5a234b
20 changed files with 111511 additions and 34 deletions

View File

@@ -13,6 +13,7 @@ ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES := main.c
ifeq ($(CONFIG_LIB_LV),y)
SRC_DIR += lv_app
SRC_DIR += tinyttf_app
endif
ifeq ($(CONFIG_APPLICATION_OTA),y)

View File

@@ -0,0 +1,3 @@
SRC_FILES := ttf_demo.c lv_example_tiny_ttf_1.c lv_example_tiny_ttf_2.c
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -0,0 +1,12 @@
## Tiny TTF font engine
用于在触摸屏上渲染矢量字体若要使用该引擎需开启LVGL。
### Usage
`lv_conf.h`中开启`LV_USE_TINY_TTF`,可以使用`lv_tiny_ttf_create_data(data, data_size, line_height)`创建字体创建字体后像LVGL正常字体一样使用。
默认情况下TTF或者OTF文件必须作为数组嵌入到程序`ubuntu_font`如果要从sd卡中读取文件需开启`LV_TINY_TTF_FILE_SUPPORT``LV_USE_FS_POSIX`
> 注意从sd卡中读取字库文件会比较慢请谨慎使用
默认情况下字体使用4KB缓存来加速渲染可以使用`lv_tiny_ttf_create_data_ex(data, data_size, line_height, cache_size)`或者`lv_tiny_ttf_create_file_ex(path, line_height, cache_size)`更改此大小
### API
见 xiuos/APP_Framework/lib/lvgl/src/extra/libs/tiny_ttf/lv_tiny_ttf.h

View File

@@ -0,0 +1,39 @@
/**
* @file lv_example_tiny_ttf.h
*
*/
#ifndef LV_EXAMPLE_TINY_TTF_H
#define LV_EXAMPLE_TINY_TTF_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_example_tiny_ttf_1(void);
void lv_example_tiny_ttf_2(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_EXAMPLE_TINY_TTF_H*/

View File

@@ -0,0 +1,25 @@
#include <../../lib/lvgl/examples/lv_examples.h>
#if LV_USE_TINY_TTF && LV_BUILD_EXAMPLES
#include "ubuntu_font_ch.h"
/**
* Load a font with Tiny_TTF
*/
void lv_example_tiny_ttf_1(void)
{
/*Create style with the new font*/
static lv_style_t style;
lv_style_init(&style);
lv_font_t * font = lv_tiny_ttf_create_data(ubuntu_font, sizeof(ubuntu_font), 35);
lv_style_set_text_font(&style, font);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);
/*Create a label with the new style*/
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_obj_add_style(label, &style, 0);
lv_label_set_text(label, "你好世界\nI'm a font\ncreated\nwith Tiny TTF");
lv_obj_center(label);
}
#endif

View File

@@ -0,0 +1,30 @@
#include <../../lib/lvgl/examples/lv_examples.h>
#if LV_USE_TINY_TTF && LV_TINY_TTF_FILE_SUPPORT //&& LV_BUILD_EXAMPLES
#define MAX_READ_LENGTH 1000
#include <stdio.h>
#include <string.h>
#include <transform.h>
/**
* Load a font with Tiny_TTF from file
*/
void lv_example_tiny_ttf_2(void)
{
/*Create style with the new font*/
static lv_style_t style;
lv_style_init(&style);
lv_font_t * font = lv_tiny_ttf_create_file("G:/normal.ttf", 35);
lv_style_set_text_font(&style, font);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);
/*Create a label with the new style*/
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_obj_set_size(label, 240, 136);
lv_obj_add_style(label, &style, 0);
lv_label_set_text(label, "你好世界\nI'm a font\ncreated\nwith Tiny TTF");
lv_obj_center(label);
lv_tiny_ttf_destroy(font);
}
#endif

Binary file not shown.

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file: ttf_demo.c
* @brief: a application using tinyttf
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2023/3/15
*
*/
#include <lvgl.h>
#include <lv_port_indev_template.h>
#include <transform.h>
extern void lv_example_tiny_ttf_1(void);
extern void lv_example_tiny_ttf_2(void);
void* ttf_thread(void *parameter)
{
/* display demo; you may replace with your LVGL application at here */
lv_example_tiny_ttf_1();
// lv_example_tiny_ttf_1();
/* handle the tasks of LVGL */
while(1)
{
lv_task_handler();
PrivTaskDelay(10);
}
}
pthread_t lvgl_task;
static int ttf_demo_init(void)
{
pthread_attr_t attr;
attr.schedparam.sched_priority = 25;
attr.stacksize = 4096;
PrivTaskCreate(&lvgl_task, &attr, ttf_thread, NULL);
return 0;
}
PRIV_SHELL_CMD_FUNCTION(ttf_demo_init, a tinyttf init sample, PRIV_SHELL_CMD_MAIN_ATTR);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff