From 599c99b5894b253765f4984ab278b41cb54b3a67 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 01:42:44 -0600 Subject: [PATCH 01/26] [paint] Add arbitrary-path clip API Add push_clip_path_start / push_clip_path_end to the hb_paint_funcs_t vtable, for callers that want to clip paint output to an arbitrary shape (not just a glyph or rectangle). hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); hb_draw_move_to (df, dd, NULL, ...); hb_draw_line_to (df, dd, NULL, ...); ... hb_draw_close_path (df, dd, NULL); hb_paint_push_clip_path_end (pf, pd); /* paint ops here are clipped to the emitted path */ hb_paint_pop_clip (pf, pd); The backend hands back a draw_funcs + draw_data pair (transfer none) that accumulates the clip path; end() signals the caller is done drawing clip geometry and the accumulated path becomes an active clip. pop_clip closes the scope, symmetric with push_clip_glyph / push_clip_rectangle. Only public API and the nil vtable stubs land here. Backend implementations (hb-vector, hb-raster, hb-gpu) follow in separate commits. Partial: https://github.com/harfbuzz/harfbuzz/issues/5930 Assisted-by: Claude Opus 4.6 (1M context) --- docs/harfbuzz-sections.txt | 6 +++ src/hb-paint.cc | 57 +++++++++++++++++++++++ src/hb-paint.h | 95 +++++++++++++++++++++++++++++++++++++- src/hb-paint.hh | 9 ++++ 4 files changed, 165 insertions(+), 2 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index c0b74a5f4..b0c0bd5bc 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -270,6 +270,10 @@ hb_paint_push_clip_glyph_func_t hb_paint_funcs_set_push_clip_glyph_func hb_paint_push_clip_rectangle_func_t hb_paint_funcs_set_push_clip_rectangle_func +hb_paint_push_clip_path_start_func_t +hb_paint_funcs_set_push_clip_path_start_func +hb_paint_push_clip_path_end_func_t +hb_paint_funcs_set_push_clip_path_end_func hb_paint_pop_clip_func_t hb_paint_funcs_set_pop_clip_func hb_paint_color_func_t @@ -309,6 +313,8 @@ hb_paint_pop_transform hb_paint_color_glyph hb_paint_push_clip_glyph hb_paint_push_clip_rectangle +hb_paint_push_clip_path_start +hb_paint_push_clip_path_end hb_paint_pop_clip hb_paint_color hb_paint_image diff --git a/src/hb-paint.cc b/src/hb-paint.cc index ff7dceca8..f210364fc 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -71,6 +71,15 @@ hb_paint_push_clip_rectangle_nil (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax, void *user_data) {} +static hb_draw_funcs_t * +hb_paint_push_clip_path_start_nil (hb_paint_funcs_t *funcs, void *paint_data, + void **draw_data, + void *user_data) { if (draw_data) *draw_data = nullptr; return nullptr; } + +static void +hb_paint_push_clip_path_end_nil (hb_paint_funcs_t *funcs, void *paint_data, + void *user_data) {} + static void hb_paint_pop_clip_nil (hb_paint_funcs_t *funcs, void *paint_data, void *user_data) {} @@ -581,6 +590,54 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, funcs->push_clip_rectangle (paint_data, xmin, ymin, xmax, ymax); } +/** + * hb_paint_push_clip_path_start: + * @funcs: paint functions + * @paint_data: associated data passed by the caller + * @draw_data: (out) (nullable): location to receive the draw data + * the caller should pass alongside the returned draw funcs. + * + * Begin clipping to an arbitrary path. Returns a + * #hb_draw_funcs_t (transfer none) that the caller uses to + * emit the clip outline via hb_draw_*() calls, using the + * returned @draw_data as the draw data. Finish the path + * with hb_paint_push_clip_path_end(); pop the clip later + * with hb_paint_pop_clip(). + * + * Return value: (transfer none): draw funcs that accumulate + * the clip path, or `NULL` if the backend does not implement + * arbitrary-path clipping. + * + * XSince: REPLACEME + */ +hb_draw_funcs_t * +hb_paint_push_clip_path_start (hb_paint_funcs_t *funcs, + void *paint_data, + void **draw_data) +{ + void *scratch = nullptr; + if (!draw_data) draw_data = &scratch; + return funcs->push_clip_path_start (paint_data, draw_data); +} + +/** + * hb_paint_push_clip_path_end: + * @funcs: paint functions + * @paint_data: associated data passed by the caller + * + * Signal that the arbitrary-clip path started by + * hb_paint_push_clip_path_start() is fully drawn. The + * accumulated path now acts as a clip on the paint context + * until a matching hb_paint_pop_clip() call. + * + * XSince: REPLACEME + */ +void +hb_paint_push_clip_path_end (hb_paint_funcs_t *funcs, void *paint_data) +{ + funcs->push_clip_path_end (paint_data); +} + /** * hb_paint_pop_clip: * @funcs: paint functions diff --git a/src/hb-paint.h b/src/hb-paint.h index 6311418ba..e61e6384d 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -30,6 +30,7 @@ #define HB_PAINT_H #include "hb-common.h" +#include "hb-draw.h" HB_BEGIN_DECLS @@ -212,6 +213,52 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs, float xmax, float ymax, void *user_data); +/** + * hb_paint_push_clip_path_start_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() + * @draw_data: (out): location to store the draw data the caller should + * pass alongside the returned draw funcs. + * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_path_start_func() + * + * A virtual method for the #hb_paint_funcs_t to begin clipping + * to an arbitrary path. The backend returns a + * #hb_draw_funcs_t (transfer none) that the caller feeds the + * clip outline to via hb_draw_*() calls, plus a + * @draw_data value (transfer none) to pass alongside those + * calls. The path is closed by a matching call to the + * #hb_paint_push_clip_path_end_func_t vfunc; the clip remains + * in effect until a later #hb_paint_pop_clip_func_t call. + * + * Return value: (transfer none): draw funcs that accumulate + * the clip path, or `NULL` if arbitrary-path clipping is not + * supported. + * + * XSince: REPLACEME + */ +typedef hb_draw_funcs_t * (*hb_paint_push_clip_path_start_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + void **draw_data, + void *user_data); + +/** + * hb_paint_push_clip_path_end_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() + * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_path_end_func() + * + * A virtual method for the #hb_paint_funcs_t to close the + * clip path started by the #hb_paint_push_clip_path_start_func_t + * vfunc. The emitted path is now active as a clip; subsequent + * paint ops are masked by it until a matching + * #hb_paint_pop_clip_func_t call. + * + * XSince: REPLACEME + */ +typedef void (*hb_paint_push_clip_path_end_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + void *user_data); + /** * hb_paint_pop_clip_func_t: * @funcs: paint functions object @@ -219,8 +266,9 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs, * @user_data: User data pointer passed to hb_paint_funcs_set_pop_clip_func() * * A virtual method for the #hb_paint_funcs_t to undo - * the effect of a prior call to the #hb_paint_funcs_push_clip_glyph_func_t - * or #hb_paint_funcs_push_clip_rectangle_func_t vfuncs. + * the effect of a prior call to the #hb_paint_funcs_push_clip_glyph_func_t, + * #hb_paint_funcs_push_clip_rectangle_func_t, or + * #hb_paint_funcs_push_clip_path_end_func_t vfuncs. * * Since: 7.0.0 */ @@ -819,6 +867,40 @@ hb_paint_funcs_set_push_clip_rectangle_func (hb_paint_funcs_t void *user_data, hb_destroy_func_t destroy); +/** + * hb_paint_funcs_set_push_clip_path_start_func: + * @funcs: A paint functions struct + * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-path-start callback + * @user_data: Data to pass to @func + * @destroy: (nullable): Function to call when @user_data is no longer needed + * + * Sets the push-clip-path-start callback on the paint functions struct. + * + * XSince: REPLACEME + */ +HB_EXTERN void +hb_paint_funcs_set_push_clip_path_start_func (hb_paint_funcs_t *funcs, + hb_paint_push_clip_path_start_func_t func, + void *user_data, + hb_destroy_func_t destroy); + +/** + * hb_paint_funcs_set_push_clip_path_end_func: + * @funcs: A paint functions struct + * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-path-end callback + * @user_data: Data to pass to @func + * @destroy: (nullable): Function to call when @user_data is no longer needed + * + * Sets the push-clip-path-end callback on the paint functions struct. + * + * XSince: REPLACEME + */ +HB_EXTERN void +hb_paint_funcs_set_push_clip_path_end_func (hb_paint_funcs_t *funcs, + hb_paint_push_clip_path_end_func_t func, + void *user_data, + hb_destroy_func_t destroy); + /** * hb_paint_funcs_set_pop_clip_func: * @funcs: A paint functions struct @@ -1024,6 +1106,15 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, float xmin, float ymin, float xmax, float ymax); +HB_EXTERN hb_draw_funcs_t * +hb_paint_push_clip_path_start (hb_paint_funcs_t *funcs, + void *paint_data, + void **draw_data); + +HB_EXTERN void +hb_paint_push_clip_path_end (hb_paint_funcs_t *funcs, + void *paint_data); + HB_EXTERN void hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data); diff --git a/src/hb-paint.hh b/src/hb-paint.hh index bb499fc49..148bfc974 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -36,6 +36,8 @@ HB_PAINT_FUNC_IMPLEMENT (color_glyph) \ HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \ HB_PAINT_FUNC_IMPLEMENT (push_clip_rectangle) \ + HB_PAINT_FUNC_IMPLEMENT (push_clip_path_start) \ + HB_PAINT_FUNC_IMPLEMENT (push_clip_path_end) \ HB_PAINT_FUNC_IMPLEMENT (pop_clip) \ HB_PAINT_FUNC_IMPLEMENT (color) \ HB_PAINT_FUNC_IMPLEMENT (image) \ @@ -103,6 +105,13 @@ struct hb_paint_funcs_t { func.push_clip_rectangle (this, paint_data, xmin, ymin, xmax, ymax, !user_data ? nullptr : user_data->push_clip_rectangle); } + hb_draw_funcs_t *push_clip_path_start (void *paint_data, + void **draw_data) + { return func.push_clip_path_start (this, paint_data, draw_data, + !user_data ? nullptr : user_data->push_clip_path_start); } + void push_clip_path_end (void *paint_data) + { func.push_clip_path_end (this, paint_data, + !user_data ? nullptr : user_data->push_clip_path_end); } void pop_clip (void *paint_data) { func.pop_clip (this, paint_data, !user_data ? nullptr : user_data->pop_clip); } From a0c670108e10d2615f1f1ad0ce129db7b6c2dbcf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 01:51:24 -0600 Subject: [PATCH 02/26] [paint] Add usage example to hb_paint_push_clip_path_start docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Illustrate the expected call sequence: start → draw_* → close_path → end → (painted ops) → pop_clip, so implementers of the paint API don't have to reassemble the contract from the individual function docs. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-paint.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hb-paint.cc b/src/hb-paint.cc index f210364fc..8edad9398 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -604,6 +604,19 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, * with hb_paint_push_clip_path_end(); pop the clip later * with hb_paint_pop_clip(). * + * Usage: + * + * |[ + * hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); + * hb_draw_move_to (df, dd, NULL, ...); + * hb_draw_line_to (df, dd, NULL, ...); + * ... + * hb_draw_close_path (df, dd, NULL); + * hb_paint_push_clip_path_end (pf, pd); + * /* paint ops here are clipped to the emitted path */ + * hb_paint_pop_clip (pf, pd); + * ]| + * * Return value: (transfer none): draw funcs that accumulate * the clip path, or `NULL` if the backend does not implement * arbitrary-path clipping. From 93777bcb19258ba2bf883cd775bfb5c0f1810243 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:05:36 -0600 Subject: [PATCH 03/26] [paint] Use language="plain" in clip-path usage block HarfBuzz gtk-doc convention is |[, not "C". Aligns with every other code block in src/. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-paint.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 8edad9398..b5e7c829a 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -606,7 +606,7 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, * * Usage: * - * |[ + * |[ * hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); * hb_draw_move_to (df, dd, NULL, ...); * hb_draw_line_to (df, dd, NULL, ...); From e358e565e53041313c83b4454ba1bd0694b57f80 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:08:26 -0600 Subject: [PATCH 04/26] [vector-paint] Implement arbitrary-path clip Wire push_clip_path_start / push_clip_path_end into the vector-paint (SVG) backend. start() clears the per-paint scratch path and hands back the SVG path sink + its draw funcs; end() emits a into defs and opens a matching on the body. The existing pop_clip closes that group. IDs use the "cp" prefix to distinguish from "c" (rects) and "clip-g" (glyph clips). clip_path_counter is reset along with the other body counters on paint reset. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector-paint.cc | 52 ++++++++++++++++++++++++++++++++++++++++++ src/hb-vector-paint.hh | 3 +++ 2 files changed, 55 insertions(+) diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index 09a815f5c..73eccc948 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -341,6 +341,8 @@ static void hb_vector_paint_push_transform (hb_paint_funcs_t *, void *, static void hb_vector_paint_pop_transform (hb_paint_funcs_t *, void *, 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 *); +static void hb_vector_paint_push_clip_path_end (hb_paint_funcs_t *, void *, void *); static void hb_vector_paint_pop_clip (hb_paint_funcs_t *, void *, void *); static void hb_vector_paint_color (hb_paint_funcs_t *, void *, hb_bool_t, hb_color_t, void *); static hb_bool_t hb_vector_paint_image (hb_paint_funcs_t *, void *, hb_blob_t *, unsigned, unsigned, hb_tag_t, float, hb_glyph_extents_t *, void *); @@ -363,6 +365,8 @@ static struct hb_vector_paint_funcs_lazy_loader_t 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_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); + hb_paint_funcs_set_push_clip_path_end_func (funcs, (hb_paint_push_clip_path_end_func_t) hb_vector_paint_push_clip_path_end, nullptr, nullptr); hb_paint_funcs_set_pop_clip_func (funcs, (hb_paint_pop_clip_func_t) hb_vector_paint_pop_clip, nullptr, nullptr); hb_paint_funcs_set_color_func (funcs, (hb_paint_color_func_t) hb_vector_paint_color, nullptr, nullptr); hb_paint_funcs_set_image_func (funcs, (hb_paint_image_func_t) hb_vector_paint_image, nullptr, nullptr); @@ -565,6 +569,53 @@ hb_vector_paint_push_clip_rectangle (hb_paint_funcs_t *, hb_buf_append_str (&paint->current_body (), ")\">\n"); } +static hb_draw_funcs_t * +hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *, + void *paint_data, + void **draw_data, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!hb_vector_paint_ensure_initialized (paint))) + { + *draw_data = nullptr; + return nullptr; + } + + paint->path.clear (); + paint->clip_path_sink = {&paint->path, paint->precision}; + *draw_data = &paint->clip_path_sink; + return hb_vector_svg_path_draw_funcs_get (); +} + +static void +hb_vector_paint_push_clip_path_end (hb_paint_funcs_t *, + void *paint_data, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!hb_vector_paint_ensure_initialized (paint))) + return; + + const char *pfx = paint->id_prefix.arrayZ; + unsigned pfx_len = paint->id_prefix.length; + unsigned clip_id = paint->clip_path_counter++; + + hb_buf_append_str (&paint->defs, "defs, pfx, pfx_len); + hb_buf_append_str (&paint->defs, "cp"); + hb_buf_append_unsigned (&paint->defs, clip_id); + hb_buf_append_str (&paint->defs, "\">defs, paint->path.arrayZ, paint->path.length); + hb_buf_append_str (&paint->defs, "\"/>\n"); + + hb_buf_append_str (&paint->current_body (), "current_body (), pfx, pfx_len); + hb_buf_append_str (&paint->current_body (), "cp"); + hb_buf_append_unsigned (&paint->current_body (), clip_id); + hb_buf_append_str (&paint->current_body (), ")\">\n"); +} + static void hb_vector_paint_pop_clip (hb_paint_funcs_t *, void *paint_data, @@ -1661,6 +1712,7 @@ hb_vector_paint_clear (hb_vector_paint_t *paint) paint->transform_group_depth = 0; paint->transform_group_overflow_depth = 0; paint->clip_rect_counter = 0; + paint->clip_path_counter = 0; paint->gradient_counter = 0; paint->color_glyph_counter = 0; paint->color_glyph_depth = 0; diff --git a/src/hb-vector-paint.hh b/src/hb-vector-paint.hh index f62809dc7..f8cdcd289 100644 --- a/src/hb-vector-paint.hh +++ b/src/hb-vector-paint.hh @@ -7,6 +7,7 @@ #include "hb-geometry.hh" #include "hb-machinery.hh" #include "hb-map.hh" +#include "hb-vector-svg-path.hh" #include "hb-vector-svg-utils.hh" #include "hb-vector-svg.hh" @@ -61,6 +62,8 @@ struct hb_vector_paint_t unsigned transform_group_overflow_depth = 0; unsigned clip_rect_counter = 0; + unsigned clip_path_counter = 0; + hb_vector_svg_path_sink_t clip_path_sink = {nullptr, 0}; unsigned gradient_counter = 0; unsigned color_glyph_counter = 0; unsigned color_glyph_depth = 0; From 834826289e4a064b86ecb47f0665e8ec452b83b7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:29:18 -0600 Subject: [PATCH 05/26] [vector] Fold svg-path sink into a format-aware vector-path Rename hb-vector-svg-path.{cc,hh} to hb-vector-path.{cc,hh} and make the sink format-aware (SVG or PDF), so the PDF backend can reuse it for arbitrary-path clipping without spinning up its own path serializer. hb_vector_svg_path_sink_t gains a hb_vector_format_t field and becomes hb_vector_path_sink_t; the draw callbacks switch on format and emit SVG path-data or PDF path operators into the external buffer. hb-vector-draw.cc and hb-vector-paint.cc (push_clip_glyph + the recent arbitrary clip-path start) are updated to the new name with format=SVG. No behavior change on the SVG side. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/harfbuzz-world.cc | 2 +- src/hb-vector-draw.cc | 6 +- src/hb-vector-paint.cc | 10 +- src/hb-vector-paint.hh | 4 +- src/hb-vector-path.cc | 207 ++++++++++++++++++ ...b-vector-svg-path.hh => hb-vector-path.hh} | 17 +- src/hb-vector-svg-path.cc | 144 ------------ src/meson.build | 4 +- 8 files changed, 232 insertions(+), 162 deletions(-) create mode 100644 src/hb-vector-path.cc rename src/{hb-vector-svg-path.hh => hb-vector-path.hh} (71%) delete mode 100644 src/hb-vector-svg-path.cc diff --git a/src/harfbuzz-world.cc b/src/harfbuzz-world.cc index 2def1672e..e196bb2d9 100644 --- a/src/harfbuzz-world.cc +++ b/src/harfbuzz-world.cc @@ -156,7 +156,7 @@ #include "hb-vector-draw.cc" #include "hb-vector-paint-pdf.cc" #include "hb-vector-paint.cc" -#include "hb-vector-svg-path.cc" +#include "hb-vector-path.cc" #include "hb-vector-svg-utils.cc" #include "hb-vector.cc" #include "hb-zlib.cc" diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index 66cc4fda5..8ebfa9404 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -27,7 +27,7 @@ #include "hb.hh" #include "hb-vector-draw.hh" -#include "hb-vector-svg-path.hh" +#include "hb-vector-path.hh" #include #include @@ -606,8 +606,8 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, if (!hb_set_has (draw->defined_glyphs, glyph)) { draw->path.clear (); - hb_vector_svg_path_sink_t sink = {&draw->path, draw->precision}; - hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); + hb_vector_path_sink_t sink = {&draw->path, draw->precision, HB_VECTOR_FORMAT_SVG}; + hb_font_draw_glyph (font, glyph, hb_vector_path_draw_funcs_get (), &sink); if (!draw->path.length) return false; hb_buf_append_str (&draw->defs, " @@ -502,8 +502,8 @@ hb_vector_paint_push_clip_glyph (hb_paint_funcs_t *, { hb_set_add (paint->defined_outlines, glyph); paint->path.clear (); - hb_vector_svg_path_sink_t sink = {&paint->path, paint->precision}; - hb_font_draw_glyph (font, glyph, hb_vector_svg_path_draw_funcs_get (), &sink); + hb_vector_path_sink_t sink = {&paint->path, paint->precision, HB_VECTOR_FORMAT_SVG}; + hb_font_draw_glyph (font, glyph, hb_vector_path_draw_funcs_get (), &sink); hb_buf_append_str (&paint->defs, "defs, pfx, pfx_len); hb_buf_append_c (&paint->defs, 'p'); @@ -583,9 +583,9 @@ hb_vector_paint_push_clip_path_start (hb_paint_funcs_t *, } paint->path.clear (); - paint->clip_path_sink = {&paint->path, paint->precision}; + paint->clip_path_sink = {&paint->path, paint->precision, HB_VECTOR_FORMAT_SVG}; *draw_data = &paint->clip_path_sink; - return hb_vector_svg_path_draw_funcs_get (); + return hb_vector_path_draw_funcs_get (); } static void diff --git a/src/hb-vector-paint.hh b/src/hb-vector-paint.hh index f8cdcd289..2b31d44dc 100644 --- a/src/hb-vector-paint.hh +++ b/src/hb-vector-paint.hh @@ -7,7 +7,7 @@ #include "hb-geometry.hh" #include "hb-machinery.hh" #include "hb-map.hh" -#include "hb-vector-svg-path.hh" +#include "hb-vector-path.hh" #include "hb-vector-svg-utils.hh" #include "hb-vector-svg.hh" @@ -63,7 +63,7 @@ struct hb_vector_paint_t unsigned clip_rect_counter = 0; unsigned clip_path_counter = 0; - hb_vector_svg_path_sink_t clip_path_sink = {nullptr, 0}; + hb_vector_path_sink_t clip_path_sink = {nullptr, 0, HB_VECTOR_FORMAT_INVALID}; unsigned gradient_counter = 0; unsigned color_glyph_counter = 0; unsigned color_glyph_depth = 0; diff --git a/src/hb-vector-path.cc b/src/hb-vector-path.cc new file mode 100644 index 000000000..b3536314f --- /dev/null +++ b/src/hb-vector-path.cc @@ -0,0 +1,207 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Author(s): Behdad Esfahbod + */ + +#include "hb.hh" + +#include "hb-geometry.hh" +#include "hb-machinery.hh" +#include "hb-vector-path.hh" +#include "hb-vector-svg-utils.hh" +#include "hb-vector-svg.hh" + +static inline void +hb_vector_path_append_xy (hb_vector_path_sink_t *s, float x, float y) +{ + hb_buf_append_num (s->path, x, s->precision); + hb_buf_append_c (s->path, + s->format == HB_VECTOR_FORMAT_PDF ? ' ' : ','); + hb_buf_append_num (s->path, y, s->precision); +} + +static void +hb_vector_path_move_to (hb_draw_funcs_t *, + void *draw_data, + hb_draw_state_t *, + float to_x, float to_y, + void *) +{ + auto *s = (hb_vector_path_sink_t *) draw_data; + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_vector_path_append_xy (s, to_x, to_y); + hb_buf_append_str (s->path, " m\n"); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, 'M'); + hb_vector_path_append_xy (s, to_x, to_y); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } +} + +static void +hb_vector_path_line_to (hb_draw_funcs_t *, + void *draw_data, + hb_draw_state_t *, + float to_x, float to_y, + void *) +{ + auto *s = (hb_vector_path_sink_t *) draw_data; + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_vector_path_append_xy (s, to_x, to_y); + hb_buf_append_str (s->path, " l\n"); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, 'L'); + hb_vector_path_append_xy (s, to_x, to_y); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } +} + +static void +hb_vector_path_quadratic_to (hb_draw_funcs_t *, + void *draw_data, + hb_draw_state_t *st, + float cx, float cy, + float to_x, float to_y, + void *) +{ + auto *s = (hb_vector_path_sink_t *) draw_data; + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + { + /* PDF has no quadratic operator; promote to cubic using + * the current pen position from draw-state. */ + float sx = st->current_x, sy = st->current_y; + float c1x = sx + 2.f / 3.f * (cx - sx); + float c1y = sy + 2.f / 3.f * (cy - sy); + float c2x = to_x + 2.f / 3.f * (cx - to_x); + float c2y = to_y + 2.f / 3.f * (cy - to_y); + hb_vector_path_append_xy (s, c1x, c1y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, c2x, c2y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, to_x, to_y); + hb_buf_append_str (s->path, " c\n"); + break; + } + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, 'Q'); + hb_vector_path_append_xy (s, cx, cy); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, to_x, to_y); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } +} + +static void +hb_vector_path_cubic_to (hb_draw_funcs_t *, + void *draw_data, + hb_draw_state_t *, + float c1x, float c1y, + float c2x, float c2y, + float to_x, float to_y, + void *) +{ + auto *s = (hb_vector_path_sink_t *) draw_data; + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_vector_path_append_xy (s, c1x, c1y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, c2x, c2y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, to_x, to_y); + hb_buf_append_str (s->path, " c\n"); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, 'C'); + hb_vector_path_append_xy (s, c1x, c1y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, c2x, c2y); + hb_buf_append_c (s->path, ' '); + hb_vector_path_append_xy (s, to_x, to_y); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } +} + +static void +hb_vector_path_close_path (hb_draw_funcs_t *, + void *draw_data, + hb_draw_state_t *, + void *) +{ + auto *s = (hb_vector_path_sink_t *) draw_data; + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_buf_append_str (s->path, "h\n"); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, 'Z'); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } +} + +static inline void +free_static_vector_path_draw_funcs (); + +static struct hb_vector_path_draw_funcs_lazy_loader_t + : hb_draw_funcs_lazy_loader_t +{ + static hb_draw_funcs_t *create () + { + hb_draw_funcs_t *funcs = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) hb_vector_path_move_to, nullptr, nullptr); + hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) hb_vector_path_line_to, nullptr, nullptr); + hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_path_quadratic_to, nullptr, nullptr); + hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_path_cubic_to, nullptr, nullptr); + hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_path_close_path, nullptr, nullptr); + hb_draw_funcs_make_immutable (funcs); + hb_atexit (free_static_vector_path_draw_funcs); + return funcs; + } +} static_vector_path_draw_funcs; + +static inline void +free_static_vector_path_draw_funcs () +{ + static_vector_path_draw_funcs.free_instance (); +} + +hb_draw_funcs_t * +hb_vector_path_draw_funcs_get (void) +{ + return static_vector_path_draw_funcs.get_unconst (); +} diff --git a/src/hb-vector-svg-path.hh b/src/hb-vector-path.hh similarity index 71% rename from src/hb-vector-svg-path.hh rename to src/hb-vector-path.hh index bfa1573cf..9ec614958 100644 --- a/src/hb-vector-svg-path.hh +++ b/src/hb-vector-path.hh @@ -24,20 +24,27 @@ * Author(s): Behdad Esfahbod */ -#ifndef HB_VECTOR_SVG_PATH_HH -#define HB_VECTOR_SVG_PATH_HH +#ifndef HB_VECTOR_PATH_HH +#define HB_VECTOR_PATH_HH #include "hb.hh" #include "hb-vector.hh" +#include "hb-vector.h" #include "hb-draw.h" -struct hb_vector_svg_path_sink_t +/* Lightweight path sink: serializes hb_draw_* calls into an + * external char buffer as either SVG path-data or PDF path + * operators, depending on format. Used by the vector paint + * backends to accumulate arbitrary clip paths (and by the + * SVG backend to emit glyph outlines into defs). */ +struct hb_vector_path_sink_t { hb_vector_t *path; unsigned precision; + hb_vector_format_t format; }; HB_INTERNAL hb_draw_funcs_t * -hb_vector_svg_path_draw_funcs_get (void); +hb_vector_path_draw_funcs_get (void); -#endif /* HB_VECTOR_SVG_PATH_HH */ +#endif /* HB_VECTOR_PATH_HH */ diff --git a/src/hb-vector-svg-path.cc b/src/hb-vector-svg-path.cc deleted file mode 100644 index eee19d0ac..000000000 --- a/src/hb-vector-svg-path.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright © 2026 Behdad Esfahbod - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Author(s): Behdad Esfahbod - */ - -#include "hb.hh" - -#include "hb-machinery.hh" -#include "hb-vector-svg-path.hh" -#include "hb-vector-svg-utils.hh" - -static void -hb_vector_svg_path_move_to (hb_draw_funcs_t *, - void *draw_data, - hb_draw_state_t *, - float to_x, float to_y, - void *) -{ - auto *s = (hb_vector_svg_path_sink_t *) draw_data; - hb_buf_append_c (s->path, 'M'); - hb_buf_append_num (s->path, to_x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, to_y, s->precision); -} - -static void -hb_vector_svg_path_line_to (hb_draw_funcs_t *, - void *draw_data, - hb_draw_state_t *, - float to_x, float to_y, - void *) -{ - auto *s = (hb_vector_svg_path_sink_t *) draw_data; - hb_buf_append_c (s->path, 'L'); - hb_buf_append_num (s->path, to_x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, to_y, s->precision); -} - -static void -hb_vector_svg_path_quadratic_to (hb_draw_funcs_t *, - void *draw_data, - hb_draw_state_t *, - float cx, float cy, - float to_x, float to_y, - void *) -{ - auto *s = (hb_vector_svg_path_sink_t *) draw_data; - hb_buf_append_c (s->path, 'Q'); - hb_buf_append_num (s->path, cx, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, cy, s->precision); - hb_buf_append_c (s->path, ' '); - hb_buf_append_num (s->path, to_x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, to_y, s->precision); -} - -static void -hb_vector_svg_path_cubic_to (hb_draw_funcs_t *, - void *draw_data, - hb_draw_state_t *, - float c1x, float c1y, - float c2x, float c2y, - float to_x, float to_y, - void *) -{ - auto *s = (hb_vector_svg_path_sink_t *) draw_data; - hb_buf_append_c (s->path, 'C'); - hb_buf_append_num (s->path, c1x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, c1y, s->precision); - hb_buf_append_c (s->path, ' '); - hb_buf_append_num (s->path, c2x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, c2y, s->precision); - hb_buf_append_c (s->path, ' '); - hb_buf_append_num (s->path, to_x, s->precision); - hb_buf_append_c (s->path, ','); - hb_buf_append_num (s->path, to_y, s->precision); -} - -static void -hb_vector_svg_path_close_path (hb_draw_funcs_t *, - void *draw_data, - hb_draw_state_t *, - void *) -{ - auto *s = (hb_vector_svg_path_sink_t *) draw_data; - hb_buf_append_c (s->path, 'Z'); -} - -static inline void -free_static_svg_path_draw_funcs (); - -static struct hb_vector_svg_path_draw_funcs_lazy_loader_t - : hb_draw_funcs_lazy_loader_t -{ - static hb_draw_funcs_t *create () - { - hb_draw_funcs_t *funcs = hb_draw_funcs_create (); - hb_draw_funcs_set_move_to_func (funcs, (hb_draw_move_to_func_t) hb_vector_svg_path_move_to, nullptr, nullptr); - hb_draw_funcs_set_line_to_func (funcs, (hb_draw_line_to_func_t) hb_vector_svg_path_line_to, nullptr, nullptr); - hb_draw_funcs_set_quadratic_to_func (funcs, (hb_draw_quadratic_to_func_t) hb_vector_svg_path_quadratic_to, nullptr, nullptr); - hb_draw_funcs_set_cubic_to_func (funcs, (hb_draw_cubic_to_func_t) hb_vector_svg_path_cubic_to, nullptr, nullptr); - hb_draw_funcs_set_close_path_func (funcs, (hb_draw_close_path_func_t) hb_vector_svg_path_close_path, nullptr, nullptr); - hb_draw_funcs_make_immutable (funcs); - hb_atexit (free_static_svg_path_draw_funcs); - return funcs; - } -} static_svg_path_draw_funcs; - -static inline void -free_static_svg_path_draw_funcs () -{ - static_svg_path_draw_funcs.free_instance (); -} - -hb_draw_funcs_t * -hb_vector_svg_path_draw_funcs_get (void) -{ - return static_svg_path_draw_funcs.get_unconst (); -} diff --git a/src/meson.build b/src/meson.build index 3f7a01c31..6d1cb22b1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -729,10 +729,10 @@ hb_vector_sources = files( 'hb-zlib.hh', 'hb-vector.cc', 'hb-vector-draw.cc', - 'hb-vector-svg-path.cc', + 'hb-vector-path.cc', 'hb-vector-paint.cc', 'hb-vector-paint-pdf.cc', - 'hb-vector-svg-path.hh', + 'hb-vector-path.hh', 'hb-vector-svg-utils.cc', 'hb-vector-svg-utils.hh', 'hb-static.cc', From afb6a5411eed03d791a3e9608e3df77bd78857fe Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:29:27 -0600 Subject: [PATCH 06/26] [vector-paint-pdf] Implement arbitrary-path clip Wire push_clip_path_start / push_clip_path_end through the PDF backend using the shared hb_vector_path_sink_t. start() emits 'q' to save state and hands back a sink that streams PDF path operators directly into the body buffer; end() closes with 'W n' to install the accumulated path as the clip. The existing pop_clip closes the q/Q pair. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector-paint-pdf.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 83340fbe1..85d7261a3 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -398,6 +398,39 @@ hb_pdf_paint_push_clip_rectangle (hb_paint_funcs_t *, hb_buf_append_str (&body, " re W n\n"); } +static hb_draw_funcs_t * +hb_pdf_paint_push_clip_path_start (hb_paint_funcs_t *, + void *paint_data, + void **draw_data, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!hb_pdf_paint_ensure_initialized (paint))) + { + *draw_data = nullptr; + return nullptr; + } + + auto &body = paint->current_body (); + hb_buf_append_str (&body, "q\n"); + /* Stream path operators straight into the body; end() seals + * the path with "W n" to turn it into the clip region. */ + paint->clip_path_sink = {&body, paint->precision, HB_VECTOR_FORMAT_PDF}; + *draw_data = &paint->clip_path_sink; + return hb_vector_path_draw_funcs_get (); +} + +static void +hb_pdf_paint_push_clip_path_end (hb_paint_funcs_t *, + void *paint_data, + void *) +{ + auto *paint = (hb_vector_paint_t *) paint_data; + if (unlikely (!hb_pdf_paint_ensure_initialized (paint))) + return; + hb_buf_append_str (&paint->current_body (), "W n\n"); +} + static void hb_pdf_paint_pop_clip (hb_paint_funcs_t *, void *paint_data, @@ -1217,6 +1250,8 @@ static struct hb_pdf_paint_funcs_lazy_loader_t 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_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); + hb_paint_funcs_set_push_clip_path_end_func (funcs, (hb_paint_push_clip_path_end_func_t) hb_pdf_paint_push_clip_path_end, nullptr, nullptr); hb_paint_funcs_set_pop_clip_func (funcs, (hb_paint_pop_clip_func_t) hb_pdf_paint_pop_clip, nullptr, nullptr); hb_paint_funcs_set_color_func (funcs, (hb_paint_color_func_t) hb_pdf_paint_color, nullptr, nullptr); hb_paint_funcs_set_image_func (funcs, (hb_paint_image_func_t) hb_pdf_paint_image, nullptr, nullptr); From 100c992dc5deadae403f87800cf62b4c7e38bf7f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:47:36 -0600 Subject: [PATCH 07/26] [raster-paint] Implement arbitrary-path clip Wire push_clip_path_start / push_clip_path_end into the raster backend. Factor the existing emitter-based clip helper in two so both paths share the mask-render + clip-intersect tail: * hb_raster_paint_finalize_path_clip does the render, alpha-buffer allocate, and intersect-with-old-clip work. * The emitter-based helper now preps clip_rdr with the current effective transform, calls emit() to populate edges, then calls the finalize helper. * push_clip_path_start preps clip_rdr exactly the same way and hands the caller the raster-draw funcs + clip_rdr as draw-data; the caller drives the path in. _end just runs the finalize pass. Since clip_rdr is shared across all clip pushes, this reuses the object's recycled mask-image and edge buffers without extra allocations per clip. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-raster-paint.cc | 95 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 17 deletions(-) diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 46e972595..261a9e1c8 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -186,25 +186,17 @@ hb_raster_paint_push_empty_clip (hb_raster_paint_t *c, unsigned w, unsigned h) (void) c->clip_stack.push (std::move (new_clip)); } +/* 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 + * helpers (push_clip_glyph) and by push_clip_path_end once + * the caller has drawn the path into @rdr. */ static void -hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, - hb_raster_paint_clip_mask_emit_t emit, - void *emit_data) +hb_raster_paint_finalize_path_clip (hb_raster_paint_t *c, + hb_raster_draw_t *rdr, + hb_raster_image_t *surf, + unsigned w, unsigned h) { - ensure_initialized (c); - - hb_raster_image_t *surf = c->current_surface (); - if (unlikely (!surf)) return; - - unsigned w = surf->extents.width; - unsigned h = surf->extents.height; - - hb_raster_clip_t new_clip = c->acquire_clip (w, h); - - 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); - emit (rdr, emit_data); hb_raster_image_t *mask_img = hb_raster_draw_render (rdr); if (unlikely (!mask_img)) @@ -213,6 +205,8 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, return; } + hb_raster_clip_t new_clip = c->acquire_clip (w, h); + /* Allocate alpha buffer and intersect with previous clip */ size_t clip_size = (size_t) new_clip.stride * h; if (unlikely (clip_size > HB_RASTER_MAX_BUFFER_SIZE || @@ -326,6 +320,27 @@ hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, hb_raster_paint_push_empty_clip (c, w, h); } +static void +hb_raster_paint_push_clip_from_emitter (hb_raster_paint_t *c, + hb_raster_paint_clip_mask_emit_t emit, + void *emit_data) +{ + ensure_initialized (c); + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf)) return; + + unsigned w = surf->extents.width; + unsigned h = surf->extents.height; + + 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); + emit (rdr, emit_data); + + hb_raster_paint_finalize_path_clip (c, rdr, surf, w, h); +} + struct hb_raster_paint_glyph_clip_data_t { hb_codepoint_t glyph; @@ -583,6 +598,50 @@ hb_raster_paint_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED, hb_raster_paint_push_empty_clip (c, surf->extents.width, surf->extents.height); } +static hb_draw_funcs_t * +hb_raster_paint_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void **draw_data, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + ensure_initialized (c); + + /* Prime clip_rdr with the current effective transform; the + * caller then drives hb_draw_*() into it, and _end renders + * the accumulated edges into a mask and intersects with the + * current clip. */ + if (unlikely (!c->surface_stack.length || !c->clip_rdr)) + { + *draw_data = nullptr; + return nullptr; + } + + 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); + + *draw_data = rdr; + return hb_raster_draw_get_funcs (); +} + +static void +hb_raster_paint_push_clip_path_end (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + hb_raster_paint_t *c = (hb_raster_paint_t *) paint_data; + + hb_raster_image_t *surf = c->current_surface (); + if (unlikely (!surf || !c->clip_rdr)) return; + + unsigned w = surf->extents.width; + unsigned h = surf->extents.height; + + hb_raster_paint_finalize_path_clip (c, c->clip_rdr, surf, w, h); +} + static void hb_raster_paint_pop_clip (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -1626,6 +1685,8 @@ static struct hb_raster_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t 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); + hb_paint_funcs_set_push_clip_path_start_func (funcs, hb_raster_paint_push_clip_path_start, nullptr, nullptr); + hb_paint_funcs_set_push_clip_path_end_func (funcs, hb_raster_paint_push_clip_path_end, nullptr, nullptr); hb_paint_funcs_set_pop_clip_func (funcs, hb_raster_paint_pop_clip, nullptr, nullptr); hb_paint_funcs_set_push_group_func (funcs, hb_raster_paint_push_group, nullptr, nullptr); hb_paint_funcs_set_pop_group_func (funcs, hb_raster_paint_pop_group, nullptr, nullptr); From 04770049454ba2941dcd6058b431e3be0bc40af1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 02:58:04 -0600 Subject: [PATCH 08/26] [gpu-paint] Implement arbitrary-path clip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each GPU paint clip becomes a Slug sub-blob in c->sub_blobs (curves + band index + extents) that the encoded shader tests against independently — there's no glyph-id lookup at shader time. That means an arbitrary user-drawn path is representable on GPU: hand the caller the same hb_gpu_draw_get_funcs() the glyph-clip path already feeds through hb_gpu_draw_glyph, and encode the result into a sub-blob the same way. push_clip_path_start preps scratch_draw (the existing per-clip encoder scratch) with the paint's font scale and captures cur_transform for the forthcoming sub-blob. push_clip_path_end runs hb_gpu_draw_encode on the captured geometry and commits the resulting sub-blob and its design- unit extents to clip_stack. pending_clip_t grows a sub_blob_index field and four extent fields; emit_clip_sub_ blob short-circuits for path clips (sub_blob_index >= 0) by accumulating the stored extents and returning the pre-baked index, skipping re-encoding per layer. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-gpu-paint.cc | 95 ++++++++++++++++++++++++++++++++++++++++++++- src/hb-gpu-paint.hh | 17 +++++++- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 145dde20a..e91770b1a 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -89,7 +89,7 @@ hb_gpu_paint_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED, c->clip_depth++; return; } - c->clip_stack[c->clip_depth] = { glyph, font, c->cur_transform }; + c->clip_stack[c->clip_depth] = { glyph, font, c->cur_transform, -1, 0, 0, 0, 0 }; c->clip_depth++; } @@ -102,6 +102,84 @@ hb_gpu_paint_pop_clip (hb_paint_funcs_t *funcs HB_UNUSED, if (likely (c->clip_depth > 0)) c->clip_depth--; } +/* Arbitrary-path clip: hand the caller the same hb_gpu_draw + * funcs the encoder uses for glyph outlines, with scratch_draw + * as the accumulator. push_clip_path_end encodes the captured + * geometry into a sub-blob and commits it to clip_stack just + * like a glyph clip. No font ref needed — the sub-blob is a + * self-contained slug bundle. */ +static hb_draw_funcs_t * +hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + void **draw_data, + void *user_data HB_UNUSED) +{ + hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data; + + if (unlikely (c->clip_depth >= HB_GPU_PAINT_MAX_CLIP_DEPTH)) + { + c->unsupported = true; + *draw_data = nullptr; + return nullptr; + } + + if (unlikely (!c->scratch_draw)) + { + c->scratch_draw = hb_gpu_draw_create_or_fail (); + if (unlikely (!c->scratch_draw)) + { + c->unsupported = true; + *draw_data = nullptr; + return nullptr; + } + } + + hb_gpu_draw_clear (c->scratch_draw); + hb_gpu_draw_set_scale (c->scratch_draw, c->x_scale, c->y_scale); + + c->pending_clip_path_transform = c->cur_transform; + c->pending_clip_path = true; + + *draw_data = c->scratch_draw; + return hb_gpu_draw_get_funcs (); +} + +static void +hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data; + + if (unlikely (!c->pending_clip_path)) + return; + c->pending_clip_path = false; + + hb_glyph_extents_t ext; + hb_blob_t *blob = hb_gpu_draw_encode (c->scratch_draw, &ext); + if (unlikely (!blob || !c->sub_blobs.push_or_fail (blob))) + { + hb_blob_destroy (blob); + c->unsupported = true; + return; + } + int idx = (int) (c->sub_blobs.length - 1); + + int x0 = ext.x_bearing; + int x1 = ext.x_bearing + ext.width; + int y0 = ext.y_bearing; + int y1 = ext.y_bearing + ext.height; + + c->clip_stack[c->clip_depth] = { + HB_CODEPOINT_INVALID, nullptr, + c->pending_clip_path_transform, + idx, + hb_min (x0, x1), hb_min (y0, y1), + hb_max (x0, x1), hb_max (y0, y1), + }; + c->clip_depth++; +} + static void hb_gpu_paint_push_transform (hb_paint_funcs_t *funcs HB_UNUSED, void *paint_data, @@ -332,6 +410,18 @@ static int emit_clip_sub_blob (hb_gpu_paint_t *c, const hb_gpu_paint_t::pending_clip_t &clip) { + /* Path clips were already encoded into sub_blobs at + * push_clip_path_end time; just accumulate extents and hand + * back the pre-baked index. */ + if (clip.sub_blob_index >= 0) + { + c->ext_min_x = hb_min (c->ext_min_x, clip.ext_x0); + c->ext_max_x = hb_max (c->ext_max_x, clip.ext_x1); + c->ext_min_y = hb_min (c->ext_min_y, clip.ext_y0); + c->ext_max_y = hb_max (c->ext_max_y, clip.ext_y1); + return clip.sub_blob_index; + } + if (unlikely (!c->scratch_draw)) { c->scratch_draw = hb_gpu_draw_create_or_fail (); @@ -889,6 +979,8 @@ static struct hb_gpu_paint_funcs_lazy_loader_t hb_paint_funcs_set_push_transform_func (funcs, hb_gpu_paint_push_transform, nullptr, nullptr); hb_paint_funcs_set_pop_transform_func (funcs, hb_gpu_paint_pop_transform, nullptr, nullptr); hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_gpu_paint_push_clip_glyph, nullptr, nullptr); + hb_paint_funcs_set_push_clip_path_start_func (funcs, hb_gpu_paint_push_clip_path_start, nullptr, nullptr); + hb_paint_funcs_set_push_clip_path_end_func (funcs, hb_gpu_paint_push_clip_path_end, nullptr, nullptr); hb_paint_funcs_set_pop_clip_func (funcs, hb_gpu_paint_pop_clip, nullptr, nullptr); hb_paint_funcs_set_push_group_func (funcs, hb_gpu_paint_push_group, nullptr, nullptr); hb_paint_funcs_set_pop_group_func (funcs, hb_gpu_paint_pop_group, nullptr, nullptr); @@ -1414,6 +1506,7 @@ hb_gpu_paint_clear (hb_gpu_paint_t *paint) hb_blob_destroy (b); paint->sub_blobs.reset (); paint->clip_depth = 0; + paint->pending_clip_path = false; paint->unsupported = false; paint->cur_transform = {1, 0, 0, 1, 0, 0}; paint->transform_stack.reset (); diff --git a/src/hb-gpu-paint.hh b/src/hb-gpu-paint.hh index b9a074f2f..120dc1088 100644 --- a/src/hb-gpu-paint.hh +++ b/src/hb-gpu-paint.hh @@ -283,13 +283,26 @@ struct hb_gpu_paint_t * we use for the gradient but not the clip outline. */ struct pending_clip_t { - hb_codepoint_t glyph; - hb_font_t *font; /* borrowed */ + hb_codepoint_t glyph; /* HB_CODEPOINT_INVALID for path clips */ + hb_font_t *font; /* borrowed; nullptr for path clips */ hb_transform_t transform; + /* Path clips are encoded into a sub-blob at push_clip_path_end + * time; glyph clips re-encode per consuming layer. For path + * clips, sub_blob_index is the pre-baked index and ext_* the + * captured design-unit extents. For glyph clips, sub_blob_index + * is -1 and the ext_* fields are unused. */ + int sub_blob_index; + int ext_x0, ext_y0, ext_x1, ext_y1; }; pending_clip_t clip_stack[3]; unsigned clip_depth = 0; + /* Carries the cur_transform captured at push_clip_path_start + * through to push_clip_path_end, where the encoded clip is + * committed to clip_stack. */ + hb_transform_t pending_clip_path_transform = {}; + bool pending_clip_path = false; + /* Set when the paint walk emits v1-only callbacks we do not yet * support. hb_gpu_paint_encode() returns NULL in that case. */ bool unsupported = false; From 2b732039d147c6069cf8b5a6c3606870e9b772d4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:03:17 -0600 Subject: [PATCH 09/26] NEWS: Document arbitrary-path clip paint API Add the push_clip_path_start / _end additions under a new "Paint API" bullet and list the six new public symbols (two entry points, two setters, two func_t typedefs) in the "New API, Paint" block. Co-Authored-By: Claude Opus 4.6 (1M context) --- NEWS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/NEWS b/NEWS index 57a39c1d4..d646eee34 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,22 @@ Overview of changes leading to NEXT (REPLACEME) - Various fuzzer fixes for `harfbuzz-raster`, `harfbuzz-vector`, and `harfbuzz-gpu` libraries. +- Paint API: + * New arbitrary-path clip: + hb_paint_push_clip_path_start / _end let callers clip to + a caller-supplied outline, not just a font glyph. + push_clip_path_start returns the draw-funcs (and matching + draw data) for the backend's path accumulator; the caller + drives hb_draw_*() into it, then calls + push_clip_path_end, followed by painted ops, then + hb_paint_pop_clip() to release the clip. Implemented for + all paint backends: vector (SVG defs + clipPath + url ref), + vector PDF (q / path / W n), raster (path rendered to an + alpha mask, intersected with the current clip), and GPU + (the path is encoded into a Slug sub-blob so the fragment + shader clips against it the same way it clips against + glyph outlines). + - New API, Paint: +hb_paint_push_group_for() +hb_paint_funcs_set_push_group_for_func() @@ -64,6 +80,12 @@ Overview of changes leading to NEXT (REPLACEME) +hb_paint_normalize_color_line() +hb_paint_sweep_gradient_tiles() +hb_paint_sweep_gradient_tile_func_t + +hb_paint_push_clip_path_start() + +hb_paint_push_clip_path_end() + +hb_paint_funcs_set_push_clip_path_start_func() + +hb_paint_funcs_set_push_clip_path_end_func() + +hb_paint_push_clip_path_start_func_t + +hb_paint_push_clip_path_end_func_t - New API, GPU library: +hb_gpu_paint_t From 9674752f61d48473e7212a38f96f86f575e89ffc Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:05:34 -0600 Subject: [PATCH 10/26] [cmake] Rename hb-vector-svg-path to hb-vector-path Follow-up to the meson rename so CMake builds pick up the file too. Co-Authored-By: Claude Opus 4.6 (1M context) --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8d26a50f..bf61e639d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,10 +258,10 @@ set (vector_project_sources ${PROJECT_SOURCE_DIR}/src/hb-zlib.hh ${PROJECT_SOURCE_DIR}/src/hb-vector.cc ${PROJECT_SOURCE_DIR}/src/hb-vector-draw.cc - ${PROJECT_SOURCE_DIR}/src/hb-vector-svg-path.cc + ${PROJECT_SOURCE_DIR}/src/hb-vector-path.cc ${PROJECT_SOURCE_DIR}/src/hb-vector-paint.cc ${PROJECT_SOURCE_DIR}/src/hb-vector-paint-pdf.cc - ${PROJECT_SOURCE_DIR}/src/hb-vector-svg-path.hh + ${PROJECT_SOURCE_DIR}/src/hb-vector-path.hh ${PROJECT_SOURCE_DIR}/src/hb-vector-svg-utils.cc ${PROJECT_SOURCE_DIR}/src/hb-vector-svg-utils.hh ${PROJECT_SOURCE_DIR}/src/hb-static.cc From f3c36ef3d697ff757e9c78da78e9e5dccf9b194c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:13:44 -0600 Subject: [PATCH 11/26] [test] Add API tests for push_clip_path_start/_end Folded into the existing test-paint binary. Two tests, both font-independent (registered ahead of the glyph-based flavor setup so they run even on builds without the test COLRv1 font): * test_push_clip_path_nil_returns_null: an unset paint-funcs table returns NULL from push_clip_path_start and clears the out-param draw_data, and push_clip_path_end is safe to call on the nil stub. * test_push_clip_path_round_trip: registered start/end fire in order, the returned draw-funcs + draw-data round-trip through the public entry points, and every hb_draw_*() call reaches the sink accumulator. Asserts the count includes hb_draw_close_path's synthetic back-to-start line_to so the contract is documented by the test. Co-Authored-By: Claude Opus 4.6 (1M context) --- test/api/test-paint.c | 164 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/test/api/test-paint.c b/test/api/test-paint.c index 77d283441..5a2e2b152 100644 --- a/test/api/test-paint.c +++ b/test/api/test-paint.c @@ -630,12 +630,176 @@ test_color_stops_ft (void) g_test_skip ("FreeType COLRv1 support not present"); } + +/* ── Arbitrary-path clip API (push_clip_path_start/_end) ─────────── */ + +static void +test_push_clip_path_nil_returns_null (void) +{ + /* Unset callbacks fall through to nil stubs; start must return + * NULL + clear draw_data so callers know the backend can't do + * arbitrary-path clipping. */ + hb_paint_funcs_t *funcs = hb_paint_funcs_create (); + void *draw_data = (void *) 0xdeadbeef; + hb_draw_funcs_t *df = hb_paint_push_clip_path_start (funcs, NULL, &draw_data); + g_assert_null (df); + g_assert_null (draw_data); + + /* end is a no-op on the nil stub. */ + hb_paint_push_clip_path_end (funcs, NULL); + + /* Also: NULL draw_data must be accepted; the entry point routes + * it through an internal scratch. */ + df = hb_paint_push_clip_path_start (funcs, NULL, NULL); + g_assert_null (df); + + hb_paint_funcs_destroy (funcs); +} + +typedef struct +{ + int move_to_calls; + int line_to_calls; + int close_path_calls; + float last_x, last_y; + hb_bool_t start_called; + hb_bool_t end_called; + int pop_clip_calls; + hb_draw_funcs_t *start_draw_funcs_out; +} clip_path_rec_t; + +static void +clip_path_sink_move_to (hb_draw_funcs_t *funcs HB_UNUSED, + void *draw_data, + hb_draw_state_t *st HB_UNUSED, + float x, float y, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) draw_data; + r->move_to_calls++; + r->last_x = x; r->last_y = y; +} + +static void +clip_path_sink_line_to (hb_draw_funcs_t *funcs HB_UNUSED, + void *draw_data, + hb_draw_state_t *st HB_UNUSED, + float x, float y, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) draw_data; + r->line_to_calls++; + r->last_x = x; r->last_y = y; +} + +static void +clip_path_sink_close_path (hb_draw_funcs_t *funcs HB_UNUSED, + void *draw_data, + hb_draw_state_t *st HB_UNUSED, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) draw_data; + r->close_path_calls++; +} + +static hb_draw_funcs_t * +clip_path_start_cb (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void **draw_data, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) paint_data; + r->start_called = TRUE; + *draw_data = r; + return r->start_draw_funcs_out; +} + +static void +clip_path_end_cb (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) paint_data; + r->end_called = TRUE; +} + +static void +clip_path_pop_clip_cb (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + clip_path_rec_t *r = (clip_path_rec_t *) paint_data; + r->pop_clip_calls++; +} + +/* Round-trip: registered start/end fire in order, the returned + * draw-funcs + draw-data propagate to the caller, and every + * hb_draw_*() call on those funcs reaches the accumulator. */ +static void +test_push_clip_path_round_trip (void) +{ + hb_draw_funcs_t *sink = hb_draw_funcs_create (); + hb_draw_funcs_set_move_to_func (sink, clip_path_sink_move_to, NULL, NULL); + hb_draw_funcs_set_line_to_func (sink, clip_path_sink_line_to, NULL, NULL); + hb_draw_funcs_set_close_path_func (sink, clip_path_sink_close_path, NULL, NULL); + hb_draw_funcs_make_immutable (sink); + + clip_path_rec_t r = {0}; + r.start_draw_funcs_out = sink; + + hb_paint_funcs_t *pfuncs = hb_paint_funcs_create (); + hb_paint_funcs_set_push_clip_path_start_func (pfuncs, clip_path_start_cb, NULL, NULL); + hb_paint_funcs_set_push_clip_path_end_func (pfuncs, clip_path_end_cb, NULL, NULL); + hb_paint_funcs_set_pop_clip_func (pfuncs, clip_path_pop_clip_cb, NULL, NULL); + hb_paint_funcs_make_immutable (pfuncs); + + void *draw_data = NULL; + hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pfuncs, &r, &draw_data); + + g_assert_true (r.start_called); + g_assert_nonnull (df); + g_assert_true (df == sink); + g_assert_true (draw_data == &r); + + hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; + hb_draw_move_to (df, draw_data, &st, 1.f, 2.f); + hb_draw_line_to (df, draw_data, &st, 3.f, 4.f); + hb_draw_line_to (df, draw_data, &st, 5.f, 6.f); + hb_draw_close_path (df, draw_data, &st); + + g_assert_cmpint (r.move_to_calls, ==, 1); + /* hb_draw_close_path synthesizes a line_to back to the contour + * start, so our two explicit line_tos show up as three. */ + g_assert_cmpint (r.line_to_calls, ==, 3); + g_assert_cmpint (r.close_path_calls, ==, 1); + /* The synthetic closing line_to took the pen back to the + * move_to point (1, 2). */ + g_assert_cmpfloat (r.last_x, ==, 1.f); + g_assert_cmpfloat (r.last_y, ==, 2.f); + + hb_paint_push_clip_path_end (pfuncs, &r); + g_assert_true (r.end_called); + + hb_paint_pop_clip (pfuncs, &r); + g_assert_cmpint (r.pop_clip_calls, ==, 1); + + hb_paint_funcs_destroy (pfuncs); + hb_draw_funcs_destroy (sink); +} + + int main (int argc, char **argv) { int status = 0; hb_test_init (&argc, &argv); + + /* Register font-free API tests first so the missing-font bail + * 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); + for (unsigned int i = 0; i < G_N_ELEMENTS (paint_tests); i++) { hb_test_add_data_flavor (&paint_tests[i], paint_tests[i].output, test_hb_paint_ot); From 8f735c05cd0338ffebdd8ca40453cbaedc5fe9ec Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:30:18 -0600 Subject: [PATCH 12/26] [draw] Normalize w/h in hb_draw_rect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Negative w/h are documented as supported but the stroked variant's math (outer grows by stroke_width, inner shrinks by stroke_width) silently inverts — outer ends up smaller than inner, the ring becomes a filled outer rect, and arbitrary-path clip users (who feed raw font glyph extents with y_bearing-style negative height) see the clip fill everything instead of just the stroke ring. Normalize w/h to non-negative at the top of hb_draw_rect so the rest of the stroke math produces the expected outer-contains-inner ring. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-draw.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hb-draw.cc b/src/hb-draw.cc index 1dc14ba90..c17398e70 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -596,6 +596,12 @@ hb_draw_rect (hb_draw_funcs_t *dfuncs, void *draw_data, if (stroke_width <= 0.f || !std::isfinite (stroke_width)) return; + + /* Normalize to non-negative width/height so the stroke math + * below (outer grows by sw, inner shrinks by sw) produces the + * expected outer-contains-inner ring regardless of w/h signs. */ + if (w < 0.f) { x += w; w = -w; } + if (h < 0.f) { y += h; h = -h; } /* w or h == 0 is still meaningful when stroking: a stroked * zero-height rect is a horizontal line of length w; zero * width is a vertical line. Both degenerate to a single From 134066df5734284f725c469bd666151de379de59 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:30:29 -0600 Subject: [PATCH 13/26] [util/raster] Port --show-extents to the paint API (paint mode) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the manual BGRA 1-pixel overlay with a per-glyph hb_paint_push_clip_path_start/_end + hb_draw_rect + paint foreground sequence, wrapped in the new shared helper util_emit_extents_rect_paint in helper-extents-overlay.hh. Each glyph now bakes its own extents ring into the glyph's rendered mask via the raster-paint backend's arbitrary- path clip, so compositing picks it up alongside the glyph ink (same code path as the color layers). Pads the nominal rect outward by stroke_width/2 so the stroke's inner edge sits at the ink box — otherwise the inner half would knock out against glyph ink under non- zero-winding clipping. Normalizes w/h to positive before padding so the outward shift is unambiguous regardless of y_bearing / height sign conventions. Draw-mode loops (finish_draw_solid, finish_draw_palette) still use the old collect+overlay path and will follow up. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/helper-extents-overlay.hh | 58 ++++++++++++++++++++++++++++++++++ util/raster-output.hh | 36 ++++++++++++++++----- 2 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 util/helper-extents-overlay.hh diff --git a/util/helper-extents-overlay.hh b/util/helper-extents-overlay.hh new file mode 100644 index 000000000..9ef9cfc53 --- /dev/null +++ b/util/helper-extents-overlay.hh @@ -0,0 +1,58 @@ +/* + * Copyright © 2026 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Author(s): Behdad Esfahbod + */ + +#ifndef HELPER_EXTENTS_OVERLAY_HH +#define HELPER_EXTENTS_OVERLAY_HH + +#include + +/* --show-extents overlay: emit a stroked rectangle into a paint + * context via the arbitrary-path clip API plus hb_paint_color. + * The paint backend's clip-path sink receives hb_draw_rect(), + * which expands to an outer + inner contour whose coverage + * ring is the stroke. Then paint_color fills that clipped + * region with the paint's current foreground so the overlay + * takes on whatever color a draw-mode glyph would render in. + * + * Draw-only pipelines skip this helper — they just call + * hb_draw_rect() on the glyph draw context so the rectangle + * lands in the same output as the glyph outline. */ +static inline void +util_emit_extents_rect_paint (hb_paint_funcs_t *pf, void *pd, + float x, float y, float w, float h, + float stroke_width) +{ + void *dd = nullptr; + hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); + if (!df) return; + hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; + hb_draw_rect (df, dd, &st, x, y, w, h, stroke_width); + hb_paint_push_clip_path_end (pf, pd); + hb_paint_color (pf, pd, /*is_foreground*/ 1, HB_COLOR (0, 0, 0, 255)); + hb_paint_pop_clip (pf, pd); +} + +#endif /* HELPER_EXTENTS_OVERLAY_HH */ diff --git a/util/raster-output.hh b/util/raster-output.hh index 380ec8647..ef100f7a5 100644 --- a/util/raster-output.hh +++ b/util/raster-output.hh @@ -30,6 +30,7 @@ #include "options.hh" #include "output-options.hh" #include "view-options.hh" +#include "helper-extents-overlay.hh" #include "helper-image-output.hh" #include "hb-raster.h" #include "hb-ot.h" @@ -321,6 +322,33 @@ struct raster_output_t : output_options_t, view_options_t hb_raster_paint_glyph (pnt, font, g.gid, pen_x, pen_y); + if (show_extents) + { + hb_glyph_extents_t ge; + if (hb_font_get_glyph_extents (font, g.gid, &ge) && + (ge.width != 0 || ge.height != 0)) + { + float rx = pen_x + (float) ge.x_bearing; + float ry = pen_y + (float) ge.y_bearing; + float rw = (float) ge.width; + float rh = (float) ge.height; + /* Normalize to positive w/h so the outward padding + * below is unambiguous regardless of the y_bearing / + * height sign convention. */ + if (rw < 0) { rx += rw; rw = -rw; } + if (rh < 0) { ry += rh; rh = -rh; } + /* Pad the nominal rect outward by stroke_width / 2 so + * the stroke's inner edge sits at the ink box, instead + * of straddling it (and its inner half knocking out + * against the glyph ink). */ + float sw = scalbnf (1.f, (int) subpixel_bits); + float half = 0.5f * sw; + util_emit_extents_rect_paint (hb_raster_paint_get_funcs (), pnt, + rx - half, ry - half, + rw + sw, rh + sw, sw); + } + } + hb_raster_image_t *img = hb_raster_paint_render (pnt); if (img) { @@ -357,15 +385,7 @@ struct raster_output_t : output_options_t, view_options_t } if (iter + 1 == num_iterations) - { - if (show_extents) - { - std::vector rects; - collect_ink_extents_rects (sx, sy, step, vertical, ext, rects); - overlay_rects_bgra (out_buf, w, h, stride, rects); - } write_bgra_image (out_img); - } } hb_raster_image_destroy (out_img); } From 77817c597e0d5963f81ae5abb2c6cf3103efd318 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 03:35:25 -0600 Subject: [PATCH 14/26] [util/raster] Port --show-extents draw mode; factor shared math MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add util_emit_extents_rect_into_draw in helper-extents- overlay.hh — takes a draw funcs pair + glyph extents + pen position + stroke_width and emits the padded stroked rect in one place. util_emit_extents_rect_into_paint (renamed from _paint for clarity) now wraps it in the push_clip_path_start/_end + paint_color + pop_clip dance. Both raster draw loops (finish_draw_solid accumulated into one rdr, finish_draw_palette per-glyph) now bake the extents ring into the draw context with util_emit_extents_rect_into_ draw, alongside the glyph outline in foreground color. finish_paint's call site collapses from an inline coord-normalize-and-pad block to a single helper call. Uses copysignf on the padding so the "outward" shift tracks the y_bearing/height sign instead of needing a caller-side normalize; pairs with the hb_draw_rect fix for negative w/h in the same branch. Drop the now-unused collect_ink_extents_rects / overlay_rects_bgra / overlay_rects_rgb / rect_i_t helpers that implemented the old manual BGRA overlay pass. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/helper-extents-overlay.hh | 56 ++++++++--- util/raster-output.hh | 167 +++++---------------------------- 2 files changed, 66 insertions(+), 157 deletions(-) diff --git a/util/helper-extents-overlay.hh b/util/helper-extents-overlay.hh index 9ef9cfc53..f9d6f1795 100644 --- a/util/helper-extents-overlay.hh +++ b/util/helper-extents-overlay.hh @@ -29,27 +29,53 @@ #include -/* --show-extents overlay: emit a stroked rectangle into a paint - * context via the arbitrary-path clip API plus hb_paint_color. - * The paint backend's clip-path sink receives hb_draw_rect(), - * which expands to an outer + inner contour whose coverage - * ring is the stroke. Then paint_color fills that clipped - * region with the paint's current foreground so the overlay - * takes on whatever color a draw-mode glyph would render in. +#include + +/* --show-extents overlay helpers. * - * Draw-only pipelines skip this helper — they just call - * hb_draw_rect() on the glyph draw context so the rectangle - * lands in the same output as the glyph outline. */ + * In DRAW mode, emit a stroked extents rectangle directly into the + * glyph's draw context so it gets rendered/encoded alongside the + * glyph outline in the glyph's foreground color. + * + * In PAINT mode, push an arbitrary-path clip with the same stroked + * rectangle and fill it with the paint's current foreground; the + * draw-mode and paint-mode emitters share all of the coord math. */ + static inline void -util_emit_extents_rect_paint (hb_paint_funcs_t *pf, void *pd, - float x, float y, float w, float h, - float stroke_width) +util_emit_extents_rect_into_draw (hb_draw_funcs_t *df, void *dd, + const hb_glyph_extents_t *ge, + float pen_x, float pen_y, + float stroke_width) +{ + if (ge->width == 0 && ge->height == 0) + return; + /* Pad outward by stroke_width / 2 so the stroke's inner edge + * sits at the ink box instead of straddling it (and its inner + * half knocking out against glyph ink under non-zero winding). + * Using copysignf on the padding handles glyph-extent + * conventions where height is negative (Y-up). */ + float half = 0.5f * stroke_width; + float sx = copysignf (half, ge->width ? (float) ge->width : 1.f); + float sy = copysignf (half, ge->height ? (float) ge->height : 1.f); + hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; + hb_draw_rect (df, dd, &st, + pen_x + (float) ge->x_bearing - sx, + pen_y + (float) ge->y_bearing - sy, + (float) ge->width + 2 * sx, + (float) ge->height + 2 * sy, + stroke_width); +} + +static inline void +util_emit_extents_rect_into_paint (hb_paint_funcs_t *pf, void *pd, + const hb_glyph_extents_t *ge, + float pen_x, float pen_y, + float stroke_width) { void *dd = nullptr; hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); if (!df) return; - hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; - hb_draw_rect (df, dd, &st, x, y, w, h, stroke_width); + util_emit_extents_rect_into_draw (df, dd, ge, pen_x, pen_y, stroke_width); hb_paint_push_clip_path_end (pf, pd); hb_paint_color (pf, pd, /*is_foreground*/ 1, HB_COLOR (0, 0, 0, 255)); hb_paint_pop_clip (pf, pd); diff --git a/util/raster-output.hh b/util/raster-output.hh index ef100f7a5..993384377 100644 --- a/util/raster-output.hh +++ b/util/raster-output.hh @@ -250,6 +250,14 @@ struct raster_output_t : output_options_t, view_options_t float pen_y = g.y + off_y; hb_raster_draw_set_transform (rdr, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); hb_raster_draw_glyph (rdr, font, g.gid, pen_x, pen_y); + if (show_extents) + { + hb_glyph_extents_t ge; + if (hb_font_get_glyph_extents (font, g.gid, &ge)) + util_emit_extents_rect_into_draw ( + hb_raster_draw_get_funcs (), rdr, + &ge, pen_x, pen_y, extents_stroke_width ()); + } } } @@ -269,13 +277,17 @@ struct raster_output_t : output_options_t, view_options_t private: struct glyph_instance_t { hb_codepoint_t gid; float x, y; }; - struct rect_i_t { int x0, y0, x1, y1; }; struct line_t { float advance_x = 0.f, advance_y = 0.f; std::vector glyphs; }; + float extents_stroke_width () const + { + return scalbnf (1.f, (int) subpixel_bits); + } + void finish_paint (float sx, float sy, float step, bool vertical, unsigned int num_iterations) { hb_raster_extents_t ext; @@ -325,28 +337,10 @@ struct raster_output_t : output_options_t, view_options_t if (show_extents) { hb_glyph_extents_t ge; - if (hb_font_get_glyph_extents (font, g.gid, &ge) && - (ge.width != 0 || ge.height != 0)) - { - float rx = pen_x + (float) ge.x_bearing; - float ry = pen_y + (float) ge.y_bearing; - float rw = (float) ge.width; - float rh = (float) ge.height; - /* Normalize to positive w/h so the outward padding - * below is unambiguous regardless of the y_bearing / - * height sign convention. */ - if (rw < 0) { rx += rw; rw = -rw; } - if (rh < 0) { ry += rh; rh = -rh; } - /* Pad the nominal rect outward by stroke_width / 2 so - * the stroke's inner edge sits at the ink box, instead - * of straddling it (and its inner half knocking out - * against the glyph ink). */ - float sw = scalbnf (1.f, (int) subpixel_bits); - float half = 0.5f * sw; - util_emit_extents_rect_paint (hb_raster_paint_get_funcs (), pnt, - rx - half, ry - half, - rw + sw, rh + sw, sw); - } + if (hb_font_get_glyph_extents (font, g.gid, &ge)) + util_emit_extents_rect_into_paint ( + hb_raster_paint_get_funcs (), pnt, + &ge, pen_x, pen_y, extents_stroke_width ()); } hb_raster_image_t *img = hb_raster_paint_render (pnt); @@ -431,6 +425,14 @@ struct raster_output_t : output_options_t, view_options_t hb_raster_draw_set_extents (rdr, &ext); hb_raster_draw_set_transform (rdr, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); hb_raster_draw_glyph (rdr, font, g.gid, g.x + off_x, g.y + off_y); + if (show_extents) + { + hb_glyph_extents_t ge; + if (hb_font_get_glyph_extents (font, g.gid, &ge)) + util_emit_extents_rect_into_draw ( + hb_raster_draw_get_funcs (), rdr, + &ge, g.x + off_x, g.y + off_y, extents_stroke_width ()); + } hb_raster_image_t *img = hb_raster_draw_render (rdr); if (!img) { glyph_index++; continue; } @@ -480,15 +482,7 @@ struct raster_output_t : output_options_t, view_options_t } if (iter + 1 == num_iterations) - { - if (show_extents) - { - std::vector rects; - collect_ink_extents_rects (sx, sy, step, vertical, ext, rects); - overlay_rects_bgra (out_buf, w, h, stride, rects); - } write_bgra_image (out_img); - } } hb_raster_draw_reset (rdr); @@ -626,110 +620,6 @@ struct raster_output_t : output_options_t, view_options_t return fg_color; } - void collect_ink_extents_rects (float sx, float sy, float step, bool vertical, - const hb_raster_extents_t &ext, - std::vector &rects) const - { - rects.clear (); - for (unsigned li = 0; li < lines.size (); li++) - { - float off_x = vertical ? -(step * (float) li) : 0.f; - float off_y = vertical ? 0.f : -(step * (float) li); - - for (const auto &g : lines[li].glyphs) - { - hb_glyph_extents_t gext; - if (!hb_font_get_glyph_extents (font, g.gid, &gext)) - continue; - - float gx = (g.x + off_x) * sx; - float gy = (g.y + off_y) * sy; - float x0 = gx + gext.x_bearing * sx; - float y0 = gy + (gext.y_bearing + gext.height) * sy; - float x1 = gx + (gext.x_bearing + gext.width) * sx; - float y1 = gy + gext.y_bearing * sy; - - int ix0 = (int) floorf (hb_min (x0, x1)) - ext.x_origin; - int iy0 = (int) floorf (hb_min (y0, y1)) - ext.y_origin; - int ix1 = (int) ceilf (hb_max (x0, x1)) - ext.x_origin; - int iy1 = (int) ceilf (hb_max (y0, y1)) - ext.y_origin; - rects.push_back ({ix0, iy0, ix1, iy1}); - } - } - } - - static void overlay_rects_bgra (uint8_t *buf, unsigned w, unsigned h, unsigned stride, - const std::vector &rects) - { - for (const auto &rc : rects) - { - int x0 = hb_max (0, hb_min ((int) w, rc.x0)); - int x1 = hb_max (0, hb_min ((int) w, rc.x1)); - int y0 = hb_max (0, hb_min ((int) h, rc.y0)); - int y1 = hb_max (0, hb_min ((int) h, rc.y1)); - if (x1 - x0 < 1 || y1 - y0 < 1) continue; - - auto blend_at = [&] (int x, int y) - { - uint32_t d; - hb_memcpy (&d, buf + y * stride + x * 4, 4); - uint8_t db = (uint8_t) (d & 0xFF); - uint8_t dg = (uint8_t) ((d >> 8) & 0xFF); - uint8_t dr = (uint8_t) ((d >> 16) & 0xFF); - uint8_t da = (uint8_t) (d >> 24); - uint8_t ob = (uint8_t) ((db + 255) / 2); - uint8_t og = (uint8_t) (dg / 2); - uint8_t orr = (uint8_t) ((dr + 255) / 2); - uint8_t oa = hb_max (da, (uint8_t) 128); - uint32_t o = (uint32_t) ob | ((uint32_t) og << 8) | ((uint32_t) orr << 16) | ((uint32_t) oa << 24); - hb_memcpy (buf + y * stride + x * 4, &o, 4); - }; - - for (int x = x0; x < x1; x++) - { - blend_at (x, y0); - blend_at (x, y1 - 1); - } - for (int y = y0; y < y1; y++) - { - blend_at (x0, y); - blend_at (x1 - 1, y); - } - } - } - - static void overlay_rects_rgb (std::vector &buf, unsigned w, unsigned h, - const std::vector &rects) - { - for (const auto &rc : rects) - { - int x0 = hb_max (0, hb_min ((int) w, rc.x0)); - int x1 = hb_max (0, hb_min ((int) w, rc.x1)); - int y0 = hb_max (0, hb_min ((int) h, rc.y0)); - int y1 = hb_max (0, hb_min ((int) h, rc.y1)); - if (x1 - x0 < 1 || y1 - y0 < 1) continue; - - auto blend_at = [&] (int x, int y) - { - uint8_t *p = &buf[(y * w + x) * 3]; - p[0] = (uint8_t) ((p[0] + 255) / 2); - p[1] = (uint8_t) (p[1] / 2); - p[2] = (uint8_t) ((p[2] + 255) / 2); - }; - - for (int x = x0; x < x1; x++) - { - blend_at (x, y0); - blend_at (x, y1 - 1); - } - for (int y = y0; y < y1; y++) - { - blend_at (x0, y); - blend_at (x1 - 1, y); - } - } - } - static uint8_t mul8 (uint8_t a, uint8_t b) { unsigned t = (unsigned) a * b + 128; @@ -938,13 +828,6 @@ struct raster_output_t : output_options_t, view_options_t hb_memcpy (dst + y * bgra_actual_ext.stride + x * 4, &px, 4); } - if (show_extents) - { - std::vector rects; - collect_ink_extents_rects (sx, sy, step, vertical, ext, rects); - overlay_rects_bgra (dst, ext.width, ext.height, bgra_actual_ext.stride, rects); - } - write_bgra_image (bgra); hb_raster_image_destroy (bgra); } From 98470a3e0274567fa3c306810b0cf840dfaf32e3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 12:46:46 -0600 Subject: [PATCH 15/26] [draw] Rename hb_draw_rect to hb_draw_rectangle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit API rename for the not-yet-released stroked/filled rectangle helper added to hb-draw — full names (hb_draw_line, hb_draw_circle, hb_draw_rectangle) read better than mixed full/abbreviated. Updates the public header, impl, the gpu doc reference, the GPU API test, the GPU demo's extents overlay, the extents-overlay paint helper, and the docs section listing. Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/harfbuzz-sections.txt | 2 +- src/hb-draw.cc | 12 ++++++------ src/hb-draw.h | 8 ++++---- src/hb-gpu.h | 2 +- test/api/test-gpu.cc | 4 ++-- util/gpu/demo-font.cc | 2 +- util/helper-extents-overlay.hh | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index b0c0bd5bc..d0ee82fea 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -241,7 +241,7 @@ hb_draw_cubic_to hb_draw_close_path hb_draw_line_cap_t hb_draw_line -hb_draw_rect +hb_draw_rectangle hb_draw_circle HB_DRAW_STATE_DEFAULT hb_draw_funcs_t diff --git a/src/hb-draw.cc b/src/hb-draw.cc index c17398e70..67972a43c 100644 --- a/src/hb-draw.cc +++ b/src/hb-draw.cc @@ -553,7 +553,7 @@ _hb_draw_rect_contour (hb_draw_funcs_t *dfuncs, void *draw_data, } /** - * hb_draw_rect: + * hb_draw_rectangle: * @dfuncs: draw functions * @draw_data: associated draw data passed by the caller * @st: current draw state @@ -579,11 +579,11 @@ _hb_draw_rect_contour (hb_draw_funcs_t *dfuncs, void *draw_data, * XSince: REPLACEME **/ void -hb_draw_rect (hb_draw_funcs_t *dfuncs, void *draw_data, - hb_draw_state_t *st, - float x, float y, - float w, float h, - float stroke_width) +hb_draw_rectangle (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, + float x, float y, + float w, float h, + float stroke_width) { if (std::isnan (stroke_width)) { diff --git a/src/hb-draw.h b/src/hb-draw.h index 2fbcbd5ad..1e60db66b 100644 --- a/src/hb-draw.h +++ b/src/hb-draw.h @@ -373,10 +373,10 @@ hb_draw_line (hb_draw_funcs_t *dfuncs, void *draw_data, hb_draw_line_cap_t cap); HB_EXTERN void -hb_draw_rect (hb_draw_funcs_t *dfuncs, void *draw_data, - hb_draw_state_t *st, - float x, float y, - float w, float h, +hb_draw_rectangle (hb_draw_funcs_t *dfuncs, void *draw_data, + hb_draw_state_t *st, + float x, float y, + float w, float h, float stroke_width); HB_EXTERN void diff --git a/src/hb-gpu.h b/src/hb-gpu.h index 66a8763e5..77ace8efb 100644 --- a/src/hb-gpu.h +++ b/src/hb-gpu.h @@ -137,7 +137,7 @@ hb_gpu_draw_glyph_or_fail (hb_gpu_draw_t *draw, * / hb_draw_line_to() / hb_draw_quadratic_to() / * hb_draw_cubic_to() / hb_draw_close_path() with the funcs from * hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data. The - * helpers hb_draw_line() / hb_draw_rect() / hb_draw_circle() + * helpers hb_draw_line() / hb_draw_rectangle() / hb_draw_circle() * cover common primitives (tapered lines, rectangles, circles). * * Coordinate system: the blob format quantizes coordinates to diff --git a/test/api/test-gpu.cc b/test/api/test-gpu.cc index a7d66dcd6..3fdb7d3b6 100644 --- a/test/api/test-gpu.cc +++ b/test/api/test-gpu.cc @@ -567,7 +567,7 @@ test_shapes (void) hb_blob_destroy (blob); /* Filled rect (stroke_width = NaN). */ - hb_draw_rect (dfuncs, draw, &st, + hb_draw_rectangle (dfuncs, draw, &st, 0.f, 0.f, 20.f, 10.f, (float) std::nan ("")); blob = hb_gpu_draw_encode (draw, &ext); @@ -578,7 +578,7 @@ test_shapes (void) /* Stroked rect: outer edge extends stroke_width/2 beyond the * nominal rect on each side. */ - hb_draw_rect (dfuncs, draw, &st, + hb_draw_rectangle (dfuncs, draw, &st, 0.f, 0.f, 20.f, 10.f, 2.f); blob = hb_gpu_draw_encode (draw, &ext); g_assert_nonnull (blob); diff --git a/util/gpu/demo-font.cc b/util/gpu/demo-font.cc index fd7f35f3c..849bd9373 100644 --- a/util/gpu/demo-font.cc +++ b/util/gpu/demo-font.cc @@ -146,7 +146,7 @@ _demo_font_upload_glyph (demo_font_t *font, float h = (float) -g.height + sw; /* positive */ hb_draw_funcs_t *dfuncs = hb_gpu_draw_get_funcs (); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; - hb_draw_rect (dfuncs, font->d, &st, x, y, w, h, sw); + hb_draw_rectangle (dfuncs, font->d, &st, x, y, w, h, sw); } } blob = hb_gpu_draw_encode (font->d, &hb_ext); diff --git a/util/helper-extents-overlay.hh b/util/helper-extents-overlay.hh index f9d6f1795..134aadcea 100644 --- a/util/helper-extents-overlay.hh +++ b/util/helper-extents-overlay.hh @@ -58,7 +58,7 @@ util_emit_extents_rect_into_draw (hb_draw_funcs_t *df, void *dd, float sx = copysignf (half, ge->width ? (float) ge->width : 1.f); float sy = copysignf (half, ge->height ? (float) ge->height : 1.f); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; - hb_draw_rect (df, dd, &st, + hb_draw_rectangle (df, dd, &st, pen_x + (float) ge->x_bearing - sx, pen_y + (float) ge->y_bearing - sy, (float) ge->width + 2 * sx, From acfb6784c395844e9b6c9ee7079b993730d163be Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 12:47:00 -0600 Subject: [PATCH 16/26] [vector-draw] Flush leftover scratch path on render MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hb_vector_draw_glyph for SVG copies the glyph outline into defs and emits a in body, but didn't clear the internal draw->path scratch on its way out — and the PDF path wasn't clearing it after appending to body either. The render functions then mutually-excluded body vs path emission with an else-if, so any free-form draw ops a caller did via hb_draw_*() on hb_vector_draw_get_funcs() would either inherit the trailing glyph bytes (SVG) or be silently dropped (PDF render only fired when body was empty). Two-line fix: clear draw->path at the end of each glyph emission so subsequent draw-funcs calls start with an empty scratch, and turn the render branches into two sibling ifs so any leftover free-form path gets flushed as its own (SVG) or path + "f\n" (PDF) alongside the body content. Unblocks --show-extents in hb-vector by letting the util just call hb_draw_rectangle on the draw context after each glyph. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector-draw.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index 8ebfa9404..429b08ba4 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -598,6 +598,7 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, hb_buf_append_len (&draw->body, draw->path.arrayZ, draw->path.length); hb_buf_append_str (&draw->body, "f\n"); + draw->path.clear (); return true; } @@ -618,6 +619,9 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, hb_buf_append_len (&draw->defs, draw->path.arrayZ, draw->path.length); hb_buf_append_str (&draw->defs, "\"/>\n"); hb_set_add (draw->defined_glyphs, glyph); + /* Clear so any subsequent free-form draw ops on this + * context start with an empty scratch. */ + draw->path.clear (); } float xx = draw->transform.xx; @@ -769,8 +773,11 @@ hb_vector_draw_render_pdf (hb_vector_draw_t *draw) if (draw->body.length) hb_buf_append_len (&stream, draw->body.arrayZ, draw->body.length); - else if (draw->path.length) + if (draw->path.length) { + /* Free-form draw ops accumulated after the last glyph + * (e.g. extents-overlay rectangles) need their own fill + * appended to the stream. */ hb_buf_append_len (&stream, draw->path.arrayZ, draw->path.length); hb_buf_append_str (&stream, "f\n"); } @@ -870,11 +877,13 @@ hb_vector_draw_render_svg (hb_vector_draw_t *draw) } if (draw->body.length) - { hb_buf_append_len (&out, draw->body.arrayZ, draw->body.length); - } - else if (draw->path.length) + if (draw->path.length) { + /* Free-form draw ops accumulated after the last glyph + * (e.g. extents-overlay rectangles via hb_draw_rectangle on + * hb_vector_draw_get_funcs) live in the scratch path + * and need their own element. */ hb_buf_append_str (&out, "path.arrayZ, draw->path.length); hb_buf_append_str (&out, "\"/>\n"); From 38f1760d7dc888b27bddaace2f3bff6c5798bbb8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 12:48:41 -0600 Subject: [PATCH 17/26] [vector-draw] Flush pending free-form path on glyph entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous render-side flush handled the trailing batch of free-form draw ops, but each new hb_vector_draw_glyph call wipes the scratch first thing — so any rect (etc.) queued between two glyphs was silently dropped. Add a flush at the top of hb_vector_draw_glyph that emits the accumulated scratch as its own /fill before proceeding. Lets callers interleave hb_draw_*() calls between glyphs and have every batch land in the output. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-vector-draw.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index 429b08ba4..bb2008617 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -581,6 +581,27 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, } } + /* Flush any pending free-form path the caller accumulated + * via hb_draw_*() on hb_vector_draw_get_funcs() before this + * glyph clobbers the scratch buffer. */ + if (draw->path.length) + { + switch (draw->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_buf_append_len (&draw->body, draw->path.arrayZ, draw->path.length); + hb_buf_append_str (&draw->body, "f\n"); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_str (&draw->body, "body, draw->path.arrayZ, draw->path.length); + hb_buf_append_str (&draw->body, "\"/>\n"); + break; + case HB_VECTOR_FORMAT_INVALID: default: break; + } + draw->path.clear (); + } + switch (draw->format) { case HB_VECTOR_FORMAT_PDF: @@ -589,7 +610,6 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, hb_transform_t<> saved = draw->transform; draw->transform = {1, 0, 0, 1, pen_x, pen_y}; - draw->path.clear (); hb_font_draw_glyph (font, glyph, hb_vector_draw_funcs_get (), draw); draw->transform = saved; From cf5325f4f5126fa1f053e4fa7986d60a71f89455 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 12:48:52 -0600 Subject: [PATCH 18/26] [util/vector] Port --show-extents to the paint API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bake the per-glyph extents rectangle into the same draw or paint context that rendered the glyph, via the shared helper from helper-extents-overlay.hh. Matches the raster util's port: in paint mode, the rect goes through push_clip_path_start/end + paint_color (foreground); in draw mode, hb_draw_rectangle on hb_vector_draw_get_funcs appends to the scratch which the next glyph's entry-flush (or render) emits as its own /fill. Drops the standalone emit_extents_overlay function and its FF0000-dot + FF00FF-stroke SVG markup — the new overlay renders in the glyph's foreground color, same as the raster port. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/vector-output.hh | 71 +++++++++++-------------------------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/util/vector-output.hh b/util/vector-output.hh index 3e8f20cbe..3d4d32426 100644 --- a/util/vector-output.hh +++ b/util/vector-output.hh @@ -30,6 +30,7 @@ #include #include +#include "helper-extents-overlay.hh" #include "output-options.hh" #include "view-options.hh" #include "hb-vector.h" @@ -282,12 +283,28 @@ struct vector_output_t : output_options_t<>, view_options_t hb_vector_paint_glyph (paint, upem_font, g.gid, pen_x, pen_y, extents_mode); had_paint = true; + if (show_extents) + { + hb_glyph_extents_t ge; + if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) + util_emit_extents_rect_into_paint ( + hb_vector_paint_get_funcs (), paint, + &ge, pen_x, pen_y, (float) normalized_stroke_width); + } } else { hb_vector_draw_glyph (draw, upem_font, g.gid, pen_x, pen_y, extents_mode); had_draw = true; + if (show_extents) + { + hb_glyph_extents_t ge; + if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) + util_emit_extents_rect_into_draw ( + hb_vector_draw_get_funcs (), draw, + &ge, pen_x, pen_y, (float) normalized_stroke_width); + } } } } @@ -897,9 +914,6 @@ struct vector_output_t : output_options_t<>, view_options_t if (is_draw_blob && !(foreground_use_palette && foreground_palette && foreground_palette->len)) emit_fill_group_close (); - if (show_extents) - emit_extents_overlay (direction == HB_DIRECTION_INVALID ? HB_DIRECTION_LTR : direction, line_step); - fputs ("\n", out_fp); } @@ -949,9 +963,6 @@ struct vector_output_t : output_options_t<>, view_options_t if (paint_body.len) write_slice_resolving_palette_vars (paint_body); - if (show_extents) - emit_extents_overlay (direction == HB_DIRECTION_INVALID ? HB_DIRECTION_LTR : direction, line_step); - fputs ("\n", out_fp); } @@ -1032,54 +1043,6 @@ struct vector_output_t : output_options_t<>, view_options_t } } - void emit_extents_overlay (hb_direction_t dir, float step) - { - const bool vertical = HB_DIRECTION_IS_VERTICAL (dir); - const float dot_r = hb_max (1.f, step * 0.01f); - fputs ("\n", out_fp); - for (unsigned li = 0; li < lines.size (); li++) - { - float off_x = vertical ? -(step * (float) li) : 0.f; - float off_y = vertical ? 0.f : -(step * (float) li); - const line_t &line = lines[li]; - for (const auto &g : line.glyphs) - { - fprintf (out_fp, "\n", - precision + 4, (double) (g.x + off_x), - precision + 4, (double) (-(g.y + off_y)), - precision + 4, (double) dot_r); - } - } - fputs ("\n", out_fp); - - fprintf (out_fp, "\n", - precision + 4, normalized_stroke_width); - for (unsigned li = 0; li < lines.size (); li++) - { - float off_x = vertical ? -(step * (float) li) : 0.f; - float off_y = vertical ? 0.f : -(step * (float) li); - const line_t &line = lines[li]; - for (const auto &g : line.glyphs) - { - hb_glyph_extents_t ge; - if (!hb_font_get_glyph_extents (upem_font, g.gid, &ge)) - continue; - float x = g.x + off_x + ge.x_bearing; - float y = g.y + off_y + ge.y_bearing; - float w = ge.width; - float h = ge.height; - if (!w || !h) - continue; - fprintf (out_fp, "\n", - precision + 4, (double) x, - precision + 4, (double) (-y), - precision + 4, (double) w, - precision + 4, (double) (-h)); - } - } - fputs ("\n", out_fp); - } - void get_line_metrics (hb_direction_t dir, float *asc, float *desc, float *gap) const { if (have_font_extents) From fe77507f14c50113c7f63280fb4cffba29af3405 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 12:54:51 -0600 Subject: [PATCH 19/26] [util/gpu] Port --show-extents to the shared paint helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use util_emit_extents_rect_into_{draw,paint} from helper-extents-overlay.hh so the GPU demo's extents overlay matches the raster and vector ports — same coordinate, padding, and stroke convention; same foreground-color fill via the arbitrary-path clip API in paint mode. Adds --show-extents support for the paint (color-glyph) path, which previously only the draw path implemented. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/gpu/demo-font.cc | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/util/gpu/demo-font.cc b/util/gpu/demo-font.cc index 849bd9373..042aba1c9 100644 --- a/util/gpu/demo-font.cc +++ b/util/gpu/demo-font.cc @@ -4,6 +4,7 @@ #include "demo-font.h" #include "demo-atlas.h" +#include "../helper-extents-overlay.hh" #include @@ -120,34 +121,20 @@ _demo_font_upload_glyph (demo_font_t *font, { hb_glyph_extents_t hb_ext = {}; hb_blob_t *blob; + int x_scale, y_scale; + hb_font_get_scale (font->font, &x_scale, &y_scale); + float sw = (float) (x_scale * 0.01); if (font->draw_only) { hb_gpu_draw_clear (font->d); hb_gpu_draw_glyph (font->d, font->font, glyph_index); if (font->show_extents) { - /* Embed a stroked rectangle around the glyph's ink - * extents in the same blob. Pad the nominal rect - * outward by stroke_width / 2 so the stroke sits - * entirely outside the ink box (otherwise the inner - * half of the stroke would knock out against the - * glyph shape, since both fill in the same blob). */ - hb_glyph_extents_t g = {}; - if (hb_font_get_glyph_extents (font->font, glyph_index, &g) && - (g.width != 0 || g.height != 0)) - { - int x_scale, y_scale; - hb_font_get_scale (font->font, &x_scale, &y_scale); - float sw = (float) (x_scale * 0.01); - float half = 0.5f * sw; - float x = (float) g.x_bearing - half; - float y = (float) (g.y_bearing + g.height) - half; /* min_y */ - float w = (float) g.width + sw; - float h = (float) -g.height + sw; /* positive */ - hb_draw_funcs_t *dfuncs = hb_gpu_draw_get_funcs (); - hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; - hb_draw_rectangle (dfuncs, font->d, &st, x, y, w, h, sw); - } + hb_glyph_extents_t g; + if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) + util_emit_extents_rect_into_draw ( + hb_gpu_draw_get_funcs (), font->d, + &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); } blob = hb_gpu_draw_encode (font->d, &hb_ext); } @@ -155,6 +142,14 @@ _demo_font_upload_glyph (demo_font_t *font, { hb_gpu_paint_clear (font->p); hb_gpu_paint_glyph (font->p, font->font, glyph_index); + if (font->show_extents) + { + hb_glyph_extents_t g; + if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) + util_emit_extents_rect_into_paint ( + hb_gpu_paint_get_funcs (), font->p, + &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); + } blob = hb_gpu_paint_encode (font->p, &hb_ext); } unsigned int len = blob ? hb_blob_get_length (blob) : 0; @@ -164,8 +159,6 @@ _demo_font_upload_glyph (demo_font_t *font, glyph_info->extents.max_y = hb_ext.y_bearing; glyph_info->extents.min_y = hb_ext.y_bearing + hb_ext.height; glyph_info->advance = hb_font_get_glyph_h_advance (font->font, glyph_index); - int x_scale, y_scale; - hb_font_get_scale (font->font, &x_scale, &y_scale); glyph_info->upem = y_scale; glyph_info->is_empty = (len == 0); From 591748f1e14c4a98974c76dd2a0dd814dba16f23 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 13:30:12 -0600 Subject: [PATCH 20/26] [draw][paint] Make get_funcs instance-aware; add get_format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The six public draw / paint funcs getters across raster, vector, and gpu used to be singletons: hb_raster_draw_get_funcs (void) hb_raster_paint_get_funcs (void) hb_vector_draw_get_funcs (void) hb_vector_paint_get_funcs (void) hb_gpu_draw_get_funcs (void) hb_gpu_paint_get_funcs (void) That works fine for raster and gpu, where there's a single backend per type, but breaks for the vector backend where SVG and PDF have separate funcs sets — callers using the public getter always got SVG funcs and silently produced SVG markup inside PDF output streams when invoking the new arbitrary-path clip API on a PDF context. Make all six take a const-pointer to the relevant context instance. vector_paint dispatches on paint->format; the other five just use the instance for symmetry today (room for future format-style dispatch later). Also expose hb_vector_draw_get_format / hb_vector_paint_ get_format public getters so callers (or third parties) can ask a vector context for its format without poking at internals. Also: hb_vector_paint_push_clip_path_end now wraps the emitted SVG clipPath's path in transform="scale(1,-1)" so free-form arbitrary clips at base body level land in the same coord system the per-glyph wrappers establish. Without this, free-form clip-path arbitrary outlines emitted between paint_glyph calls came out mirrored across the X axis. Updates internal callers (hb_vector_paint_glyph, hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_ start, hb_gpu_paint_push_clip_path_start, the GPU pen adapter), util sites (raster-output.hh, vector-output.hh, gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc), and the docs section index. Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/harfbuzz-sections.txt | 2 ++ src/hb-gpu-draw.cc | 11 ++++----- src/hb-gpu-paint.cc | 15 +++++++------ src/hb-gpu.h | 4 ++-- src/hb-raster-draw.cc | 11 ++++----- src/hb-raster-paint.cc | 17 +++++++------- src/hb-raster.h | 4 ++-- src/hb-vector-draw.cc | 45 +++++++++++++++++++++++++++---------- src/hb-vector-paint-pdf.cc | 2 +- src/hb-vector-paint.cc | 46 ++++++++++++++++++++++++++++++++------ src/hb-vector.h | 10 +++++++-- test/api/test-gpu.cc | 22 +++++++++--------- test/api/test-raster.cc | 2 +- util/gpu/demo-font.cc | 4 ++-- util/raster-output.hh | 6 ++--- util/vector-output.hh | 4 ++-- 16 files changed, 135 insertions(+), 70 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index d0ee82fea..7e1e01db6 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -1100,6 +1100,7 @@ hb_vector_draw_get_scale_factor hb_vector_draw_set_extents hb_vector_draw_get_extents hb_vector_draw_set_glyph_extents +hb_vector_draw_get_format hb_vector_draw_get_funcs hb_vector_draw_glyph hb_vector_draw_glyph_or_fail @@ -1130,6 +1131,7 @@ hb_vector_paint_set_palette hb_vector_paint_get_palette hb_vector_paint_set_custom_palette_color hb_vector_paint_clear_custom_palette_colors +hb_vector_paint_get_format hb_vector_paint_get_funcs hb_vector_paint_glyph hb_vector_paint_glyph_or_fail diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index a9ff17af3..9ab22571e 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -908,10 +908,11 @@ hb_gpu_draw_get_user_data (const hb_gpu_draw_t *draw, /** * hb_gpu_draw_get_funcs: + * @draw: a GPU draw context. * - * Fetches the singleton #hb_draw_funcs_t that feeds outline data - * into an #hb_gpu_draw_t. Pass the #hb_gpu_draw_t as the - * @draw_data argument when calling the draw functions. + * Fetches the #hb_draw_funcs_t that feeds outline data into + * @draw. Pass @draw as the @draw_data argument when calling + * the draw functions. * * Return value: (transfer none): * The GPU draw functions @@ -919,7 +920,7 @@ hb_gpu_draw_get_user_data (const hb_gpu_draw_t *draw, * Since: 14.0.0 **/ hb_draw_funcs_t * -hb_gpu_draw_get_funcs (void) +hb_gpu_draw_get_funcs (const hb_gpu_draw_t *draw HB_UNUSED) { return static_gpu_draw_funcs.get_unconst (); } @@ -991,7 +992,7 @@ hb_gpu_draw_glyph_or_fail (hb_gpu_draw_t *draw, hb_gpu_draw_set_scale (draw, x_scale, y_scale); return hb_font_draw_glyph_or_fail (font, glyph, - hb_gpu_draw_get_funcs (), + hb_gpu_draw_get_funcs (draw), draw); } diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index e91770b1a..fa0e81c1e 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -141,7 +141,7 @@ hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED, c->pending_clip_path = true; *draw_data = c->scratch_draw; - return hb_gpu_draw_get_funcs (); + return hb_gpu_draw_get_funcs (c->scratch_draw); } static void @@ -452,7 +452,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, hb_gpu_paint_pen_t pen = {}; pen.transform = clip.transform; - pen.dfuncs = hb_gpu_draw_get_funcs (); + pen.dfuncs = hb_gpu_draw_get_funcs (c->scratch_draw); pen.data = c->scratch_draw; pen.down_st = HB_DRAW_STATE_DEFAULT; ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph, @@ -1113,10 +1113,11 @@ hb_gpu_paint_get_user_data (const hb_gpu_paint_t *paint, /** * hb_gpu_paint_get_funcs: + * @paint: a GPU paint context. * - * Fetches the singleton #hb_paint_funcs_t that feeds paint data - * into an #hb_gpu_paint_t. Pass the #hb_gpu_paint_t as the - * @paint_data argument when calling the paint functions. + * Fetches the #hb_paint_funcs_t that feeds paint data into + * @paint. Pass @paint as the @paint_data argument when + * calling the paint functions. * * Return value: (transfer none): * The GPU paint functions @@ -1124,7 +1125,7 @@ hb_gpu_paint_get_user_data (const hb_gpu_paint_t *paint, * XSince: REPLACEME **/ hb_paint_funcs_t * -hb_gpu_paint_get_funcs (void) +hb_gpu_paint_get_funcs (const hb_gpu_paint_t *paint HB_UNUSED) { return static_gpu_paint_funcs.get_unconst (); } @@ -1306,7 +1307,7 @@ hb_gpu_paint_glyph (hb_gpu_paint_t *paint, hb_font_get_scale (font, &x_scale, &y_scale); hb_gpu_paint_set_scale (paint, x_scale, y_scale); hb_font_paint_glyph (font, glyph, - hb_gpu_paint_get_funcs (), paint, + hb_gpu_paint_get_funcs (paint), paint, paint->palette, HB_COLOR (0, 0, 0, 0xff)); } diff --git a/src/hb-gpu.h b/src/hb-gpu.h index 77ace8efb..7ff18d633 100644 --- a/src/hb-gpu.h +++ b/src/hb-gpu.h @@ -120,7 +120,7 @@ hb_gpu_draw_get_scale (const hb_gpu_draw_t *draw, /* Draw */ HB_EXTERN hb_draw_funcs_t * -hb_gpu_draw_get_funcs (void); +hb_gpu_draw_get_funcs (const hb_gpu_draw_t *draw); HB_EXTERN void hb_gpu_draw_glyph (hb_gpu_draw_t *draw, @@ -207,7 +207,7 @@ hb_gpu_paint_get_user_data (const hb_gpu_paint_t *paint, hb_user_data_key_t *key); HB_EXTERN hb_paint_funcs_t * -hb_gpu_paint_get_funcs (void); +hb_gpu_paint_get_funcs (const hb_gpu_paint_t *paint); HB_EXTERN void hb_gpu_paint_set_palette (hb_gpu_paint_t *paint, diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index ba1873b4d..de704a55b 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -935,10 +935,11 @@ free_static_raster_draw_funcs () /** * hb_raster_draw_get_funcs: + * @draw: a rasterizer draw context. * - * Fetches the singleton #hb_draw_funcs_t that feeds outline data - * into an #hb_raster_draw_t. Pass the #hb_raster_draw_t as the - * @draw_data argument when calling the draw functions. + * Fetches the #hb_draw_funcs_t that feeds outline data into + * @draw. Pass @draw as the @draw_data argument when calling + * the draw functions. * * Return value: (transfer none): * The rasterizer draw functions @@ -946,7 +947,7 @@ free_static_raster_draw_funcs () * Since: 13.0.0 **/ hb_draw_funcs_t * -hb_raster_draw_get_funcs (void) +hb_raster_draw_get_funcs (const hb_raster_draw_t *draw HB_UNUSED) { return static_raster_draw_funcs.get_unconst (); } @@ -987,7 +988,7 @@ hb_raster_draw_glyph_or_fail (hb_raster_draw_t *draw, dx + xx * pen_x + xy * pen_y, dy + yx * pen_x + yy * pen_y); hb_bool_t ret = hb_font_draw_glyph_or_fail (font, glyph, - hb_raster_draw_get_funcs (), draw); + hb_raster_draw_get_funcs (draw), draw); hb_raster_draw_set_transform (draw, xx, yx, xy, yy, dx, dy); return ret; } diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index 261a9e1c8..b9aa392ed 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -352,7 +352,7 @@ hb_raster_paint_emit_clip_glyph_mask (hb_raster_draw_t *rdr, void *user_data) { hb_raster_paint_glyph_clip_data_t *data = (hb_raster_paint_glyph_clip_data_t *) user_data; /* Let draw-render choose tight glyph extents; we map by mask origin below. */ - hb_font_draw_glyph (data->font, data->glyph, hb_raster_draw_get_funcs (), rdr); + hb_font_draw_glyph (data->font, data->glyph, hb_raster_draw_get_funcs (rdr), rdr); } static void @@ -623,7 +623,7 @@ hb_raster_paint_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED, hb_raster_draw_set_transform (rdr, t.xx, t.yx, t.xy, t.yy, t.x0, t.y0); *draw_data = rdr; - return hb_raster_draw_get_funcs (); + return hb_raster_draw_get_funcs (rdr); } static void @@ -2165,10 +2165,11 @@ hb_raster_paint_set_custom_palette_color (hb_raster_paint_t *paint, /** * hb_raster_paint_get_funcs: + * @paint: a rasterizer paint context. * - * Fetches the singleton #hb_paint_funcs_t that renders color glyphs - * into an #hb_raster_paint_t. Pass the #hb_raster_paint_t as the - * @paint_data argument when calling hb_font_paint_glyph(). + * Fetches the #hb_paint_funcs_t that renders color glyphs into + * @paint. Pass @paint as the @paint_data argument when calling + * hb_font_paint_glyph(). * * Return value: (transfer none): * The rasterizer paint functions @@ -2176,7 +2177,7 @@ hb_raster_paint_set_custom_palette_color (hb_raster_paint_t *paint, * Since: 13.0.0 **/ hb_paint_funcs_t * -hb_raster_paint_get_funcs (void) +hb_raster_paint_get_funcs (const hb_raster_paint_t *paint HB_UNUSED) { return static_raster_paint_funcs.get_unconst (); } @@ -2213,11 +2214,11 @@ hb_raster_paint_glyph_impl (hb_raster_paint_t *paint, hb_bool_t ret = true; if (fallible) ret = hb_font_paint_glyph_or_fail (font, glyph, - hb_raster_paint_get_funcs (), paint, + hb_raster_paint_get_funcs (paint), paint, paint->palette, paint->foreground); else hb_font_paint_glyph (font, glyph, - hb_raster_paint_get_funcs (), paint, + hb_raster_paint_get_funcs (paint), paint, paint->palette, paint->foreground); hb_raster_paint_set_transform (paint, xx, yx, xy, yy, dx, dy); return ret; diff --git a/src/hb-raster.h b/src/hb-raster.h index 6e4437be8..47caedb78 100644 --- a/src/hb-raster.h +++ b/src/hb-raster.h @@ -193,7 +193,7 @@ hb_raster_draw_set_glyph_extents (hb_raster_draw_t *draw, const hb_glyph_extents_t *glyph_extents); HB_EXTERN hb_draw_funcs_t * -hb_raster_draw_get_funcs (void); +hb_raster_draw_get_funcs (const hb_raster_draw_t *draw); HB_EXTERN void hb_raster_draw_glyph (hb_raster_draw_t *draw, @@ -314,7 +314,7 @@ hb_raster_paint_set_custom_palette_color (hb_raster_paint_t *paint, hb_color_t color); HB_EXTERN hb_paint_funcs_t * -hb_raster_paint_get_funcs (void); +hb_raster_paint_get_funcs (const hb_raster_paint_t *paint); HB_EXTERN void hb_raster_paint_glyph (hb_raster_paint_t *paint, diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index bb2008617..f50047a01 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -510,17 +510,35 @@ hb_vector_draw_set_glyph_extents (hb_vector_draw_t *draw, return ret; } +/** + * hb_vector_draw_get_format: + * @draw: a vector draw context. + * + * Gets the output format @draw was created with. + * + * Return value: the output format. + * + * XSince: REPLACEME + */ +hb_vector_format_t +hb_vector_draw_get_format (const hb_vector_draw_t *draw) +{ + return draw->format; +} + /** * hb_vector_draw_get_funcs: + * @draw: a vector draw context. * - * Gets draw callbacks implemented by the vector draw backend. + * Gets draw callbacks for feeding outline data into @draw. + * Pass @draw as the @draw_data argument when calling them. * - * Return value: (transfer none): immutable #hb_draw_funcs_t singleton. + * Return value: (transfer none): immutable #hb_draw_funcs_t. * * Since: 13.0.0 */ hb_draw_funcs_t * -hb_vector_draw_get_funcs (void) +hb_vector_draw_get_funcs (const hb_vector_draw_t *draw HB_UNUSED) { return hb_vector_draw_funcs_get (); } @@ -583,7 +601,9 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, /* Flush any pending free-form path the caller accumulated * via hb_draw_*() on hb_vector_draw_get_funcs() before this - * glyph clobbers the scratch buffer. */ + * glyph clobbers the scratch buffer. Wrap the SVG case in + * the same scale(1,-1) Y-flip per-glyph applies, so + * the free-form coords share the glyph's coord system. */ if (draw->path.length) { switch (draw->format) @@ -593,9 +613,9 @@ hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw, hb_buf_append_str (&draw->body, "f\n"); break; case HB_VECTOR_FORMAT_SVG: - hb_buf_append_str (&draw->body, "body, "body, draw->path.arrayZ, draw->path.length); - hb_buf_append_str (&draw->body, "\"/>\n"); + hb_buf_append_str (&draw->body, "\"/>\n"); break; case HB_VECTOR_FORMAT_INVALID: default: break; } @@ -900,13 +920,14 @@ hb_vector_draw_render_svg (hb_vector_draw_t *draw) hb_buf_append_len (&out, draw->body.arrayZ, draw->body.length); if (draw->path.length) { - /* Free-form draw ops accumulated after the last glyph - * (e.g. extents-overlay rectangles via hb_draw_rectangle on - * hb_vector_draw_get_funcs) live in the scratch path - * and need their own element. */ - hb_buf_append_str (&out, " elements apply scale(_, -sy) to convert, so wrap + * the leftover here in the same Y-flip. */ + hb_buf_append_str (&out, "path.arrayZ, draw->path.length); - hb_buf_append_str (&out, "\"/>\n"); + hb_buf_append_str (&out, "\"/>\n"); } hb_buf_append_str (&out, "\n"); diff --git a/src/hb-vector-paint-pdf.cc b/src/hb-vector-paint-pdf.cc index 85d7261a3..3d26d956e 100644 --- a/src/hb-vector-paint-pdf.cc +++ b/src/hb-vector-paint-pdf.cc @@ -310,7 +310,7 @@ hb_pdf_emit_glyph_path (hb_vector_paint_t *paint, tmp.path.alloc (1024); hb_font_draw_glyph (font, glyph, - hb_vector_draw_get_funcs (), + hb_vector_draw_get_funcs (&tmp), &tmp); hb_buf_append_len (buf, tmp.path.arrayZ, tmp.path.length); diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index 74fedef3a..71fa8b2f3 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -601,11 +601,17 @@ hb_vector_paint_push_clip_path_end (hb_paint_funcs_t *, unsigned pfx_len = paint->id_prefix.length; unsigned clip_id = paint->clip_path_counter++; + /* The accumulated path is in font Y-up coords (the + * convention used inside per-glyph + * wrappers); this clip is emitted at base body level + * (free-form between glyphs), so flip its geometry inside + * the clipPath via the path's own transform attribute, + * keeping the body's at body Y-down. */ hb_buf_append_str (&paint->defs, "defs, pfx, pfx_len); hb_buf_append_str (&paint->defs, "cp"); hb_buf_append_unsigned (&paint->defs, clip_id); - hb_buf_append_str (&paint->defs, "\">defs, "\">defs, paint->path.arrayZ, paint->path.length); hb_buf_append_str (&paint->defs, "\"/>\n"); @@ -1350,19 +1356,45 @@ hb_vector_paint_clear_custom_palette_colors (hb_vector_paint_t *paint) paint->custom_palette_colors.clear (); } +/** + * hb_vector_paint_get_format: + * @paint: a vector paint context. + * + * Gets the output format @paint was created with. + * + * Return value: the output format. + * + * XSince: REPLACEME + */ +hb_vector_format_t +hb_vector_paint_get_format (const hb_vector_paint_t *paint) +{ + return paint->format; +} + /** * hb_vector_paint_get_funcs: + * @paint: a vector paint context. * - * Gets paint callbacks implemented by the vector paint backend. + * Gets paint callbacks for emitting paint operations into @paint. + * Pass @paint as the @paint_data argument when calling them. * - * Return value: (transfer none): immutable #hb_paint_funcs_t singleton. + * Return value: (transfer none): immutable #hb_paint_funcs_t. * * Since: 13.0.0 */ hb_paint_funcs_t * -hb_vector_paint_get_funcs (void) +hb_vector_paint_get_funcs (const hb_vector_paint_t *paint) { - return hb_vector_paint_funcs_get (); + switch (paint ? paint->format : HB_VECTOR_FORMAT_INVALID) + { + case HB_VECTOR_FORMAT_PDF: + return hb_vector_paint_pdf_funcs_get (); + case HB_VECTOR_FORMAT_SVG: + case HB_VECTOR_FORMAT_INVALID: + default: + return hb_vector_paint_funcs_get (); + } } static hb_bool_t @@ -1494,12 +1526,12 @@ hb_vector_paint_glyph_impl (hb_vector_paint_t *paint, hb_bool_t ret = true; if (fallible) ret = hb_font_paint_glyph_or_fail (font, glyph, - hb_vector_paint_get_funcs (), paint, + hb_vector_paint_get_funcs (paint), paint, (unsigned) paint->palette, paint->foreground); else hb_font_paint_glyph (font, glyph, - hb_vector_paint_get_funcs (), paint, + hb_vector_paint_get_funcs (paint), paint, (unsigned) paint->palette, paint->foreground); if (unlikely (!ret)) diff --git a/src/hb-vector.h b/src/hb-vector.h index db95cc370..830289053 100644 --- a/src/hb-vector.h +++ b/src/hb-vector.h @@ -151,8 +151,11 @@ HB_EXTERN hb_bool_t hb_vector_draw_set_glyph_extents (hb_vector_draw_t *draw, const hb_glyph_extents_t *glyph_extents); +HB_EXTERN hb_vector_format_t +hb_vector_draw_get_format (const hb_vector_draw_t *draw); + HB_EXTERN hb_draw_funcs_t * -hb_vector_draw_get_funcs (void); +hb_vector_draw_get_funcs (const hb_vector_draw_t *draw); HB_EXTERN void hb_vector_draw_glyph (hb_vector_draw_t *draw, @@ -276,8 +279,11 @@ hb_vector_paint_set_custom_palette_color (hb_vector_paint_t *paint, HB_EXTERN void hb_vector_paint_clear_custom_palette_colors (hb_vector_paint_t *paint); +HB_EXTERN hb_vector_format_t +hb_vector_paint_get_format (const hb_vector_paint_t *paint); + HB_EXTERN hb_paint_funcs_t * -hb_vector_paint_get_funcs (void); +hb_vector_paint_get_funcs (const hb_vector_paint_t *paint); HB_EXTERN void hb_vector_paint_glyph (hb_vector_paint_t *paint, diff --git a/test/api/test-gpu.cc b/test/api/test-gpu.cc index 3fdb7d3b6..fd4a47ade 100644 --- a/test/api/test-gpu.cc +++ b/test/api/test-gpu.cc @@ -179,11 +179,11 @@ test_reset (void) static void test_draw_funcs (void) { - hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (nullptr); g_assert_nonnull (funcs); - /* Should be the same singleton each time. */ - g_assert_true (funcs == hb_gpu_draw_get_funcs ()); + /* Should be the same instance each time. */ + g_assert_true (funcs == hb_gpu_draw_get_funcs (nullptr)); } static void @@ -201,7 +201,7 @@ test_encode_quantizes_extents_outward (void) hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail (); g_assert_nonnull (draw); - hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (draw); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; hb_draw_move_to (funcs, draw, &st, 0.24f, 0.24f); hb_draw_line_to (funcs, draw, &st, 0.76f, 0.24f); @@ -229,7 +229,7 @@ test_encode_preserves_touching_contours (void) hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail (); g_assert_nonnull (draw); - hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (draw); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; hb_draw_move_to (funcs, draw, &st, 0.f, 0.f); @@ -256,7 +256,7 @@ test_recycle_blob (void) hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail (); g_assert_nonnull (draw); - hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (draw); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; hb_draw_move_to (funcs, draw, &st, 0.f, 0.f); @@ -297,7 +297,7 @@ test_extents_saturate_overflow (void) hb_gpu_draw_t *draw = hb_gpu_draw_create_or_fail (); g_assert_nonnull (draw); - hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *funcs = hb_gpu_draw_get_funcs (draw); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; hb_draw_move_to (funcs, draw, &st, -0x1p31f, 0.f); @@ -335,10 +335,10 @@ test_paint_create_destroy (void) static void test_paint_get_funcs (void) { - hb_paint_funcs_t *funcs = hb_gpu_paint_get_funcs (); + hb_paint_funcs_t *funcs = hb_gpu_paint_get_funcs (nullptr); g_assert_nonnull (funcs); - /* Singleton. */ - g_assert_true (funcs == hb_gpu_paint_get_funcs ()); + /* Same instance each call. */ + g_assert_true (funcs == hb_gpu_paint_get_funcs (nullptr)); } static void @@ -528,7 +528,7 @@ test_shapes (void) * the encoder's representable range. */ hb_gpu_draw_set_scale (draw, 1000, 1000); - hb_draw_funcs_t *dfuncs = hb_gpu_draw_get_funcs (); + hb_draw_funcs_t *dfuncs = hb_gpu_draw_get_funcs (draw); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; /* Tapered line. */ diff --git a/test/api/test-raster.cc b/test/api/test-raster.cc index 0d97c8e6b..144e84f05 100644 --- a/test/api/test-raster.cc +++ b/test/api/test-raster.cc @@ -36,7 +36,7 @@ static void draw_rect (hb_raster_draw_t *rdr, float x0, float y0, float x1, float y1) { - hb_draw_funcs_t *df = hb_raster_draw_get_funcs (); + hb_draw_funcs_t *df = hb_raster_draw_get_funcs (rdr); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; hb_draw_move_to (df, rdr, &st, x0, y0); diff --git a/util/gpu/demo-font.cc b/util/gpu/demo-font.cc index 042aba1c9..245282c29 100644 --- a/util/gpu/demo-font.cc +++ b/util/gpu/demo-font.cc @@ -133,7 +133,7 @@ _demo_font_upload_glyph (demo_font_t *font, hb_glyph_extents_t g; if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) util_emit_extents_rect_into_draw ( - hb_gpu_draw_get_funcs (), font->d, + hb_gpu_draw_get_funcs (font->d), font->d, &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); } blob = hb_gpu_draw_encode (font->d, &hb_ext); @@ -147,7 +147,7 @@ _demo_font_upload_glyph (demo_font_t *font, hb_glyph_extents_t g; if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) util_emit_extents_rect_into_paint ( - hb_gpu_paint_get_funcs (), font->p, + hb_gpu_paint_get_funcs (font->p), font->p, &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); } blob = hb_gpu_paint_encode (font->p, &hb_ext); diff --git a/util/raster-output.hh b/util/raster-output.hh index 993384377..1c3593ace 100644 --- a/util/raster-output.hh +++ b/util/raster-output.hh @@ -255,7 +255,7 @@ struct raster_output_t : output_options_t, view_options_t hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) util_emit_extents_rect_into_draw ( - hb_raster_draw_get_funcs (), rdr, + hb_raster_draw_get_funcs (rdr), rdr, &ge, pen_x, pen_y, extents_stroke_width ()); } } @@ -339,7 +339,7 @@ struct raster_output_t : output_options_t, view_options_t hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) util_emit_extents_rect_into_paint ( - hb_raster_paint_get_funcs (), pnt, + hb_raster_paint_get_funcs (pnt), pnt, &ge, pen_x, pen_y, extents_stroke_width ()); } @@ -430,7 +430,7 @@ struct raster_output_t : output_options_t, view_options_t hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) util_emit_extents_rect_into_draw ( - hb_raster_draw_get_funcs (), rdr, + hb_raster_draw_get_funcs (rdr), rdr, &ge, g.x + off_x, g.y + off_y, extents_stroke_width ()); } diff --git a/util/vector-output.hh b/util/vector-output.hh index 3d4d32426..f353cf8f2 100644 --- a/util/vector-output.hh +++ b/util/vector-output.hh @@ -288,7 +288,7 @@ struct vector_output_t : output_options_t<>, view_options_t hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) util_emit_extents_rect_into_paint ( - hb_vector_paint_get_funcs (), paint, + hb_vector_paint_get_funcs (paint), paint, &ge, pen_x, pen_y, (float) normalized_stroke_width); } } @@ -302,7 +302,7 @@ struct vector_output_t : output_options_t<>, view_options_t hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) util_emit_extents_rect_into_draw ( - hb_vector_draw_get_funcs (), draw, + hb_vector_draw_get_funcs (draw), draw, &ge, pen_x, pen_y, (float) normalized_stroke_width); } } From 48fdb0ec34468bf30511469ab6aaa336def5b2e7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 13:31:09 -0600 Subject: [PATCH 21/26] [cairo] Implement arbitrary-path clip in paint funcs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wire push_clip_path_start / push_clip_path_end into the cairo paint backend. start() saves the cairo state, opens a fresh path, and hands the caller hb_cairo_draw_get_funcs with the cairo_t as draw data — same draw funcs that push_clip_glyph already uses internally to walk a glyph outline as a cairo path. end() closes the path and calls cairo_clip; pop_clip's cairo_restore tears down the saved state as before. Lets cairo paint consumers compose arbitrary-path clips (say, an outline for a non-glyph shape) the same way push_clip_glyph builds a glyph clip. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/hb-cairo.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index c93206a38..ddb5d23dc 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -227,6 +227,33 @@ hb_cairo_push_clip_rectangle (hb_paint_funcs_t *pfuncs HB_UNUSED, cairo_clip (cr); } +static hb_draw_funcs_t * +hb_cairo_push_clip_path_start (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void **draw_data, + 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); + *draw_data = cr; + return hb_cairo_draw_get_funcs (); +} + +static void +hb_cairo_push_clip_path_end (hb_paint_funcs_t *pfuncs HB_UNUSED, + void *paint_data, + void *user_data HB_UNUSED) +{ + hb_cairo_context_t *c = (hb_cairo_context_t *) paint_data; + cairo_t *cr = c->cr; + + cairo_close_path (cr); + cairo_clip (cr); +} + static void hb_cairo_pop_clip (hb_paint_funcs_t *pfuncs HB_UNUSED, void *paint_data, @@ -428,6 +455,8 @@ static struct hb_cairo_paint_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t< 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); + hb_paint_funcs_set_push_clip_path_start_func (funcs, hb_cairo_push_clip_path_start, nullptr, nullptr); + hb_paint_funcs_set_push_clip_path_end_func (funcs, hb_cairo_push_clip_path_end, nullptr, nullptr); hb_paint_funcs_set_pop_clip_func (funcs, hb_cairo_pop_clip, nullptr, nullptr); hb_paint_funcs_set_push_group_func (funcs, hb_cairo_push_group, nullptr, nullptr); hb_paint_funcs_set_pop_group_func (funcs, hb_cairo_pop_group, nullptr, nullptr); From 88dc4c99263f67ac3abe5e9d17e5ebe6984aa3c0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 13:34:55 -0600 Subject: [PATCH 22/26] NEWS: Document get_funcs signature change and draw helpers * Add the six raster/vector/gpu draw+paint get_funcs signature change to "Changed API, general". * List hb_vector_draw_get_format / hb_vector_paint_get_format under "New API, Vector library". * Add a "New API, Draw" section for the new shape helpers (hb_draw_line, hb_draw_rectangle, hb_draw_circle) and the hb_draw_line_cap_t / HB_DRAW_LINE_CAP_* constants that came in earlier this dev cycle but weren't yet listed. Co-Authored-By: Claude Opus 4.6 (1M context) --- NEWS | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/NEWS b/NEWS index d646eee34..4aabb8c7d 100644 --- a/NEWS +++ b/NEWS @@ -72,6 +72,15 @@ Overview of changes leading to NEXT (REPLACEME) shader clips against it the same way it clips against glyph outlines). +- New API, Draw: + +hb_draw_line() + +hb_draw_rectangle() + +hb_draw_circle() + +hb_draw_line_cap_t + +HB_DRAW_LINE_CAP_BUTT + +HB_DRAW_LINE_CAP_ROUND + +HB_DRAW_LINE_CAP_SQUARE + - New API, Paint: +hb_paint_push_group_for() +hb_paint_funcs_set_push_group_for_func() @@ -129,11 +138,13 @@ Overview of changes leading to NEXT (REPLACEME) +HB_VECTOR_FORMAT_PDF +hb_vector_draw_clear() +hb_vector_draw_get_precision() + +hb_vector_draw_get_format() +hb_vector_draw_glyph_or_fail() +hb_vector_draw_set_svg_prefix() +hb_vector_draw_get_svg_prefix() +hb_vector_paint_clear() +hb_vector_paint_get_precision() + +hb_vector_paint_get_format() +hb_vector_paint_get_foreground() +hb_vector_paint_get_palette() +hb_vector_paint_glyph_or_fail() @@ -185,6 +196,19 @@ Overview of changes leading to NEXT (REPLACEME) - Changed API, general: * Many read-only getters gained const on their object argument. + * Six public draw / paint funcs getters across raster, + vector, and gpu now take a const-pointer to the relevant + context instance instead of being singletons: + hb_raster_draw_get_funcs (const hb_raster_draw_t *) + hb_raster_paint_get_funcs (const hb_raster_paint_t *) + hb_vector_draw_get_funcs (const hb_vector_draw_t *) + hb_vector_paint_get_funcs (const hb_vector_paint_t *) + hb_gpu_draw_get_funcs (const hb_gpu_draw_t *) + hb_gpu_paint_get_funcs (const hb_gpu_paint_t *) + This is what lets vector_paint dispatch to SVG- vs PDF- + flavored callbacks transparently when called from outside + code; the others currently use the instance for symmetry + only. Overview of changes leading to 14.1.0 From c152eaceb31fab8c41c9c33595c15926cc279d22 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 14:17:01 -0600 Subject: [PATCH 23/26] [util] --show-extents: add a filled dot at the pen origin Extend the shared overlay helper (and rename it from util_emit_extents_rect_into_* to util_emit_extents_overlay_ into_*) to emit two pieces of geometry per glyph: the existing stroked rect around the ink box, plus a filled dot at the pen origin via hb_draw_circle. Both go in the foreground color through the same draw / paint flow. The dot helps debug glyph positioning at a glance and gives the previously-uncalled hb_draw_circle a real caller in the suite. Raster, vector, and gpu utils pick up the dot automatically via the renamed helper. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/gpu/demo-font.cc | 4 +- util/helper-extents-overlay.hh | 78 ++++++++++++++++++++-------------- util/raster-output.hh | 6 +-- util/vector-output.hh | 4 +- 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/util/gpu/demo-font.cc b/util/gpu/demo-font.cc index 245282c29..879c8350b 100644 --- a/util/gpu/demo-font.cc +++ b/util/gpu/demo-font.cc @@ -132,7 +132,7 @@ _demo_font_upload_glyph (demo_font_t *font, { hb_glyph_extents_t g; if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) - util_emit_extents_rect_into_draw ( + util_emit_extents_overlay_into_draw ( hb_gpu_draw_get_funcs (font->d), font->d, &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); } @@ -146,7 +146,7 @@ _demo_font_upload_glyph (demo_font_t *font, { hb_glyph_extents_t g; if (hb_font_get_glyph_extents (font->font, glyph_index, &g)) - util_emit_extents_rect_into_paint ( + util_emit_extents_overlay_into_paint ( hb_gpu_paint_get_funcs (font->p), font->p, &g, /*pen_x*/ 0.f, /*pen_y*/ 0.f, sw); } diff --git a/util/helper-extents-overlay.hh b/util/helper-extents-overlay.hh index 134aadcea..79eee0186 100644 --- a/util/helper-extents-overlay.hh +++ b/util/helper-extents-overlay.hh @@ -31,51 +31,65 @@ #include -/* --show-extents overlay helpers. +/* --show-extents overlay helpers: a stroked rectangle around + * each glyph's ink box, plus a filled dot at the glyph's pen + * origin. Both render in the foreground color. * - * In DRAW mode, emit a stroked extents rectangle directly into the - * glyph's draw context so it gets rendered/encoded alongside the - * glyph outline in the glyph's foreground color. + * In DRAW mode, the geometry goes straight into the glyph's + * draw context so it gets rendered/encoded alongside the + * outline in the foreground color. * - * In PAINT mode, push an arbitrary-path clip with the same stroked - * rectangle and fill it with the paint's current foreground; the - * draw-mode and paint-mode emitters share all of the coord math. */ + * In PAINT mode, the same geometry feeds an arbitrary-path + * clip and the clipped region is filled with the paint's + * current foreground; the draw-mode and paint-mode emitters + * share all of the coord math. */ static inline void -util_emit_extents_rect_into_draw (hb_draw_funcs_t *df, void *dd, - const hb_glyph_extents_t *ge, - float pen_x, float pen_y, - float stroke_width) +util_emit_extents_overlay_into_draw (hb_draw_funcs_t *df, void *dd, + const hb_glyph_extents_t *ge, + float pen_x, float pen_y, + float stroke_width) { - if (ge->width == 0 && ge->height == 0) - return; - /* Pad outward by stroke_width / 2 so the stroke's inner edge - * sits at the ink box instead of straddling it (and its inner - * half knocking out against glyph ink under non-zero winding). - * Using copysignf on the padding handles glyph-extent - * conventions where height is negative (Y-up). */ - float half = 0.5f * stroke_width; - float sx = copysignf (half, ge->width ? (float) ge->width : 1.f); - float sy = copysignf (half, ge->height ? (float) ge->height : 1.f); hb_draw_state_t st = HB_DRAW_STATE_DEFAULT; - hb_draw_rectangle (df, dd, &st, - pen_x + (float) ge->x_bearing - sx, - pen_y + (float) ge->y_bearing - sy, - (float) ge->width + 2 * sx, - (float) ge->height + 2 * sy, - stroke_width); + + /* Stroked rectangle around the ink box. Padded outward by + * stroke_width / 2 so the stroke's inner edge sits at the + * box, instead of straddling it (and the inner half + * knocking out against glyph ink under non-zero winding). + * copysignf on the padding keeps the shift outward + * regardless of glyph-extent height-sign convention. */ + if (ge->width != 0 || ge->height != 0) + { + float half = 0.5f * stroke_width; + float sx = copysignf (half, ge->width ? (float) ge->width : 1.f); + float sy = copysignf (half, ge->height ? (float) ge->height : 1.f); + hb_draw_rectangle (df, dd, &st, + pen_x + (float) ge->x_bearing - sx, + pen_y + (float) ge->y_bearing - sy, + (float) ge->width + 2 * sx, + (float) ge->height + 2 * sy, + stroke_width); + } + + /* Filled dot at the glyph origin (pen_x, pen_y). Radius + * scales with stroke_width so the dot stays visible at the + * same render scale the stroke does. */ + hb_draw_circle (df, dd, &st, + pen_x, pen_y, + /*radius*/ 2.f * stroke_width, + /*stroke_width*/ NAN); } static inline void -util_emit_extents_rect_into_paint (hb_paint_funcs_t *pf, void *pd, - const hb_glyph_extents_t *ge, - float pen_x, float pen_y, - float stroke_width) +util_emit_extents_overlay_into_paint (hb_paint_funcs_t *pf, void *pd, + const hb_glyph_extents_t *ge, + float pen_x, float pen_y, + float stroke_width) { void *dd = nullptr; hb_draw_funcs_t *df = hb_paint_push_clip_path_start (pf, pd, &dd); if (!df) return; - util_emit_extents_rect_into_draw (df, dd, ge, pen_x, pen_y, stroke_width); + util_emit_extents_overlay_into_draw (df, dd, ge, pen_x, pen_y, stroke_width); hb_paint_push_clip_path_end (pf, pd); hb_paint_color (pf, pd, /*is_foreground*/ 1, HB_COLOR (0, 0, 0, 255)); hb_paint_pop_clip (pf, pd); diff --git a/util/raster-output.hh b/util/raster-output.hh index 1c3593ace..969c883ff 100644 --- a/util/raster-output.hh +++ b/util/raster-output.hh @@ -254,7 +254,7 @@ struct raster_output_t : output_options_t, view_options_t { hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) - util_emit_extents_rect_into_draw ( + util_emit_extents_overlay_into_draw ( hb_raster_draw_get_funcs (rdr), rdr, &ge, pen_x, pen_y, extents_stroke_width ()); } @@ -338,7 +338,7 @@ struct raster_output_t : output_options_t, view_options_t { hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) - util_emit_extents_rect_into_paint ( + util_emit_extents_overlay_into_paint ( hb_raster_paint_get_funcs (pnt), pnt, &ge, pen_x, pen_y, extents_stroke_width ()); } @@ -429,7 +429,7 @@ struct raster_output_t : output_options_t, view_options_t { hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (font, g.gid, &ge)) - util_emit_extents_rect_into_draw ( + util_emit_extents_overlay_into_draw ( hb_raster_draw_get_funcs (rdr), rdr, &ge, g.x + off_x, g.y + off_y, extents_stroke_width ()); } diff --git a/util/vector-output.hh b/util/vector-output.hh index f353cf8f2..00488333b 100644 --- a/util/vector-output.hh +++ b/util/vector-output.hh @@ -287,7 +287,7 @@ struct vector_output_t : output_options_t<>, view_options_t { hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) - util_emit_extents_rect_into_paint ( + util_emit_extents_overlay_into_paint ( hb_vector_paint_get_funcs (paint), paint, &ge, pen_x, pen_y, (float) normalized_stroke_width); } @@ -301,7 +301,7 @@ struct vector_output_t : output_options_t<>, view_options_t { hb_glyph_extents_t ge; if (hb_font_get_glyph_extents (upem_font, g.gid, &ge)) - util_emit_extents_rect_into_draw ( + util_emit_extents_overlay_into_draw ( hb_vector_draw_get_funcs (draw), draw, &ge, pen_x, pen_y, (float) normalized_stroke_width); } From f7ebd549edd7ff306aa040e1f8cbcd0b1f59de2e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 14:17:10 -0600 Subject: [PATCH 24/26] [util/hb-view] --show-extents: foreground color, no per-color split Drop the bespoke red pen dot + magenta extents rectangle in favor of a single foreground-color overlay that matches the look raster, vector, and gpu now produce after their port to the shared helper: stroked rect around each glyph's ink box, plus a filled dot at the pen origin. Cairo's annotation pass stays native (post-glyph drawing through cairo, not via hb_paint funcs); only the colors and the dot rendering changed. Co-Authored-By: Claude Opus 4.6 (1M context) --- util/view-cairo.hh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/util/view-cairo.hh b/util/view-cairo.hh index fd407165a..7766e19b7 100644 --- a/util/view-cairo.hh +++ b/util/view-cairo.hh @@ -108,20 +108,16 @@ view_cairo_t::draw_lines (cairo_t *cr, hb_font_t *font, double leading, int vert { cairo_save (cr); - cairo_set_source_rgba (cr, 1., 0., 0., .5); - cairo_set_line_width (cr, 10); - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - for (unsigned i = 0; i < l.num_glyphs; i++) { - cairo_move_to (cr, l.glyphs[i].x, l.glyphs[i].y); - cairo_rel_line_to (cr, 0, 0); - } - cairo_stroke (cr); - - cairo_restore (cr); - cairo_save (cr); - - cairo_set_source_rgba (cr, 1., 0., 1., .5); - cairo_set_line_width (cr, 3); + /* Foreground for parity with the other utils' --show- + * extents overlay (raster, vector, gpu). Stroked rect + * around each glyph's ink box, plus a filled dot at the + * pen origin. */ + cairo_set_source_rgba (cr, + foreground_color.r / 255., + foreground_color.g / 255., + foreground_color.b / 255., + foreground_color.a / 255.); + cairo_set_line_width (cr, 1); for (unsigned i = 0; i < l.num_glyphs; i++) { hb_glyph_extents_t hb_extents; @@ -137,6 +133,13 @@ view_cairo_t::draw_lines (cairo_t *cr, hb_font_t *font, double leading, int vert } cairo_stroke (cr); + /* Filled origin dot. */ + for (unsigned i = 0; i < l.num_glyphs; i++) + { + cairo_arc (cr, l.glyphs[i].x, l.glyphs[i].y, 2., 0., 2 * G_PI); + cairo_fill (cr); + } + cairo_restore (cr); } From 6636f042fc6c3cac4d7d91387f8ecefcd3d8757a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 16:02:12 -0600 Subject: [PATCH 25/26] Address PR #5933 review feedback - Reset Since tags to XSince: REPLACEME for changed get_funcs signatures (gpu, raster, vector draw+paint). - Replace (transfer none) annotation syntax with prose in clip_path_start docs (hb-paint.cc and hb-paint.h). - Document that returned draw funcs/data are only valid until the matching clip_path_end call, and no other paint calls should be made in between. - Use switch instead of ternary for format in hb-vector-path.cc. Assisted-by: Claude Opus 4.6 (1M context) --- src/hb-gpu-draw.cc | 2 +- src/hb-paint.cc | 12 ++++++++---- src/hb-paint.h | 13 +++++++------ src/hb-raster-draw.cc | 2 +- src/hb-raster-paint.cc | 2 +- src/hb-vector-draw.cc | 2 +- src/hb-vector-paint.cc | 2 +- src/hb-vector-path.cc | 13 +++++++++++-- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index 9ab22571e..63c30ddfd 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -917,7 +917,7 @@ hb_gpu_draw_get_user_data (const hb_gpu_draw_t *draw, * Return value: (transfer none): * The GPU draw functions * - * Since: 14.0.0 + * XSince: REPLACEME **/ hb_draw_funcs_t * hb_gpu_draw_get_funcs (const hb_gpu_draw_t *draw HB_UNUSED) diff --git a/src/hb-paint.cc b/src/hb-paint.cc index b5e7c829a..f5ed66c6e 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -597,10 +597,14 @@ hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data, * @draw_data: (out) (nullable): location to receive the draw data * the caller should pass alongside the returned draw funcs. * - * Begin clipping to an arbitrary path. Returns a - * #hb_draw_funcs_t (transfer none) that the caller uses to - * emit the clip outline via hb_draw_*() calls, using the - * returned @draw_data as the draw data. Finish the path + * Begin clipping to an arbitrary path. Returns an + * #hb_draw_funcs_t owned by the backend (the caller must not + * free it) that the caller uses to emit the clip outline via + * hb_draw_*() calls, using the returned @draw_data as the + * draw data. The returned draw funcs and draw data are only + * valid until the matching hb_paint_push_clip_path_end() call; + * no other paint calls should be made between start and end + * except hb_draw_*() on the returned funcs. Finish the path * with hb_paint_push_clip_path_end(); pop the clip later * with hb_paint_pop_clip(). * diff --git a/src/hb-paint.h b/src/hb-paint.h index e61e6384d..b6a94d994 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -222,12 +222,13 @@ typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs, * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_path_start_func() * * A virtual method for the #hb_paint_funcs_t to begin clipping - * to an arbitrary path. The backend returns a - * #hb_draw_funcs_t (transfer none) that the caller feeds the - * clip outline to via hb_draw_*() calls, plus a - * @draw_data value (transfer none) to pass alongside those - * calls. The path is closed by a matching call to the - * #hb_paint_push_clip_path_end_func_t vfunc; the clip remains + * to an arbitrary path. The backend returns an + * #hb_draw_funcs_t it owns (the caller must not free it) + * that the caller feeds the clip outline to via hb_draw_*() + * calls, plus a @draw_data value to pass alongside those + * calls. Both are only valid until the matching + * #hb_paint_push_clip_path_end_func_t call; no other paint + * calls should be made in between. The clip remains * in effect until a later #hb_paint_pop_clip_func_t call. * * Return value: (transfer none): draw funcs that accumulate diff --git a/src/hb-raster-draw.cc b/src/hb-raster-draw.cc index de704a55b..1150c99fe 100644 --- a/src/hb-raster-draw.cc +++ b/src/hb-raster-draw.cc @@ -944,7 +944,7 @@ free_static_raster_draw_funcs () * Return value: (transfer none): * The rasterizer draw functions * - * Since: 13.0.0 + * XSince: REPLACEME **/ hb_draw_funcs_t * hb_raster_draw_get_funcs (const hb_raster_draw_t *draw HB_UNUSED) diff --git a/src/hb-raster-paint.cc b/src/hb-raster-paint.cc index b9aa392ed..bfe6517b6 100644 --- a/src/hb-raster-paint.cc +++ b/src/hb-raster-paint.cc @@ -2174,7 +2174,7 @@ hb_raster_paint_set_custom_palette_color (hb_raster_paint_t *paint, * Return value: (transfer none): * The rasterizer paint functions * - * Since: 13.0.0 + * XSince: REPLACEME **/ hb_paint_funcs_t * hb_raster_paint_get_funcs (const hb_raster_paint_t *paint HB_UNUSED) diff --git a/src/hb-vector-draw.cc b/src/hb-vector-draw.cc index f50047a01..36bd819a2 100644 --- a/src/hb-vector-draw.cc +++ b/src/hb-vector-draw.cc @@ -535,7 +535,7 @@ hb_vector_draw_get_format (const hb_vector_draw_t *draw) * * Return value: (transfer none): immutable #hb_draw_funcs_t. * - * Since: 13.0.0 + * XSince: REPLACEME */ hb_draw_funcs_t * hb_vector_draw_get_funcs (const hb_vector_draw_t *draw HB_UNUSED) diff --git a/src/hb-vector-paint.cc b/src/hb-vector-paint.cc index 71fa8b2f3..3435169f4 100644 --- a/src/hb-vector-paint.cc +++ b/src/hb-vector-paint.cc @@ -1381,7 +1381,7 @@ hb_vector_paint_get_format (const hb_vector_paint_t *paint) * * Return value: (transfer none): immutable #hb_paint_funcs_t. * - * Since: 13.0.0 + * XSince: REPLACEME */ hb_paint_funcs_t * hb_vector_paint_get_funcs (const hb_vector_paint_t *paint) diff --git a/src/hb-vector-path.cc b/src/hb-vector-path.cc index b3536314f..a6447417a 100644 --- a/src/hb-vector-path.cc +++ b/src/hb-vector-path.cc @@ -36,8 +36,17 @@ static inline void hb_vector_path_append_xy (hb_vector_path_sink_t *s, float x, float y) { hb_buf_append_num (s->path, x, s->precision); - hb_buf_append_c (s->path, - s->format == HB_VECTOR_FORMAT_PDF ? ' ' : ','); + switch (s->format) + { + case HB_VECTOR_FORMAT_PDF: + hb_buf_append_c (s->path, ' '); + break; + case HB_VECTOR_FORMAT_SVG: + hb_buf_append_c (s->path, ','); + break; + case HB_VECTOR_FORMAT_INVALID: default: + break; + } hb_buf_append_num (s->path, y, s->precision); } From 76d543adc981bda0f73f49e5b083e0055dfc6a69 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 16 Apr 2026 16:23:32 -0600 Subject: [PATCH 26/26] fixup! [draw][paint] Make get_funcs instance-aware; add get_format --- src/hb-gpu-paint.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index fa0e81c1e..163711930 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -1274,7 +1274,7 @@ hb_gpu_paint_glyph_or_fail (hb_gpu_paint_t *paint, hb_font_get_scale (font, &x_scale, &y_scale); hb_gpu_paint_set_scale (paint, x_scale, y_scale); return hb_font_paint_glyph_or_fail (font, glyph, - hb_gpu_paint_get_funcs (), paint, + hb_gpu_paint_get_funcs (paint), paint, paint->palette, /* Foreground value is never read * from our encoded blob -- the