[paint] Preserve void extents through transformations (#6548)

Honk paints an empty outline as one of its COLR layers. Transforming its
void bounding box orders the sentinel corners into a real rectangle at
(-1,-1)-(0,0), even with the identity transform. That rectangle expands
the accent's ink bounds toward the origin and shifts fallback marks by
hundreds of units.

Keep void extents void when applying a transform. Add shaping regressions
for normal and double scale and vertical layout using a default-instance
Honk subset, with its OFL embedded in the name table.

Current read-fonts already computes the correct COLR bounds. Removing
only the empty layer also makes unpatched HarfBuzz match HarfRust,
confirming the cause of harfrust#553.

Update the existing vertical-origin overflow fixture to use an explicit
COLR clip box. Assert that its height still clamps to INT_MIN so the
original negation-overflow regression stays covered after void bounds
stop producing artificial ink.

Testing: meson test -C build (276 passed).

Fixes: https://github.com/harfbuzz/harfrust/issues/553
Assisted-by: OpenAI Codex
This commit is contained in:
Behdad Esfahbod authored and GitHub committed 2026-11-01 19:26:02 -07:00
1 parent a945625923
commit e8a7f183fe
4 files changed
+28 -13

No files matched your search

+3
View File
@@ -188,6 +188,9 @@ struct hb_transform_t
void transform_extents (hb_extents_t<Float> &extents) const
{
/* Transforming a void box's sentinel corners would give it area. */
if (unlikely (extents.is_void ())) return;
Float quad_x[4], quad_y[4];
quad_x[0] = extents.xmin;
+18 -13
View File
@@ -219,28 +219,33 @@ test_ot_var_axis_on_zero_named_instance (void)
static void
test_ot_font_v_origin_extents_overflow (void)
{
/* A COLRv1 glyph with a clip box from y=-32768 to y=32767. At the
* scale below, its height clamps to INT_MIN, exercising the overflow
* guard without relying on bounds manufactured from an empty outline. */
static const char data[] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x43, 0x4f, 0x4c, 0x52, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x09,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x10, 0x00, 0x00,
0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x11, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0c,
0x00, 0x00, 0x17, 0x00, 0x00, 0x02, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
(char) 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x1d, 0x00,
0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x04, 0x03, 0x20,
0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00
0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x43, 0x4f, 0x4c, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
0x00, 0x00, 0x00, 0x46, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a,
0x02, (char) 0xff, (char) 0xff, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, (char) 0x80, 0x00, 0x00, 0x01,
0x7f, (char) 0xff
};
hb_blob_t *blob = hb_blob_create (data, sizeof (data), HB_MEMORY_MODE_READONLY,
NULL, NULL);
hb_face_t *face = hb_face_create (blob, 0);
hb_face_set_upem (face, 1);
hb_font_t *font = hb_font_create (face);
hb_position_t x, y;
hb_font_set_scale (font, 12, 12);
hb_font_set_scale (font, 65536, 65536);
hb_glyph_extents_t extents;
g_assert_true (hb_font_get_glyph_extents (font, 0, &extents));
g_assert_cmpint (extents.height, ==, G_MININT);
g_assert_true (hb_font_get_glyph_v_origin (font, 0, &x, &y));
g_assert_cmpint (y, ==, -1073741719);
g_assert_cmpint (y, ==, 1073709056);
hb_font_destroy (font);
hb_face_destroy (face);
@@ -1,3 +1,10 @@
@font-funcs=ot
../fonts/ee39587d13b2afa5499cc79e45780aa79293bbd4.ttf;--show-extents;U+1F42F;[gid1=0+2963<0,2179,2963,-2789>]
../fonts/fcbaa518d3cce441ed37ae3b1fed6a19e9b54efd.ttf;--show-extents;U+1F600;[gid4=0+2550<0,1898,2555,-2405>]
# Honk (OFL), pinned to MORF=15, SHLN=0. The accent's first COLR layer is empty.
# An empty clip must stay empty when transformed, rather than adding ink
# at the origin and changing mark placement (harfbuzz/harfrust#553).
../fonts/ba51123c80fa9526c9c3032cd41c22700a4bc3e2.ttf;--show-extents;U+1E49,0306;[nmacronbelow=0+1060<-40,968,1140,-1152>|uni0306=0@-1024,199+0<128,1168,732,-274>]
../fonts/ba51123c80fa9526c9c3032cd41c22700a4bc3e2.ttf;--show-extents --font-size=4000;U+1E49,0306;[nmacronbelow=0+2120<-80,1936,2280,-2304>|uni0306=0@-2048,398+0<256,2336,1464,-548>]
../fonts/ba51123c80fa9526c9c3032cd41c22700a4bc3e2.ttf;--show-extents --direction=ttb;U+1E49,0306;[nmacronbelow=0@-530,-1612+0,-2440<-40,968,1140,-1152>|uni0306=0@36,1733+0<128,1168,732,-274>]