Merge pull request #4024 from harfbuzz/test-paint-variable

test-paint: Add variable font tests
This commit is contained in:
Matthias Clasen 2023-01-12 21:26:24 -05:00 committed by GitHub
commit d250148db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 318 additions and 24 deletions

Binary file not shown.

View File

@ -0,0 +1,22 @@
# random seed: R02S4cc6a292019f2eefbbaf24127cc6b053
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 0 0 1e+03 1e+03
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 174
start transform 1 0 0 1 0 0
sweep gradient
center 500 600
angles 0 6.28
colors 0
0.25 250 240 230 255
0.417 0 0 255 255
0.583 255 0 0 255
0.75 47 79 79 255
end transform
end clip
end transform
end transform
end clip

View File

@ -0,0 +1,30 @@
# random seed: R02Sa8358a35595768d4b3f0424c492c70f9
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 250 250 882 1.02e+03
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 3
start transform 1 0 0 1 0 0
solid 0 0 255 127
end transform
end clip
end transform
push group
start transform 1 0 0 1 1e+03 1e+03
start transform 1 -0.364 -0.176 1 0 0
start transform 1 0 0 1 -1e+03 -1e+03
start transform 1 0 -0 1 0 0
start clip glyph 3
start transform 1 0 0 1 0 0
solid 255 165 0 178
end transform
end clip
end transform
end transform
end transform
end transform
pop group mode 4
end transform
end clip

View File

@ -0,0 +1,26 @@
# random seed: R02S5710187ea075c431f16412c38d1f7407
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 250 250 950 950
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 3
start transform 1 0 0 1 0 0
solid 0 0 255 127
end transform
end clip
end transform
push group
start transform 1 0 0 1 200 200
start transform 1 0 -0 1 0 0
start clip glyph 3
start transform 1 0 0 1 0 0
solid 255 165 0 178
end transform
end clip
end transform
end transform
pop group mode 4
end transform
end clip

View File

@ -0,0 +1,47 @@
# random seed: R02S486e6425a6369f1d079b0c273210d642
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 0 0 1e+03 1e+03
start transform 1 0 0 1 0 0
push group
start transform 1 0 -0 1 0 0
start clip glyph 3
start transform 1 0 0 1 0 0
solid 0 0 0 255
end transform
end clip
end transform
pop group mode 3
push group
start transform 1 0 0 1 333 667
start transform 0.5 0 0 0.5 0 0
start transform 1 0 0 1 -333 -667
start transform 1 0 -0 1 0 0
start clip glyph 2
start transform 1 0 0 1 0 0
solid 255 220 1 255
end transform
end clip
end transform
end transform
end transform
end transform
push group
start transform 1 0 0 1 667 333
start transform 0.5 0 0 0.5 0 0
start transform 1 0 0 1 -667 -333
start transform 1 0 -0 1 0 0
start clip glyph 2
start transform 1 0 0 1 0 0
solid 104 199 232 255
end transform
end clip
end transform
end transform
end transform
end transform
pop group mode 5
pop group mode 3
end transform
end clip

View File

@ -0,0 +1,30 @@
# random seed: R02S3997a362a4af7aea0e7c6f803c91771c
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 0 500 500 1e+03
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 2
start transform 1 0 0 1 0 0
radial gradient
p0 166 768 radius 0
p1 166 768 radius 256
colors 2
0 0 128 0 255
0.5 255 255 255 255
1 255 0 0 255
end transform
end clip
end transform
push group
start transform 1 0 -0 1 0 0
start clip glyph 159
start transform 1 0 0 1 0 0
solid 128 128 128 102
end transform
end clip
end transform
pop group mode 3
end transform
end clip

View File

@ -0,0 +1,22 @@
# random seed: R02S4f2af10d205b3b3052f5a575490a2686
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 100 250 1.2e+03 950
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 165
start transform 1 0 0 1 0 0
linear gradient
p0 100 950
p1 2.3e+03 950
p2 -1e+03 250
colors 0
0 255 0 0 255
0.5 0 0 255 255
1 255 255 0 255
end transform
end clip
end transform
end transform
end clip

View File

