1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4
5 #include "unity/unity.h"
6
setUp(void)7 void setUp(void)
8 {
9 /* Function run before every test */
10 }
11
tearDown(void)12 void tearDown(void)
13 {
14 /* Function run after every test */
15 }
16
test_tiny_ttf_rendering_test(void)17 void test_tiny_ttf_rendering_test(void)
18 {
19 #if LV_USE_TINY_TTF
20 /*Create a font*/
21 extern const uint8_t test_ubuntu_font[];
22 extern size_t test_ubuntu_font_size;
23 lv_font_t * font = lv_tiny_ttf_create_data(test_ubuntu_font, test_ubuntu_font_size, 30);
24
25 /*Create style with the new font*/
26 static lv_style_t style;
27 lv_style_init(&style);
28 lv_style_set_text_font(&style, font);
29 lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);
30 lv_style_set_bg_opa(&style, LV_OPA_COVER);
31 lv_style_set_bg_color(&style, lv_color_hex(0xffaaaa));
32
33 /*Create a label with the new style*/
34 lv_obj_t * label = lv_label_create(lv_screen_active());
35 lv_obj_add_style(label, &style, 0);
36 lv_label_set_text(label, "Hello world\n"
37 "I'm a font created with Tiny TTF\n"
38 "Accents: ÁÉÍÓÖŐÜŰ áéíóöőüű");
39 lv_obj_center(label);
40
41 #ifndef NON_AMD64_BUILD
42 TEST_ASSERT_EQUAL_SCREENSHOT("libs/tiny_ttf_1.png");
43 #endif
44
45 lv_obj_delete(label);
46 lv_tiny_ttf_destroy(font);
47 #else
48 TEST_PASS();
49 #endif
50 }
51
test_tiny_ttf_kerning(void)52 void test_tiny_ttf_kerning(void)
53 {
54 #if LV_USE_TINY_TTF
55 extern const uint8_t test_kern_one_otf[];
56 extern size_t test_kern_one_otf_size;
57 lv_font_t * font_normal = lv_tiny_ttf_create_data(test_kern_one_otf, test_kern_one_otf_size, 80);
58 lv_font_t * font_none = lv_tiny_ttf_create_data(test_kern_one_otf, test_kern_one_otf_size, 80);
59 lv_font_set_kerning(font_none, LV_FONT_KERNING_NONE);
60
61 lv_obj_t * cont = lv_obj_create(lv_screen_active());
62 lv_obj_set_size(cont, lv_pct(90), lv_pct(90));
63 lv_obj_center(cont);
64 lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
65 lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
66
67 lv_obj_t * label_normal = lv_label_create(cont);
68 lv_label_set_text(label_normal, "ıTuTuTı");
69 lv_obj_set_style_text_font(label_normal, font_normal, LV_PART_MAIN);
70
71 lv_obj_t * label_none = lv_label_create(cont);
72 lv_label_set_text(label_none, "ıTuTuTı");
73 lv_obj_set_style_text_font(label_none, font_none, LV_PART_MAIN);
74
75 TEST_ASSERT_EQUAL_SCREENSHOT("libs/tiny_ttf_2.png");
76
77 lv_obj_delete(cont);
78 lv_tiny_ttf_destroy(font_normal);
79 lv_tiny_ttf_destroy(font_none);
80 #else
81 TEST_PASS();
82 #endif
83 }
84
85 #endif
86