• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016  Google, Inc.
3  * Copyright © 2018  Ebrahim Byagowi
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
7  * Permission is hereby granted, without written agreement and without
8  * license or royalty fees, to use, copy, modify, and distribute this
9  * software and its documentation for any purpose, provided that the
10  * above copyright notice and the following two paragraphs appear in
11  * all copies of this software.
12  *
13  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17  * DAMAGE.
18  *
19  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24  *
25  * Google Author(s): Sascha Brawer
26  */
27 
28 #include "hb-test.h"
29 
30 #include <hb-ot.h>
31 
32 /* Unit tests for hb-ot-color.h */
33 
34 /* Test font with the following CPAL v0 table, as TTX and manual disassembly:
35 
36   <CPAL>
37     <version value="0"/>
38     <numPaletteEntries value="2"/>
39     <palette index="0">
40       <color index="0" value="#000000FF"/>
41       <color index="1" value="#66CCFFFF"/>
42     </palette>
43     <palette index="1">
44       <color index="0" value="#000000FF"/>
45       <color index="1" value="#800000FF"/>
46     </palette>
47   </CPAL>
48 
49    0 | 0000                           # version=0
50    2 | 0002                           # numPaletteEntries=2
51    4 | 0002                           # numPalettes=2
52    6 | 0004                           # numColorRecords=4
53    8 | 00000010                       # offsetToFirstColorRecord=16
54   12 | 0000 0002                      # colorRecordIndex=[0, 2]
55   16 | 000000ff ffcc66ff              # colorRecord #0, #1 (BGRA)
56   24 | 000000ff 000080ff              # colorRecord #2, #3 (BGRA)
57  */
58 static hb_face_t *cpal_v0 = NULL;
59 
60 /* Test font with the following CPAL v1 table, as TTX and manual disassembly:
61 
62   <CPAL>
63     <version value="1"/>
64     <numPaletteEntries value="2"/>
65     <palette index="0" label="257" type="2">
66       <color index="0" value="#000000FF"/>
67       <color index="1" value="#66CCFFFF"/>
68     </palette>
69     <palette index="1" label="65535" type="1">
70       <color index="0" value="#000000FF"/>
71       <color index="1" value="#FFCC66FF"/>
72     </palette>
73     <palette index="2" label="258" type="0">
74       <color index="0" value="#000000FF"/>
75       <color index="1" value="#800000FF"/>
76     </palette>
77     <paletteEntryLabels>
78       <label index="0" value="65535"/>
79       <label index="1" value="256"/>
80     </paletteEntryLabels>
81   </CPAL>
82 
83    0 | 0001                           # version=1
84    2 | 0002                           # numPaletteEntries=2
85    4 | 0003                           # numPalettes=3
86    6 | 0006                           # numColorRecords=6
87    8 | 0000001e                       # offsetToFirstColorRecord=30
88   12 | 0000 0002 0004                 # colorRecordIndex=[0, 2, 4]
89   18 | 00000036                       # offsetToPaletteTypeArray=54
90   22 | 00000042                       # offsetToPaletteLabelArray=66
91   26 | 00000048                       # offsetToPaletteEntryLabelArray=72
92   30 | 000000ff ffcc66ff 000000ff     # colorRecord #0, #1, #2 (BGRA)
93   42 | 66ccffff 000000ff 000080ff     # colorRecord #3, #4, #5 (BGRA)
94   54 | 00000002 00000001 00000000     # paletteFlags=[2, 1, 0]
95   66 | 0101 ffff 0102                 # paletteName=[257, 0xffff, 258]
96   72 | ffff 0100                      # paletteEntryLabel=[0xffff, 256]
97 */
98 static hb_face_t *cpal_v1 = NULL;
99 
100 static hb_face_t *cpal = NULL;
101 static hb_face_t *cbdt = NULL;
102 static hb_face_t *sbix = NULL;
103 static hb_face_t *svg = NULL;
104 static hb_face_t *empty = NULL;
105 static hb_face_t *colrv1 = NULL;
106 
107 #define assert_color_rgba(colors, i, r, g, b, a) G_STMT_START {	\
108   const hb_color_t *_colors = (colors); \
109   const size_t _i = (i); \
110   const uint8_t red = (r), green = (g), blue = (b), alpha = (a); \
111   if (hb_color_get_red (_colors[_i]) != red) { \
112     g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
113 				"colors[" #i "]", _colors[_i], "==", red, 'x'); \
114   } \
115   if (hb_color_get_green (_colors[_i]) != green) { \
116     g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
117 				"colors[" #i "]", _colors[_i], "==", green, 'x'); \
118   } \
119   if (hb_color_get_blue (_colors[_i]) != blue) { \
120     g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
121 				"colors[" #i "]", colors[_i], "==", blue, 'x'); \
122   } \
123   if (hb_color_get_alpha (_colors[_i]) != alpha) { \
124     g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
125 				"colors[" #i "]", _colors[_i], "==", alpha, 'x'); \
126   } \
127 } G_STMT_END
128 
129 
130 static void
test_hb_ot_color_palette_get_count(void)131 test_hb_ot_color_palette_get_count (void)
132 {
133   g_assert_cmpint (hb_ot_color_palette_get_count (hb_face_get_empty()), ==, 0);
134   g_assert_cmpint (hb_ot_color_palette_get_count (cpal_v0), ==, 2);
135   g_assert_cmpint (hb_ot_color_palette_get_count (cpal_v1), ==, 3);
136 }
137 
138 
139 static void
test_hb_ot_color_palette_get_name_id_empty(void)140 test_hb_ot_color_palette_get_name_id_empty (void)
141 {
142   /* numPalettes=0, so all calls are for out-of-bounds palette indices */
143   g_assert_cmpint (hb_ot_color_palette_get_name_id (hb_face_get_empty(), 0), ==, HB_OT_NAME_ID_INVALID);
144   g_assert_cmpint (hb_ot_color_palette_get_name_id (hb_face_get_empty(), 1), ==, HB_OT_NAME_ID_INVALID);
145 }
146 
147 
148 static void
test_hb_ot_color_palette_get_name_id_v0(void)149 test_hb_ot_color_palette_get_name_id_v0 (void)
150 {
151   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 0), ==, HB_OT_NAME_ID_INVALID);
152   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 1), ==, HB_OT_NAME_ID_INVALID);
153 
154   /* numPalettes=2, so palette #2 is out of bounds */
155   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 2), ==, HB_OT_NAME_ID_INVALID);
156 }
157 
158 
159 static void
test_hb_ot_color_palette_get_name_id_v1(void)160 test_hb_ot_color_palette_get_name_id_v1 (void)
161 {
162   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 0), ==, 257);
163   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 1), ==, HB_OT_NAME_ID_INVALID);
164   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 2), ==, 258);
165 
166   /* numPalettes=3, so palette #3 is out of bounds */
167   g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 3), ==, HB_OT_NAME_ID_INVALID);
168 }
169 
170 
171 static void
test_hb_ot_color_palette_get_flags_empty(void)172 test_hb_ot_color_palette_get_flags_empty (void)
173 {
174   /* numPalettes=0, so all calls are for out-of-bounds palette indices */
175   g_assert_cmpint (hb_ot_color_palette_get_flags (hb_face_get_empty(), 0), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
176   g_assert_cmpint (hb_ot_color_palette_get_flags (hb_face_get_empty(), 1), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
177 }
178 
179 
180 static void
test_hb_ot_color_palette_get_flags_v0(void)181 test_hb_ot_color_palette_get_flags_v0 (void)
182 {
183   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 0), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
184   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 1), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
185 
186   /* numPalettes=2, so palette #2 is out of bounds */
187   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 2), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
188 }
189 
190 
191 static void
test_hb_ot_color_palette_get_flags_v1(void)192 test_hb_ot_color_palette_get_flags_v1 (void)
193 {
194   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v1, 0), ==, HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_DARK_BACKGROUND);
195   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v1, 1), ==, HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_LIGHT_BACKGROUND);
196   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 2), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
197 
198   /* numPalettes=3, so palette #3 is out of bounds */
199   g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 3), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
200 }
201 
202 
203 static void
test_hb_ot_color_palette_get_colors_empty(void)204 test_hb_ot_color_palette_get_colors_empty (void)
205 {
206   g_assert_cmpint (hb_ot_color_palette_get_colors (empty, 0, 0, NULL, NULL), ==, 0);
207 }
208 
209 
210 static void
test_hb_ot_color_palette_get_colors_v0(void)211 test_hb_ot_color_palette_get_colors_v0 (void)
212 {
213   unsigned int num_colors = hb_ot_color_palette_get_colors (cpal_v0, 0, 0, NULL, NULL);
214   hb_color_t *colors = (hb_color_t*) malloc (num_colors * sizeof (hb_color_t));
215   size_t colors_size = num_colors * sizeof(*colors);
216   g_assert_cmpint (num_colors, ==, 2);
217 
218   /* Palette #0, start_index=0 */
219   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
220   g_assert_cmpint (num_colors, ==, 2);
221   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
222   assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
223 
224   /* Palette #1, start_index=0 */
225   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 1, 0, &num_colors, colors), ==, 2);
226   g_assert_cmpint (num_colors, ==, 2);
227   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
228   assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
229 
230   /* Palette #2 (there are only #0 and #1 in the font, so this is out of bounds) */
231   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 2, 0, &num_colors, colors), ==, 0);
232 
233   /* Palette #0, start_index=1 */
234   memset(colors, 0x33, colors_size);
235   num_colors = 2;
236   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 1, &num_colors, colors), ==, 2);
237   g_assert_cmpint (num_colors, ==, 1);
238   assert_color_rgba (colors, 0, 0x66, 0xcc, 0xff, 0xff);
239   assert_color_rgba (colors, 1, 0x33, 0x33, 0x33, 0x33);  /* untouched */
240 
241   /* Palette #0, start_index=0, pretend that we have only allocated space for 1 color */
242   memset(colors, 0x44, colors_size);
243   num_colors = 1;
244   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
245   g_assert_cmpint (num_colors, ==, 1);
246   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
247   assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44);  /* untouched */
248 
249   /* start_index > numPaletteEntries */
250   memset (colors, 0x44, colors_size);
251   num_colors = 2;
252   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 9876, &num_colors, colors), ==, 2);
253   g_assert_cmpint (num_colors, ==, 0);
254   assert_color_rgba (colors, 0, 0x44, 0x44, 0x44, 0x44);  /* untouched */
255   assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44);  /* untouched */
256 
257   free (colors);
258 }
259 
260 
261 static void
test_hb_ot_color_palette_get_colors_v1(void)262 test_hb_ot_color_palette_get_colors_v1 (void)
263 {
264   hb_color_t colors[3];
265   unsigned int num_colors = hb_ot_color_palette_get_colors (cpal_v1, 0, 0, NULL, NULL);
266   size_t colors_size = 3 * sizeof (hb_color_t);
267   g_assert_cmpint (num_colors, ==, 2);
268 
269   /* Palette #0, start_index=0 */
270   memset (colors, 0x77, colors_size);
271   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 0, 0, &num_colors, colors), ==, 2);
272   g_assert_cmpint (num_colors, ==, 2);
273   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
274   assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
275   assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77);  /* untouched */
276 
277   /* Palette #1, start_index=0 */
278   memset (colors, 0x77, colors_size);
279   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 1, 0, &num_colors, colors), ==, 2);
280   g_assert_cmpint (num_colors, ==, 2);
281   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
282   assert_color_rgba (colors, 1, 0xff, 0xcc, 0x66, 0xff);
283   assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77);  /* untouched */
284 
285   /* Palette #2, start_index=0 */
286   memset (colors, 0x77, colors_size);
287   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 2, 0, &num_colors, colors), ==, 2);
288   g_assert_cmpint (num_colors, ==, 2);
289   assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
290   assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
291   assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77);  /* untouched */
292 
293   /* Palette #3 (out of bounds), start_index=0 */
294   memset (colors, 0x77, colors_size);
295   g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 3, 0, &num_colors, colors), ==, 0);
296   g_assert_cmpint (num_colors, ==, 0);
297   assert_color_rgba (colors, 0, 0x77, 0x77, 0x77, 0x77);  /* untouched */
298   assert_color_rgba (colors, 1, 0x77, 0x77, 0x77, 0x77);  /* untouched */
299   assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77);  /* untouched */
300 }
301 
302 
303 static void
test_hb_ot_color_palette_color_get_name_id(void)304 test_hb_ot_color_palette_color_get_name_id (void)
305 {
306   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 0), ==, HB_OT_NAME_ID_INVALID);
307   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 1), ==, HB_OT_NAME_ID_INVALID);
308   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 2), ==, HB_OT_NAME_ID_INVALID);
309   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 0), ==, HB_OT_NAME_ID_INVALID);
310   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 1), ==, HB_OT_NAME_ID_INVALID);
311   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 2), ==, HB_OT_NAME_ID_INVALID);
312   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 0), ==, HB_OT_NAME_ID_INVALID);
313   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 1), ==, 256);
314   g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 2), ==, HB_OT_NAME_ID_INVALID);
315 }
316 
317 
318 static void
test_hb_ot_color_glyph_get_layers(void)319 test_hb_ot_color_glyph_get_layers (void)
320 {
321   hb_ot_color_layer_t layers[1];
322   unsigned int count = 1;
323   unsigned int num_layers;
324 
325   g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 0, 0,
326 						  NULL, NULL), ==, 0);
327   g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 1, 0,
328 						  NULL, NULL), ==, 0);
329   g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 2, 0,
330 						  NULL, NULL), ==, 2);
331 
332   num_layers = hb_ot_color_glyph_get_layers (cpal_v1, 2, 0, &count, layers);
333 
334   g_assert_cmpuint (num_layers, ==, 2);
335   g_assert_cmpuint (count, ==, 1);
336   g_assert_cmpuint (layers[0].glyph, ==, 3);
337   g_assert_cmpuint (layers[0].color_index, ==, 1);
338 
339   count = 1;
340   hb_ot_color_glyph_get_layers (cpal_v1, 2, 1, &count, layers);
341 
342   g_assert_cmpuint (num_layers, ==, 2);
343   g_assert_cmpuint (count, ==, 1);
344   g_assert_cmpuint (layers[0].glyph, ==, 4);
345   g_assert_cmpuint (layers[0].color_index, ==, 0);
346 }
347 
348 static void
test_hb_ot_color_has_data(void)349 test_hb_ot_color_has_data (void)
350 {
351   g_assert (hb_ot_color_has_layers (empty) == FALSE);
352   g_assert (hb_ot_color_has_layers (cpal_v0) == TRUE);
353   g_assert (hb_ot_color_has_layers (cpal_v1) == TRUE);
354   g_assert (hb_ot_color_has_layers (cpal) == TRUE);
355   g_assert (hb_ot_color_has_layers (cbdt) == FALSE);
356   g_assert (hb_ot_color_has_layers (sbix) == FALSE);
357   g_assert (hb_ot_color_has_layers (svg) == FALSE);
358   g_assert (hb_ot_color_has_layers (colrv1) == FALSE);
359 
360   g_assert (hb_ot_color_has_palettes (empty) == FALSE);
361   g_assert (hb_ot_color_has_palettes (cpal_v0) == TRUE);
362   g_assert (hb_ot_color_has_palettes (cpal_v1) == TRUE);
363   g_assert (hb_ot_color_has_palettes (cpal) == TRUE);
364   g_assert (hb_ot_color_has_palettes (cbdt) == FALSE);
365   g_assert (hb_ot_color_has_palettes (sbix) == FALSE);
366   g_assert (hb_ot_color_has_palettes (svg) == FALSE);
367   g_assert (hb_ot_color_has_palettes (colrv1) == TRUE);
368 
369   g_assert (hb_ot_color_has_svg (empty) == FALSE);
370   g_assert (hb_ot_color_has_svg (cpal_v0) == FALSE);
371   g_assert (hb_ot_color_has_svg (cpal_v1) == FALSE);
372   g_assert (hb_ot_color_has_svg (cpal) == FALSE);
373   g_assert (hb_ot_color_has_svg (cbdt) == FALSE);
374   g_assert (hb_ot_color_has_svg (sbix) == FALSE);
375   g_assert (hb_ot_color_has_svg (svg) == TRUE);
376   g_assert (hb_ot_color_has_svg (colrv1) == FALSE);
377 
378   g_assert (hb_ot_color_has_png (empty) == FALSE);
379   g_assert (hb_ot_color_has_png (cpal_v0) == FALSE);
380   g_assert (hb_ot_color_has_png (cpal_v1) == FALSE);
381   g_assert (hb_ot_color_has_png (cpal) == FALSE);
382   g_assert (hb_ot_color_has_png (cbdt) == TRUE);
383   g_assert (hb_ot_color_has_png (sbix) == TRUE);
384   g_assert (hb_ot_color_has_png (svg) == FALSE);
385   g_assert (hb_ot_color_has_png (colrv1) == FALSE);
386 
387   g_assert (hb_ot_color_has_paint (empty) == FALSE);
388   g_assert (hb_ot_color_has_paint (cpal_v0) == FALSE);
389   g_assert (hb_ot_color_has_paint (cpal_v1) == FALSE);
390   g_assert (hb_ot_color_has_paint (cpal) == FALSE);
391   g_assert (hb_ot_color_has_paint (cbdt) == FALSE);
392   g_assert (hb_ot_color_has_paint (sbix) == FALSE);
393   g_assert (hb_ot_color_has_paint (svg) == FALSE);
394   g_assert (hb_ot_color_has_paint (colrv1) == TRUE);
395 }
396 
397 static void
test_hb_ot_color_glyph_has_paint(void)398 test_hb_ot_color_glyph_has_paint (void)
399 {
400   g_assert (hb_ot_color_has_paint (colrv1));
401   g_assert (hb_ot_color_glyph_has_paint (colrv1, 10));
402   g_assert (!hb_ot_color_glyph_has_paint (colrv1, 20));
403 }
404 
405 static void
test_hb_ot_color_svg(void)406 test_hb_ot_color_svg (void)
407 {
408   hb_blob_t *blob;
409   unsigned int length;
410   const char *data;
411 
412   blob = hb_ot_color_glyph_reference_svg (svg, 0);
413   g_assert (hb_blob_get_length (blob) == 0);
414 
415   blob = hb_ot_color_glyph_reference_svg (svg, 1);
416   data = hb_blob_get_data (blob, &length);
417   g_assert_cmpuint (length, ==, 146);
418   g_assert (strncmp (data, "<?xml", 4) == 0);
419   g_assert (strncmp (data + 140, "</svg>", 5) == 0);
420   hb_blob_destroy (blob);
421 
422   blob = hb_ot_color_glyph_reference_svg (empty, 0);
423   g_assert (hb_blob_get_length (blob) == 0);
424 }
425 
426 
427 static void
test_hb_ot_color_png(void)428 test_hb_ot_color_png (void)
429 {
430   hb_blob_t *blob;
431   unsigned int length;
432   const char *data;
433   hb_glyph_extents_t extents;
434   hb_font_t *cbdt_font;
435 
436   /* sbix */
437   hb_font_t *sbix_font;
438   sbix_font = hb_font_create (sbix);
439   blob = hb_ot_color_glyph_reference_png (sbix_font, 0);
440   hb_font_get_glyph_extents (sbix_font, 0, &extents);
441   g_assert_cmpint (extents.x_bearing, ==, 0);
442   g_assert_cmpint (extents.y_bearing, ==, 0);
443   g_assert_cmpint (extents.width, ==, 0);
444   g_assert_cmpint (extents.height, ==, 0);
445   g_assert (hb_blob_get_length (blob) == 0);
446 
447   blob = hb_ot_color_glyph_reference_png (sbix_font, 1);
448   data = hb_blob_get_data (blob, &length);
449   g_assert_cmpuint (length, ==, 224);
450   g_assert (strncmp (data + 1, "PNG", 3) == 0);
451   hb_font_get_glyph_extents (sbix_font, 1, &extents);
452   g_assert_cmpint (extents.x_bearing, ==, 0);
453   g_assert_cmpint (extents.y_bearing, ==, 800);
454   g_assert_cmpint (extents.width, ==, 800);
455   g_assert_cmpint (extents.height, ==, -800);
456   hb_blob_destroy (blob);
457   hb_font_destroy (sbix_font);
458 
459   /* cbdt */
460   cbdt_font = hb_font_create (cbdt);
461   blob = hb_ot_color_glyph_reference_png (cbdt_font, 0);
462   g_assert (hb_blob_get_length (blob) == 0);
463 
464   blob = hb_ot_color_glyph_reference_png (cbdt_font, 1);
465   data = hb_blob_get_data (blob, &length);
466   g_assert_cmpuint (length, ==, 88);
467   g_assert (strncmp (data + 1, "PNG", 3) == 0);
468   hb_font_get_glyph_extents (cbdt_font, 1, &extents);
469   g_assert_cmpint (extents.x_bearing, ==, 0);
470   g_assert_cmpint (extents.y_bearing, ==, 1024);
471   g_assert_cmpint (extents.width, ==, 1024);
472   g_assert_cmpint (extents.height, ==, -1024);
473   hb_blob_destroy (blob);
474   hb_font_destroy (cbdt_font);
475 }
476 
477 int
main(int argc,char ** argv)478 main (int argc, char **argv)
479 {
480   int status = 0;
481 
482   hb_test_init (&argc, &argv);
483   cpal_v0 = hb_test_open_font_file ("fonts/cpal-v0.ttf");
484   cpal_v1 = hb_test_open_font_file ("fonts/cpal-v1.ttf");
485   cpal = hb_test_open_font_file ("fonts/chromacheck-colr.ttf");
486   cbdt = hb_test_open_font_file ("fonts/chromacheck-cbdt.ttf");
487   sbix = hb_test_open_font_file ("fonts/chromacheck-sbix.ttf");
488   svg = hb_test_open_font_file ("fonts/chromacheck-svg.ttf");
489   colrv1 = hb_test_open_font_file ("fonts/noto_handwriting-cff2_colr_1.otf");
490   empty = hb_face_get_empty ();
491   hb_test_add (test_hb_ot_color_palette_get_count);
492   hb_test_add (test_hb_ot_color_palette_get_name_id_empty);
493   hb_test_add (test_hb_ot_color_palette_get_name_id_v0);
494   hb_test_add (test_hb_ot_color_palette_get_name_id_v1);
495   hb_test_add (test_hb_ot_color_palette_get_flags_empty);
496   hb_test_add (test_hb_ot_color_palette_get_flags_v0);
497   hb_test_add (test_hb_ot_color_palette_get_flags_v1);
498   hb_test_add (test_hb_ot_color_palette_get_colors_empty);
499   hb_test_add (test_hb_ot_color_palette_get_colors_v0);
500   hb_test_add (test_hb_ot_color_palette_get_colors_v1);
501   hb_test_add (test_hb_ot_color_palette_color_get_name_id);
502   hb_test_add (test_hb_ot_color_glyph_get_layers);
503   hb_test_add (test_hb_ot_color_has_data);
504   hb_test_add (test_hb_ot_color_png);
505   hb_test_add (test_hb_ot_color_svg);
506   hb_test_add (test_hb_ot_color_glyph_has_paint);
507 
508   status = hb_test_run();
509   hb_face_destroy (cpal_v0);
510   hb_face_destroy (cpal_v1);
511   hb_face_destroy (cpal);
512   hb_face_destroy (cbdt);
513   hb_face_destroy (sbix);
514   hb_face_destroy (svg);
515   hb_face_destroy (colrv1);
516   return status;
517 }
518