feat(freetype): add new freetype testcase (#5207)

This commit is contained in:
Benign X 2024-01-07 15:39:50 +08:00 committed by GitHub
parent b4bdb6e526
commit 2633a33b48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 329 additions and 40 deletions

View File

@ -94,7 +94,7 @@ jobs:
install: |
apt-get update -y
apt-get install build-essential ccache python3 libpng-dev ruby-full gcovr cmake libjpeg62-turbo-dev -q -y
apt-get install build-essential ccache libgcc-10-dev python3 libpng-dev ruby-full gcovr cmake libjpeg62-turbo-dev libfreetype6-dev libasan6 -q -y
/usr/sbin/update-ccache-symlinks
echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc

View File

@ -15,6 +15,7 @@ void lv_example_freetype_1(void)
{
/*Create a font*/
lv_font_t * font = lv_freetype_font_create(PATH_PREFIX "lvgl/examples/libs/freetype/Lato-Regular.ttf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
24,
LV_FREETYPE_FONT_STYLE_NORMAL);

View File

@ -6,14 +6,38 @@ if(ESP_PLATFORM)
else()
cmake_minimum_required(VERSION 3.13)
project(lvgl_tests LANGUAGES C)
cmake_minimum_required(VERSION 3.18)
project(lvgl_tests LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 99)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
function(filter_compiler_options lang options_out)
set(options ${ARGN})
foreach(option ${options})
string(TOUPPER FLAG_SUPPORTED_FOR_${lang}_${option} option_var_name)
if (${lang} STREQUAL C)
check_c_compiler_flag(${option} ${option_var_name})
elseif (${lang} STREQUAL CXX)
check_cxx_compiler_flag(${option} ${option_var_name})
else()
message(FATAL_ERROR "Unknown language ${lang}")
endif ()
if(${option_var_name})
list(APPEND ${options_out} ${option})
endif()
endforeach()
set(${options_out} ${${options_out}} PARENT_SCOPE)
endfunction()
find_program(VALGRIND_EXECUTABLE valgrind)
if (VALGRIND_EXECUTABLE)
set(MEMORYCHECK_COMMAND ${VALGRIND_EXECUTABLE})
set(MEMORYCHECK_COMMAND_OPTIONS --error-exitcode=1)
endif()
include(CTest)
set(LVGL_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@ -64,12 +88,14 @@ elseif (OPTIONS_FULL_32BIT)
set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_FULL_32BIT})
elseif (OPTIONS_TEST_SYSHEAP)
set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_TEST_SYSHEAP} -fsanitize=address -fsanitize=leak -fsanitize=undefined --coverage)
set (TEST_LIBS --coverage -fsanitize=address -fsanitize=leak -fsanitize=undefined)
filter_compiler_options (C TEST_LIBS --coverage -fsanitize=leak -fsanitize=undefined)
list(APPEND TEST_LIBS -fsanitize=address)
set (LV_CONF_BUILD_DISABLE_EXAMPLES ON)
set (ENABLE_TESTS ON)
elseif (OPTIONS_TEST_DEFHEAP)
set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_TEST_DEFHEAP})
set (TEST_LIBS --coverage -fsanitize=address -fsanitize=leak -fsanitize=undefined)
filter_compiler_options (C TEST_LIBS --coverage -fsanitize=leak -fsanitize=undefined)
list(APPEND TEST_LIBS -fsanitize=address)
set (LV_CONF_BUILD_DISABLE_EXAMPLES ON)
set (ENABLE_TESTS ON)
elseif (OPTIONS_TEST_MEMORYCHECK)
@ -117,54 +143,36 @@ set(COMPILE_OPTIONS
-Wunreachable-code
-Werror=float-conversion
-Werror=strict-aliasing
-Wno-double-promotion
-Wno-unused-but-set-parameter
-Wno-unreachable-code
${BUILD_OPTIONS}
${BUILD_TARGET_DEF}
)
filter_compiler_options(C LVGL_COMPILE_OPTIONS ${COMPILE_OPTIONS})
# Options test cases are compiled with.
set(LVGL_TESTFILE_COMPILE_OPTIONS
${COMPILE_OPTIONS}
-Wno-missing-prototypes
)
filter_compiler_options(C LVGL_TESTFILE_COMPILE_OPTIONS ${LVGL_COMPILE_OPTIONS} -Wno-missing-prototypes)
set(LVGL_THORVG_COMPILE_OPTIONS
-DLV_CONF_PATH=${LVGL_TEST_DIR}/src/lv_test_conf.h
-DLV_BUILD_TEST
-pedantic-errors
-Wall
-Wclobbered
-Wdeprecated
-Wdouble-promotion
-Wempty-body
-Werror
-Wextra
-Wformat-security
-Wmaybe-uninitialized
-Wpointer-arith
-Wmultichar
-Wno-pedantic
-Wno-unused-parameter
-Wreturn-type
-Wshift-negative-value
-Wsizeof-pointer-memaccess
-Wtype-limits
-Wundef
-Wuninitialized
-Wunreachable-code
-Werror=float-conversion
-Werror=strict-aliasing
${BUILD_OPTIONS}
${BUILD_TARGET_DEF}
filter_compiler_options(CXX LVGL_THORVG_COMPILE_OPTIONS
${COMPILE_OPTIONS}
-Wno-shadow
-Wno-unused-parameter
-Wno-c++11-extensions
-Wno-missing-prototypes
-Wno-deprecated-copy-with-user-provided-dtor
-Wno-float-conversion
)
get_filename_component(LVGL_DIR ${LVGL_TEST_DIR} DIRECTORY)
# Include lvgl project file.
include(${LVGL_DIR}/CMakeLists.txt)
target_compile_options(lvgl PUBLIC ${COMPILE_OPTIONS})
target_compile_options(lvgl PUBLIC ${LVGL_COMPILE_OPTIONS})
target_compile_options(lvgl_thorvg PUBLIC ${LVGL_THORVG_COMPILE_OPTIONS})
if (TARGET lvgl_examples)
target_compile_options(lvgl_examples PUBLIC ${COMPILE_OPTIONS})
target_compile_options(lvgl_examples PUBLIC ${LVGL_COMPILE_OPTIONS})
endif()
@ -225,6 +233,14 @@ set(generate_test_runner_config ${CMAKE_CURRENT_SOURCE_DIR}/config.yml)
find_package(JPEG REQUIRED)
include_directories(${JPEG_INCLUDE_DIR})
# libpng is required for the png test case
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
# libfreetype is required for the font test case
find_package(Freetype REQUIRED)
include_directories(${FREETYPE_INCLUDE_DIRS})
# disable test targets for build only tests
if (ENABLE_TESTS)
file( GLOB_RECURSE TEST_CASE_FILES src/test_cases/*.c )
@ -253,7 +269,16 @@ foreach( test_case_fname ${TEST_CASE_FILES} )
${test_case_fname}
${test_runner_fname}
)
target_link_libraries(${test_name} PRIVATE test_common lvgl_demos lvgl lvgl_thorvg png ${JPEG_LIBRARIES} m ${TEST_LIBS})
target_link_libraries(${test_name} PRIVATE
test_common
lvgl_demos
lvgl
lvgl_thorvg
${PNG_LIBRARIES}
${FREETYPE_LIBRARIES}
${JPEG_LIBRARIES}
m
${TEST_LIBS})
target_include_directories(${test_name} PUBLIC ${TEST_INCLUDE_DIRS})
target_compile_options(${test_name} PUBLIC ${LVGL_TESTFILE_COMPILE_OPTIONS})

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -98,3 +98,10 @@
#define LV_BIN_DECODER_RAM_LOAD 1
#define LV_CACHE_DEF_SIZE (10 * 1024 * 1024)
#define LV_USE_FREETYPE 1
#define LV_FREETYPE_CACHE_SIZE 768
#define LV_FREETYPE_USE_LVGL_PORT 0
#define LV_FREETYPE_CACHE_FT_FACES 8
#define LV_FREETYPE_CACHE_FT_SIZES 8
#define LV_FREETYPE_CACHE_FT_OUTLINES 10

View File

@ -0,0 +1,92 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
#if __WORDSIZE == 64
#define TEST_FREETYPE_ASSERT_EQUAL_SCREENSHOT(NAME) TEST_ASSERT_EQUAL_SCREENSHOT("libs/freetype_" NAME ".lp64.png")
#elif __WORDSIZE == 32
#define TEST_FREETYPE_ASSERT_EQUAL_SCREENSHOT(NAME) TEST_ASSERT_EQUAL_SCREENSHOT("libs/freetype_" NAME ".lp32.png")
#endif
static const char * UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_CN =
"鉴于对人类家庭所有成员的固有尊严及其平等的和不移的权利的承认,乃是世界自由、正义与和平的基础...";
static const char * UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_EN =
"Whereas recognition of the inherent dignity and of the equal and inalienable rights of all members of the human family is the foundation of freedom, justice and peace in the world...";
static const char * UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_JP =
"人間の家族のすべての構成員の固有の尊厳と平等で譲渡不能な権利とを承認することは、自由と正義と平和の基礎である...";
void setUp(void)
{
/* Function run before every test */
}
void tearDown(void)
{
/* Function run after every test */
}
void test_freetype_rendering_test(void)
{
#if LV_USE_FREETYPE
/*Create a font*/
lv_font_t * font_italic = lv_freetype_font_create("./src/test_files/fonts/noto/NotoSansSC-Regular.ttf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
24,
LV_FREETYPE_FONT_STYLE_ITALIC);
lv_font_t * font_normal = lv_freetype_font_create("./src/test_files/fonts/noto/NotoSansSC-Regular.ttf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
24,
LV_FREETYPE_FONT_STYLE_NORMAL);
lv_font_t * font_normal_small = lv_freetype_font_create("./src/test_files/fonts/noto/NotoSansSC-Regular.ttf",
LV_FREETYPE_FONT_RENDER_MODE_BITMAP,
12,
LV_FREETYPE_FONT_STYLE_NORMAL);
if(!font_italic || !font_normal || !font_normal_small) {
LV_LOG_ERROR("freetype font create failed.");
TEST_FAIL();
}
/*Create style with the new font*/
static lv_style_t style_italic;
lv_style_init(&style_italic);
lv_style_set_text_font(&style_italic, font_italic);
lv_style_set_text_align(&style_italic, LV_TEXT_ALIGN_CENTER);
static lv_style_t style_normal;
lv_style_init(&style_normal);
lv_style_set_text_font(&style_normal, font_normal);
lv_style_set_text_align(&style_normal, LV_TEXT_ALIGN_CENTER);
static lv_style_t style_normal_small;
lv_style_init(&style_normal_small);
lv_style_set_text_font(&style_normal_small, font_normal_small);
/*Create a label with the new style*/
lv_obj_t * label0 = lv_label_create(lv_screen_active());
lv_obj_add_style(label0, &style_italic, 0);
lv_obj_set_width(label0, lv_obj_get_width(lv_screen_active()) - 20);
lv_label_set_text(label0, UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_CN);
lv_obj_align(label0, LV_ALIGN_TOP_MID, 0, 10);
lv_obj_t * label1 = lv_label_create(lv_screen_active());
lv_obj_add_style(label1, &style_normal, 0);
lv_obj_set_width(label1, lv_obj_get_width(lv_screen_active()) - 20);
lv_label_set_text(label1, UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_EN);
lv_obj_align_to(label1, label0, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t * label2 = lv_label_create(lv_screen_active());
lv_obj_add_style(label2, &style_normal_small, 0);
lv_obj_set_width(label2, lv_obj_get_width(lv_screen_active()) - 20);
lv_label_set_text(label2, UNIVERSAL_DECLARATION_OF_HUMAN_RIGHTS_JP);
lv_obj_align_to(label2, label1, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
TEST_FREETYPE_ASSERT_EQUAL_SCREENSHOT("1");
#else
TEST_PASS();
#endif
}
#endif

Binary file not shown.

View File

@ -0,0 +1,93 @@
Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@ -0,0 +1,71 @@
Noto Sans SC Variable Font
==========================
This download contains Noto Sans SC as both a variable font and static fonts.
Noto Sans SC is a variable font with this axis:
wght
This means all the styles are contained in a single file:
NotoSansSC-VariableFont_wght.ttf
If your app fully supports variable fonts, you can now pick intermediate styles
that arent available as static fonts. Not all apps support variable fonts, and
in those cases you can use the static font files for Noto Sans SC:
static/NotoSansSC-Thin.ttf
static/NotoSansSC-ExtraLight.ttf
static/NotoSansSC-Light.ttf
static/NotoSansSC-Regular.ttf
static/NotoSansSC-Medium.ttf
static/NotoSansSC-SemiBold.ttf
static/NotoSansSC-Bold.ttf
static/NotoSansSC-ExtraBold.ttf
static/NotoSansSC-Black.ttf
Get started
-----------
1. Install the font files you want to use
2. Use your app's font picker to view the font family and all the
available styles
Learn more about variable fonts
-------------------------------
https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
https://variablefonts.typenetwork.com
https://medium.com/variable-fonts
In desktop apps
https://theblog.adobe.com/can-variable-fonts-illustrator-cc
https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts
Online
https://developers.google.com/fonts/docs/getting_started
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts
Installing fonts
MacOS: https://support.apple.com/en-us/HT201749
Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows
Android Apps
https://developers.google.com/fonts/docs/android
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
License
-------
Please read the full license text (OFL.txt) to understand the permissions,
restrictions and requirements for usage, redistribution, and modification.
You can use them in your products & projects print or digital,
commercial or otherwise.
This isn't legal advice, please consider consulting a lawyer and see the full
license for all details.