1 /*
2 * Copyright © 2019 Ebrahim Byagowi
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 */
24
25 #ifdef HB_EXPERIMENTAL_API
26 #include "hb-test.h"
27
28 #include <hb.h>
29
30 /* Unit tests for hb-style.h */
31
32 #define assert_cmpfloat(n1, n2) g_assert_cmpint ((int) (n1 * 100.f), ==, (int) (n2 * 100.f))
33
34 #define HB_STYLE_TAG_ITALIC HB_TAG ('i','t','a','l')
35 #define HB_STYLE_TAG_OPTICAL_SIZE HB_TAG ('o','p','s','z')
36 #define HB_STYLE_TAG_SLANT HB_TAG ('s','l','n','t')
37 #define HB_STYLE_TAG_WIDTH HB_TAG ('w','d','t','h')
38 #define HB_STYLE_TAG_WEIGHT HB_TAG ('w','g','h','t')
39
40 static void
test_empty_face(void)41 test_empty_face (void)
42 {
43 hb_font_t *empty = hb_font_get_empty ();
44
45 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_ITALIC), 0);
46 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_OPTICAL_SIZE), 12);
47 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_SLANT), 0);
48 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_WIDTH), 100);
49 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_WEIGHT), 400);
50 }
51
52 static void
test_regular_face(void)53 test_regular_face (void)
54 {
55 hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
56 hb_font_t *font = hb_font_create (face);
57
58 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
59 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
60 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
61 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
62 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 400);
63
64 hb_font_destroy (font);
65 hb_face_destroy (face);
66 }
67
68 static void
test_face_user_setting(void)69 test_face_user_setting (void)
70 {
71 hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
72 hb_font_t *font = hb_font_create (face);
73
74 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
75 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
76 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
77 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
78 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 389.34f); /* its default weight */
79 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
80
81 hb_font_set_var_named_instance (font, 0);
82
83 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
84 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
85 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
86 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
87 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 200);
88 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
89
90 hb_font_set_var_named_instance (font, 1);
91
92 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
93 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
94 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
95 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
96 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 300);
97 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
98
99 hb_font_set_var_named_instance (font, 2);
100
101 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
102 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
103 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
104 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
105 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 400);
106 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
107
108 hb_font_set_var_named_instance (font, 3);
109
110 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
111 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
112 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
113 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
114 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT),600);
115 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
116
117 hb_font_set_var_named_instance (font, 4);
118
119 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
120 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
121 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
122 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
123 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 700);
124 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
125
126 hb_font_set_var_named_instance (font, 5);
127
128 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
129 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
130 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
131 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
132 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
133 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
134
135 hb_font_set_var_named_instance (font, 6);
136
137 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
138 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
139 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
140 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
141 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
142 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 50);
143
144 hb_font_set_var_named_instance (font, 7);
145
146 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
147 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
148 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT), 0);
149 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
150 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
151 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 100);
152
153 hb_font_destroy (font);
154 hb_face_destroy (face);
155 }
156
157 int
main(int argc,char ** argv)158 main (int argc, char **argv)
159 {
160 hb_test_init (&argc, &argv);
161
162 hb_test_add (test_empty_face);
163 hb_test_add (test_regular_face);
164 hb_test_add (test_face_user_setting);
165
166 return hb_test_run ();
167 }
168 #else
main()169 int main () {}
170 #endif
171