1 /*
2 * Copyright © 2023 Red Hat, Inc.
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 * Author(s): Matthias Clasen
25 */
26
27 #include "hb-test.h"
28
29
30 static void
31 test_glyph_extents (void)
32 {
33 hb_face_t *face;
34 hb_font_t *font;
35 hb_glyph_extents_t extents;
36 hb_bool_t ret;
37
38 /* This font contains a COLRv1 glyph with a ClipBox,
39 * and various components without. The main thing
40 * we test here is that glyphs with no paint return
41 * 0,0,0,0 and not meaningless numbers.
42 */
43
44 face = hb_test_open_font_file ("fonts/adwaita.ttf");
45 font = hb_font_create (face);
46
47 ret = hb_font_get_glyph_extents (font, 0, &extents);
48 g_assert_true (ret);
49 g_assert_true (extents.x_bearing == 0 &&
50 extents.y_bearing == 0 &&
51 extents.width == 0 &&
52 extents.height == 0);
53
54 ret = hb_font_get_glyph_extents (font, 1, &extents);
55 g_assert_true (ret);
56 g_assert_true (extents.x_bearing == 0 &&
57 extents.y_bearing == 0 &&
58 extents.width == 0 &&
59 extents.height == 0);
60
61 ret = hb_font_get_glyph_extents (font, 2, &extents);
62 g_assert_true (ret);
63 g_assert_true (extents.x_bearing == 180 &&
64 extents.y_bearing == 960 &&
65 extents.width == 1060 &&
66 extents.height == -1220);
67
68 ret = hb_font_get_glyph_extents (font, 3, &extents);
69 g_assert_true (ret);
70 g_assert_true (extents.x_bearing == 188 &&
71 extents.y_bearing == 950 &&
72 extents.width == 900 &&
73 extents.height == -1200);
74
75 ret = hb_font_get_glyph_extents (font, 4, &extents);
76 g_assert_true (ret);
77 g_assert_true (extents.x_bearing == 413 &&
78 extents.y_bearing == 50 &&
79 extents.width == 150 &&
80 extents.height == -75);
81
82 ret = hb_font_get_glyph_extents (font, 5, &extents);
83 g_assert_true (ret);
84 g_assert_true (extents.x_bearing == 638 &&
85 extents.y_bearing == 350 &&
86 extents.width == 600 &&
87 extents.height == -600);
88
89 ret = hb_font_get_glyph_extents (font, 1000, &extents);
90 g_assert_false (ret);
91
92 hb_font_destroy (font);
93 hb_face_destroy (face);
94 }
95
96 int
97 main (int argc, char **argv)
98 {
99 hb_test_init (&argc, &argv);
100
101 hb_test_add (test_glyph_extents);
102
103 return hb_test_run();
104 }