test-paint.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * Copyright © 2022 Matthias Clasen
  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. #include "hb-test.h"
  25. #include <hb-features.h>
  26. #include <hb-ot.h>
  27. #ifdef HB_HAS_FREETYPE
  28. #include <hb-ft.h>
  29. #if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21300
  30. #include FT_COLOR_H
  31. #endif
  32. #endif
  33. static inline hb_bool_t
  34. have_ft_colrv1 (void)
  35. {
  36. #if defined(HB_HAS_FREETYPE) && (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21300
  37. return TRUE;
  38. #else
  39. return FALSE;
  40. #endif
  41. }
  42. /* Unit tests for hb-paint.h */
  43. /* ---- */
  44. typedef struct {
  45. int level;
  46. GString *string;
  47. } paint_data_t;
  48. static void print (paint_data_t *data, const char *format, ...) G_GNUC_PRINTF (2, 3);
  49. static void
  50. print (paint_data_t *data,
  51. const char *format,
  52. ...)
  53. {
  54. va_list args;
  55. g_string_append_printf (data->string, "%*s", 2 * data->level, "");
  56. va_start (args, format);
  57. g_string_append_vprintf (data->string, format, args);
  58. va_end (args);
  59. g_string_append (data->string, "\n");
  60. }
  61. static void
  62. push_transform (hb_paint_funcs_t *funcs HB_UNUSED,
  63. void *paint_data,
  64. float xx, float yx,
  65. float xy, float yy,
  66. float dx, float dy,
  67. void *user_data HB_UNUSED)
  68. {
  69. paint_data_t *data = paint_data;
  70. print (data, "start transform %.3g %.3g %.3g %.3g %.3g %.3g", xx, yx, xy, yy, dx, dy);
  71. data->level++;
  72. }
  73. static void
  74. pop_transform (hb_paint_funcs_t *funcs HB_UNUSED,
  75. void *paint_data,
  76. void *user_data HB_UNUSED)
  77. {
  78. paint_data_t *data = paint_data;
  79. data->level--;
  80. print (data, "end transform");
  81. }
  82. static hb_bool_t
  83. paint_color_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
  84. void *paint_data,
  85. hb_codepoint_t glyph,
  86. hb_font_t *font HB_UNUSED,
  87. void *user_data HB_UNUSED)
  88. {
  89. paint_data_t *data = paint_data;
  90. print (data, "paint color glyph %u; acting as failed", glyph);
  91. return FALSE;
  92. }
  93. static void
  94. push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED,
  95. void *paint_data,
  96. hb_codepoint_t glyph,
  97. hb_font_t *font HB_UNUSED,
  98. void *user_data HB_UNUSED)
  99. {
  100. paint_data_t *data = paint_data;
  101. print (data, "start clip glyph %u", glyph);
  102. data->level++;
  103. }
  104. static void
  105. push_clip_rectangle (hb_paint_funcs_t *funcs HB_UNUSED,
  106. void *paint_data,
  107. float xmin, float ymin, float xmax, float ymax,
  108. void *user_data HB_UNUSED)
  109. {
  110. paint_data_t *data = paint_data;
  111. print (data, "start clip rectangle %.3g %.3g %.3g %.3g", xmin, ymin, xmax, ymax);
  112. data->level++;
  113. }
  114. static void
  115. pop_clip (hb_paint_funcs_t *funcs HB_UNUSED,
  116. void *paint_data,
  117. void *user_data HB_UNUSED)
  118. {
  119. paint_data_t *data = paint_data;
  120. data->level--;
  121. print (data, "end clip");
  122. }
  123. static void
  124. paint_color (hb_paint_funcs_t *funcs HB_UNUSED,
  125. void *paint_data,
  126. hb_bool_t use_foreground HB_UNUSED,
  127. hb_color_t color,
  128. void *user_data HB_UNUSED)
  129. {
  130. paint_data_t *data = paint_data;
  131. print (data, "solid %d %d %d %d",
  132. hb_color_get_red (color),
  133. hb_color_get_green (color),
  134. hb_color_get_blue (color),
  135. hb_color_get_alpha (color));
  136. }
  137. static hb_bool_t
  138. paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
  139. void *paint_data,
  140. hb_blob_t *blob HB_UNUSED,
  141. unsigned int width,
  142. unsigned int height,
  143. hb_tag_t format,
  144. float slant,
  145. hb_glyph_extents_t *extents,
  146. void *user_data HB_UNUSED)
  147. {
  148. paint_data_t *data = paint_data;
  149. char buf[5] = { 0, };
  150. hb_tag_to_string (format, buf);
  151. print (data, "image type %s size %u %u slant %.3g extents %d %d %d %d\n",
  152. buf, width, height, slant,
  153. extents->x_bearing, extents->y_bearing, extents->width, extents->height);
  154. return TRUE;
  155. }
  156. static void
  157. print_color_line (paint_data_t *data,
  158. hb_color_line_t *color_line)
  159. {
  160. hb_color_stop_t *stops;
  161. unsigned int len;
  162. len = hb_color_line_get_color_stops (color_line, 0, NULL, NULL);
  163. stops = alloca (len * sizeof (hb_color_stop_t));
  164. hb_color_line_get_color_stops (color_line, 0, &len, stops);
  165. print (data, "colors %d", hb_color_line_get_extend (color_line));
  166. data->level += 1;
  167. for (unsigned int i = 0; i < len; i++)
  168. print (data, "%.3g %d %d %d %d",
  169. stops[i].offset,
  170. hb_color_get_red (stops[i].color),
  171. hb_color_get_green (stops[i].color),
  172. hb_color_get_blue (stops[i].color),
  173. hb_color_get_alpha (stops[i].color));
  174. data->level -= 1;
  175. }
  176. static void
  177. paint_linear_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
  178. void *paint_data,
  179. hb_color_line_t *color_line,
  180. float x0, float y0,
  181. float x1, float y1,
  182. float x2, float y2,
  183. void *user_data HB_UNUSED)
  184. {
  185. paint_data_t *data = paint_data;
  186. print (data, "linear gradient");
  187. data->level += 1;
  188. print (data, "p0 %.3g %.3g", x0, y0);
  189. print (data, "p1 %.3g %.3g", x1, y1);
  190. print (data, "p2 %.3g %.3g", x2, y2);
  191. print_color_line (data, color_line);
  192. data->level -= 1;
  193. }
  194. static void
  195. paint_radial_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
  196. void *paint_data,
  197. hb_color_line_t *color_line,
  198. float x0, float y0, float r0,
  199. float x1, float y1, float r1,
  200. void *user_data HB_UNUSED)
  201. {
  202. paint_data_t *data = paint_data;
  203. print (data, "radial gradient");
  204. data->level += 1;
  205. print (data, "p0 %.3g %.3g radius %.3g", x0, y0, r0);
  206. print (data, "p1 %.3g %.3g radius %.3g", x1, y1, r1);
  207. print_color_line (data, color_line);
  208. data->level -= 1;
  209. }
  210. static void
  211. paint_sweep_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
  212. void *paint_data,
  213. hb_color_line_t *color_line,
  214. float cx, float cy,
  215. float start_angle,
  216. float end_angle,
  217. void *user_data HB_UNUSED)
  218. {
  219. paint_data_t *data = paint_data;
  220. print (data, "sweep gradient");
  221. data->level++;
  222. print (data, "center %.3g %.3g", cx, cy);
  223. print (data, "angles %.3g %.3g", start_angle, end_angle);
  224. print_color_line (data, color_line);
  225. data->level -= 1;
  226. }
  227. static void
  228. push_group (hb_paint_funcs_t *funcs HB_UNUSED,
  229. void *paint_data,
  230. void *user_data HB_UNUSED)
  231. {
  232. paint_data_t *data = paint_data;
  233. print (data, "push group");
  234. data->level++;
  235. }
  236. static void
  237. pop_group (hb_paint_funcs_t *funcs HB_UNUSED,
  238. void *paint_data,
  239. hb_paint_composite_mode_t mode,
  240. void *user_data HB_UNUSED)
  241. {
  242. paint_data_t *data = paint_data;
  243. data->level--;
  244. print (data, "pop group mode %d", mode);
  245. }
  246. static hb_paint_funcs_t *
  247. get_test_paint_funcs (void)
  248. {
  249. static hb_paint_funcs_t *funcs = NULL;
  250. if (!funcs)
  251. {
  252. funcs = hb_paint_funcs_create ();
  253. hb_paint_funcs_set_push_transform_func (funcs, push_transform, NULL, NULL);
  254. hb_paint_funcs_set_pop_transform_func (funcs, pop_transform, NULL, NULL);
  255. hb_paint_funcs_set_color_glyph_func (funcs, paint_color_glyph, NULL, NULL);
  256. hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL);
  257. hb_paint_funcs_set_push_clip_rectangle_func (funcs, push_clip_rectangle, NULL, NULL);
  258. hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, NULL, NULL);
  259. hb_paint_funcs_set_push_group_func (funcs, push_group, NULL, NULL);
  260. hb_paint_funcs_set_pop_group_func (funcs, pop_group, NULL, NULL);
  261. hb_paint_funcs_set_color_func (funcs, paint_color, NULL, NULL);
  262. hb_paint_funcs_set_image_func (funcs, paint_image, NULL, NULL);
  263. hb_paint_funcs_set_linear_gradient_func (funcs, paint_linear_gradient, NULL, NULL);
  264. hb_paint_funcs_set_radial_gradient_func (funcs, paint_radial_gradient, NULL, NULL);
  265. hb_paint_funcs_set_sweep_gradient_func (funcs, paint_sweep_gradient, NULL, NULL);
  266. hb_paint_funcs_make_immutable (funcs);
  267. }
  268. return funcs;
  269. }
  270. typedef struct {
  271. const char *font_file;
  272. float slant;
  273. hb_codepoint_t glyph;
  274. unsigned int palette;
  275. const char *output;
  276. } paint_test_t;
  277. #define NOTO_HAND "fonts/noto_handwriting-cff2_colr_1.otf"
  278. #define TEST_GLYPHS "fonts/test_glyphs-glyf_colr_1.ttf"
  279. #define TEST_GLYPHS_VF "fonts/test_glyphs-glyf_colr_1_variable.ttf"
  280. #define BAD_COLRV1 "fonts/bad_colrv1.ttf"
  281. #define ROCHER_ABC "fonts/RocherColorGX.abc.ttf"
  282. /* To verify the rendering visually, use
  283. *
  284. * hb-view --font-slant SLANT --font-palette PALETTE FONT --glyphs [gidGID=0+1000]
  285. *
  286. * where GID is the glyph value of the test.
  287. */
  288. static paint_test_t paint_tests[] = {
  289. /* COLRv1 */
  290. { NOTO_HAND, 0., 10, 0, "hand-10" },
  291. { NOTO_HAND, 0.2f,10, 0, "hand-10.2" },
  292. { TEST_GLYPHS, 0, 6, 0, "test-6" }, // linear gradient
  293. { TEST_GLYPHS, 0, 10, 0, "test-10" }, // sweep gradient
  294. { TEST_GLYPHS, 0, 92, 0, "test-92" }, // radial gradient
  295. { TEST_GLYPHS, 0, 106, 0, "test-106" },
  296. { TEST_GLYPHS, 0, 116, 0, "test-116" }, // compositing
  297. { TEST_GLYPHS, 0, 123, 0, "test-123" },
  298. { TEST_GLYPHS, 0, 154, 0, "test-154" },
  299. { TEST_GLYPHS, 0, 165, 0, "test-165" }, // linear gradient
  300. { TEST_GLYPHS, 0, 175, 0, "test-175" }, // layers
  301. { TEST_GLYPHS_VF, 0, 6, 0, "testvf-6" },
  302. { TEST_GLYPHS_VF, 0, 10, 0, "testvf-10" },
  303. { TEST_GLYPHS_VF, 0, 92, 0, "testvf-92" },
  304. { TEST_GLYPHS_VF, 0, 106, 0, "testvf-106" },
  305. { TEST_GLYPHS_VF, 0, 116, 0, "testvf-116" },
  306. { TEST_GLYPHS_VF, 0, 123, 0, "testvf-123" },
  307. { TEST_GLYPHS_VF, 0, 154, 0, "testvf-154" },
  308. { TEST_GLYPHS_VF, 0, 165, 0, "testvf-165" },
  309. { TEST_GLYPHS_VF, 0, 175, 0, "testvf-175" },
  310. { BAD_COLRV1, 0, 154, 0, "bad-154" }, // recursion
  311. /* COLRv0 */
  312. { ROCHER_ABC, 0.3f, 1, 0, "rocher-1" },
  313. { ROCHER_ABC, 0.3f, 2, 2, "rocher-2" },
  314. { ROCHER_ABC, 0, 3, 200, "rocher-3" },
  315. };
  316. static void
  317. test_hb_paint (gconstpointer d,
  318. hb_bool_t use_ft HB_UNUSED)
  319. {
  320. const paint_test_t *test = d;
  321. hb_face_t *face;
  322. hb_font_t *font;
  323. hb_paint_funcs_t *funcs;
  324. paint_data_t data;
  325. char *file;
  326. char *buffer;
  327. gsize len;
  328. GError *error = NULL;
  329. face = hb_test_open_font_file (test->font_file);
  330. font = hb_font_create (face);
  331. hb_font_set_synthetic_slant (font, test->slant);
  332. #ifdef HB_HAS_FREETYPE
  333. if (use_ft)
  334. hb_ft_font_set_funcs (font);
  335. #endif
  336. funcs = get_test_paint_funcs ();
  337. data.string = g_string_new ("");
  338. data.level = 0;
  339. hb_font_paint_glyph (font, test->glyph, funcs, &data, 0, HB_COLOR (0, 0, 0, 255));
  340. /* Run
  341. *
  342. * GENERATE_DATA=1 G_TEST_SRCDIR=./test/api ./build/test/api/test-paint -p TESTCASE > test/api/results/OUTPUT
  343. *
  344. * to produce the expected results file.
  345. */
  346. if (getenv ("GENERATE_DATA"))
  347. {
  348. g_print ("%s", data.string->str);
  349. exit (0);
  350. }
  351. file = g_test_build_filename (G_TEST_DIST, "results", test->output, NULL);
  352. if (!g_file_get_contents (file, &buffer, &len, &error))
  353. {
  354. g_test_message ("File %s not found.", file);
  355. g_test_fail ();
  356. return;
  357. }
  358. char **lines = g_strsplit (data.string->str, "\n", 0);
  359. char **expected;
  360. if (strstr (buffer, "\r\n"))
  361. expected = g_strsplit (buffer, "\r\n", 0);
  362. else
  363. expected = g_strsplit (buffer, "\n", 0);
  364. /* Strip initial comments */
  365. int i;
  366. for (i = 0; expected[i]; i++)
  367. {
  368. if (expected[i][0] != '#')
  369. {
  370. if (i > 0)
  371. {
  372. char **tmp = g_strdupv (expected + i);
  373. g_strfreev (expected);
  374. expected = tmp;
  375. }
  376. break;
  377. }
  378. }
  379. if (g_strv_length (lines) != g_strv_length (expected))
  380. {
  381. g_test_message ("Unexpected number of lines in output (%d instead of %d):\n%s", g_strv_length (lines), g_strv_length (expected), data.string->str);
  382. g_test_fail ();
  383. }
  384. else
  385. {
  386. unsigned int length = g_strv_length (lines);
  387. for (unsigned int i = 0; i < length; i++)
  388. {
  389. if (strcmp (lines[i], expected[i]) != 0)
  390. {
  391. int pos;
  392. for (pos = 0; lines[i][pos]; pos++)
  393. if (lines[i][pos] != expected[i][pos])
  394. break;
  395. g_test_message ("Unexpected output at %d:%d (%c instead of %c):\n%s", i, pos, lines[i][pos], expected[i][pos], data.string->str);
  396. g_test_fail ();
  397. }
  398. }
  399. }
  400. g_strfreev (lines);
  401. g_strfreev (expected);
  402. g_free (buffer);
  403. g_free (file);
  404. g_string_free (data.string, TRUE);
  405. hb_font_destroy (font);
  406. hb_face_destroy (face);
  407. }
  408. static void
  409. test_compare_ot_ft (const char *file, hb_codepoint_t glyph)
  410. {
  411. hb_face_t *face;
  412. hb_font_t *font;
  413. hb_paint_funcs_t *funcs;
  414. GString *ot_str;
  415. paint_data_t data;
  416. face = hb_test_open_font_file (file);
  417. font = hb_font_create (face);
  418. funcs = get_test_paint_funcs ();
  419. data.string = g_string_new ("");
  420. data.level = 0;
  421. hb_font_paint_glyph (font, glyph, funcs, &data, 0, HB_COLOR (0, 0, 0, 255));
  422. g_assert_true (data.level == 0);
  423. ot_str = data.string;
  424. #ifdef HB_HAS_FREETYPE
  425. hb_ft_font_set_funcs (font);
  426. #endif
  427. data.string = g_string_new ("");
  428. data.level = 0;
  429. hb_font_paint_glyph (font, glyph, funcs, &data, 0, HB_COLOR (0, 0, 0, 255));
  430. g_assert_true (data.level == 0);
  431. g_assert_cmpstr (ot_str->str, ==, data.string->str);
  432. g_string_free (data.string, TRUE);
  433. hb_font_destroy (font);
  434. hb_face_destroy (face);
  435. g_string_free (ot_str, TRUE);
  436. }
  437. static void
  438. test_hb_paint_ot (gconstpointer data)
  439. {
  440. test_hb_paint (data, 0);
  441. }
  442. static void
  443. test_hb_paint_ft (gconstpointer data)
  444. {
  445. if (have_ft_colrv1 ())
  446. test_hb_paint (data, 1);
  447. else
  448. g_test_skip ("FreeType COLRv1 support not present");
  449. }
  450. static void
  451. test_compare_ot_ft_novf (gconstpointer d)
  452. {
  453. if (have_ft_colrv1 ())
  454. test_compare_ot_ft (TEST_GLYPHS, GPOINTER_TO_UINT (d));
  455. else
  456. g_test_skip ("FreeType COLRv1 support not present");
  457. }
  458. static void
  459. test_compare_ot_ft_vf (gconstpointer d)
  460. {
  461. if (have_ft_colrv1 ())
  462. test_compare_ot_ft (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d));
  463. else
  464. g_test_skip ("FreeType COLRv1 support not present");
  465. }
  466. static void
  467. scrutinize_linear_gradient (hb_paint_funcs_t *funcs HB_UNUSED,
  468. void *paint_data,
  469. hb_color_line_t *color_line,
  470. float x0 HB_UNUSED, float y0 HB_UNUSED,
  471. float x1 HB_UNUSED, float y1 HB_UNUSED,
  472. float x2 HB_UNUSED, float y2 HB_UNUSED,
  473. void *user_data HB_UNUSED)
  474. {
  475. hb_bool_t *result = paint_data;
  476. hb_color_stop_t *stops;
  477. unsigned int len;
  478. hb_color_stop_t *stops2;
  479. unsigned int len2;
  480. *result = FALSE;
  481. len = hb_color_line_get_color_stops (color_line, 0, NULL, NULL);
  482. if (len == 0)
  483. return;
  484. stops = malloc (len * sizeof (hb_color_stop_t));
  485. stops2 = malloc (len * sizeof (hb_color_stop_t));
  486. hb_color_line_get_color_stops (color_line, 0, &len, stops);
  487. hb_color_line_get_color_stops (color_line, 0, &len, stops2);
  488. // check that we can get stops twice
  489. if (memcmp (stops, stops2, len * sizeof (hb_color_stop_t)) != 0)
  490. {
  491. free (stops);
  492. free (stops2);
  493. return;
  494. }
  495. // check that we can get a single stop in the middle
  496. len2 = 1;
  497. hb_color_line_get_color_stops (color_line, len - 1, &len2, stops2);
  498. if (memcmp (&stops[len - 1], stops2, sizeof (hb_color_stop_t)) != 0)
  499. {
  500. free (stops);
  501. free (stops2);
  502. return;
  503. }
  504. free (stops);
  505. free (stops2);
  506. *result = TRUE;
  507. }
  508. static void
  509. test_color_stops (hb_bool_t use_ft HB_UNUSED)
  510. {
  511. hb_face_t *face;
  512. hb_font_t *font;
  513. hb_paint_funcs_t *funcs;
  514. hb_bool_t result = FALSE;
  515. face = hb_test_open_font_file (NOTO_HAND);
  516. font = hb_font_create (face);
  517. #ifdef HB_HAS_FREETYPE
  518. if (use_ft)
  519. hb_ft_font_set_funcs (font);
  520. #endif
  521. funcs = hb_paint_funcs_create ();
  522. hb_paint_funcs_set_linear_gradient_func (funcs, scrutinize_linear_gradient, NULL, NULL);
  523. hb_font_paint_glyph (font, 10, funcs, &result, 0, HB_COLOR (0, 0, 0, 255));
  524. g_assert_true (result);
  525. hb_paint_funcs_destroy (funcs);
  526. hb_font_destroy (font);
  527. hb_face_destroy (face);
  528. }
  529. static void
  530. test_color_stops_ot (void)
  531. {
  532. test_color_stops (0);
  533. }
  534. static void
  535. test_color_stops_ft (void)
  536. {
  537. if (have_ft_colrv1 ())
  538. test_color_stops (1);
  539. else
  540. g_test_skip ("FreeType COLRv1 support not present");
  541. }
  542. int
  543. main (int argc, char **argv)
  544. {
  545. int status = 0;
  546. hb_test_init (&argc, &argv);
  547. for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++)
  548. {
  549. hb_test_add_data_flavor (&paint_tests[i], paint_tests[i].output, test_hb_paint_ot);
  550. hb_test_add_data_flavor (&paint_tests[i], paint_tests[i].output, test_hb_paint_ft);
  551. }
  552. hb_face_t *face = hb_test_open_font_file (TEST_GLYPHS);
  553. unsigned glyph_count = hb_face_get_glyph_count (face);
  554. for (unsigned int i = 1; i < glyph_count; i++)
  555. {
  556. char buf[20];
  557. snprintf (buf, 20, "test-%u", i);
  558. hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_novf);
  559. hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_vf);
  560. }
  561. hb_face_destroy (face);
  562. hb_test_add (test_color_stops_ot);
  563. hb_test_add (test_color_stops_ft);
  564. status = hb_test_run();
  565. return status;
  566. }