From c9a26fbf47f01fdd55df1a0ccc81111cb07bf108 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 20 Apr 2025 04:22:32 -0600 Subject: [PATCH] [COLRv1] Move paint boundedness check to font layer This way it will apply to fontations and future implementations as well. But this slows down things apparently, specially if the font does use clipboxes. So I'm going to revert. --- src/OT/Color/COLR/COLR.hh | 21 +-------------------- src/hb-font.hh | 14 ++++++++++++++ src/hb-ft-colr.hh | 18 +----------------- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 0672033ea..c315c550f 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -2695,7 +2695,6 @@ struct COLR { // COLRv1 glyph - bool is_bounded = true; if (clip) { hb_glyph_extents_t extents; @@ -2710,30 +2709,12 @@ struct COLR extents.y_bearing); } else - { clip = false; - is_bounded = false; - } - - if (!is_bounded) - { - auto *bounded_funcs = hb_paint_bounded_get_funcs (); - scratch.paint_bounded.clear (); - - paint_glyph (font, glyph, - bounded_funcs, &scratch.paint_bounded, - palette_index, foreground, - false, - scratch); - - is_bounded = scratch.paint_bounded.is_bounded (); - } } c.funcs->push_font_transform (c.data, font); - if (is_bounded) - c.recurse (*paint); + c.recurse (*paint); c.funcs->pop_transform (c.data); diff --git a/src/hb-font.hh b/src/hb-font.hh index 5e23bd040..acb0a2eda 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -35,6 +35,7 @@ #include "hb-atomic.hh" #include "hb-shaper.hh" #include "hb-outline.hh" +#include "hb-paint-bounded.hh" /* @@ -524,6 +525,19 @@ struct hb_font_t unsigned int palette, hb_color_t foreground) { + /* COLRv1 spec says a glyph must not be painted if the paint graph + * draws unbounded. Implement this here such that all font-funcs + * benefit, since we have the code. */ + auto *bounded_funcs = hb_paint_bounded_get_funcs (); + hb_paint_bounded_context_t bounded_data; + klass->get.f.paint_glyph (this, user_data, + glyph, + bounded_funcs, &bounded_data, + palette, foreground, + !klass->user_data ? nullptr : klass->user_data->paint_glyph); + if (!bounded_data.is_bounded ()) + return; + klass->get.f.paint_glyph (this, user_data, glyph, paint_funcs, paint_data, diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 051201bd9..45cf81c13 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -28,7 +28,6 @@ #include "hb.hh" #include "hb-decycler.hh" -#include "hb-paint-bounded.hh" #include FT_COLOR_H @@ -513,7 +512,6 @@ hb_ft_paint_glyph_colr (hb_font_t *font, 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)) { @@ -527,25 +525,11 @@ hb_ft_paint_glyph_colr (hb_font_t *font, font->slant_xy * clip_box.top_right.y)), clip_box.top_right.y); clip = true; - is_bounded = true; - } - if (!is_bounded) - { - auto *bounded_funcs = hb_paint_bounded_get_funcs (); - hb_paint_bounded_context_t bounded_data; - hb_ft_paint_context_t ce (ft_font, font, - bounded_funcs, &bounded_data, - palette_array, palette_index, foreground); - hb_decycler_node_t node2 (ce.glyphs_decycler); - node2.visit (gid); - ce.recurse (paint); - is_bounded = bounded_data.is_bounded (); } c.funcs->push_font_transform (c.data, font); - if (is_bounded) - c.recurse (paint); + c.recurse (paint); c.funcs->pop_transform (c.data);