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_font_[gs]et_var_coords_ */
32 test_get_var_coords (void)
34 #ifdef HB_EXPERIMENTAL_API
35 #ifndef G_APPROX_VALUE
36 #define G_APPROX_VALUE(a, b, epsilon) \
37 (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
42 hb_face_t *face = hb_test_open_font_file ("fonts/TestCFF2VF.otf");
43 hb_font_t *font = hb_font_create (face);
45 /* Normalized coords as input */
46 int normalized_coords[] = {100, 0};
47 hb_font_set_var_coords_normalized (font, normalized_coords, 2);
48 g_assert_cmpint ((int) hb_font_get_var_coords_design (font, NULL)[0], ==, 403);
49 g_assert_cmpint ((int) hb_font_get_var_coords_normalized (font, NULL)[0], ==, 100);
51 /* Design coords as input */
52 float design_coords[] = {206.f, 0};
53 hb_font_set_var_coords_design (font, design_coords, 2);
54 g_assert_cmpint ((int) hb_font_get_var_coords_normalized (font, NULL)[0], ==, -16117);
55 g_assert_cmpint ((int) hb_font_get_var_coords_design (font, NULL)[0], ==, 206);
57 for (float weight = 200; weight < 901; ++weight)
60 hb_ot_var_normalize_coords (face, 1, &weight, &normalized);
61 hb_font_set_var_coords_normalized (font, &normalized, 1);
62 float converted_back = hb_font_get_var_coords_design (font, NULL)[0];
63 // fprintf (stderr, "%f: %d => %f\n", weight, normalized, converted_back);
64 g_assert_true (G_APPROX_VALUE (converted_back, weight, EPSILON));
67 hb_font_destroy (font);
68 hb_face_destroy (face);
73 test_get_var_get_axis_infos (void)
75 hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf");
77 g_assert_cmpint (hb_ot_var_get_axis_count (face), ==, 2);
79 hb_ot_var_axis_info_t info;
82 g_assert_cmpint (hb_ot_var_get_axis_infos (face, 0, &c, &info), ==, 2);
83 g_assert (info.tag == HB_TAG ('w','g','h','t'));
84 g_assert_cmpint (c, ==, 1);
86 hb_ot_var_get_axis_infos (face, 1, &c, &info);
87 g_assert (info.tag == HB_TAG ('w','d','t','h'));
88 g_assert_cmpint (c, ==, 1);
90 hb_ot_var_get_axis_infos (face, 2, &c, &info);
91 g_assert_cmpint (c, ==, 0);
93 hb_face_destroy (face);
97 main (int argc, char **argv)
99 hb_test_init (&argc, &argv);
100 hb_test_add (test_get_var_coords);
101 hb_test_add (test_get_var_get_axis_infos);
102 return hb_test_run ();