@ -0,0 +1,36 @@
# random seed: R02S4c022e014005a52e2898416210be4ddf
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 0 0 1e+03 1e+03
start transform 1 0 0 1 0 0
push group
start transform 1 0 0 1 150 0
start transform 1 0 -0 1 0 0
start clip glyph 174
start transform 1 0 0 1 0 0
solid 0 128 0 255
end transform
end clip
end transform
end transform
pop group mode 3
push group
start transform 1 0 0 1 -150 0
start transform 1 0 -0 1 0 0
start clip glyph 174
start transform 1 0 0 1 0 0
linear gradient
p0 500 250
p1 500 950
p2 600 250
colors 1
0 255 0 0 255
1 0 0 255 255
end transform
end clip
end transform
end transform
pop group mode 3
end transform
end clip

21
test/api/results/testvf-6 Normal file
View File

@ -0,0 +1,21 @@
# random seed: R02Sc96e8c0cb2d824e493d9a1088730d188
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 100 250 900 950
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 6
start transform 1 0 0 1 0 0
linear gradient
p0 100 250
p1 900 250
p2 100 300
colors 1
0 255 0 0 255
1 0 0 255 255
end transform
end clip
end transform
end transform
end clip

View File

@ -0,0 +1,21 @@
# random seed: R02See3981a17ce77670e1392178e6b57952
# Start of hb tests
# Start of paint tests
# Start of ot tests
start clip rectangle 0 0 1e+03 1e+03
start transform 1 0 0 1 0 0
start transform 1 0 -0 1 0 0
start clip glyph 2
start transform 1 0 0 1 0 0
radial gradient
p0 166 768 radius 0
p1 166 768 radius 256
colors 1
0 0 128 0 255
0.5 255 255 255 255
1 255 0 0 255
end transform
end clip
end transform
end transform
end clip

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 */
@ -304,12 +315,13 @@ typedef struct {
#define NOTO_HAND "fonts/noto_handwriting-cff2_colr_1.otf" #define NOTO_HAND "fonts/noto_handwriting-cff2_colr_1.otf"
#define TEST_GLYPHS "fonts/test_glyphs-glyf_colr_1.ttf" #define TEST_GLYPHS "fonts/test_glyphs-glyf_colr_1.ttf"
#define TEST_GLYPHS_VF "fonts/test_glyphs-glyf_colr_1_variable.ttf"
#define BAD_COLRV1 "fonts/bad_colrv1.ttf" #define BAD_COLRV1 "fonts/bad_colrv1.ttf"
#define ROCHER_ABC "fonts/RocherColorGX.abc.ttf" #define ROCHER_ABC "fonts/RocherColorGX.abc.ttf"
/* To verify the rendering visually, use /* To verify the rendering visually, use
* *
* hb-view --font-size SCALE --font-slant SLANT --font-palette PALETTE FONT --glyphs [gidGID=0+1000] * hb-view --font-slant SLANT --font-palette PALETTE FONT --glyphs [gidGID=0+1000]
* *
* where GID is the glyph value of the test. * where GID is the glyph value of the test.
*/ */
@ -317,6 +329,7 @@ static paint_test_t paint_tests[] = {
/* COLRv1 */ /* COLRv1 */
{ NOTO_HAND, 0., 10, 0, "hand-10" }, { NOTO_HAND, 0., 10, 0, "hand-10" },
{ NOTO_HAND, 0.2, 10, 0, "hand-10.2" }, { NOTO_HAND, 0.2, 10, 0, "hand-10.2" },
{ TEST_GLYPHS, 0, 6, 0, "test-6" }, // linear gradient { TEST_GLYPHS, 0, 6, 0, "test-6" }, // linear gradient
{ TEST_GLYPHS, 0, 10, 0, "test-10" }, // sweep gradient { TEST_GLYPHS, 0, 10, 0, "test-10" }, // sweep gradient
{ TEST_GLYPHS, 0, 92, 0, "test-92" }, // radial gradient { TEST_GLYPHS, 0, 92, 0, "test-92" }, // radial gradient
@ -326,7 +339,19 @@ static paint_test_t paint_tests[] = {
{ TEST_GLYPHS, 0, 154, 0, "test-154" }, { TEST_GLYPHS, 0, 154, 0, "test-154" },
{ TEST_GLYPHS, 0, 165, 0, "test-165" }, // linear gradient { TEST_GLYPHS, 0, 165, 0, "test-165" }, // linear gradient
{ TEST_GLYPHS, 0, 175, 0, "test-175" }, // layers { TEST_GLYPHS, 0, 175, 0, "test-175" }, // layers
{ TEST_GLYPHS_VF, 0, 6, 0, "testvf-6" },
{ TEST_GLYPHS_VF, 0, 10, 0, "testvf-10" },
{ TEST_GLYPHS_VF, 0, 92, 0, "testvf-92" },
{ TEST_GLYPHS_VF, 0, 106, 0, "testvf-106" },
{ TEST_GLYPHS_VF, 0, 116, 0, "testvf-116" },
{ TEST_GLYPHS_VF, 0, 123, 0, "testvf-123" },
{ TEST_GLYPHS_VF, 0, 154, 0, "testvf-154" },
{ TEST_GLYPHS_VF, 0, 165, 0, "testvf-165" },
{ TEST_GLYPHS_VF, 0, 175, 0, "testvf-175" },
{ BAD_COLRV1, 0, 154, 0, "bad-154" }, // recursion { BAD_COLRV1, 0, 154, 0, "bad-154" }, // recursion
/* COLRv0 */ /* COLRv0 */
{ ROCHER_ABC, 0.3, 1, 0, "rocher-1" }, { ROCHER_ABC, 0.3, 1, 0, "rocher-1" },
{ ROCHER_ABC, 0.3, 2, 2, "rocher-2" }, { ROCHER_ABC, 0.3, 2, 2, "rocher-2" },
@ -352,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
@ -443,21 +468,15 @@ test_hb_paint (gconstpointer d,
} }
static void static void
test_compare_ot_ft (gconstpointer d) test_compare_ot_ft (const char *file, hb_codepoint_t glyph)
{ {
hb_codepoint_t glyph = GPOINTER_TO_UINT (d);
hb_face_t *face; hb_face_t *face;
hb_font_t *font; hb_font_t *font;
hb_paint_funcs_t *funcs; hb_paint_funcs_t *funcs;
GString *ot_str; GString *ot_str;
paint_data_t data; paint_data_t data;
#ifndef HAVE_FT_COLRv1 face = hb_test_open_font_file (file);
g_test_skip ("FreeType COLRv1 support not present");
return;
#endif
face = hb_test_open_font_file (TEST_GLYPHS);
font = hb_font_create (face); font = hb_font_create (face);
funcs = get_test_paint_funcs (); funcs = get_test_paint_funcs ();
@ -471,7 +490,9 @@ test_compare_ot_ft (gconstpointer d)
ot_str = data.string; ot_str = data.string;
#ifdef HB_HAS_FREETYPE
hb_ft_font_set_funcs (font); hb_ft_font_set_funcs (font);
#endif
data.string = g_string_new (""); data.string = g_string_new ("");
data.level = 0; data.level = 0;
@ -498,11 +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");
}
static void
test_compare_ot_ft_novf (gconstpointer d)
{
if (have_ft_colrv1 ())
test_compare_ot_ft (TEST_GLYPHS, GPOINTER_TO_UINT (d));
else
g_test_skip ("FreeType COLRv1 support not present");
}
static void
test_compare_ot_ft_vf (gconstpointer d)
{
if (have_ft_colrv1 ())
test_compare_ot_ft (TEST_GLYPHS_VF, GPOINTER_TO_UINT (d));
else
g_test_skip ("FreeType COLRv1 support not present"); g_test_skip ("FreeType COLRv1 support not present");
#endif
} }
static void static void
@ -567,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
@ -593,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
@ -613,11 +650,13 @@ main (int argc, char **argv)
} }
hb_face_t *face = hb_test_open_font_file (TEST_GLYPHS); hb_face_t *face = hb_test_open_font_file (TEST_GLYPHS);
for (unsigned int i = 1; i < hb_face_get_glyph_count (face); i++) unsigned glyph_count = hb_face_get_glyph_count (face);
for (unsigned int i = 1; i < glyph_count; i++)
{ {
char buf[20]; char buf[20];
snprintf (buf, 20, "test-%u", i); snprintf (buf, 20, "test-%u", i);
hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft); hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_novf);
hb_test_add_data_flavor (GUINT_TO_POINTER (i), buf, test_compare_ot_ft_vf);
} }
hb_face_destroy (face); hb_face_destroy (face);