blob: 49b87997ee8f64d72a88d757d89f223f6bf67e53 [file] [log] [blame]
Michiharu Ariza6238edb2018-10-04 13:59:36 -07001/*
Michiharu Ariza0dfa5842018-11-12 08:47:07 -08002 * Copyright © 2018 Adobe Inc.
Michiharu Ariza6238edb2018-10-04 13:59:36 -07003 *
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 * Adobe Author(s): Michiharu Ariza
25 */
26
27#include "hb-test.h"
28#include <hb-ot.h>
29
30/* Unit tests for CFF/CFF2 glyph extents */
31
32static void
33test_extents_cff1 (void)
34{
Michiharu Arizab11032a2018-10-22 15:52:37 -070035 hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.abc.otf");
Michiharu Ariza6238edb2018-10-04 13:59:36 -070036 g_assert (face);
37 hb_font_t *font = hb_font_create (face);
38 hb_face_destroy (face);
39 g_assert (font);
40 hb_ot_font_set_funcs (font);
41
42 hb_glyph_extents_t extents;
43 hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
44 g_assert (result);
45
46 g_assert_cmpint (extents.x_bearing, ==, 52);
47 g_assert_cmpint (extents.y_bearing, ==, 498);
48 g_assert_cmpint (extents.width, ==, 381);
49 g_assert_cmpint (extents.height, ==, -510);
50
Michiharu Arizaca371722018-10-11 11:55:55 -070051 hb_font_destroy (font);
52
Michiharu Ariza3d3df552018-10-22 15:23:39 -070053 hb_face_t *face_j = hb_test_open_font_file ("fonts/SourceHanSans-Regular.41,3041,4C2E.otf");
Michiharu Arizaa6b6faf2018-10-11 10:53:44 -070054 g_assert (face_j);
55 hb_font_t *font_j = hb_font_create (face_j);
56 hb_face_destroy (face_j);
57 g_assert (font_j);
58 hb_ot_font_set_funcs (font_j);
59
60 hb_bool_t result_j = hb_font_get_glyph_extents (font_j, 3, &extents);
61 g_assert (result_j);
62
63 g_assert_cmpint (extents.x_bearing, ==, 34);
64 g_assert_cmpint (extents.y_bearing, ==, 840);
65 g_assert_cmpint (extents.width, ==, 920);
66 g_assert_cmpint (extents.height, ==, -907);
67
Michiharu Arizaca371722018-10-11 11:55:55 -070068 hb_font_destroy (font_j);
Michiharu Ariza6238edb2018-10-04 13:59:36 -070069}
70
Michiharu Arizab51418f2018-10-08 15:05:36 -070071static void
Michiharu Arizae555ed92018-10-18 13:04:41 -070072test_extents_cff1_flex (void)
73{
Michiharu Ariza3d3df552018-10-22 15:23:39 -070074 hb_face_t *face = hb_test_open_font_file ("fonts/cff1_flex.otf");
Michiharu Arizae555ed92018-10-18 13:04:41 -070075 g_assert (face);
76 hb_font_t *font = hb_font_create (face);
77 hb_face_destroy (face);
78 g_assert (font);
79 hb_ot_font_set_funcs (font);
80
81 hb_glyph_extents_t extents;
82 hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
83 g_assert (result);
84
85 g_assert_cmpint (extents.x_bearing, ==, -20);
86 g_assert_cmpint (extents.y_bearing, ==, 520);
87 g_assert_cmpint (extents.width, ==, 540);
88 g_assert_cmpint (extents.height, ==, -540);
89
90 hb_font_destroy (font);
91}
92
93static void
Michiharu Ariza3787c072018-11-14 13:38:03 -080094test_extents_cff1_seac (void)
95{
96 hb_face_t *face = hb_test_open_font_file ("fonts/cff1_seac.otf");
97 g_assert (face);
98 hb_font_t *font = hb_font_create (face);
99 hb_face_destroy (face);
100 g_assert (font);
101 hb_ot_font_set_funcs (font);
102
103 hb_glyph_extents_t extents;
104 hb_bool_t result = hb_font_get_glyph_extents (font, 3, &extents); /* Agrave */
105 g_assert (result);
106
107 g_assert_cmpint (extents.x_bearing, ==, 3);
108 g_assert_cmpint (extents.y_bearing, ==, 861);
109 g_assert_cmpint (extents.width, ==, 538);
110 g_assert_cmpint (extents.height, ==, -861);
111
112 result = hb_font_get_glyph_extents (font, 4, &extents); /* Udieresis */
113 g_assert (result);
114
115 g_assert_cmpint (extents.x_bearing, ==, 87);
116 g_assert_cmpint (extents.y_bearing, ==, 827);
117 g_assert_cmpint (extents.width, ==, 471);
118 g_assert_cmpint (extents.height, ==, -839);
119
120 hb_font_destroy (font);
121}
122
123static void
Michiharu Arizab51418f2018-10-08 15:05:36 -0700124test_extents_cff2 (void)
125{
Michiharu Ariza3d3df552018-10-22 15:23:39 -0700126 hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype.abc.otf");
Michiharu Arizab51418f2018-10-08 15:05:36 -0700127 g_assert (face);
128 hb_font_t *font = hb_font_create (face);
129 hb_face_destroy (face);
130 g_assert (font);
131 hb_ot_font_set_funcs (font);
132
133 hb_glyph_extents_t extents;
134 hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
135 g_assert (result);
136
137 g_assert_cmpint (extents.x_bearing, ==, 46);
138 g_assert_cmpint (extents.y_bearing, ==, 487);
139 g_assert_cmpint (extents.width, ==, 455);
140 g_assert_cmpint (extents.height, ==, -500);
141
142 float coords[2] = { 600.0f, 50.0f };
143 hb_font_set_var_coords_design (font, coords, 2);
144 result = hb_font_get_glyph_extents (font, 1, &extents);
145 g_assert (result);
146
147 g_assert_cmpint (extents.x_bearing, ==, 38);
148 g_assert_cmpint (extents.y_bearing, ==, 493);
149 g_assert_cmpint (extents.width, ==, 481);
150 g_assert_cmpint (extents.height, ==, -508);
151
152 hb_font_destroy (font);
153}
154
Michiharu Arizaaf61c3b2018-10-10 18:35:12 -0700155static void
156test_extents_cff2_vsindex (void)
157{
Michiharu Ariza3d3df552018-10-22 15:23:39 -0700158 hb_face_t *face = hb_test_open_font_file ("fonts/AdobeVFPrototype_vsindex.otf");
Michiharu Arizaaf61c3b2018-10-10 18:35:12 -0700159 g_assert (face);
160 hb_font_t *font = hb_font_create (face);
161 hb_face_destroy (face);
162 g_assert (font);
163 hb_ot_font_set_funcs (font);
164
165 hb_glyph_extents_t extents;
166 float coords[2] = { 800.0f, 50.0f };
167 hb_font_set_var_coords_design (font, coords, 2);
Michiharu Arizaba055a82018-10-22 16:20:04 -0700168 hb_bool_t result = hb_font_get_glyph_extents (font, 1, &extents);
Michiharu Arizaaf61c3b2018-10-10 18:35:12 -0700169 g_assert (result);
170
171 g_assert_cmpint (extents.x_bearing, ==, 11);
172 g_assert_cmpint (extents.y_bearing, ==, 656);
173 g_assert_cmpint (extents.width, ==, 653);
174 g_assert_cmpint (extents.height, ==, -656);
175
176 result = hb_font_get_glyph_extents (font, 2, &extents);
177 g_assert (result);
178
179 g_assert_cmpint (extents.x_bearing, ==, 7);
180 g_assert_cmpint (extents.y_bearing, ==, 669);
181 g_assert_cmpint (extents.width, ==, 650);
182 g_assert_cmpint (extents.height, ==, -669);
183
184 hb_font_destroy (font);
185}
186
Michiharu Ariza6238edb2018-10-04 13:59:36 -0700187int
188main (int argc, char **argv)
189{
190 hb_test_init (&argc, &argv);
191
192 hb_test_add (test_extents_cff1);
Michiharu Arizae555ed92018-10-18 13:04:41 -0700193 hb_test_add (test_extents_cff1_flex);
Michiharu Ariza3787c072018-11-14 13:38:03 -0800194 hb_test_add (test_extents_cff1_seac);
Michiharu Arizab51418f2018-10-08 15:05:36 -0700195 hb_test_add (test_extents_cff2);
Michiharu Arizaaf61c3b2018-10-10 18:35:12 -0700196 hb_test_add (test_extents_cff2_vsindex);
Michiharu Ariza6238edb2018-10-04 13:59:36 -0700197
198 return hb_test_run ();
199}