[test-paint] Detect FreeType COLRv1 from struct size

This commit is contained in:
Behdad Esfahbod 2023-01-12 19:12:46 -07:00
parent b783967242
commit 60a4f2e6f5
1 changed files with 31 additions and 24 deletions

View File

@ -29,9 +29,20 @@
#ifdef HB_HAS_FREETYPE #ifdef HB_HAS_FREETYPE
#include <hb-ft.h> #include <hb-ft.h>
#if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21101 #if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21101
#define HAVE_FT_COLRv1 #include FT_COLOR_H
#endif #endif
static inline hb_bool_t
have_ft_colrv1 (void)
{
#if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21101
// https://github.com/harfbuzz/harfbuzz/issues/4013
return sizeof (FT_ColorStop) == 8;
#endif
return FALSE;
}
#endif #endif
/* Unit tests for hb-paint.h */ /* Unit tests for hb-paint.h */
@ -366,7 +377,7 @@ test_hb_paint (gconstpointer d,
hb_font_set_synthetic_slant (font, test->slant); hb_font_set_synthetic_slant (font, test->slant);
#ifdef HAVE_FT_COLRv1 #ifdef HB_HAS_FREETYPE
if (use_ft) if (use_ft)
hb_ft_font_set_funcs (font); hb_ft_font_set_funcs (font);
#endif #endif
@ -479,7 +490,7 @@ test_compare_ot_ft (const char *file, hb_codepoint_t glyph)
ot_str = data.string; ot_str = data.string;
#ifdef HAVE_FT_COLRv1 #ifdef HB_HAS_FREETYPE
hb_ft_font_set_funcs (font); hb_ft_font_set_funcs (font);
#endif #endif
@ -508,31 +519,28 @@ test_hb_paint_ot (gconstpointer data)
static void static void
test_hb_paint_ft (gconstpointer data) test_hb_paint_ft (gconstpointer data)
{ {
#ifdef HAVE_FT_COLRv1 if (have_ft_colrv1 ())
test_hb_paint (data, 1); test_hb_paint (data, 1);
#else else
g_test_skip ("FreeType COLRv1 support not present"); g_test_skip ("FreeType COLRv1 support not present");
#endif
} }
static void static void
test_compare_ot_ft_novf (gconstpointer d) test_compare_ot_ft_novf (gconstpointer d)
{ {
#ifdef HAVE_FT_COLRv1 if (have_ft_colrv1 ())
test_compare_ot_ft (TEST_GLYPHS, GPOINTER_TO_UINT (d)); test_compare_ot_ft (TEST_GLYPHS, GPOINTER_TO_UINT (d));
#else else
g_test_skip ("FreeType COLRv1 support not present"); g_test_skip ("FreeType COLRv1 support not present");
#endif
} }
static void static void
test_compare_ot_ft_vf (gconstpointer d) test_compare_ot_ft_vf (gconstpointer d)
{ {
#ifdef HAVE_FT_COLRv1 if (have_ft_colrv1 ())
test_compare_ot_ft (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d)); test_compare_ot_ft (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d));
#else else
g_test_skip ("FreeType COLRv1 support not present"); g_test_skip ("FreeType COLRv1 support not present");
#endif
} }
static void static void
@ -597,7 +605,7 @@ test_color_stops (hb_bool_t use_ft)
face = hb_test_open_font_file (NOTO_HAND); face = hb_test_open_font_file (NOTO_HAND);
font = hb_font_create (face); font = hb_font_create (face);
#ifdef HAVE_FT_COLRv1 #ifdef HB_HAS_FREETYPE
if (use_ft) if (use_ft)
hb_ft_font_set_funcs (font); hb_ft_font_set_funcs (font);
#endif #endif
@ -623,11 +631,10 @@ test_color_stops_ot (void)
static void static void
test_color_stops_ft (void) test_color_stops_ft (void)
{ {
#ifdef HAVE_FT_COLRv1 if (have_ft_colrv1 ())
test_color_stops (1); test_color_stops (1);
#else else
g_test_skip ("FreeType COLRv1 support not present"); g_test_skip ("FreeType COLRv1 support not present");
#endif
} }
int int