1 /*
2 * Copyright © 2022 Google, 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 */
25
26 #include "hb-test.h"
27 #include "hb-subset-test.h"
28
29 #include "hb-subset-serialize.h"
30
31 char test_gsub_data[106] = "\x0\x1\x0\x0\x0\xa\x0\x1e\x0\x2c\x0\x1\x6c\x61\x74\x6e\x0\x8\x0\x4\x0\x0\x0\x0\xff\xff\x0\x1\x0\x0\x0\x1\x74\x65\x73\x74\x0\x8\x0\x0\x0\x1\x0\x1\x0\x2\x0\x2a\x0\x6\x0\x5\x0\x0\x0\x1\x0\x8\x0\x1\x0\x8\x0\x1\x0\xe\x0\x1\x0\x1\x0\x1\x0\x1\x0\x4\x0\x2\x0\x1\x0\x2\x0\x1\x0\x0\x0\x1\x0\x0\x0\x1\x0\x8\x0\x1\x0\x6\x0\x1\x0\x1\x0\x1\x0\x2";
32
33 static void
test_hb_repack_with_cy_struct(void)34 test_hb_repack_with_cy_struct (void)
35 {
36 hb_subset_serialize_object_t *hb_objs = calloc (15, sizeof (hb_subset_serialize_object_t));
37
38 hb_objs[0].head = &(test_gsub_data[100]);
39 hb_objs[0].tail = &(test_gsub_data[105]) + 1;
40 hb_objs[0].num_real_links = 0;
41 hb_objs[0].num_virtual_links = 0;
42 hb_objs[0].real_links = NULL;
43 hb_objs[0].virtual_links = NULL;
44
45 hb_objs[1].head = &(test_gsub_data[94]);
46 hb_objs[1].tail = &(test_gsub_data[100]);
47 hb_objs[1].num_real_links = 1;
48 hb_objs[1].num_virtual_links = 0;
49 hb_objs[1].real_links = malloc (sizeof (hb_subset_serialize_link_t));
50 hb_objs[1].real_links[0].width = 2;
51 hb_objs[1].real_links[0].position = 2;
52 hb_objs[1].real_links[0].objidx = 1;
53 hb_objs[1].virtual_links = NULL;
54
55
56 hb_objs[2].head = &(test_gsub_data[86]);
57 hb_objs[2].tail = &(test_gsub_data[94]);
58 hb_objs[2].num_real_links = 1;
59 hb_objs[2].num_virtual_links = 0;
60 hb_objs[2].real_links = malloc (sizeof (hb_subset_serialize_link_t));
61 hb_objs[2].real_links[0].width = 2;
62 hb_objs[2].real_links[0].position = 6;
63 hb_objs[2].real_links[0].objidx = 2;
64 hb_objs[2].virtual_links = NULL;
65
66 hb_objs[3].head = &(test_gsub_data[76]);
67 hb_objs[3].tail = &(test_gsub_data[86]);
68 hb_objs[3].num_real_links = 0;
69 hb_objs[3].num_virtual_links = 0;
70 hb_objs[3].real_links = NULL;
71 hb_objs[3].virtual_links = NULL;
72
73 hb_objs[4].head = &(test_gsub_data[72]);
74 hb_objs[4].tail = &(test_gsub_data[76]);
75 hb_objs[4].num_real_links = 1;
76 hb_objs[4].num_virtual_links = 0;
77 hb_objs[4].real_links = malloc (sizeof (hb_subset_serialize_link_t));
78 hb_objs[4].real_links[0].width = 2;
79 hb_objs[4].real_links[0].position = 2;
80 hb_objs[4].real_links[0].objidx = 4;
81 hb_objs[4].virtual_links = NULL;
82
83 hb_objs[5].head = &(test_gsub_data[66]);
84 hb_objs[5].tail = &(test_gsub_data[72]);
85 hb_objs[5].num_real_links = 0;
86 hb_objs[5].num_virtual_links = 0;
87 hb_objs[5].real_links = NULL;
88 hb_objs[5].virtual_links = NULL;
89
90 hb_objs[6].head = &(test_gsub_data[58]);
91 hb_objs[6].tail = &(test_gsub_data[66]);
92 hb_objs[6].num_real_links = 2;
93 hb_objs[6].num_virtual_links = 0;
94 hb_objs[6].real_links = calloc (2, sizeof (hb_subset_serialize_link_t));
95 hb_objs[6].real_links[0].width = 2;
96 hb_objs[6].real_links[0].position = 6;
97 hb_objs[6].real_links[0].objidx = 5;
98 hb_objs[6].real_links[1].width = 2;
99 hb_objs[6].real_links[1].position = 2;
100 hb_objs[6].real_links[1].objidx = 6;
101 hb_objs[6].virtual_links = NULL;
102
103 hb_objs[7].head = &(test_gsub_data[50]);
104 hb_objs[7].tail = &(test_gsub_data[58]);
105 hb_objs[7].num_real_links = 1;
106 hb_objs[7].num_virtual_links = 0;
107 hb_objs[7].real_links = malloc (sizeof (hb_subset_serialize_link_t));
108 hb_objs[7].real_links[0].width = 2;
109 hb_objs[7].real_links[0].position = 6;
110 hb_objs[7].real_links[0].objidx = 7;
111 hb_objs[7].virtual_links = NULL;
112
113 hb_objs[8].head = &(test_gsub_data[44]);
114 hb_objs[8].tail = &(test_gsub_data[50]);
115 hb_objs[8].num_real_links = 2;
116 hb_objs[8].num_virtual_links = 0;
117 hb_objs[8].real_links = calloc (2, sizeof (hb_subset_serialize_link_t));
118 hb_objs[8].real_links[0].width = 2;
119 hb_objs[8].real_links[0].position = 2;
120 hb_objs[8].real_links[0].objidx = 3;
121 hb_objs[8].real_links[1].width = 2;
122 hb_objs[8].real_links[1].position = 4;
123 hb_objs[8].real_links[1].objidx = 8;
124 hb_objs[8].virtual_links = NULL;
125
126 hb_objs[9].head = &(test_gsub_data[38]);
127 hb_objs[9].tail = &(test_gsub_data[44]);
128 hb_objs[9].num_real_links = 0;
129 hb_objs[9].num_virtual_links = 0;
130 hb_objs[9].real_links = NULL;
131 hb_objs[9].virtual_links = NULL;
132
133 hb_objs[10].head = &(test_gsub_data[30]);
134 hb_objs[10].tail = &(test_gsub_data[38]);
135 hb_objs[10].num_real_links = 1;
136 hb_objs[10].num_virtual_links = 0;
137 hb_objs[10].real_links = malloc (sizeof (hb_subset_serialize_link_t));
138 hb_objs[10].real_links[0].width = 2;
139 hb_objs[10].real_links[0].position = 6;
140 hb_objs[10].real_links[0].objidx = 10;
141 hb_objs[10].virtual_links = NULL;
142
143 hb_objs[11].head = &(test_gsub_data[22]);
144 hb_objs[11].tail = &(test_gsub_data[30]);
145 hb_objs[11].num_real_links = 0;
146 hb_objs[11].num_virtual_links = 0;
147 hb_objs[11].real_links = NULL;
148 hb_objs[11].virtual_links = NULL;
149
150 hb_objs[12].head = &(test_gsub_data[18]);
151 hb_objs[12].tail = &(test_gsub_data[22]);
152 hb_objs[12].num_real_links = 1;
153 hb_objs[12].num_virtual_links = 0;
154 hb_objs[12].real_links = malloc (sizeof (hb_subset_serialize_link_t));
155 hb_objs[12].real_links[0].width = 2;
156 hb_objs[12].real_links[0].position = 0;
157 hb_objs[12].real_links[0].objidx = 12;
158 hb_objs[12].virtual_links = NULL;
159
160 hb_objs[13].head = &(test_gsub_data[10]);
161 hb_objs[13].tail = &(test_gsub_data[18]);
162 hb_objs[13].num_real_links = 1;
163 hb_objs[13].num_virtual_links = 0;
164 hb_objs[13].real_links = malloc (sizeof (hb_subset_serialize_link_t));
165 hb_objs[13].real_links[0].width = 2;
166 hb_objs[13].real_links[0].position = 6;
167 hb_objs[13].real_links[0].objidx = 13;
168 hb_objs[13].virtual_links = NULL;
169
170 hb_objs[14].head = &(test_gsub_data[0]);
171 hb_objs[14].tail = &(test_gsub_data[10]);
172 hb_objs[14].num_real_links = 3;
173 hb_objs[14].num_virtual_links = 0;
174 hb_objs[14].real_links = calloc (3, sizeof (hb_subset_serialize_link_t));
175 hb_objs[14].real_links[0].width = 2;
176 hb_objs[14].real_links[0].position = 8;
177 hb_objs[14].real_links[0].objidx = 9;
178 hb_objs[14].real_links[1].width = 2;
179 hb_objs[14].real_links[1].position = 6;
180 hb_objs[14].real_links[1].objidx = 11;
181 hb_objs[14].real_links[2].width = 2;
182 hb_objs[14].real_links[2].position = 4;
183 hb_objs[14].real_links[2].objidx = 14;
184 hb_objs[14].virtual_links = NULL;
185
186 hb_blob_t *result = hb_subset_serialize_or_fail (HB_TAG_NONE, hb_objs, 15);
187
188 hb_face_t *face_expected = hb_test_open_font_file ("fonts/repacker_expected.otf");
189 hb_blob_t *expected_blob = hb_face_reference_table (face_expected, HB_TAG ('G','S','U','B'));
190 fprintf(stderr, "expected %d bytes, actual %d bytes\n", hb_blob_get_length(expected_blob), hb_blob_get_length (result));
191
192 if (hb_blob_get_length (expected_blob) != 0 ||
193 hb_blob_get_length (result) != 0)
194 hb_test_assert_blobs_equal (expected_blob, result);
195
196 hb_face_destroy (face_expected);
197 hb_blob_destroy (expected_blob);
198 hb_blob_destroy (result);
199
200 for (unsigned i = 0 ; i < 15; i++)
201 {
202 if (hb_objs[i].real_links != NULL)
203 free (hb_objs[i].real_links);
204 }
205
206 free (hb_objs);
207 }
208
209
210 int
main(int argc,char ** argv)211 main (int argc, char **argv)
212 {
213 hb_test_init (&argc, &argv);
214
215 hb_test_add (test_hb_repack_with_cy_struct);
216
217 return hb_test_run();
218 }
219