Skip to content

Commit 1cff877

Browse files
authored
Add tests for COLRv1 glyph extents (#157)
1 parent ef875b7 commit 1cff877

5 files changed

Lines changed: 262 additions & 3 deletions

File tree

scripts/gen-shaping-tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
# This custom test fails because harfbuzz uses a set digest in AAT to abort early
4848
# which we don't do yet. Is basically the same as morx_20_005, but with `--show-flags`
4949
"glyph_flags_002",
50+
51+
# These currently return different results from harfbuzz.
52+
"colr_003",
53+
"colr_006",
54+
"colr_007",
55+
"colr_008",
56+
"colr_009",
57+
"colr_010",
58+
"colr_011",
59+
"colr_012",
60+
"colr_014",
61+
"colr_015",
62+
"colr_016",
63+
"colr_018",
5064
]
5165

5266

@@ -222,6 +236,8 @@ def convert_test_files(root_dir, hb_shape_exe, tests_dir, tests_name, files, cus
222236
root_dir, hb_shape_exe, tests_name, file, idx + 1, test, fonts, custom
223237
)
224238

239+
# Strip the extra trailing newline to avoid formatting churn
240+
rust_code = rust_code[:-1]
225241
tests_name_snake_case = tests_name.replace("-", "_")
226242
with open(f"../tests/shaping/{tests_name_snake_case}.rs", "w") as f:
227243
f.write(rust_code)

