diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 62d3a3ce1..6cbfdfaae 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -2700,19 +2700,10 @@ struct COLR // COLRv1 glyph bool is_bounded = true; + hb_glyph_extents_t extents = {}; if (clip) { - hb_glyph_extents_t extents; - if (get_clip (glyph, &extents, instancer)) - { - font->scale_glyph_extents (&extents); - c.funcs->push_clip_rectangle (c.data, - extents.x_bearing, - extents.y_bearing + extents.height, - extents.x_bearing + extents.width, - extents.y_bearing); - } - else + if (!get_clip (glyph, &extents, instancer)) { clip = false; is_bounded = false; @@ -2735,14 +2726,21 @@ struct COLR c.funcs->push_font_transform (c.data, font); + if (clip) + c.funcs->push_clip_rectangle (c.data, + extents.x_bearing, + extents.y_bearing + extents.height, + extents.x_bearing + extents.width, + extents.y_bearing); + if (is_bounded) c.recurse (*paint); - c.funcs->pop_transform (c.data); - if (clip) c.funcs->pop_clip (c.data); + c.funcs->pop_transform (c.data); + return true; } } diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index d7a361169..f1ed22098 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -78,6 +78,25 @@ static void _hb_ft_paint (hb_ft_paint_context_t *c, FT_OpaquePaint opaque_paint); +static void +_hb_ft_unscale_clip_box (hb_font_t *font, + const FT_ClipBox *clip_box, + float *xmin, float *ymin, + float *xmax, float *ymax) +{ + /* The FreeType ClipBox is in scaled coordinates. Convert it back to + * font units before pushing it under the font transform. + */ + float upem = font->face->get_upem (); + float xscale = upem / (font->x_scale ? font->x_scale : upem); + float yscale = upem / (font->y_scale ? font->y_scale : upem); + + *xmin = clip_box->bottom_left.x * xscale; + *ymin = clip_box->bottom_left.y * yscale; + *xmax = clip_box->top_right.x * xscale; + *ymax = clip_box->top_right.y * yscale; +} + struct hb_ft_paint_context_t { hb_ft_paint_context_t (const hb_ft_font_t *ft_font_, @@ -372,19 +391,10 @@ _hb_ft_paint (hb_ft_paint_context_t *c, if (has_clip_box) { - /* The FreeType ClipBox is in scaled coordinates, whereas we need - * unscaled clipbox here. Oh well... - */ - - float upem = c->font->face->get_upem (); - float xscale = upem / (c->font->x_scale ? c->font->x_scale : upem); - float yscale = upem / (c->font->y_scale ? c->font->y_scale : upem); - - c->funcs->push_clip_rectangle (c->data, - clip_box.bottom_left.x * xscale, - clip_box.bottom_left.y * yscale, - clip_box.top_right.x * xscale, - clip_box.top_right.y * yscale); + float xmin, ymin, xmax, ymax; + _hb_ft_unscale_clip_box (c->font, &clip_box, + &xmin, &ymin, &xmax, &ymax); + c->funcs->push_clip_rectangle (c->data, xmin, ymin, xmax, ymax); } c->recurse (other_paint); @@ -515,19 +525,9 @@ hb_ft_paint_glyph_colr (hb_font_t *font, hb_decycler_node_t node (c.glyphs_decycler); node.visit (gid); - bool clip = false; - bool is_bounded = false; FT_ClipBox clip_box; - if (FT_Get_Color_Glyph_ClipBox (ft_face, gid, &clip_box)) - { - c.funcs->push_clip_rectangle (c.data, - clip_box.bottom_left.x, - clip_box.bottom_left.y, - clip_box.top_right.x, - clip_box.top_right.y); - clip = true; - is_bounded = true; - } + bool clip = FT_Get_Color_Glyph_ClipBox (ft_face, gid, &clip_box); + bool is_bounded = clip; if (!is_bounded) { auto *bounded_funcs = hb_paint_bounded_get_funcs (); @@ -543,14 +543,22 @@ hb_ft_paint_glyph_colr (hb_font_t *font, c.funcs->push_font_transform (c.data, font); + if (clip) + { + float xmin, ymin, xmax, ymax; + _hb_ft_unscale_clip_box (font, &clip_box, + &xmin, &ymin, &xmax, &ymax); + c.funcs->push_clip_rectangle (c.data, xmin, ymin, xmax, ymax); + } + if (is_bounded) c.recurse (paint); - c.funcs->pop_transform (c.data); - if (clip) c.funcs->pop_clip (c.data); + c.funcs->pop_transform (c.data); + return true; } diff --git a/test/api/results-paint/bad-154 b/test/api/results-paint/bad-154 index 37f00c0a4..1dcf2489b 100644 --- a/test/api/results-paint/bad-154 +++ b/test/api/results-paint/bad-154 @@ -1,5 +1,5 @@ -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 rectangle 0 500 500 1e+03 push group push group start transform 1 0 0 1 0 0 @@ -11,5 +11,5 @@ start clip rectangle 0 500 500 1e+03 end transform pop group mode 3 pop group mode 3 - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/hand-10 b/test/api/results-paint/hand-10 index 020430683..1db9f6ec6 100644 --- a/test/api/results-paint/hand-10 +++ b/test/api/results-paint/hand-10 @@ -1,5 +1,5 @@ -start clip rectangle 64 -224 1.22e+03 928 - start transform 1 0 0 1 0 0 +start transform 1 0 0 1 0 0 + start clip rectangle 64 -224 1.22e+03 928 start transform 1 0 0 1 0 0 start clip glyph 13 start transform 1 0 0 1 0 0 @@ -93,5 +93,5 @@ start clip rectangle 64 -224 1.22e+03 928 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/hand-10.2 b/test/api/results-paint/hand-10.2 index ab805da7d..0b1f096f6 100644 --- a/test/api/results-paint/hand-10.2 +++ b/test/api/results-paint/hand-10.2 @@ -1,6 +1,6 @@ start transform 1 0 0.2 1 0 0 - start clip rectangle 64 -224 1.22e+03 928 - start transform 1 0 0 1 0 0 + start transform 1 0 0 1 0 0 + start clip rectangle 64 -224 1.22e+03 928 start transform 1 0 0 1 0 0 start clip glyph 13 start transform 1 0 0 1 0 0 @@ -94,6 +94,6 @@ start transform 1 0 0.2 1 0 0 end transform end clip end transform - end transform - end clip + end clip + end transform end transform diff --git a/test/api/results-paint/test-10 b/test/api/results-paint/test-10 index 594d6892a..785efc3a6 100644 --- a/test/api/results-paint/test-10 +++ b/test/api/results-paint/test-10 @@ -1,5 +1,5 @@ -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 rectangle 100 250 900 950 start transform 1 0 0 1 0 0 start clip glyph 10 start transform 1 0 0 1 0 0 @@ -13,5 +13,5 @@ start clip rectangle 100 250 900 950 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/test-123 b/test/api/results-paint/test-123 index fb700903b..2afe0285a 100644 --- a/test/api/results-paint/test-123 +++ b/test/api/results-paint/test-123 @@ -1,5 +1,5 @@ -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 rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 start clip glyph 3 start transform 1 0 0 1 0 0 @@ -29,5 +29,5 @@ start clip rectangle 0 0 1e+03 1e+03 end transform pop group mode 3 pop group mode 3 - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/test-154 b/test/api/results-paint/test-154 index bfdcff6ac..750a0503c 100644 --- a/test/api/results-paint/test-154 +++ b/test/api/results-paint/test-154 @@ -1,5 +1,5 @@ -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 rectangle 100 250 900 950 start transform 1 0 0 1 0 0 start clip glyph 154 start transform 1 0 0 1 0 0 @@ -7,5 +7,5 @@ start clip rectangle 100 250 900 950 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/test-92 b/test/api/results-paint/test-92 index 93ad98e08..11e7e4496 100644 --- a/test/api/results-paint/test-92 +++ b/test/api/results-paint/test-92 @@ -1,5 +1,5 @@ -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 rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 start clip glyph 2 start transform 1 0 0 1 0 0 @@ -14,5 +14,5 @@ start clip rectangle 0 0 1e+03 1e+03 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/testvf-10 b/test/api/results-paint/testvf-10 index 594d6892a..785efc3a6 100644 --- a/test/api/results-paint/testvf-10 +++ b/test/api/results-paint/testvf-10 @@ -1,5 +1,5 @@ -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 rectangle 100 250 900 950 start transform 1 0 0 1 0 0 start clip glyph 10 start transform 1 0 0 1 0 0 @@ -13,5 +13,5 @@ start clip rectangle 100 250 900 950 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/testvf-123 b/test/api/results-paint/testvf-123 index fb700903b..2afe0285a 100644 --- a/test/api/results-paint/testvf-123 +++ b/test/api/results-paint/testvf-123 @@ -1,5 +1,5 @@ -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 rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 start clip glyph 3 start transform 1 0 0 1 0 0 @@ -29,5 +29,5 @@ start clip rectangle 0 0 1e+03 1e+03 end transform pop group mode 3 pop group mode 3 - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/testvf-154 b/test/api/results-paint/testvf-154 index bfdcff6ac..750a0503c 100644 --- a/test/api/results-paint/testvf-154 +++ b/test/api/results-paint/testvf-154 @@ -1,5 +1,5 @@ -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 rectangle 100 250 900 950 start transform 1 0 0 1 0 0 start clip glyph 154 start transform 1 0 0 1 0 0 @@ -7,5 +7,5 @@ start clip rectangle 100 250 900 950 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/api/results-paint/testvf-92 b/test/api/results-paint/testvf-92 index 93ad98e08..11e7e4496 100644 --- a/test/api/results-paint/testvf-92 +++ b/test/api/results-paint/testvf-92 @@ -1,5 +1,5 @@ -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 rectangle 0 0 1e+03 1e+03 start transform 1 0 0 1 0 0 start clip glyph 2 start transform 1 0 0 1 0 0 @@ -14,5 +14,5 @@ start clip rectangle 0 0 1e+03 1e+03 end transform end clip end transform - end transform -end clip + end clip +end transform diff --git a/test/vector/data/expected/basic/handwriting-cff-colr-1.svg b/test/vector/data/expected/basic/handwriting-cff-colr-1.svg index d930dc0bd..ae4d35ddd 100644 --- a/test/vector/data/expected/basic/handwriting-cff-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-cff-colr-1.svg @@ -1,6 +1,6 @@ - + @@ -34,8 +34,8 @@ - + diff --git a/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg b/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg index 2b2ded383..61792c743 100644 --- a/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg @@ -1,6 +1,6 @@ - + @@ -34,8 +34,8 @@ - +