Imported Upstream version 3.4.0
[platform/upstream/harfbuzz.git] / test / api / test-style.c
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 #include "hb-test.h"
26
27 #include <hb.h>
28
29 /* Unit tests for hb-style.h */
30
31 #define assert_cmpfloat(n1, n2) g_assert_cmpint ((int) (n1 * 100.f), ==, (int) (n2 * 100.f))
32
33 static void
34 test_empty_face (void)
35 {
36   hb_font_t *empty = hb_font_get_empty ();
37
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);
43 }
44
45 static void
46 test_regular_face (void)
47 {
48   hb_face_t *face = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf");
49   hb_font_t *font = hb_font_create (face);
50
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);
56
57   hb_font_destroy (font);
58   hb_face_destroy (face);
59 }
60
61 static void
62 test_face_user_setting (void)
63 {
64   hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
65   hb_font_t *font = hb_font_create (face);
66
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);
73
74   hb_font_set_var_named_instance (font, 0);
75
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);
82
83   hb_font_set_var_named_instance (font, 1);
84
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);
91
92   hb_font_set_var_named_instance (font, 2);
93
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);
100
101   hb_font_set_var_named_instance (font, 3);
102
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);
109
110   hb_font_set_var_named_instance (font, 4);
111
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);
118
119   hb_font_set_var_named_instance (font, 5);
120
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);
127
128   hb_font_set_var_named_instance (font, 6);
129
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);
136
137   hb_font_set_var_named_instance (font, 7);
138
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);
145
146   hb_font_destroy (font);
147   hb_face_destroy (face);
148 }
149
150 int
151 main (int argc, char **argv)
152 {
153   hb_test_init (&argc, &argv);
154
155   hb_test_add (test_empty_face);
156   hb_test_add (test_regular_face);
157   hb_test_add (test_face_user_setting);
158
159   return hb_test_run ();
160 }