2 * Copyright © 2019 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
29 /* Unit tests for hb-style.h */
31 #define assert_cmpfloat(n1, n2) g_assert_cmpint ((int) (n1 * 100.f), ==, (int) (n2 * 100.f))
34 test_empty_face (void)
36 hb_font_t *empty = hb_font_get_empty ();
38 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_ITALIC), 0);
39 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_OPTICAL_SIZE), 12);
40 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_SLANT_ANGLE), 0);
41 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_WIDTH), 100);
42 assert_cmpfloat (hb_style_get_value (empty, HB_STYLE_TAG_WEIGHT), 400);
46 test_regular_face (void)
48 hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
49 hb_font_t *font = hb_font_create (face);
51 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
52 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
53 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
54 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
55 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 400);
57 hb_font_destroy (font);
58 hb_face_destroy (face);
62 test_face_user_setting (void)
64 hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
65 hb_font_t *font = hb_font_create (face);
67 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
68 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
69 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
70 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
71 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 389.34f); /* its default weight */
72 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
74 hb_font_set_var_named_instance (font, 0);
76 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
77 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
78 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
79 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
80 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 200);
81 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
83 hb_font_set_var_named_instance (font, 1);
85 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
86 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
87 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
88 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
89 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 300);
90 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
92 hb_font_set_var_named_instance (font, 2);
94 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
95 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
96 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
97 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
98 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 400);
99 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
101 hb_font_set_var_named_instance (font, 3);
103 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
104 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
105 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
106 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
107 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT),600);
108 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
110 hb_font_set_var_named_instance (font, 4);
112 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
113 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
114 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
115 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
116 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 700);
117 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
119 hb_font_set_var_named_instance (font, 5);
121 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
122 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
123 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
124 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
125 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
126 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 0);
128 hb_font_set_var_named_instance (font, 6);
130 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
131 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
132 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
133 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
134 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
135 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 50);
137 hb_font_set_var_named_instance (font, 7);
139 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_ITALIC), 0);
140 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_OPTICAL_SIZE), 12);
141 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), 0);
142 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WIDTH), 100);
143 assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_WEIGHT), 900);
144 assert_cmpfloat (hb_style_get_value (font, (hb_style_tag_t) HB_TAG ('C','N','T','R')), 100);
146 hb_font_destroy (font);
147 hb_face_destroy (face);
151 main (int argc, char **argv)
153 hb_test_init (&argc, &argv);
155 hb_test_add (test_empty_face);
156 hb_test_add (test_regular_face);
157 hb_test_add (test_face_user_setting);
159 return hb_test_run ();