src/hb/face.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ impl<'a> hb_font_t<'a> {
266266
glyph_extents.height = (-f32::from(img.height) * scale).round() as i32;
267267
return true;
268268
}
269-
// TODO: Add tests for this. We should use all glyphs from
270-
// https://github.com/googlefonts/color-fonts/blob/main/fonts/test_glyphs-glyf_colr_1_no_cliplist.ttf
271-
// and test their output against harfbuzz.
272269
} else if let Some(colr) = self.ttfp_face.tables().colr {
273270
if colr.is_simple() {
274271
return false;

tests/custom/colr.tests

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0100,U+F0101,U+F0102,U+F0103;
2+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0200,U+F0201,U+F0202,U+F0203,U+F0204,U+F0205,U+F0206,U+F0207,U+F0208,U+F0209,U+F020A,U+F020B,U+F020C,U+F020D,U+F020E,U+F020F,U+F0210,U+F0211,U+F0212,U+F0213,U+F0214,U+F0215,U+F0216,U+F0217,U+F0218,U+F0219,U+F021A,U+F021B,U+F021C,U+F021D,U+F021E,U+F021F,U+F0220,U+F0221,U+F0222,U+F0223,U+F0224,U+F0225,U+F0226,U+F0227,U+F0228,U+F0229,U+F022A,U+F022B,U+F022C,U+F022D,U+F022E,U+F022F,U+F0230,U+F0231,U+F0232,U+F0233,U+F0234,U+F0235,U+F0236,U+F0237,U+F0238,U+F0239,U+F023A,U+F023B,U+F023C,U+F023D,U+F023E,U+F023F,U+F0240,U+F0241,U+F0242,U+F0243,U+F0244,U+F0245,U+F0246,U+F0247;
3+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0300,U+F0301,U+F0302,U+F0303,U+F0304,U+F0305;
4+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0500,U+F0501,U+F0502;
5+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0503,U+F0504,U+F0505,U+F0506,U+F0507,U+F0508;
6+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0600,U+F0601,U+F0602,U+F0603;
7+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0700,U+F0701,U+F0702,U+F0703,U+F0704,U+F0705;
8+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0800,U+F0801,U+F0802,U+F0803;
9+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0900,U+F0901,U+F0902,U+F0903,U+F0904,U+F0905,U+F0906;
10+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0A00,U+F0A01,U+F0A02,U+F0A03,U+F0A04,U+F0A05,U+F0A06,U+F0A07,U+F0A08,U+F0A09,U+F0A0A,U+F0A0B,U+F0A0C,U+F0A0D,U+F0A0E,U+F0A0F,U+F0A10,U+F0A11,U+F0A12,U+F0A13,U+F0A14,U+F0A15,U+F0A16,U+F0A17,U+F0A18,U+F0A19,U+F0A1A,U+F0A1B;
11+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0B00,U+F0B01,U+F0B02,U+F0B03,U+F0B04,U+F0B05,U+F0B06,U+F0B07;
12+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0C00,U+F0C01,U+F0C02,U+F0C03,U+F0C04,U+F0C05,U+F0C06,U+F0C07,U+F0C08,U+F0C09,U+F0C0A;
13+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0D00;
14+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0E00,U+F0E01;
15+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F0F00,U+F0F01,U+F0F02,U+F0F03,U+F0F04,U+F0F05,U+F0F06;
16+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F1000;
17+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F1100,U+F1101;
18+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F1200;
19+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F1300,U+F1301,U+F1302,U+F1303,U+F1304,U+F1305,U+F1306,U+F1307,U+F1308,U+F1309,U+F130A,U+F130B,U+F130C,U+F130D,U+F130E,U+F130F,U+F1310,U+F1311,U+F1312,U+F1313,U+F1314,U+F1315,U+F1316,U+F1317;
20+
tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf;--show-extents;U+F1400,U+F1401,U+F1402,U+F1403,U+F1404,U+F1405,U+F1406,U+F1407,U+F1408,U+F1409,U+F140A,U+F140B,U+F140C,U+F140D,U+F140E,U+F140F;
20.9 KB
Binary file not shown.

tests/shaping/custom.rs

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,232 @@ fn bugs_003() {
4040
);
4141
}
4242

43+
#[test]
44+
fn colr_001() {
45+
assert_eq!(
46+
shape(
47+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
48+
"\u{F0100}\u{F0101}\u{F0102}\u{F0103}",
49+
"--show-extents",
50+
),
51+
"linear_repeat_0_1=0+1000<100,950,800,-700>|\
52+
linear_repeat_0.2_0.8=1+1000<100,950,800,-700>|\
53+
linear_repeat_0_1.5=2+1000<100,950,800,-700>|\
54+
linear_repeat_0.5_1.5=3+1000<100,950,800,-700>"
55+
);
56+
}
57+
58+
#[test]
59+
fn colr_002() {
60+
assert_eq!(
61+
shape(
62+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
63+
"\u{F0200}\u{F0201}\u{F0202}\u{F0203}\u{F0204}\u{F0205}\u{F0206}\u{F0207}\u{F0208}\u{F0209}\
64+
\u{F020A}\u{F020B}\u{F020C}\u{F020D}\u{F020E}\u{F020F}\u{F0210}\u{F0211}\u{F0212}\u{F0213}\
65+
\u{F0214}\u{F0215}\u{F0216}\u{F0217}\u{F0218}\u{F0219}\u{F021A}\u{F021B}\u{F021C}\u{F021D}\
66+
\u{F021E}\u{F021F}\u{F0220}\u{F0221}\u{F0222}\u{F0223}\u{F0224}\u{F0225}\u{F0226}\u{F0227}\
67+
\u{F0228}\u{F0229}\u{F022A}\u{F022B}\u{F022C}\u{F022D}\u{F022E}\u{F022F}\u{F0230}\u{F0231}\
68+
\u{F0232}\u{F0233}\u{F0234}\u{F0235}\u{F0236}\u{F0237}\u{F0238}\u{F0239}\u{F023A}\u{F023B}\
69+
\u{F023C}\u{F023D}\u{F023E}\u{F023F}\u{F0240}\u{F0241}\u{F0242}\u{F0243}\u{F0244}\u{F0245}\
70+
\u{F0246}\u{F0247}",
71+
"--show-extents",
72+
),
73+
"sweep_0_360_pad_narrow=0+1000<150,950,700,-700>|\
74+
sweep_60_300_pad_narrow=1+1000<150,950,700,-700>|\
75+
sweep_0_90_pad_narrow=2+1000<150,950,700,-700>|\
76+
sweep_90_0_pad_narrow=3+1000<150,950,700,-700>|\
77+
sweep_45_90_pad_narrow=4+1000<150,950,700,-700>|\
78+
sweep_90_45_pad_narrow=5+1000<150,950,700,-700>|\
79+
sweep_247.5_292.5_pad_narrow=6+1000<150,950,700,-700>|\
80+
sweep_-45_45_pad_narrow=7+1000<150,950,700,-700>|\
81+
sweep_45_-45_pad_narrow=8+1000<150,950,700,-700>|\
82+
sweep_270_440_pad_narrow=9+1000<150,950,700,-700>|\
83+
sweep_440_270_pad_narrow=10+1000<150,950,700,-700>|\
84+
sweep_-180_540_pad_narrow=11+1000<150,950,700,-700>|\
85+
sweep_0_360_reflect_narrow=12+1000<150,950,700,-700>|\
86+
sweep_60_300_reflect_narrow=13+1000<150,950,700,-700>|\
87+
sweep_0_90_reflect_narrow=14+1000<150,950,700,-700>|\
88+
sweep_90_0_reflect_narrow=15+1000<150,950,700,-700>|\
89+
sweep_45_90_reflect_narrow=16+1000<150,950,700,-700>|\
90+
sweep_90_45_reflect_narrow=17+1000<150,950,700,-700>|\
91+
sweep_247.5_292.5_reflect_narrow=18+1000<150,950,700,-700>|\
92+
sweep_-45_45_reflect_narrow=19+1000<150,950,700,-700>|\
93+
sweep_45_-45_reflect_narrow=20+1000<150,950,700,-700>|\
94+
sweep_270_440_reflect_narrow=21+1000<150,950,700,-700>|\
95+
sweep_440_270_reflect_narrow=22+1000<150,950,700,-700>|\
96+
sweep_-180_540_reflect_narrow=23+1000<150,950,700,-700>|\
97+
sweep_0_360_repeat_narrow=24+1000<150,950,700,-700>|\
98+
sweep_60_300_repeat_narrow=25+1000<150,950,700,-700>|\
99+
sweep_0_90_repeat_narrow=26+1000<150,950,700,-700>|\
100+
sweep_90_0_repeat_narrow=27+1000<150,950,700,-700>|\
101+
sweep_45_90_repeat_narrow=28+1000<150,950,700,-700>|\
102+
sweep_90_45_repeat_narrow=29+1000<150,950,700,-700>|\
103+
sweep_247.5_292.5_repeat_narrow=30+1000<150,950,700,-700>|\
104+
sweep_-45_45_repeat_narrow=31+1000<150,950,700,-700>|\
105+
sweep_45_-45_repeat_narrow=32+1000<150,950,700,-700>|\
106+
sweep_270_440_repeat_narrow=33+1000<150,950,700,-700>|\
107+
sweep_440_270_repeat_narrow=34+1000<150,950,700,-700>|\
108+
sweep_-180_540_repeat_narrow=35+1000<150,950,700,-700>|\
109+
sweep_0_360_pad_wide=36+1000<150,950,700,-700>|\
110+
sweep_60_300_pad_wide=37+1000<150,950,700,-700>|\
111+
sweep_0_90_pad_wide=38+1000<150,950,700,-700>|\
112+
sweep_90_0_pad_wide=39+1000<150,950,700,-700>|\
113+
sweep_45_90_pad_wide=40+1000<150,950,700,-700>|\
114+
sweep_90_45_pad_wide=41+1000<150,950,700,-700>|\
115+
sweep_247.5_292.5_pad_wide=42+1000<150,950,700,-700>|\
116+
sweep_-45_45_pad_wide=43+1000<150,950,700,-700>|\
117+
sweep_45_-45_pad_wide=44+1000<150,950,700,-700>|\
118+
sweep_270_440_pad_wide=45+1000<150,950,700,-700>|\
119+
sweep_440_270_pad_wide=46+1000<150,950,700,-700>|\
120+
sweep_-180_540_pad_wide=47+1000<150,950,700,-700>|\
121+
sweep_0_360_reflect_wide=48+1000<150,950,700,-700>|\
122+
sweep_60_300_reflect_wide=49+1000<150,950,700,-700>|\
123+
sweep_0_90_reflect_wide=50+1000<150,950,700,-700>|\
124+
sweep_90_0_reflect_wide=51+1000<150,950,700,-700>|\
125+
sweep_45_90_reflect_wide=52+1000<150,950,700,-700>|\
126+
sweep_90_45_reflect_wide=53+1000<150,950,700,-700>|\
127+
sweep_247.5_292.5_reflect_wide=54+1000<150,950,700,-700>|\
128+
sweep_-45_45_reflect_wide=55+1000<150,950,700,-700>|\
129+
sweep_45_-45_reflect_wide=56+1000<150,950,700,-700>|\
130+
sweep_270_440_reflect_wide=57+1000<150,950,700,-700>|\
131+
sweep_440_270_reflect_wide=58+1000<150,950,700,-700>|\
132+
sweep_-180_540_reflect_wide=59+1000<150,950,700,-700>|\
133+
sweep_0_360_repeat_wide=60+1000<150,950,700,-700>|\
134+
sweep_60_300_repeat_wide=61+1000<150,950,700,-700>|\
135+
sweep_0_90_repeat_wide=62+1000<150,950,700,-700>|\
136+
sweep_90_0_repeat_wide=63+1000<150,950,700,-700>|\
137+
sweep_45_90_repeat_wide=64+1000<150,950,700,-700>|\
138+
sweep_90_45_repeat_wide=65+1000<150,950,700,-700>|\
139+
sweep_247.5_292.5_repeat_wide=66+1000<150,950,700,-700>|\
140+
sweep_-45_45_repeat_wide=67+1000<150,950,700,-700>|\
141+
sweep_45_-45_repeat_wide=68+1000<150,950,700,-700>|\
142+
sweep_270_440_repeat_wide=69+1000<150,950,700,-700>|\
143+
sweep_440_270_repeat_wide=70+1000<150,950,700,-700>|\
144+
sweep_-180_540_repeat_wide=71+1000<150,950,700,-700>"
145+
);
146+
}
147+
148+
#[test]
149+
fn colr_004() {
150+
assert_eq!(
151+
shape(
152+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
153+
"\u{F0500}\u{F0501}\u{F0502}",
154+
"--show-extents",
155+
),
156+
"linear_gradient_extend_mode_pad=0+1000<0,1000,1000,-1000>|\
157+
linear_gradient_extend_mode_repeat=1+1000<0,1000,1000,-1000>|\
158+
linear_gradient_extend_mode_reflect=2+1000<0,1000,1000,-1000>"
159+
);
160+
}
161+
162+
#[test]
163+
fn colr_005() {
164+
assert_eq!(
165+
shape(
166+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
167+
"\u{F0503}\u{F0504}\u{F0505}\u{F0506}\u{F0507}\u{F0508}",
168+
"--show-extents",
169+
),
170+
"radial_contained_gradient_extend_mode_pad=0+1000<0,1000,1000,-1000>|\
171+
radial_contained_gradient_extend_mode_repeat=1+1000<0,1000,1000,-1000>|\
172+
radial_contained_gradient_extend_mode_reflect=2+1000<0,1000,1000,-1000>|\
173+
radial_horizontal_gradient_extend_mode_pad=3+1000<0,1000,1000,-1000>|\
174+
radial_horizontal_gradient_extend_mode_repeat=4+1000<0,1000,1000,-1000>|\
175+
radial_horizontal_gradient_extend_mode_reflect=5+1000<0,1000,1000,-1000>"
176+
);
177+
}
178+
179+
#[test]
180+
fn colr_013() {
181+
assert_eq!(
182+
shape(
183+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
184+
"\u{F0D00}",
185+
"--show-extents",
186+
),
187+
"gradient_p2_skewed=0+1250<100,950,1100,-700>"
188+
);
189+
}
190+
191+
#[test]
192+
fn colr_017() {
193+
assert_eq!(
194+
shape(
195+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
196+
"\u{F1100}\u{F1101}",
197+
"--show-extents",
198+
),
199+
"paintcolrglyph_cycle_first=0+1000<0,0,0,0>|\
200+
paintcolrglyph_cycle_second=1+1000<0,0,0,0>"
201+
);
202+
}
203+
204+
#[test]
205+
fn colr_019() {
206+
assert_eq!(
207+
shape(
208+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
209+
"\u{F1300}\u{F1301}\u{F1302}\u{F1303}\u{F1304}\u{F1305}\u{F1306}\u{F1307}\u{F1308}\u{F1309}\
210+
\u{F130A}\u{F130B}\u{F130C}\u{F130D}\u{F130E}\u{F130F}\u{F1310}\u{F1311}\u{F1312}\u{F1313}\
211+
\u{F1314}\u{F1315}\u{F1316}\u{F1317}",
212+
"--show-extents",
213+
),
214+
"sweep_coincident_angles_forward_blue_red_pad=0+1000<150,950,700,-700>|\
215+
sweep_coincident_angles_forward_blue_red_reflect=1+1000<150,950,700,-700>|\
216+
sweep_coincident_angles_forward_blue_red_repeat=2+1000<150,950,700,-700>|\
217+
sweep_coincident_angles_forward_linen_gray_pad=3+1000<150,950,700,-700>|\
218+
sweep_coincident_angles_forward_linen_gray_reflect=4+1000<150,950,700,-700>|\
219+
sweep_coincident_angles_forward_linen_gray_repeat=5+1000<150,950,700,-700>|\
220+
sweep_coincident_angles_reverse_blue_red_pad=6+1000<150,950,700,-700>|\
221+
sweep_coincident_angles_reverse_blue_red_reflect=7+1000<150,950,700,-700>|\
222+
sweep_coincident_angles_reverse_blue_red_repeat=8+1000<150,950,700,-700>|\
223+
sweep_coincident_angles_reverse_linen_gray_pad=9+1000<150,950,700,-700>|\
224+
sweep_coincident_angles_reverse_linen_gray_reflect=10+1000<150,950,700,-700>|\
225+
sweep_coincident_angles_reverse_linen_gray_repeat=11+1000<150,950,700,-700>|\
226+
sweep_coincident_stops_forward_blue_red_pad=12+1000<150,950,700,-700>|\
227+
sweep_coincident_stops_forward_blue_red_reflect=13+1000<150,950,700,-700>|\
228+
sweep_coincident_stops_forward_blue_red_repeat=14+1000<150,950,700,-700>|\
229+
sweep_coincident_stops_forward_linen_gray_pad=15+1000<150,950,700,-700>|\
230+
sweep_coincident_stops_forward_linen_gray_reflect=16+1000<150,950,700,-700>|\
231+
sweep_coincident_stops_forward_linen_gray_repeat=17+1000<150,950,700,-700>|\
232+
sweep_coincident_stops_reverse_blue_red_pad=18+1000<150,950,700,-700>|\
233+
sweep_coincident_stops_reverse_blue_red_reflect=19+1000<150,950,700,-700>|\
234+
sweep_coincident_stops_reverse_blue_red_repeat=20+1000<150,950,700,-700>|\
235+
sweep_coincident_stops_reverse_linen_gray_pad=21+1000<150,950,700,-700>|\
236+
sweep_coincident_stops_reverse_linen_gray_reflect=22+1000<150,950,700,-700>|\
237+
sweep_coincident_stops_reverse_linen_gray_repeat=23+1000<150,950,700,-700>"
238+
);
239+
}
240+
241+
#[test]
242+
fn colr_020() {
243+
assert_eq!(
244+
shape(
245+
"tests/fonts/rb_custom/test_glyphs-glyf_colr_1_no_cliplist.ttf",
246+
"\u{F1400}\u{F1401}\u{F1402}\u{F1403}\u{F1404}\u{F1405}\u{F1406}\u{F1407}\u{F1408}\u{F1409}\
247+
\u{F140A}\u{F140B}\u{F140C}\u{F140D}\u{F140E}\u{F140F}",
248+
"--show-extents",
249+
),
250+
"paint_glyph_nested_identity_identity=0+1000<200,770,600,-520>|\
251+
paint_glyph_nested_identity_translate=1+1000<200,770,600,-520>|\
252+
paint_glyph_nested_identity_rotate_origin=2+1000<200,770,600,-520>|\
253+
paint_glyph_nested_identity_rotate_center=3+1000<200,770,600,-520>|\
254+
paint_glyph_nested_translate_identity=4+1000<320,890,600,-520>|\
255+
paint_glyph_nested_translate_translate=5+1000<320,890,600,-520>|\
256+
paint_glyph_nested_translate_rotate_origin=6+1000<320,890,600,-520>|\
257+
paint_glyph_nested_translate_rotate_center=7+1000<320,890,600,-520>|\
258+
paint_glyph_nested_rotate_origin_identity=8+1000<63,897,681,-616>|\
259+
paint_glyph_nested_rotate_origin_translate=9+1000<63,897,681,-616>|\
260+
paint_glyph_nested_rotate_origin_rotate_origin=10+1000<63,897,681,-616>|\
261+
paint_glyph_nested_rotate_origin_rotate_center=11+1000<63,897,681,-616>|\
262+
paint_glyph_nested_rotate_center_identity=12+1000<124,899,750,-779>|\
263+
paint_glyph_nested_rotate_center_translate=13+1000<124,899,750,-779>|\
264+
paint_glyph_nested_rotate_center_rotate_origin=14+1000<124,899,750,-779>|\
265+
paint_glyph_nested_rotate_center_rotate_center=15+1000<124,899,750,-779>"
266+
);
267+
}
268+
43269
#[test]
44270
fn fuzzer_001() {
45271
assert_eq!(

0 commit comments

Comments
 (0)