test-ot-color.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. #include "hb-test.h"
  28. #include <hb-ot.h>
  29. /* Unit tests for hb-ot-color.h */
  30. /* Test font with the following CPAL v0 table, as TTX and manual disassembly:
  31. <CPAL>
  32. <version value="0"/>
  33. <numPaletteEntries value="2"/>
  34. <palette index="0">
  35. <color index="0" value="#000000FF"/>
  36. <color index="1" value="#66CCFFFF"/>
  37. </palette>
  38. <palette index="1">
  39. <color index="0" value="#000000FF"/>
  40. <color index="1" value="#800000FF"/>
  41. </palette>
  42. </CPAL>
  43. 0 | 0000 # version=0
  44. 2 | 0002 # numPaletteEntries=2
  45. 4 | 0002 # numPalettes=2
  46. 6 | 0004 # numColorRecords=4
  47. 8 | 00000010 # offsetToFirstColorRecord=16
  48. 12 | 0000 0002 # colorRecordIndex=[0, 2]
  49. 16 | 000000ff ffcc66ff # colorRecord #0, #1 (BGRA)
  50. 24 | 000000ff 000080ff # colorRecord #2, #3 (BGRA)
  51. */
  52. static hb_face_t *cpal_v0 = NULL;
  53. /* Test font with the following CPAL v1 table, as TTX and manual disassembly:
  54. <CPAL>
  55. <version value="1"/>
  56. <numPaletteEntries value="2"/>
  57. <palette index="0" label="257" type="2">
  58. <color index="0" value="#000000FF"/>
  59. <color index="1" value="#66CCFFFF"/>
  60. </palette>
  61. <palette index="1" label="65535" type="1">
  62. <color index="0" value="#000000FF"/>
  63. <color index="1" value="#FFCC66FF"/>
  64. </palette>
  65. <palette index="2" label="258" type="0">
  66. <color index="0" value="#000000FF"/>
  67. <color index="1" value="#800000FF"/>
  68. </palette>
  69. <paletteEntryLabels>
  70. <label index="0" value="65535"/>
  71. <label index="1" value="256"/>
  72. </paletteEntryLabels>
  73. </CPAL>
  74. 0 | 0001 # version=1
  75. 2 | 0002 # numPaletteEntries=2
  76. 4 | 0003 # numPalettes=3
  77. 6 | 0006 # numColorRecords=6
  78. 8 | 0000001e # offsetToFirstColorRecord=30
  79. 12 | 0000 0002 0004 # colorRecordIndex=[0, 2, 4]
  80. 18 | 00000036 # offsetToPaletteTypeArray=54
  81. 22 | 00000042 # offsetToPaletteLabelArray=66
  82. 26 | 00000048 # offsetToPaletteEntryLabelArray=72
  83. 30 | 000000ff ffcc66ff 000000ff # colorRecord #0, #1, #2 (BGRA)
  84. 42 | 66ccffff 000000ff 000080ff # colorRecord #3, #4, #5 (BGRA)
  85. 54 | 00000002 00000001 00000000 # paletteFlags=[2, 1, 0]
  86. 66 | 0101 ffff 0102 # paletteName=[257, 0xffff, 258]
  87. 72 | ffff 0100 # paletteEntryLabel=[0xffff, 256]
  88. */
  89. static hb_face_t *cpal_v1 = NULL;
  90. static hb_face_t *cpal = NULL;
  91. static hb_face_t *cbdt = NULL;
  92. static hb_face_t *sbix = NULL;
  93. static hb_face_t *svg = NULL;
  94. static hb_face_t *empty = NULL;
  95. static hb_face_t *colrv1 = NULL;
  96. #define assert_color_rgba(colors, i, r, g, b, a) G_STMT_START { \
  97. const hb_color_t *_colors = (colors); \
  98. const size_t _i = (i); \
  99. const uint8_t red = (r), green = (g), blue = (b), alpha = (a); \
  100. if (hb_color_get_red (_colors[_i]) != red) { \
  101. g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
  102. "colors[" #i "]", _colors[_i], "==", red, 'x'); \
  103. } \
  104. if (hb_color_get_green (_colors[_i]) != green) { \
  105. g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
  106. "colors[" #i "]", _colors[_i], "==", green, 'x'); \
  107. } \
  108. if (hb_color_get_blue (_colors[_i]) != blue) { \
  109. g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
  110. "colors[" #i "]", colors[_i], "==", blue, 'x'); \
  111. } \
  112. if (hb_color_get_alpha (_colors[_i]) != alpha) { \
  113. g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
  114. "colors[" #i "]", _colors[_i], "==", alpha, 'x'); \
  115. } \
  116. } G_STMT_END
  117. static void
  118. test_hb_ot_color_palette_get_count (void)
  119. {
  120. g_assert_cmpint (hb_ot_color_palette_get_count (hb_face_get_empty()), ==, 0);
  121. g_assert_cmpint (hb_ot_color_palette_get_count (cpal_v0), ==, 2);
  122. g_assert_cmpint (hb_ot_color_palette_get_count (cpal_v1), ==, 3);
  123. }
  124. static void
  125. test_hb_ot_color_palette_get_name_id_empty (void)
  126. {
  127. /* numPalettes=0, so all calls are for out-of-bounds palette indices */
  128. g_assert_cmpint (hb_ot_color_palette_get_name_id (hb_face_get_empty(), 0), ==, HB_OT_NAME_ID_INVALID);
  129. g_assert_cmpint (hb_ot_color_palette_get_name_id (hb_face_get_empty(), 1), ==, HB_OT_NAME_ID_INVALID);
  130. }
  131. static void
  132. test_hb_ot_color_palette_get_name_id_v0 (void)
  133. {
  134. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 0), ==, HB_OT_NAME_ID_INVALID);
  135. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 1), ==, HB_OT_NAME_ID_INVALID);
  136. /* numPalettes=2, so palette #2 is out of bounds */
  137. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v0, 2), ==, HB_OT_NAME_ID_INVALID);
  138. }
  139. static void
  140. test_hb_ot_color_palette_get_name_id_v1 (void)
  141. {
  142. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 0), ==, 257);
  143. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 1), ==, HB_OT_NAME_ID_INVALID);
  144. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 2), ==, 258);
  145. /* numPalettes=3, so palette #3 is out of bounds */
  146. g_assert_cmpint (hb_ot_color_palette_get_name_id (cpal_v1, 3), ==, HB_OT_NAME_ID_INVALID);
  147. }
  148. static void
  149. test_hb_ot_color_palette_get_flags_empty (void)
  150. {
  151. /* numPalettes=0, so all calls are for out-of-bounds palette indices */
  152. g_assert_cmpint (hb_ot_color_palette_get_flags (hb_face_get_empty(), 0), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  153. g_assert_cmpint (hb_ot_color_palette_get_flags (hb_face_get_empty(), 1), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  154. }
  155. static void
  156. test_hb_ot_color_palette_get_flags_v0 (void)
  157. {
  158. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 0), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  159. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 1), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  160. /* numPalettes=2, so palette #2 is out of bounds */
  161. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 2), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  162. }
  163. static void
  164. test_hb_ot_color_palette_get_flags_v1 (void)
  165. {
  166. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v1, 0), ==, HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_DARK_BACKGROUND);
  167. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v1, 1), ==, HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_LIGHT_BACKGROUND);
  168. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 2), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  169. /* numPalettes=3, so palette #3 is out of bounds */
  170. g_assert_cmpint (hb_ot_color_palette_get_flags (cpal_v0, 3), ==, HB_OT_COLOR_PALETTE_FLAG_DEFAULT);
  171. }
  172. static void
  173. test_hb_ot_color_palette_get_colors_empty (void)
  174. {
  175. g_assert_cmpint (hb_ot_color_palette_get_colors (empty, 0, 0, NULL, NULL), ==, 0);
  176. }
  177. static void
  178. test_hb_ot_color_palette_get_colors_v0 (void)
  179. {
  180. unsigned int num_colors = hb_ot_color_palette_get_colors (cpal_v0, 0, 0, NULL, NULL);
  181. hb_color_t *colors = (hb_color_t*) malloc (num_colors * sizeof (hb_color_t));
  182. size_t colors_size = num_colors * sizeof(*colors);
  183. g_assert_cmpint (num_colors, ==, 2);
  184. /* Palette #0, start_index=0 */
  185. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
  186. g_assert_cmpint (num_colors, ==, 2);
  187. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  188. assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
  189. /* Palette #1, start_index=0 */
  190. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 1, 0, &num_colors, colors), ==, 2);
  191. g_assert_cmpint (num_colors, ==, 2);
  192. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  193. assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
  194. /* Palette #2 (there are only #0 and #1 in the font, so this is out of bounds) */
  195. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 2, 0, &num_colors, colors), ==, 0);
  196. /* Palette #0, start_index=1 */
  197. memset(colors, 0x33, colors_size);
  198. num_colors = 2;
  199. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 1, &num_colors, colors), ==, 2);
  200. g_assert_cmpint (num_colors, ==, 1);
  201. assert_color_rgba (colors, 0, 0x66, 0xcc, 0xff, 0xff);
  202. assert_color_rgba (colors, 1, 0x33, 0x33, 0x33, 0x33); /* untouched */
  203. /* Palette #0, start_index=0, pretend that we have only allocated space for 1 color */
  204. memset(colors, 0x44, colors_size);
  205. num_colors = 1;
  206. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
  207. g_assert_cmpint (num_colors, ==, 1);
  208. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  209. assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44); /* untouched */
  210. /* start_index > numPaletteEntries */
  211. memset (colors, 0x44, colors_size);
  212. num_colors = 2;
  213. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v0, 0, 9876, &num_colors, colors), ==, 2);
  214. g_assert_cmpint (num_colors, ==, 0);
  215. assert_color_rgba (colors, 0, 0x44, 0x44, 0x44, 0x44); /* untouched */
  216. assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44); /* untouched */
  217. free (colors);
  218. }
  219. static void
  220. test_hb_ot_color_palette_get_colors_v1 (void)
  221. {
  222. hb_color_t colors[3];
  223. unsigned int num_colors = hb_ot_color_palette_get_colors (cpal_v1, 0, 0, NULL, NULL);
  224. size_t colors_size = 3 * sizeof (hb_color_t);
  225. g_assert_cmpint (num_colors, ==, 2);
  226. /* Palette #0, start_index=0 */
  227. memset (colors, 0x77, colors_size);
  228. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 0, 0, &num_colors, colors), ==, 2);
  229. g_assert_cmpint (num_colors, ==, 2);
  230. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  231. assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
  232. assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
  233. /* Palette #1, start_index=0 */
  234. memset (colors, 0x77, colors_size);
  235. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 1, 0, &num_colors, colors), ==, 2);
  236. g_assert_cmpint (num_colors, ==, 2);
  237. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  238. assert_color_rgba (colors, 1, 0xff, 0xcc, 0x66, 0xff);
  239. assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
  240. /* Palette #2, start_index=0 */
  241. memset (colors, 0x77, colors_size);
  242. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 2, 0, &num_colors, colors), ==, 2);
  243. g_assert_cmpint (num_colors, ==, 2);
  244. assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
  245. assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
  246. assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
  247. /* Palette #3 (out of bounds), start_index=0 */
  248. memset (colors, 0x77, colors_size);
  249. g_assert_cmpint (hb_ot_color_palette_get_colors (cpal_v1, 3, 0, &num_colors, colors), ==, 0);
  250. g_assert_cmpint (num_colors, ==, 0);
  251. assert_color_rgba (colors, 0, 0x77, 0x77, 0x77, 0x77); /* untouched */
  252. assert_color_rgba (colors, 1, 0x77, 0x77, 0x77, 0x77); /* untouched */
  253. assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
  254. }
  255. static void
  256. test_hb_ot_color_palette_color_get_name_id (void)
  257. {
  258. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 0), ==, HB_OT_NAME_ID_INVALID);
  259. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 1), ==, HB_OT_NAME_ID_INVALID);
  260. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (empty, 2), ==, HB_OT_NAME_ID_INVALID);
  261. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 0), ==, HB_OT_NAME_ID_INVALID);
  262. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 1), ==, HB_OT_NAME_ID_INVALID);
  263. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v0, 2), ==, HB_OT_NAME_ID_INVALID);
  264. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 0), ==, HB_OT_NAME_ID_INVALID);
  265. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 1), ==, 256);
  266. g_assert_cmpuint (hb_ot_color_palette_color_get_name_id (cpal_v1, 2), ==, HB_OT_NAME_ID_INVALID);
  267. }
  268. static void
  269. test_hb_ot_color_glyph_get_layers (void)
  270. {
  271. hb_ot_color_layer_t layers[1];
  272. unsigned int count = 1;
  273. unsigned int num_layers;
  274. g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 0, 0,
  275. NULL, NULL), ==, 0);
  276. g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 1, 0,
  277. NULL, NULL), ==, 0);
  278. g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 2, 0,
  279. NULL, NULL), ==, 2);
  280. num_layers = hb_ot_color_glyph_get_layers (cpal_v1, 2, 0, &count, layers);
  281. g_assert_cmpuint (num_layers, ==, 2);
  282. g_assert_cmpuint (count, ==, 1);
  283. g_assert_cmpuint (layers[0].glyph, ==, 3);
  284. g_assert_cmpuint (layers[0].color_index, ==, 1);
  285. count = 1;
  286. hb_ot_color_glyph_get_layers (cpal_v1, 2, 1, &count, layers);
  287. g_assert_cmpuint (num_layers, ==, 2);
  288. g_assert_cmpuint (count, ==, 1);
  289. g_assert_cmpuint (layers[0].glyph, ==, 4);
  290. g_assert_cmpuint (layers[0].color_index, ==, 0);
  291. }
  292. static void
  293. test_hb_ot_color_has_data (void)
  294. {
  295. g_assert (hb_ot_color_has_layers (empty) == FALSE);
  296. g_assert (hb_ot_color_has_layers (cpal_v0) == TRUE);
  297. g_assert (hb_ot_color_has_layers (cpal_v1) == TRUE);
  298. g_assert (hb_ot_color_has_layers (cpal) == TRUE);
  299. g_assert (hb_ot_color_has_layers (cbdt) == FALSE);
  300. g_assert (hb_ot_color_has_layers (sbix) == FALSE);
  301. g_assert (hb_ot_color_has_layers (svg) == FALSE);
  302. g_assert (hb_ot_color_has_layers (colrv1) == FALSE);
  303. g_assert (hb_ot_color_has_palettes (empty) == FALSE);
  304. g_assert (hb_ot_color_has_palettes (cpal_v0) == TRUE);
  305. g_assert (hb_ot_color_has_palettes (cpal_v1) == TRUE);
  306. g_assert (hb_ot_color_has_palettes (cpal) == TRUE);
  307. g_assert (hb_ot_color_has_palettes (cbdt) == FALSE);
  308. g_assert (hb_ot_color_has_palettes (sbix) == FALSE);
  309. g_assert (hb_ot_color_has_palettes (svg) == FALSE);
  310. g_assert (hb_ot_color_has_palettes (colrv1) == TRUE);
  311. g_assert (hb_ot_color_has_svg (empty) == FALSE);
  312. g_assert (hb_ot_color_has_svg (cpal_v0) == FALSE);
  313. g_assert (hb_ot_color_has_svg (cpal_v1) == FALSE);
  314. g_assert (hb_ot_color_has_svg (cpal) == FALSE);
  315. g_assert (hb_ot_color_has_svg (cbdt) == FALSE);
  316. g_assert (hb_ot_color_has_svg (sbix) == FALSE);
  317. g_assert (hb_ot_color_has_svg (svg) == TRUE);
  318. g_assert (hb_ot_color_has_svg (colrv1) == FALSE);
  319. g_assert (hb_ot_color_has_png (empty) == FALSE);
  320. g_assert (hb_ot_color_has_png (cpal_v0) == FALSE);
  321. g_assert (hb_ot_color_has_png (cpal_v1) == FALSE);
  322. g_assert (hb_ot_color_has_png (cpal) == FALSE);
  323. g_assert (hb_ot_color_has_png (cbdt) == TRUE);
  324. g_assert (hb_ot_color_has_png (sbix) == TRUE);
  325. g_assert (hb_ot_color_has_png (svg) == FALSE);
  326. g_assert (hb_ot_color_has_png (colrv1) == FALSE);
  327. g_assert (hb_ot_color_has_paint (empty) == FALSE);
  328. g_assert (hb_ot_color_has_paint (cpal_v0) == FALSE);
  329. g_assert (hb_ot_color_has_paint (cpal_v1) == FALSE);
  330. g_assert (hb_ot_color_has_paint (cpal) == FALSE);
  331. g_assert (hb_ot_color_has_paint (cbdt) == FALSE);
  332. g_assert (hb_ot_color_has_paint (sbix) == FALSE);
  333. g_assert (hb_ot_color_has_paint (svg) == FALSE);
  334. g_assert (hb_ot_color_has_paint (colrv1) == TRUE);
  335. }
  336. static void
  337. test_hb_ot_color_glyph_has_paint (void)
  338. {
  339. g_assert (hb_ot_color_has_paint (colrv1));
  340. g_assert (hb_ot_color_glyph_has_paint (colrv1, 10));
  341. g_assert (!hb_ot_color_glyph_has_paint (colrv1, 20));
  342. }
  343. static void
  344. test_hb_ot_color_svg (void)
  345. {
  346. hb_blob_t *blob;
  347. unsigned int length;
  348. const char *data;
  349. blob = hb_ot_color_glyph_reference_svg (svg, 0);
  350. g_assert (hb_blob_get_length (blob) == 0);
  351. blob = hb_ot_color_glyph_reference_svg (svg, 1);
  352. data = hb_blob_get_data (blob, &length);
  353. g_assert_cmpuint (length, ==, 146);
  354. g_assert (strncmp (data, "<?xml", 4) == 0);
  355. g_assert (strncmp (data + 140, "</svg>", 5) == 0);
  356. hb_blob_destroy (blob);
  357. blob = hb_ot_color_glyph_reference_svg (empty, 0);
  358. g_assert (hb_blob_get_length (blob) == 0);
  359. }
  360. static void
  361. test_hb_ot_color_png (void)
  362. {
  363. hb_blob_t *blob;
  364. unsigned int length;
  365. const char *data;
  366. hb_glyph_extents_t extents;
  367. hb_font_t *cbdt_font;
  368. /* sbix */
  369. hb_font_t *sbix_font;
  370. sbix_font = hb_font_create (sbix);
  371. blob = hb_ot_color_glyph_reference_png (sbix_font, 0);
  372. hb_font_get_glyph_extents (sbix_font, 0, &extents);
  373. g_assert_cmpint (extents.x_bearing, ==, 0);
  374. g_assert_cmpint (extents.y_bearing, ==, 0);
  375. g_assert_cmpint (extents.width, ==, 0);
  376. g_assert_cmpint (extents.height, ==, 0);
  377. g_assert (hb_blob_get_length (blob) == 0);
  378. blob = hb_ot_color_glyph_reference_png (sbix_font, 1);
  379. data = hb_blob_get_data (blob, &length);
  380. g_assert_cmpuint (length, ==, 224);
  381. g_assert (strncmp (data + 1, "PNG", 3) == 0);
  382. hb_font_get_glyph_extents (sbix_font, 1, &extents);
  383. g_assert_cmpint (extents.x_bearing, ==, 0);
  384. g_assert_cmpint (extents.y_bearing, ==, 800);
  385. g_assert_cmpint (extents.width, ==, 800);
  386. g_assert_cmpint (extents.height, ==, -800);
  387. hb_blob_destroy (blob);
  388. hb_font_destroy (sbix_font);
  389. /* cbdt */
  390. cbdt_font = hb_font_create (cbdt);
  391. blob = hb_ot_color_glyph_reference_png (cbdt_font, 0);
  392. g_assert (hb_blob_get_length (blob) == 0);
  393. blob = hb_ot_color_glyph_reference_png (cbdt_font, 1);
  394. data = hb_blob_get_data (blob, &length);
  395. g_assert_cmpuint (length, ==, 88);
  396. g_assert (strncmp (data + 1, "PNG", 3) == 0);
  397. hb_font_get_glyph_extents (cbdt_font, 1, &extents);
  398. g_assert_cmpint (extents.x_bearing, ==, 0);
  399. g_assert_cmpint (extents.y_bearing, ==, 1024);
  400. g_assert_cmpint (extents.width, ==, 1024);
  401. g_assert_cmpint (extents.height, ==, -1024);
  402. hb_blob_destroy (blob);
  403. hb_font_destroy (cbdt_font);
  404. }
  405. int
  406. main (int argc, char **argv)
  407. {
  408. int status = 0;
  409. hb_test_init (&argc, &argv);
  410. cpal_v0 = hb_test_open_font_file ("fonts/cpal-v0.ttf");
  411. cpal_v1 = hb_test_open_font_file ("fonts/cpal-v1.ttf");
  412. cpal = hb_test_open_font_file ("fonts/chromacheck-colr.ttf");
  413. cbdt = hb_test_open_font_file ("fonts/chromacheck-cbdt.ttf");
  414. sbix = hb_test_open_font_file ("fonts/chromacheck-sbix.ttf");
  415. svg = hb_test_open_font_file ("fonts/chromacheck-svg.ttf");
  416. colrv1 = hb_test_open_font_file ("fonts/noto_handwriting-cff2_colr_1.otf");
  417. empty = hb_face_get_empty ();
  418. hb_test_add (test_hb_ot_color_palette_get_count);
  419. hb_test_add (test_hb_ot_color_palette_get_name_id_empty);
  420. hb_test_add (test_hb_ot_color_palette_get_name_id_v0);
  421. hb_test_add (test_hb_ot_color_palette_get_name_id_v1);
  422. hb_test_add (test_hb_ot_color_palette_get_flags_empty);
  423. hb_test_add (test_hb_ot_color_palette_get_flags_v0);
  424. hb_test_add (test_hb_ot_color_palette_get_flags_v1);
  425. hb_test_add (test_hb_ot_color_palette_get_colors_empty);
  426. hb_test_add (test_hb_ot_color_palette_get_colors_v0);
  427. hb_test_add (test_hb_ot_color_palette_get_colors_v1);
  428. hb_test_add (test_hb_ot_color_palette_color_get_name_id);
  429. hb_test_add (test_hb_ot_color_glyph_get_layers);
  430. hb_test_add (test_hb_ot_color_has_data);
  431. hb_test_add (test_hb_ot_color_png);
  432. hb_test_add (test_hb_ot_color_svg);
  433. hb_test_add (test_hb_ot_color_glyph_has_paint);
  434. status = hb_test_run();
  435. hb_face_destroy (cpal_v0);
  436. hb_face_destroy (cpal_v1);
  437. hb_face_destroy (cpal);
  438. hb_face_destroy (cbdt);
  439. hb_face_destroy (sbix);
  440. hb_face_destroy (svg);
  441. hb_face_destroy (colrv1);
  442. return status;
  443. }