From a1b0b0046cba156dd72c1a40063ef6ee1b9c6f19 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 8 Jul 2026 12:54:07 +0300 Subject: [PATCH 01/11] [test/vector] Test painting a COLRv0 glyph at a large font scale Add a test for painting a COLRv0 glyph at large scale. The output shows the glyph clipped. We will fix this in the next commits. --- .../expected/basic/colrv0-large-scale.pdf | 165 ++++++++++++++++++ .../expected/basic/colrv0-large-scale.svg | 17 ++ test/vector/data/tests/basic.tests | 2 + 3 files changed, 184 insertions(+) create mode 100644 test/vector/data/expected/basic/colrv0-large-scale.pdf create mode 100644 test/vector/data/expected/basic/colrv0-large-scale.svg diff --git a/test/vector/data/expected/basic/colrv0-large-scale.pdf b/test/vector/data/expected/basic/colrv0-large-scale.pdf new file mode 100644 index 000000000..79237fd92 --- /dev/null +++ b/test/vector/data/expected/basic/colrv0-large-scale.pdf @@ -0,0 +1,165 @@ +%PDF-1.4 +%ÀÁÂÃ +1 0 obj +<< /Type /Catalog /Pages 2 0 R >> +endobj +2 0 obj +<< /Type /Pages /Kids [3 0 R] /Count 1 >> +endobj +3 0 obj +<< /Type /Page /Parent 2 0 R /MediaBox [-16 -57360 65552 8208] +/Contents 4 0 R >> +endobj +4 0 obj +<< /Length 4593 >> +stream +1 1 1 rg +-16 -57360 65568 65568 re f +q +1 0 0 1 0 0 cm +q +55936 47744 m +62336 41344 65536 33621.33 65536 24576 c +65536 15530.67 62336 7808 55936 1408 c +49536 -4992 41813.33 -8192 32768 -8192 c +23722.67 -8192 16000 -4992 9600 1408 c +3200 7808 0 15530.67 0 24576 c +0 33621.33 3200 41344 9600 47744 c +16000 54144 23722.67 57344 32768 57344 c +41813.33 57344 49536 54144 55936 47744 c +h +W n +0.8667 0.1804 0.2667 rg +-32767 -32767 65534 65534 re f +Q +q +25472 35200 m +26410.67 35200 26880 34645.33 26880 33536 c +26880 32426.67 26410.67 31872 25472 31872 c +20992 31872 l +22101.33 29312 23637.33 27050.67 25600 25088 c +25941.33 24746.67 26112 24320 26112 23808 c +26112 23381.33 25984 22997.33 25728 22656 c +25386.67 22314.67 25002.67 22144 24576 22144 c +24064 22144 23594.67 22357.33 23168 22784 c +22144 24234.67 21162.67 26112 20224 28416 c +20650.67 25344 20864 22869.33 20864 20992 c +20864 3456 l +20864 2517.33 20266.67 2048 19072 2048 c +17962.67 2048 17408 2517.33 17408 3456 c +17408 19712 l +17408 21504 17664 24064 18176 27392 c +16554.67 22101.33 14592 17877.33 12288 14720 c +11861.33 14208 11349.33 13952 10752 13952 c +10410.67 13952 10112 14037.33 9856 14208 c +9344 14634.67 9088 15104 9088 15616 c +9088 16042.67 9216 16469.33 9472 16896 c +12800 20992 15232 25984 16768 31872 c +11520 31872 l +10581.33 31872 10112 32426.67 10112 33536 c +10112 34645.33 10581.33 35200 11520 35200 c +17408 35200 l +17408 41600 l +15786.67 41258.67 14250.67 41002.67 12800 40832 c +12800 40746.67 12714.67 40704 12544 40704 c +11605.33 40704 11050.67 41216 10880 42240 c +10880 42496 l +10880 43434.67 11306.67 43989.33 12160 44160 c +16853.33 44842.67 20693.33 45952 23680 47488 c +24021.33 47658.67 24405.33 47744 24832 47744 c +25429.33 47744 25941.33 47445.33 26368 46848 c +26624 46506.67 26752 46165.33 26752 45824 c +26752 45226.67 26410.67 44757.33 25728 44416 c +24533.33 43818.67 22912 43178.67 20864 42496 c +20864 35200 l +25472 35200 l +h +33792 36224 m +33792 37162.67 34432 37632 35712 37632 c +36906.67 37632 37504 37120 37504 36096 c +37504 19328 l +42197.33 25642.67 45738.67 33706.67 48128 43520 c +48298.67 44458.67 48853.33 44928 49792 44928 c +49962.67 44928 50133.33 44885.33 50304 44800 c +51413.33 44629.33 51968 44074.67 51968 43136 c +51968 42880 51925.33 42709.33 51840 42624 c +48597.33 30677.33 43818.67 21120 37504 13952 c +37504 9088 l +37504 7978.67 38016 7338.67 39040 7168 c +39893.33 7082.67 41045.33 7040 42496 7040 c +43776 7040 44906.67 7168 45888 7424 c +46869.33 7680 47488 8234.67 47744 9088 c +48085.33 10282.67 48298.67 11946.67 48384 14080 c +48384 15104 48981.33 15616 50176 15616 c +50304 15616 l +51413.33 15530.67 51968 14933.33 51968 13824 c +51968 13696 l +51797.33 10794.67 51456 8533.33 50944 6912 c +50346.67 5290.67 49066.67 4266.67 47104 3840 c +45994.67 3669.33 44458.67 3541.33 42496 3456 c +40618.67 3456 38997.33 3541.33 37632 3712 c +35072 4053.33 33792 5418.67 33792 7808 c +33792 11264 l +31317.33 8960 28672 6954.67 25856 5248 c +25429.33 4992 25002.67 4864 24576 4864 c +23893.33 4864 23424 5162.67 23168 5760 c +22912 6016 22784 6357.33 22784 6784 c +22784 7552 23125.33 8106.67 23808 8448 c +27306.67 10410.67 30634.67 13013.33 33792 16256 c +33792 36224 l +h +29696 30592 m +29781.33 30592 29866.67 30592 29952 30592 c +30976 30421.33 31488 29866.67 31488 28928 c +31488 28672 31488 28501.33 31488 28416 c +30976 23466.67 29952 19200 28416 15616 c +27989.33 14848 27392 14464 26624 14464 c +26368 14464 26112 14506.67 25856 14592 c +25258.67 14933.33 24960 15402.67 24960 16000 c +24960 16341.33 25045.33 16682.67 25216 17024 c +26666.67 20352 27648 24405.33 28160 29184 c +28245.33 30122.67 28757.33 30592 29696 30592 c +h +42624 41984 m +43221.33 41472 43520 40917.33 43520 40320 c +43520 39978.67 43434.67 39680 43264 39424 c +42837.33 38826.67 42282.67 38528 41600 38528 c +41088 38528 40661.33 38698.67 40320 39040 c +37845.33 41002.67 35157.33 42709.33 32256 44160 c +31658.67 44501.33 31360 44970.67 31360 45568 c +31360 45909.33 31445.33 46208 31616 46464 c +32042.67 47146.67 32640 47488 33408 47488 c +33664 47488 34005.33 47402.67 34432 47232 c +37674.67 45696 40405.33 43946.67 42624 41984 c +h +50816 29952 m +51498.67 29952 52053.33 29568 52480 28800 c +53930.67 25642.67 55082.67 22058.67 55936 18048 c +56021.33 17706.67 56064 17450.67 56064 17280 c +56064 16512 55637.33 15957.33 54784 15616 c +54442.67 15616 54229.33 15616 54144 15616 c +53290.67 15616 52736 16085.33 52480 17024 c +51456 21205.33 50346.67 24661.33 49152 27392 c +48981.33 27648 48896 27946.67 48896 28288 c +48896 28970.67 49237.33 29482.67 49920 29824 c +50176 29909.33 50474.67 29952 50816 29952 c +h +W n +1 1 1 rg +-32767 -32767 65534 65534 re f +Q +Q +endstream +endobj +xref +0 5 +0000000000 65535 f +0000000015 00000 n +0000000064 00000 n +0000000121 00000 n +0000000218 00000 n +trailer +<< /Size 5 /Root 1 0 R >> +startxref +4862 +%%EOF diff --git a/test/vector/data/expected/basic/colrv0-large-scale.svg b/test/vector/data/expected/basic/colrv0-large-scale.svg new file mode 100644 index 000000000..edd4b2fb4 --- /dev/null +++ b/test/vector/data/expected/basic/colrv0-large-scale.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/test/vector/data/tests/basic.tests b/test/vector/data/tests/basic.tests index 426e6a0ff..0c7c6eec9 100644 --- a/test/vector/data/tests/basic.tests +++ b/test/vector/data/tests/basic.tests @@ -14,3 +14,5 @@ ../../../fuzzing/fonts/noto_handwriting-cff_colr_1.otf;;U+270D;../expected/basic/handwriting-cff-colr-1.svg ../../../fuzzing/fonts/noto_handwriting-cff2_colr_1.otf;;U+270D;../expected/basic/handwriting-cff-colr-1.svg ../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=65536;U+0061,U+0062,U+0063;../expected/basic/glyf-quadratics.pdf +../../../api/fonts/TwemojiMozilla.subset.default.32,3299.ttf;--font-size=65536;U+3299;../expected/basic/colrv0-large-scale.svg +../../../api/fonts/TwemojiMozilla.subset.default.32,3299.ttf;--font-size=65536;U+3299;../expected/basic/colrv0-large-scale.pdf From f7a8ef5022fa35500a0def38641b0f4d03ee9fe8 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 7 Jul 2026 16:01:50 +0300 Subject: [PATCH 02/11] [vector] Fix PDF MediaBox orientation The MediaBox negated the y-range like SVG viewBox does, but the SVG output is wrapped in scale(1,-1), and PDF content is emitted y-up. --- src/hb-vector-paint-pdf.cc | 6 +++--- test/vector/data/expected/basic/colrv0-large-scale.pdf | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index f28e1f866..8a9117ae5 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -1612,11 +1612,11 @@ hb_vector_paint_render_pdf (hb_vector_paint_t *paint) out.append_str ("3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox ["); out.append_num (ex); out.append_c (' '); - out.append_num (-(ey + eh)); + out.append_num (ey); out.append_c (' '); out.append_num (ex + ew); out.append_c (' '); - out.append_num (-ey); + out.append_num (ey + eh); out.append_str ("]\n/Contents 4 0 R"); /* Resources. */ @@ -1674,7 +1674,7 @@ hb_vector_paint_render_pdf (hb_vector_paint_t *paint) bg_prefix.append_str (" rg\n"); bg_prefix.append_num (ex); bg_prefix.append_c (' '); - bg_prefix.append_num (-(ey + eh)); + bg_prefix.append_num (ey); bg_prefix.append_c (' '); bg_prefix.append_num (ew); bg_prefix.append_c (' '); diff --git a/test/vector/data/expected/basic/colrv0-large-scale.pdf b/test/vector/data/expected/basic/colrv0-large-scale.pdf index 79237fd92..17586c3e7 100644 --- a/test/vector/data/expected/basic/colrv0-large-scale.pdf +++ b/test/vector/data/expected/basic/colrv0-large-scale.pdf @@ -7,14 +7,14 @@ endobj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj 3 0 obj -<< /Type /Page /Parent 2 0 R /MediaBox [-16 -57360 65552 8208] +<< /Type /Page /Parent 2 0 R /MediaBox [-16 -8208 65552 57360] /Contents 4 0 R >> endobj 4 0 obj -<< /Length 4593 >> +<< /Length 4592 >> stream 1 1 1 rg --16 -57360 65568 65568 re f +-16 -8208 65568 65568 re f q 1 0 0 1 0 0 cm q @@ -161,5 +161,5 @@ xref trailer << /Size 5 /Root 1 0 R >> startxref -4862 +4861 %%EOF From 421cc8f5a726d60925b91c992a82885064332ec4 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 8 Jul 2026 12:20:57 +0300 Subject: [PATCH 03/11] [paint] Add hb_paint_fill_glyph() Instead of painting COLRv0 and outline fallback layers with push_clip_glyph + color + pop_clip, add a dedicated callback for this common paint operation. The default (*_nil) implementation uses the decomposed sequence, so existing clients without a fill_glyph implementation continue to work as before. --- docs/harfbuzz-sections.txt | 3 +++ src/OT/Color/COLR/COLR.hh | 4 +--- src/hb-font.cc | 4 +--- src/hb-paint.cc | 38 ++++++++++++++++++++++++++++++ src/hb-paint.h | 47 ++++++++++++++++++++++++++++++++++++++ src/hb-paint.hh | 10 ++++++++ 6 files changed, 100 insertions(+), 6 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 95c179c2f..955e33b81 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -266,6 +266,8 @@ hb_paint_pop_transform_func_t hb_paint_funcs_set_pop_transform_func hb_paint_color_glyph_func_t hb_paint_funcs_set_color_glyph_func +hb_paint_fill_glyph_func_t +hb_paint_funcs_set_fill_glyph_func hb_paint_push_clip_glyph_func_t hb_paint_funcs_set_push_clip_glyph_func hb_paint_push_clip_rectangle_func_t @@ -311,6 +313,7 @@ hb_paint_push_font_transform hb_paint_push_inverse_font_transform hb_paint_pop_transform hb_paint_color_glyph +hb_paint_fill_glyph hb_paint_push_clip_glyph hb_paint_push_clip_rectangle hb_paint_push_clip_path_start diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 39a8231ba..7db97299b 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -2761,9 +2761,7 @@ struct COLR { hb_bool_t is_foreground; hb_color_t color = c.get_color (r.colorIdx, 1., &is_foreground); - c.funcs->push_clip_glyph (c.data, r.glyphId, c.font); - c.funcs->color (c.data, is_foreground, color); - c.funcs->pop_clip (c.data); + c.funcs->fill_glyph (c.data, r.glyphId, c.font, is_foreground, color); } return true; diff --git a/src/hb-font.cc b/src/hb-font.cc index 96fcff501..4b7bce99f 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1670,9 +1670,7 @@ hb_font_t::paint_glyph (hb_codepoint_t glyph, return; /* Fallback for outline glyph. */ - paint_funcs->push_clip_glyph (paint_data, glyph, this); - paint_funcs->color (paint_data, true, foreground); - paint_funcs->pop_clip (paint_data); + paint_funcs->fill_glyph (paint_data, glyph, this, true, foreground); } diff --git a/src/hb-paint.cc b/src/hb-paint.cc index e272ec39b..9e84fbbb9 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -60,6 +60,20 @@ hb_paint_color_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_font_t *font, void *user_data) { return false; } +static void +hb_paint_fill_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color, + void *user_data) +{ + /* Decompose into the equivalent general sequence. */ + funcs->push_clip_glyph (paint_data, glyph, font); + funcs->color (paint_data, is_foreground, color); + funcs->pop_clip (paint_data); +} + static void hb_paint_push_clip_glyph_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, @@ -551,6 +565,30 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data, return funcs->color_glyph (paint_data, glyph, font); } +/** + * hb_paint_fill_glyph: + * @funcs: paint functions + * @paint_data: associated data passed by the caller + * @glyph: the glyph ID + * @font: the font + * @is_foreground: whether the color is the foreground + * @color: The color to use + * + * Perform a "fill-glyph" paint operation: fill the glyph's shape + * with a solid color. + * + * XSince: REPLACEME + */ +void +hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color) +{ + funcs->fill_glyph (paint_data, glyph, font, is_foreground, color); +} + /** * hb_paint_push_clip_glyph: * @funcs: paint functions diff --git a/src/hb-paint.h b/src/hb-paint.h index 9057e3b72..46e83b817 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -157,6 +157,29 @@ typedef hb_bool_t (*hb_paint_color_glyph_func_t) (hb_paint_funcs_t *funcs, hb_font_t *font, void *user_data); +/** + * hb_paint_fill_glyph_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() + * @glyph: the glyph ID + * @font: the font + * @is_foreground: whether the color is the foreground + * @color: The color to use, unpremultiplied + * @user_data: User data pointer passed to hb_paint_funcs_set_fill_glyph_func() + * + * A virtual method for the #hb_paint_funcs_t to fill a glyph's + * shape with a solid color. + * + * XSince: REPLACEME + */ +typedef void (*hb_paint_fill_glyph_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color, + void *user_data); + /** * hb_paint_push_clip_glyph_func_t: * @funcs: paint functions object @@ -854,6 +877,23 @@ hb_paint_funcs_set_color_glyph_func (hb_paint_funcs_t *funcs, void *user_data, hb_destroy_func_t destroy); +/** + * hb_paint_funcs_set_fill_glyph_func: + * @funcs: A paint functions struct + * @func: (closure user_data) (destroy destroy) (scope notified): The fill-glyph callback + * @user_data: Data to pass to @func + * @destroy: (nullable): Function to call when @user_data is no longer needed + * + * Sets the fill-glyph callback on the paint functions struct. + * + * XSince: REPLACEME + */ +HB_EXTERN void +hb_paint_funcs_set_fill_glyph_func (hb_paint_funcs_t *funcs, + hb_paint_fill_glyph_func_t func, + void *user_data, + hb_destroy_func_t destroy); + /** * hb_paint_funcs_set_push_clip_glyph_func: * @funcs: A paint functions struct @@ -1117,6 +1157,13 @@ hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, hb_font_t *font); +HB_EXTERN void +hb_paint_fill_glyph (hb_paint_funcs_t *funcs, void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color); + HB_EXTERN void hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data, hb_codepoint_t glyph, diff --git a/src/hb-paint.hh b/src/hb-paint.hh index 148bfc974..f06bce45d 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -48,6 +48,7 @@ HB_PAINT_FUNC_IMPLEMENT (push_group_for) \ HB_PAINT_FUNC_IMPLEMENT (pop_group) \ HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \ + HB_PAINT_FUNC_IMPLEMENT (fill_glyph) \ /* ^--- Add new callbacks here */ struct hb_paint_funcs_t @@ -121,6 +122,15 @@ struct hb_paint_funcs_t { func.color (this, paint_data, is_foreground, color, !user_data ? nullptr : user_data->color); } + void fill_glyph (void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground, + hb_color_t color) + { func.fill_glyph (this, paint_data, + glyph, font, + is_foreground, color, + !user_data ? nullptr : user_data->fill_glyph); } bool image (void *paint_data, hb_blob_t *image, unsigned width, unsigned height, From 9ab56e867898d22cc307e17e0335aa8968691edc Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Wed, 8 Jul 2026 12:24:16 +0300 Subject: [PATCH 04/11] [vector] Implement fill_glyph callback Fill the glyph shape directly. This simplifies the SVG/PDF output and fixes the SVG clipping issue with COLRv0 layers and large scale, as there is no clip now at all. --- src/hb-vector-paint-pdf.cc | 53 +++++++++++++++++++ src/hb-vector-paint-svg.cc | 28 ++++++++++ .../expected/basic/colrv0-large-scale.pdf | 18 +++---- .../expected/basic/colrv0-large-scale.svg | 14 +---- 4 files changed, 89 insertions(+), 24 deletions(-) diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 8a9117ae5..a9f365777 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -392,6 +392,58 @@ hb_pdf_paint_pop_transform (hb_paint_funcs_t *, paint->current_body ().append_str ("Q\n"); } +static void +hb_pdf_paint_fill_glyph (hb_paint_funcs_t *, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t, + hb_color_t c, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!paint->ensure_initialized ())) + return; + + float r = hb_color_get_red (c) / 255.f; + float g = hb_color_get_green (c) / 255.f; + float b = hb_color_get_blue (c) / 255.f; + float a = hb_color_get_alpha (c) / 255.f; + + if (a < 1.f / 255.f) + return; + + auto &body = paint->current_body (); + + bool scoped = false; + /* Set alpha via ExtGState if needed, scoped so it does not leak + * into later paints. */ + if (a < 1.f - 1.f / 512.f) + { + auto *res = hb_pdf_get_resources (paint); + if (res) + { + unsigned gs_idx = res->add_extgstate_alpha (a); + body.append_str ("q\n"); + scoped = true; + body.append_str ("/GS"); + body.append_unsigned (gs_idx); + body.append_str (" gs\n"); + } + } + + body.append_num (r, 4); + body.append_c (' '); + body.append_num (g, 4); + body.append_c (' '); + body.append_num (b, 4); + body.append_str (" rg\n"); + hb_pdf_emit_glyph_path (paint, font, glyph, &body); + body.append_str ("f\n"); + if (scoped) + body.append_str ("Q\n"); +} + static void hb_pdf_paint_push_clip_glyph (hb_paint_funcs_t *, void *paint_data, @@ -1534,6 +1586,7 @@ static struct hb_pdf_paint_funcs_lazy_loader_t hb_paint_funcs_t *funcs = hb_paint_funcs_create (); hb_paint_funcs_set_push_transform_func (funcs, (hb_paint_push_transform_func_t) hb_pdf_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, (hb_paint_pop_transform_func_t) hb_pdf_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, (hb_paint_fill_glyph_func_t) hb_pdf_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, (hb_paint_push_clip_glyph_func_t) hb_pdf_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, (hb_paint_push_clip_rectangle_func_t) hb_pdf_paint_push_clip_rectangle, nullptr, nullptr); hb_paint_funcs_set_push_clip_path_start_func (funcs, (hb_paint_push_clip_path_start_func_t) hb_pdf_paint_push_clip_path_start, nullptr, nullptr); diff --git a/src/hb-vector-paint-svg.cc b/src/hb-vector-paint-svg.cc index eca53e39a..7cca077bb 100644 --- a/src/hb-vector-paint-svg.cc +++ b/src/hb-vector-paint-svg.cc @@ -268,6 +268,7 @@ static void hb_vector_paint_push_transform (hb_paint_funcs_t *, void *, float, float, float, float, float, float, void *); static void hb_vector_paint_pop_transform (hb_paint_funcs_t *, void *, void *); +static void hb_vector_paint_fill_glyph (hb_paint_funcs_t *, void *, hb_codepoint_t, hb_font_t *, hb_bool_t, hb_color_t, void *); static void hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, void *, hb_codepoint_t, hb_font_t *, void *); static void hb_vector_paint_push_clip_rectangle (hb_paint_funcs_t *, void *, float, float, float, float, void *); static hb_draw_funcs_t * hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *, void *, void **, void *); @@ -308,6 +309,7 @@ static struct hb_vector_paint_funcs_lazy_loader_t hb_paint_funcs_t *funcs = hb_paint_funcs_create (); hb_paint_funcs_set_push_transform_func (funcs, (hb_paint_push_transform_func_t) hb_vector_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, (hb_paint_pop_transform_func_t) hb_vector_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, (hb_paint_fill_glyph_func_t) hb_vector_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, (hb_paint_push_clip_glyph_func_t) hb_vector_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, (hb_paint_push_clip_rectangle_func_t) hb_vector_paint_push_clip_rectangle, nullptr, nullptr); hb_paint_funcs_set_push_clip_path_start_func (funcs, (hb_paint_push_clip_path_start_func_t) hb_vector_paint_push_clip_path_start, nullptr, nullptr); @@ -413,6 +415,32 @@ hb_vector_paint_pop_transform (hb_paint_funcs_t *, paint->current_body ().append_str ("\n"); } +static void +hb_vector_paint_fill_glyph (hb_paint_funcs_t *, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t, + hb_color_t color, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!paint->ensure_initialized ())) + return; + + paint->path.clear (); + hb_vector_path_sink_t sink = {&paint->path, paint->get_precision (), + paint->x_scale_factor, paint->y_scale_factor}; + hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); + + auto &body = paint->current_body (); + body.append_str ("path.arrayZ, paint->path.length); + body.append_str ("\" fill=\""); + body.append_svg_color (color, true); + body.append_str ("\"/>\n"); +} + static void hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, void *paint_data, diff --git a/test/vector/data/expected/basic/colrv0-large-scale.pdf b/test/vector/data/expected/basic/colrv0-large-scale.pdf index 17586c3e7..54074f06a 100644 --- a/test/vector/data/expected/basic/colrv0-large-scale.pdf +++ b/test/vector/data/expected/basic/colrv0-large-scale.pdf @@ -11,13 +11,13 @@ endobj /Contents 4 0 R >> endobj 4 0 obj -<< /Length 4592 >> +<< /Length 4518 >> stream 1 1 1 rg -16 -8208 65568 65568 re f q 1 0 0 1 0 0 cm -q +0.8667 0.1804 0.2667 rg 55936 47744 m 62336 41344 65536 33621.33 65536 24576 c 65536 15530.67 62336 7808 55936 1408 c @@ -28,11 +28,8 @@ q 16000 54144 23722.67 57344 32768 57344 c 41813.33 57344 49536 54144 55936 47744 c h -W n -0.8667 0.1804 0.2667 rg --32767 -32767 65534 65534 re f -Q -q +f +1 1 1 rg 25472 35200 m 26410.67 35200 26880 34645.33 26880 33536 c 26880 32426.67 26410.67 31872 25472 31872 c @@ -144,10 +141,7 @@ h 48896 28970.67 49237.33 29482.67 49920 29824 c 50176 29909.33 50474.67 29952 50816 29952 c h -W n -1 1 1 rg --32767 -32767 65534 65534 re f -Q +f Q endstream endobj @@ -161,5 +155,5 @@ xref trailer << /Size 5 /Root 1 0 R >> startxref -4861 +4787 %%EOF diff --git a/test/vector/data/expected/basic/colrv0-large-scale.svg b/test/vector/data/expected/basic/colrv0-large-scale.svg index edd4b2fb4..bd76c65d3 100644 --- a/test/vector/data/expected/basic/colrv0-large-scale.svg +++ b/test/vector/data/expected/basic/colrv0-large-scale.svg @@ -1,17 +1,7 @@ - - - - - - - - - - - - + + From afda4215dd9c88a1d1a0f8d4ec0092f3ad5c4059 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 03:26:26 +0300 Subject: [PATCH 05/11] [ft] Use fill_glyph for COLRv0 layers --- src/hb-ft-colr.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index af45ca754..5237dfb5d 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -600,10 +600,8 @@ hb_ft_paint_glyph_colr (hb_font_t *font, } ft_font->lock.unlock (); - paint_funcs->push_clip_glyph (paint_data, layer_glyph_index, font); + paint_funcs->fill_glyph (paint_data, layer_glyph_index, font, is_foreground, color); ft_font->lock.lock (); - paint_funcs->color (paint_data, is_foreground, color); - paint_funcs->pop_clip (paint_data); } while (FT_Get_Color_Glyph_Layer(ft_face, gid, From bec75aa8810651a6b197137002f170654408dddc Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 15:13:24 +0300 Subject: [PATCH 06/11] [cairo] Implement fill_glyph callback --- src/hb-cairo-utils.cc | 26 +++++++++++++++++++++++ src/hb-cairo-utils.hh | 5 +++++ src/hb-cairo.cc | 49 ++++++++++++++++++++++++------------------- 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc index d0888d4c5..0912cd082 100644 --- a/src/hb-cairo-utils.cc +++ b/src/hb-cairo-utils.cc @@ -94,6 +94,32 @@ _hb_cairo_destroy_blob (void *p) hb_blob_destroy ((hb_blob_t *) p); } +void +_hb_cairo_set_source_color (hb_cairo_context_t *c, + hb_bool_t use_foreground, + hb_color_t color) +{ + cairo_t *cr = c->cr; + + if (use_foreground) + { +#ifdef HAVE_CAIRO_USER_SCALED_FONT_GET_FOREGROUND_SOURCE + double r, g, b, a; + cairo_pattern_t *foreground = cairo_user_scaled_font_get_foreground_source (c->scaled_font); + if (cairo_pattern_get_rgba (foreground, &r, &g, &b, &a) == CAIRO_STATUS_SUCCESS) + cairo_set_source_rgba (cr, r, g, b, a * hb_color_get_alpha (color) / 255.); + else +#endif + cairo_set_source_rgba (cr, 0, 0, 0, hb_color_get_alpha (color) / 255.); + } + else + cairo_set_source_rgba (cr, + hb_color_get_red (color) / 255., + hb_color_get_green (color) / 255., + hb_color_get_blue (color) / 255., + hb_color_get_alpha (color) / 255.); +} + hb_bool_t _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, hb_blob_t *blob, diff --git a/src/hb-cairo-utils.hh b/src/hb-cairo-utils.hh index a26bf59d9..c9e380120 100644 --- a/src/hb-cairo-utils.hh +++ b/src/hb-cairo-utils.hh @@ -75,6 +75,11 @@ _hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode) } } +HB_INTERNAL void +_hb_cairo_set_source_color (hb_cairo_context_t *c, + hb_bool_t use_foreground, + hb_color_t color); + HB_INTERNAL hb_bool_t _hb_cairo_paint_glyph_image (hb_cairo_context_t *c, hb_blob_t *blob, diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index ddb5d23dc..add26bea7 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -166,6 +166,29 @@ hb_cairo_pop_transform (hb_paint_funcs_t *pfuncs HB_UNUSED, cairo_restore (cr); } +static void +hb_cairo_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t use_foreground, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data; + cairo_t *cr = c->cr; + + cairo_save (cr); + + cairo_new_path (cr); + hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr); + cairo_close_path (cr); + _hb_cairo_set_source_color (c, use_foreground, color); + cairo_fill (cr); + + cairo_restore (cr); +} + static hb_bool_t hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -303,23 +326,7 @@ hb_cairo_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data; cairo_t *cr = c->cr; - if (use_foreground) - { -#ifdef HAVE_CAIRO_USER_SCALED_FONT_GET_FOREGROUND_SOURCE - double r, g, b, a; - cairo_pattern_t *foreground = cairo_user_scaled_font_get_foreground_source (c->scaled_font); - if (cairo_pattern_get_rgba (foreground, &r, &g, &b, &a) == CAIRO_STATUS_SUCCESS) - cairo_set_source_rgba (cr, r, g, b, a * hb_color_get_alpha (color) / 255.); - else -#endif - cairo_set_source_rgba (cr, 0, 0, 0, hb_color_get_alpha (color) / 255.); - } - else - cairo_set_source_rgba (cr, - hb_color_get_red (color) / 255., - hb_color_get_green (color) / 255., - hb_color_get_blue (color) / 255., - hb_color_get_alpha (color) / 255.); + _hb_cairo_set_source_color (c, use_foreground, color); cairo_paint (cr); } @@ -452,6 +459,7 @@ static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t< hb_paint_funcs_set_push_transform_func (funcs, hb_cairo_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, hb_cairo_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, hb_cairo_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_color_glyph_func (funcs, hb_cairo_paint_color_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_cairo_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_cairo_push_clip_rectangle, nullptr, nullptr); @@ -675,10 +683,9 @@ hb_cairo_render_color_glyph (cairo_scaled_font_t *scaled_font, c.color_cache = (hb_map_t *) cairo_scaled_font_get_user_data (scaled_font, &color_cache_key); /* Synthesizing variant: mono glyphs render here too via the - * push_clip_glyph + foreground-fill fallback inside - * hb_font_paint_glyph. Callers that want the cheaper - * outline path for mono fonts set CAIRO_COLOR_MODE_NO_COLOR - * on the font options instead. */ + * fill_glyph foreground fallback inside hb_font_paint_glyph. + * Callers that want the cheaper outline path for mono fonts set + * CAIRO_COLOR_MODE_NO_COLOR on the font options instead. */ hb_font_paint_glyph (font, glyph, hb_cairo_paint_get_funcs (), &c, palette, color); return CAIRO_STATUS_SUCCESS; From 884a591273ca367ed9a029951225cd9d2e8980c9 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 19:21:47 +0300 Subject: [PATCH 07/11] [raster] Implement fill_glyph callback --- src/hb-raster-paint.cc | 155 +++++++++++++++++++++++++++++++++-------- 1 file changed, 125 insertions(+), 30 deletions(-) diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 24e3973f2..46ea2889a 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -196,6 +196,35 @@ hb_raster_paint_push_empty_clip (hb_raster_paint_t *c, unsigned w, unsigned h) (void) c->clip_stack.push (std::move (new_clip)); } +static bool +hb_raster_paint_intersect_mask (const hb_raster_image_t *surf, + const hb_raster_extents_t &mask_ext, + const hb_raster_clip_t &clip, + unsigned w, unsigned h, + int64_t *mask_x0, int64_t *mask_y0, + unsigned *ix0, unsigned *iy0, + unsigned *ix1, unsigned *iy1) +{ + /* Convert mask extents from surface coordinates to clip-buffer coordinates. */ + int64_t mx0 = (int64_t) mask_ext.x_origin - (int64_t) surf->extents.x_origin; + int64_t my0 = (int64_t) mask_ext.y_origin - (int64_t) surf->extents.y_origin; + + int64_t x0 = hb_max ((int64_t) clip.min_x, hb_max (mx0, (int64_t) 0)); + int64_t y0 = hb_max ((int64_t) clip.min_y, hb_max (my0, (int64_t) 0)); + int64_t x1 = hb_min ((int64_t) clip.max_x, hb_min (mx0 + mask_ext.width, (int64_t) w)); + int64_t y1 = hb_min ((int64_t) clip.max_y, hb_min (my0 + mask_ext.height, (int64_t) h)); + + if (x0 >= x1 || y0 >= y1) return false; + + *mask_x0 = mx0; + *mask_y0 = my0; + *ix0 = (unsigned) x0; + *iy0 = (unsigned) y0; + *ix1 = (unsigned) x1; + *iy1 = (unsigned) y1; + return true; +} + /* Render whatever edges have been accumulated into @rdr and * push the result as a new clip on the stack, intersecting * with the existing clip. Used by the emitter-based clip @@ -239,29 +268,17 @@ hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, return; } - /* Convert mask extents from surface coordinates to clip-buffer coordinates. */ - int64_t mask_x0 = (int64_t) mask_ext.x_origin - (int64_t) surf->extents.x_origin; - int64_t mask_y0 = (int64_t) mask_ext.y_origin - (int64_t) surf->extents.y_origin; - int64_t mask_x1 = mask_x0 + mask_ext.width; - int64_t mask_y1 = mask_y0 + mask_ext.height; - - int64_t ix0_i = hb_max ((int64_t) old_clip.min_x, hb_max (mask_x0, (int64_t) 0)); - int64_t iy0_i = hb_max ((int64_t) old_clip.min_y, hb_max (mask_y0, (int64_t) 0)); - int64_t ix1_i = hb_min ((int64_t) old_clip.max_x, hb_min (mask_x1, (int64_t) w)); - int64_t iy1_i = hb_min ((int64_t) old_clip.max_y, hb_min (mask_y1, (int64_t) h)); - - if (ix0_i >= ix1_i || iy0_i >= iy1_i) + int64_t mask_x0, mask_y0; + unsigned ix0, iy0, ix1, iy1; + if (!hb_raster_paint_intersect_mask (surf, mask_ext, old_clip, w, h, + &mask_x0, &mask_y0, + &ix0, &iy0, &ix1, &iy1)) { hb_raster_draw_recycle_image (rdr, mask_img); hb_raster_paint_push_empty_clip (c, w, h); return; } - unsigned ix0 = (unsigned) ix0_i; - unsigned iy0 = (unsigned) iy0_i; - unsigned ix1 = (unsigned) ix1_i; - unsigned iy1 = (unsigned) iy1_i; - new_clip.min_x = w; new_clip.min_y = h; new_clip.max_x = 0; new_clip.max_y = 0; @@ -697,19 +714,11 @@ hb_raster_paint_pop_group (hb_paint_funcs_t *pfuncs HB_UNUSED, } static void -hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, - void *paint_data, - hb_bool_t is_foreground HB_UNUSED, +hb_raster_paint_solid (hb_raster_paint_t *c, + hb_raster_image_t *surf, hb_color_t color, - void *user_data HB_UNUSED) + hb_raster_image_t *mask_img) { - hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; - - ensure_initialized (c); - - hb_raster_image_t *surf = c->current_surface (); - if (unlikely (!surf)) return; - uint32_t premul = color_to_premul_pixel (color); uint8_t premul_a = (uint8_t) (premul >> 24); const hb_raster_clip_t &clip = c->current_clip (); @@ -718,15 +727,36 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, if (clip.min_x >= clip.max_x || clip.min_y >= clip.max_y) return; if (premul_a == 0) return; + unsigned ix0 = clip.min_x, iy0 = clip.min_y; + unsigned ix1 = clip.max_x, iy1 = clip.max_y; + const uint8_t *mask_buf = nullptr; + hb_raster_extents_t mask_ext; + int64_t mask_x0 = 0, mask_y0 = 0; + if (mask_img) + { + mask_buf = hb_raster_image_get_buffer (mask_img); + hb_raster_image_get_extents (mask_img, &mask_ext); + if (!hb_raster_paint_intersect_mask (surf, mask_ext, clip, + surf->extents.width, surf->extents.height, + &mask_x0, &mask_y0, + &ix0, &iy0, &ix1, &iy1)) + return; + } + if (likely (!clip.is_rect)) { - for (unsigned y = clip.min_y; y < clip.max_y; y++) + for (unsigned y = iy0; y < iy1; y++) { hb_packed_t *__restrict row = (hb_packed_t *) (surf->buffer.arrayZ + y * stride); const uint8_t *__restrict clip_row = clip.alpha.arrayZ + y * clip.stride; - for (unsigned x = clip.min_x; x < clip.max_x; x++) + const uint8_t *__restrict mask_row = mask_buf ? mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride + : nullptr; + unsigned mx = (unsigned) ((int64_t) ix0 - mask_x0); + for (unsigned x = ix0; x < ix1; x++) { uint8_t clip_alpha = clip_row[x]; + if (mask_row) + clip_alpha = hb_raster_div255 (mask_row[mx++] * clip_alpha); if (clip_alpha == 0) continue; if (clip_alpha == 255) { @@ -743,6 +773,22 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, } } } + else if (mask_buf) + { + for (unsigned y = iy0; y < iy1; y++) + { + hb_packed_t *__restrict row = (hb_packed_t *) (surf->buffer.arrayZ + y * stride); + const uint8_t *__restrict mask_row = mask_buf + (unsigned) ((int64_t) y - mask_y0) * mask_ext.stride; + unsigned mx = (unsigned) ((int64_t) ix0 - mask_x0); + for (unsigned x = ix0; x < ix1; x++) + { + uint8_t mask_alpha = mask_row[mx++]; + if (mask_alpha == 0) continue; + uint32_t src = hb_raster_alpha_mul (premul, mask_alpha); + row[x] = hb_packed_t (hb_raster_src_over (src, (uint32_t) row[x])); + } + } + } else { for (unsigned y = clip.min_y; y < clip.max_y; y++) @@ -754,6 +800,54 @@ hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, } } +static void +hb_raster_paint_color (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_bool_t is_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + ensure_initialized (c); + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf)) return; + + hb_raster_paint_solid (c, surf, color, nullptr); +} + +static void +hb_raster_paint_fill_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font, + hb_bool_t is_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + ensure_initialized (c); + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf)) return; + + hb_raster_draw_t *rdr = c->clip_rdr; + hb_transform_t<> t = c->current_effective_transform (); + hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0); + + hb_raster_paint_glyph_clip_data_t data = {glyph, font}; + hb_raster_paint_emit_clip_glyph_mask (rdr, &data); + + hb_raster_image_t *mask_img = hb_raster_draw_render (rdr); + if (unlikely (!mask_img)) return; + + hb_raster_paint_solid (c, surf, color, mask_img); + + hb_raster_draw_recycle_image (rdr, mask_img); +} + static hb_bool_t hb_raster_paint_image (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -1645,6 +1739,7 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t hb_paint_funcs_set_push_transform_func (funcs, hb_raster_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, hb_raster_paint_pop_transform, nullptr, nullptr); + hb_paint_funcs_set_fill_glyph_func (funcs, hb_raster_paint_fill_glyph, nullptr, nullptr); hb_paint_funcs_set_color_glyph_func (funcs, hb_raster_paint_color_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_raster_paint_push_clip_glyph, nullptr, nullptr); hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_raster_paint_push_clip_rectangle, nullptr, nullptr); From b4ed9681838741bda1a5c05c383eac74340f0369 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 19:36:15 +0300 Subject: [PATCH 08/11] [test/paint] Test the fill_path callback --- test/api/results-paint/rocher-1 | 16 +++-------- test/api/results-paint/rocher-2 | 16 +++-------- test/api/results-paint/rocher-3 | 16 +++-------- test/api/results-paint/test-165 | 4 +-- test/api/results-paint/test-175 | 4 +-- test/api/results-paint/test-6 | 4 +-- test/api/results-paint/testvf-165 | 4 +-- test/api/results-paint/testvf-175 | 4 +-- test/api/results-paint/testvf-6 | 4 +-- test/api/test-paint.c | 48 +++++++++++++++++++++++++++++++ 10 files changed, 66 insertions(+), 54 deletions(-) diff --git a/test/api/results-paint/rocher-1 b/test/api/results-paint/rocher-1 index bede5acbd..3f5925668 100644 --- a/test/api/results-paint/rocher-1 +++ b/test/api/results-paint/rocher-1 @@ -1,14 +1,6 @@ start transform 1 0 0.3 1 0 0 - start clip glyph 8 - solid 81 61 50 255 - end clip - start clip glyph 9 - solid 245 185 68 255 - end clip - start clip glyph 10 - solid 224 142 55 255 - end clip - start clip glyph 11 - solid 245 202 86 255 - end clip + fill glyph 8 solid 81 61 50 255 + fill glyph 9 solid 245 185 68 255 + fill glyph 10 solid 224 142 55 255 + fill glyph 11 solid 245 202 86 255 end transform diff --git a/test/api/results-paint/rocher-2 b/test/api/results-paint/rocher-2 index 4cb377293..8558dfd26 100644 --- a/test/api/results-paint/rocher-2 +++ b/test/api/results-paint/rocher-2 @@ -1,14 +1,6 @@ start transform 1 0 0.3 1 0 0 - start clip glyph 12 - solid 81 61 50 255 - end clip - start clip glyph 13 - solid 245 185 68 255 - end clip - start clip glyph 14 - solid 224 142 55 255 - end clip - start clip glyph 15 - solid 245 202 86 255 - end clip + fill glyph 12 solid 81 61 50 255 + fill glyph 13 solid 245 185 68 255 + fill glyph 14 solid 224 142 55 255 + fill glyph 15 solid 245 202 86 255 end transform diff --git a/test/api/results-paint/rocher-3 b/test/api/results-paint/rocher-3 index 326fdc4f9..08072ede7 100644 --- a/test/api/results-paint/rocher-3 +++ b/test/api/results-paint/rocher-3 @@ -1,12 +1,4 @@ -start clip glyph 16 - solid 81 61 50 255 -end clip -start clip glyph 17 - solid 245 185 68 255 -end clip -start clip glyph 18 - solid 224 142 55 255 -end clip -start clip glyph 19 - solid 245 202 86 255 -end clip +fill glyph 16 solid 81 61 50 255 +fill glyph 17 solid 245 185 68 255 +fill glyph 18 solid 224 142 55 255 +fill glyph 19 solid 245 202 86 255 diff --git a/test/api/results-paint/test-165 b/test/api/results-paint/test-165 index dd59b78c5..0172bbad0 100644 --- a/test/api/results-paint/test-165 +++ b/test/api/results-paint/test-165 @@ -1,3 +1 @@ -start clip glyph 165 - solid 0 0 0 255 -end clip +fill glyph 165 solid 0 0 0 255 diff --git a/test/api/results-paint/test-175 b/test/api/results-paint/test-175 index 77ca1eead..d6f868eaf 100644 --- a/test/api/results-paint/test-175 +++ b/test/api/results-paint/test-175 @@ -1,3 +1 @@ -start clip glyph 175 - solid 0 0 0 255 -end clip +fill glyph 175 solid 0 0 0 255 diff --git a/test/api/results-paint/test-6 b/test/api/results-paint/test-6 index ad5897b56..1ac702954 100644 --- a/test/api/results-paint/test-6 +++ b/test/api/results-paint/test-6 @@ -1,3 +1 @@ -start clip glyph 6 - solid 0 0 0 255 -end clip +fill glyph 6 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-165 b/test/api/results-paint/testvf-165 index dd59b78c5..0172bbad0 100644 --- a/test/api/results-paint/testvf-165 +++ b/test/api/results-paint/testvf-165 @@ -1,3 +1 @@ -start clip glyph 165 - solid 0 0 0 255 -end clip +fill glyph 165 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-175 b/test/api/results-paint/testvf-175 index 77ca1eead..d6f868eaf 100644 --- a/test/api/results-paint/testvf-175 +++ b/test/api/results-paint/testvf-175 @@ -1,3 +1 @@ -start clip glyph 175 - solid 0 0 0 255 -end clip +fill glyph 175 solid 0 0 0 255 diff --git a/test/api/results-paint/testvf-6 b/test/api/results-paint/testvf-6 index ad5897b56..1ac702954 100644 --- a/test/api/results-paint/testvf-6 +++ b/test/api/results-paint/testvf-6 @@ -1,3 +1 @@ -start clip glyph 6 - solid 0 0 0 255 -end clip +fill glyph 6 solid 0 0 0 255 diff --git a/test/api/test-paint.c b/test/api/test-paint.c index f12ca426d..e63e26389 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -111,6 +111,24 @@ pop_transform (hb_paint_funcs_t *funcs HB_UNUSED, print (data, "end transform"); } +static void +fill_glyph (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + hb_codepoint_t glyph, + hb_font_t *font HB_UNUSED, + hb_bool_t use_foreground HB_UNUSED, + hb_color_t color, + void *user_data HB_UNUSED) +{ + paint_data_t *data = paint_data; + + print (data, "fill glyph %u solid %d %d %d %d", glyph, + hb_color_get_red (color), + hb_color_get_green (color), + hb_color_get_blue (color), + hb_color_get_alpha (color)); +} + static hb_bool_t paint_color_glyph (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data, @@ -341,6 +359,7 @@ get_test_paint_funcs (void) hb_paint_funcs_set_push_transform_func (funcs, push_transform, NULL, NULL); hb_paint_funcs_set_pop_transform_func (funcs, pop_transform, NULL, NULL); + hb_paint_funcs_set_fill_glyph_func (funcs, fill_glyph, NULL, NULL); hb_paint_funcs_set_color_glyph_func (funcs, paint_color_glyph, NULL, NULL); hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL); hb_paint_funcs_set_push_clip_rectangle_func (funcs, push_clip_rectangle, NULL, NULL); @@ -828,6 +847,34 @@ test_push_clip_path_round_trip (void) hb_draw_funcs_destroy (sink); } +/* Test the default implementation of fill_glyph does the + * push_clip_glyph + color + pop_clip sequence. */ +static void +test_fill_glyph_nil_decomposes (void) +{ + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + hb_paint_funcs_set_push_clip_glyph_func (funcs, push_clip_glyph, NULL, NULL); + hb_paint_funcs_set_color_func (funcs, paint_color, NULL, NULL); + hb_paint_funcs_set_pop_clip_func (funcs, pop_clip, NULL, NULL); + hb_paint_funcs_make_immutable (funcs); + + paint_data_t data; + data.string = g_string_new (""); + data.level = 0; + + hb_paint_fill_glyph (funcs, &data, 42, hb_font_get_empty (), + FALSE, HB_COLOR (1, 2, 3, 4)); + + g_assert_true (data.level == 0); + g_assert_cmpstr (data.string->str, ==, + "start clip glyph 42\n" + " solid 3 2 1 4\n" + "end clip\n"); + + g_string_free (data.string, TRUE); + hb_paint_funcs_destroy (funcs); +} + int main (int argc, char **argv) @@ -840,6 +887,7 @@ main (int argc, char **argv) * below doesn't prevent them from running. */ hb_test_add (test_push_clip_path_nil_returns_null); hb_test_add (test_push_clip_path_round_trip); + hb_test_add (test_fill_glyph_nil_decomposes); for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++) { From bc00cd8fb5871a874263c39fceb10e6fba47f8f7 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 21:16:46 +0300 Subject: [PATCH 09/11] [fontations] Use fill_glyph for solid glyph fills --- src/rust/font.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/rust/font.rs b/src/rust/font.rs index 84bc79b57..247bcdf0c 100644 --- a/src/rust/font.rs +++ b/src/rust/font.rs @@ -701,6 +701,32 @@ impl ColorPainter for HbColorPainter<'_> { ) { unsafe { hb_paint_push_inverse_font_transform(self.paint_funcs, self.paint_data, self.font); + } + + if brush_transform.is_none() { + if let Brush::Solid { + palette_index: color_index, + alpha, + } = brush + { + let is_foreground = color_index == 0xFFFF; + let color = self.lookup_color(color_index, alpha); + unsafe { + hb_paint_fill_glyph( + self.paint_funcs, + self.paint_data, + glyph_id.to_u32() as hb_codepoint_t, + self.font, + is_foreground as hb_bool_t, + color, + ); + } + self.pop_transform(); + return; + } + } + + unsafe { hb_paint_push_clip_glyph( self.paint_funcs, self.paint_data, From e2588968aea88f019467b3500fbede3178aa2302 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 12 Jul 2026 22:20:21 +0300 Subject: [PATCH 10/11] [COLR] Emit fill_glyph for glyph clips with a solid paint Detect the fill-glyph pattern in the COLRv1 graph: a PaintGlyph whose child is a (Var)PaintSolid, and emit a single fill_glyph instead of push_clip_glyph + color + pop_clip. --- src/OT/Color/COLR/COLR.hh | 72 +++++++++++++--- src/hb-ft-colr.hh | 85 +++++++++++++------ test/api/results-paint/bad-154 | 6 +- test/api/results-paint/hand-10 | 30 ++----- test/api/results-paint/hand-10.2 | 30 ++----- test/api/results-paint/test-106 | 12 +-- test/api/results-paint/test-116 | 12 +-- test/api/results-paint/test-123 | 18 +--- test/api/results-paint/test-154 | 6 +- test/api/results-paint/testvf-106 | 12 +-- test/api/results-paint/testvf-116 | 12 +-- test/api/results-paint/testvf-123 | 18 +--- test/api/results-paint/testvf-154 | 6 +- .../expected/basic/handwriting-cff-colr-1.svg | 72 ++++------------ .../basic/handwriting-glyf-colr-1.svg | 72 ++++------------ 15 files changed, 179 insertions(+), 284 deletions(-) diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 7db97299b..e409cb388 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -335,6 +335,12 @@ struct Variable value.get_color_stop (c, stop, varIdxBase, instancer); } + void get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + value.get_solid_color (c, varIdxBase, is_foreground, color); + } + hb_paint_extend_t get_extend () const { return value.get_extend (); @@ -390,6 +396,12 @@ struct NoVariable value.get_color_stop (c, stop, VarIdx::NO_VARIATION, instancer); } + void get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + value.get_solid_color (c, VarIdx::NO_VARIATION, is_foreground, color); + } + hb_paint_extend_t get_extend () const { return value.get_extend (); @@ -680,15 +692,21 @@ struct PaintSolid return_trace (c->check_struct (this)); } + void get_solid_color (hb_paint_context_t *c, uint32_t varIdxBase, + hb_bool_t *is_foreground, hb_color_t *color) const + { + *color = c->get_color (paletteIndex, + alpha.to_float (c->instancer (varIdxBase, 0)), + is_foreground); + } + void paint_glyph (hb_paint_context_t *c, uint32_t varIdxBase) const { TRACE_PAINT (this); hb_bool_t is_foreground; hb_color_t color; - color = c->get_color (paletteIndex, - alpha.to_float (c->instancer (varIdxBase, 0)), - &is_foreground); + get_solid_color (c, varIdxBase, &is_foreground, &color); c->funcs->color (c->data, is_foreground, color); } @@ -928,17 +946,7 @@ struct PaintGlyph return_trace (c->check_struct (this) && paint.sanitize (c, this)); } - void paint_glyph (hb_paint_context_t *c) const - { - TRACE_PAINT (this); - c->funcs->push_inverse_font_transform (c->data, c->font); - c->funcs->push_clip_glyph (c->data, gid, c->font); - c->funcs->push_font_transform (c->data, c->font); - c->recurse (this+paint); - c->funcs->pop_transform (c->data); - c->funcs->pop_clip (c->data); - c->funcs->pop_transform (c->data); - } + inline void paint_glyph (hb_paint_context_t *c) const; HBUINT8 format; /* format = 10 */ Offset24To paint; /* Offset (from beginning of PaintGlyph table) to Paint subtable. */ @@ -1892,6 +1900,16 @@ struct Paint } } + bool get_solid_color (hb_paint_context_t *c, + hb_bool_t *is_foreground, hb_color_t *color) const + { + switch (u.format.v) { + case 2: u.paintformat2.get_solid_color (c, is_foreground, color); return true; + case 3: u.paintformat3.get_solid_color (c, is_foreground, color); return true; + default: return false; + } + } + protected: union { struct { HBUINT8 v; } format; @@ -2803,6 +2821,32 @@ hb_paint_context_t::recurse (const Paint &paint) depth_left++; } +void PaintGlyph::paint_glyph (hb_paint_context_t *c) const +{ + TRACE_PAINT (this); + + hb_bool_t is_foreground; + hb_color_t color; + /* Optimize cases that can use a simple fill-glyph operation. */ + if (likely (c->depth_left > 0 && c->edge_count > 0) && + (this+paint).get_solid_color (c, &is_foreground, &color)) + { + c->edge_count--; + c->funcs->push_inverse_font_transform (c->data, c->font); + c->funcs->fill_glyph (c->data, gid, c->font, is_foreground, color); + c->funcs->pop_transform (c->data); + return; + } + + c->funcs->push_inverse_font_transform (c->data, c->font); + c->funcs->push_clip_glyph (c->data, gid, c->font); + c->funcs->push_font_transform (c->data, c->font); + c->recurse (this+paint); + c->funcs->pop_transform (c->data); + c->funcs->pop_clip (c->data); + c->funcs->pop_transform (c->data); +} + void PaintColrLayers::paint_glyph (hb_paint_context_t *c) const { TRACE_PAINT (this); diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 5237dfb5d..090ebf087 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -250,6 +250,42 @@ _hb_ft_color_line_get_extend (hb_color_line_t *color_line, } } +static void +_hb_ft_get_solid_color (hb_ft_paint_context_t *c, + const FT_ColorIndex &color_index, + hb_bool_t *is_foreground, + hb_color_t *color) +{ + *is_foreground = color_index.palette_index == 0xFFFF; + + if (*is_foreground) + { + *color = HB_COLOR (hb_color_get_blue (c->foreground), + hb_color_get_green (c->foreground), + hb_color_get_red (c->foreground), + _hb_ft_color_alpha (hb_color_get_alpha (c->foreground), + color_index.alpha)); + return; + } + + if (c->funcs->custom_palette_color (c->data, color_index.palette_index, color)) + { + *color = HB_COLOR (hb_color_get_blue (*color), + hb_color_get_green (*color), + hb_color_get_red (*color), + _hb_ft_color_alpha (hb_color_get_alpha (*color), + color_index.alpha)); + return; + } + + FT_Color ft_color = c->palette[color_index.palette_index]; + *color = HB_COLOR (ft_color.blue, + ft_color.green, + ft_color.red, + _hb_ft_color_alpha (ft_color.alpha, + color_index.alpha)); +} + void _hb_ft_paint (hb_ft_paint_context_t *c, FT_OpaquePaint opaque_paint) @@ -280,34 +316,9 @@ _hb_ft_paint (hb_ft_paint_context_t *c, break; case FT_COLR_PAINTFORMAT_SOLID: { - bool is_foreground = paint.u.solid.color.palette_index == 0xFFFF; + hb_bool_t is_foreground; hb_color_t color; - if (is_foreground) - color = HB_COLOR (hb_color_get_blue (c->foreground), - hb_color_get_green (c->foreground), - hb_color_get_red (c->foreground), - _hb_ft_color_alpha (hb_color_get_alpha (c->foreground), - paint.u.solid.color.alpha)); - else - { - if (c->funcs->custom_palette_color (c->data, paint.u.solid.color.palette_index, &color)) - { - color = HB_COLOR (hb_color_get_blue (color), - hb_color_get_green (color), - hb_color_get_red (color), - _hb_ft_color_alpha (hb_color_get_alpha (color), - paint.u.solid.color.alpha)); - } - else - { - FT_Color ft_color = c->palette[paint.u.solid.color.palette_index]; - color = HB_COLOR (ft_color.blue, - ft_color.green, - ft_color.red, - _hb_ft_color_alpha (ft_color.alpha, - paint.u.solid.color.alpha)); - } - } + _hb_ft_get_solid_color (c, paint.u.solid.color, &is_foreground, &color); c->funcs->color (c->data, is_foreground, color); } break; @@ -362,6 +373,26 @@ _hb_ft_paint (hb_ft_paint_context_t *c, break; case FT_COLR_PAINTFORMAT_GLYPH: { + /* Optimize cases that can use a simple fill-glyph operation. */ + FT_COLR_Paint fill; + if (likely (c->depth_left > 0 && c->edge_count > 0) && + FT_Get_Paint (ft_face, paint.u.glyph.paint, &fill) && + fill.format == FT_COLR_PAINTFORMAT_SOLID) + { + hb_bool_t is_foreground; + hb_color_t color; + _hb_ft_get_solid_color (c, fill.u.solid.color, &is_foreground, &color); + + c->edge_count--; + c->funcs->push_inverse_font_transform (c->data, c->font); + c->ft_font->lock.unlock (); + c->funcs->fill_glyph (c->data, paint.u.glyph.glyphID, c->font, + is_foreground, color); + c->ft_font->lock.lock (); + c->funcs->pop_transform (c->data); + break; + } + c->funcs->push_inverse_font_transform (c->data, c->font); c->ft_font->lock.unlock (); c->funcs->push_clip_glyph (c->data, paint.u.glyph.glyphID, c->font); diff --git a/test/api/results-paint/bad-154 b/test/api/results-paint/bad-154 index 1dcf2489b..bd39666e4 100644 --- a/test/api/results-paint/bad-154 +++ b/test/api/results-paint/bad-154 @@ -3,11 +3,7 @@ start transform 1 0 0 1 0 0 push group 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 + fill glyph 159 solid 128 128 128 102 end transform pop group mode 3 pop group mode 3 diff --git a/test/api/results-paint/hand-10 b/test/api/results-paint/hand-10 index 2ba03ef53..06bfb136f 100644 --- a/test/api/results-paint/hand-10 +++ b/test/api/results-paint/hand-10 @@ -29,25 +29,13 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 15 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 15 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 16 - start transform 1 0 0 1 0 0 - solid 30 136 229 255 - end transform - end clip + fill glyph 16 solid 30 136 229 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 21 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 21 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 start clip glyph 16 @@ -62,11 +50,7 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 18 - start transform 1 0 0 1 0 0 - solid 66 66 66 51 - end transform - end clip + fill glyph 18 solid 66 66 66 51 end transform start transform 1 0 0 1 0 0 start clip glyph 19 @@ -85,11 +69,7 @@ start transform 1 0 0 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 20 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 20 solid 145 103 77 255 end transform end clip end transform diff --git a/test/api/results-paint/hand-10.2 b/test/api/results-paint/hand-10.2 index 379a02b47..49a5a7c54 100644 --- a/test/api/results-paint/hand-10.2 +++ b/test/api/results-paint/hand-10.2 @@ -30,25 +30,13 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 15 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 15 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 16 - start transform 1 0 0 1 0 0 - solid 30 136 229 255 - end transform - end clip + fill glyph 16 solid 30 136 229 255 end transform start transform 1 0 0 1 0 0 - start clip glyph 21 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 21 solid 145 103 77 255 end transform start transform 1 0 0 1 0 0 start clip glyph 16 @@ -63,11 +51,7 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 18 - start transform 1 0 0 1 0 0 - solid 66 66 66 51 - end transform - end clip + fill glyph 18 solid 66 66 66 51 end transform start transform 1 0 0 1 0 0 start clip glyph 19 @@ -86,11 +70,7 @@ start transform 1 0 0.2 1 0 0 end clip end transform start transform 1 0 0 1 0 0 - start clip glyph 20 - start transform 1 0 0 1 0 0 - solid 145 103 77 255 - end transform - end clip + fill glyph 20 solid 145 103 77 255 end transform end clip end transform diff --git a/test/api/results-paint/test-106 b/test/api/results-paint/test-106 index 60bf166ff..8fe63746d 100644 --- a/test/api/results-paint/test-106 +++ b/test/api/results-paint/test-106 @@ -1,20 +1,12 @@ 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 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0.268 0 1 0 -134 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/test-116 b/test/api/results-paint/test-116 index 2b38f892e..8e9dca4ef 100644 --- a/test/api/results-paint/test-116 +++ b/test/api/results-paint/test-116 @@ -1,20 +1,12 @@ 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 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0 0 1 100 0 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/test-123 b/test/api/results-paint/test-123 index 2afe0285a..667bf84e5 100644 --- a/test/api/results-paint/test-123 +++ b/test/api/results-paint/test-123 @@ -1,30 +1,18 @@ 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 - solid 0 0 0 255 - end transform - end clip + fill glyph 3 solid 0 0 0 255 end transform push group start transform 0.5 0 0 0.5 166 334 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 + fill glyph 2 solid 255 220 1 255 end transform end transform push group start transform 0.5 0 0 0.5 334 166 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 + fill glyph 2 solid 104 199 232 255 end transform end transform pop group mode 3 diff --git a/test/api/results-paint/test-154 b/test/api/results-paint/test-154 index 750a0503c..c5644b26b 100644 --- a/test/api/results-paint/test-154 +++ b/test/api/results-paint/test-154 @@ -1,11 +1,7 @@ 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 - solid 0 0 0 255 - end transform - end clip + fill glyph 154 solid 0 0 0 255 end transform end clip end transform diff --git a/test/api/results-paint/testvf-106 b/test/api/results-paint/testvf-106 index 60bf166ff..8fe63746d 100644 --- a/test/api/results-paint/testvf-106 +++ b/test/api/results-paint/testvf-106 @@ -1,20 +1,12 @@ 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 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0.268 0 1 0 -134 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/testvf-116 b/test/api/results-paint/testvf-116 index 2b38f892e..8e9dca4ef 100644 --- a/test/api/results-paint/testvf-116 +++ b/test/api/results-paint/testvf-116 @@ -1,20 +1,12 @@ 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 255 128 - end transform - end clip + fill glyph 3 solid 0 0 255 128 end transform push group start transform 1 0 0 1 100 0 start transform 1 0 0 1 0 0 - start clip glyph 3 - start transform 1 0 0 1 0 0 - solid 255 165 0 179 - end transform - end clip + fill glyph 3 solid 255 165 0 179 end transform end transform pop group mode 4 diff --git a/test/api/results-paint/testvf-123 b/test/api/results-paint/testvf-123 index 2afe0285a..667bf84e5 100644 --- a/test/api/results-paint/testvf-123 +++ b/test/api/results-paint/testvf-123 @@ -1,30 +1,18 @@ 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 - solid 0 0 0 255 - end transform - end clip + fill glyph 3 solid 0 0 0 255 end transform push group start transform 0.5 0 0 0.5 166 334 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 + fill glyph 2 solid 255 220 1 255 end transform end transform push group start transform 0.5 0 0 0.5 334 166 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 + fill glyph 2 solid 104 199 232 255 end transform end transform pop group mode 3 diff --git a/test/api/results-paint/testvf-154 b/test/api/results-paint/testvf-154 index 750a0503c..c5644b26b 100644 --- a/test/api/results-paint/testvf-154 +++ b/test/api/results-paint/testvf-154 @@ -1,11 +1,7 @@ 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 - solid 0 0 0 255 - end transform - end clip + fill glyph 154 solid 0 0 0 255 end transform 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 ae4d35ddd..8534b1234 100644 --- a/test/vector/data/expected/basic/handwriting-cff-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-cff-colr-1.svg @@ -7,30 +7,18 @@ - + - - - - - - - - - - - - + + - - @@ -46,49 +34,29 @@ + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -97,11 +65,7 @@ - - - - - + 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 61792c743..789b5a247 100644 --- a/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg +++ b/test/vector/data/expected/basic/handwriting-glyf-colr-1.svg @@ -7,30 +7,18 @@ - + - - - - - - - - - - - - + + - - @@ -46,49 +34,29 @@ + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -97,11 +65,7 @@ - - - - - + From bbcd7d656278a8644217b7c214d96f15603752fa Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 14 Jul 2026 01:27:09 +0300 Subject: [PATCH 11/11] [doc/paint] Mention the decomposed fallback sequence for fill-glyph --- src/hb-paint.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-paint.h b/src/hb-paint.h index 46e83b817..c5e4add22 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -167,8 +167,10 @@ typedef hb_bool_t (*hb_paint_color_glyph_func_t) (hb_paint_funcs_t *funcs, * @color: The color to use, unpremultiplied * @user_data: User data pointer passed to hb_paint_funcs_set_fill_glyph_func() * - * A virtual method for the #hb_paint_funcs_t to fill a glyph's - * shape with a solid color. + * A virtual method for the #hb_paint_funcs_t to fill a glyph's shape with + * a solid color. If not implemented, a sequence of "push-clip-glyph", + * "color", "pop-clip" paint operations, in that order, will be emitted + * instead. * * XSince: REPLACEME */