diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 26f8d3af9..30ac24aad 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -291,6 +291,8 @@ hb_paint_funcs_set_sweep_gradient_func hb_paint_composite_mode_t hb_paint_push_group_func_t hb_paint_funcs_set_push_group_func +hb_paint_push_group_for_func_t +hb_paint_funcs_set_push_group_for_func hb_paint_pop_group_func_t hb_paint_funcs_set_pop_group_func hb_paint_custom_palette_color_func_t @@ -310,6 +312,7 @@ hb_paint_linear_gradient hb_paint_radial_gradient hb_paint_sweep_gradient hb_paint_push_group +hb_paint_push_group_for hb_paint_pop_group hb_paint_custom_palette_color diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index c3b5808eb..62d3a3ce1 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -1526,9 +1526,9 @@ struct PaintComposite void paint_glyph (hb_paint_context_t *c) const { TRACE_PAINT (this); - c->funcs->push_group (c->data); + c->funcs->push_group_for (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); c->recurse (this+backdrop); - c->funcs->push_group (c->data); + c->funcs->push_group_for (c->data, (hb_paint_composite_mode_t) (int) mode); c->recurse (this+src); c->funcs->pop_group (c->data, (hb_paint_composite_mode_t) (int) mode); c->funcs->pop_group (c->data, HB_PAINT_COMPOSITE_MODE_SRC_OVER); diff --git a/src/hb-paint.cc b/src/hb-paint.cc index ffdd3c3a5..68fc0cade 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -118,6 +118,14 @@ static void hb_paint_push_group_nil (hb_paint_funcs_t *funcs, void *paint_data, void *user_data) {} +static void +hb_paint_push_group_for_nil (hb_paint_funcs_t *funcs, void *paint_data, + hb_paint_composite_mode_t mode, + void *user_data) +{ + hb_paint_push_group (funcs, paint_data); +} + static void hb_paint_pop_group_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, @@ -723,6 +731,25 @@ hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data) funcs->push_group (paint_data); } +/** + * hb_paint_push_group_for: + * @funcs: paint functions + * @paint_data: associated data passed by the caller + * @mode: the compositing mode that will be used when the group is popped + * + * Perform a "push-group" paint operation, with the compositing + * mode known in advance. By default, this calls + * hb_paint_push_group(). + * + * XSince: REPLACEME + */ +void +hb_paint_push_group_for (hb_paint_funcs_t *funcs, void *paint_data, + hb_paint_composite_mode_t mode) +{ + funcs->push_group_for (paint_data, mode); +} + /** * hb_paint_pop_group: * @funcs: paint functions diff --git a/src/hb-paint.h b/src/hb-paint.h index 787118c46..4fd6c6fbc 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -660,6 +660,28 @@ typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs, void *paint_data, void *user_data); +/** + * hb_paint_push_group_for_func_t: + * @funcs: paint functions object + * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph() + * @mode: the compositing mode that will be used when the group is popped + * @user_data: User data pointer passed to hb_paint_funcs_set_push_group_for_func() + * + * A virtual method for the #hb_paint_funcs_t to use + * an intermediate surface for subsequent paint calls, + * with the compositing mode known in advance. + * + * This is like #hb_paint_push_group_func_t, but the + * compositing mode is provided at push time. By default + * this calls #hb_paint_push_group_func_t. + * + * XSince: REPLACEME + */ +typedef void (*hb_paint_push_group_for_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + hb_paint_composite_mode_t mode, + void *user_data); + /** * hb_paint_pop_group_func_t: * @funcs: paint functions object @@ -916,6 +938,23 @@ hb_paint_funcs_set_push_group_func (hb_paint_funcs_t *funcs, void *user_data, hb_destroy_func_t destroy); +/** + * hb_paint_funcs_set_push_group_for_func: + * @funcs: A paint functions struct + * @func: (closure user_data) (destroy destroy) (scope notified): The push-group-for callback + * @user_data: Data to pass to @func + * @destroy: (nullable): Function to call when @user_data is no longer needed + * + * Sets the push-group-for callback on the paint functions struct. + * + * XSince: REPLACEME + */ +HB_EXTERN void +hb_paint_funcs_set_push_group_for_func (hb_paint_funcs_t *funcs, + hb_paint_push_group_for_func_t func, + void *user_data, + hb_destroy_func_t destroy); + /** * hb_paint_funcs_set_pop_group_func: * @funcs: A paint functions struct @@ -1026,6 +1065,10 @@ hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data, HB_EXTERN void hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data); +HB_EXTERN void +hb_paint_push_group_for (hb_paint_funcs_t *funcs, void *paint_data, + hb_paint_composite_mode_t mode); + HB_EXTERN void hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode); diff --git a/src/hb-paint.hh b/src/hb-paint.hh index bbeeb0319..be4655b7b 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -43,6 +43,7 @@ HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \ HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \ HB_PAINT_FUNC_IMPLEMENT (push_group) \ + HB_PAINT_FUNC_IMPLEMENT (push_group_for) \ HB_PAINT_FUNC_IMPLEMENT (pop_group) \ HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \ /* ^--- Add new callbacks here */ @@ -146,6 +147,11 @@ struct hb_paint_funcs_t void push_group (void *paint_data) { func.push_group (this, paint_data, !user_data ? nullptr : user_data->push_group); } + void push_group_for (void *paint_data, + hb_paint_composite_mode_t mode) + { func.push_group_for (this, paint_data, + mode, + !user_data ? nullptr : user_data->push_group_for); } void pop_group (void *paint_data, hb_paint_composite_mode_t mode) { func.pop_group (this, paint_data, diff --git a/src/hb-raster-svg-context.hh b/src/hb-raster-svg-context.hh index 5589f1d4c..6ed02a0b2 100644 --- a/src/hb-raster-svg-context.hh +++ b/src/hb-raster-svg-context.hh @@ -85,10 +85,10 @@ struct hb_svg_render_context_t { hb_paint_pop_transform (pfuncs, paint); } - bool push_group () + bool push_group (hb_paint_composite_mode_t mode = HB_PAINT_COMPOSITE_MODE_SRC_OVER) { unsigned depth = paint->surface_stack.length; - hb_paint_push_group (pfuncs, paint); + hb_paint_push_group_for (pfuncs, paint, mode); return paint->surface_stack.length > depth; } void pop_group (hb_paint_composite_mode_t mode) diff --git a/src/rust/font.rs b/src/rust/font.rs index 08f44e145..8e6b526b0 100644 --- a/src/rust/font.rs +++ b/src/rust/font.rs @@ -879,9 +879,10 @@ impl ColorPainter for HbColorPainter<'_> { } } } - fn push_layer(&mut self, _mode: CompositeMode) { + fn push_layer(&mut self, mode: CompositeMode) { + let mode = mode as hb_paint_composite_mode_t; unsafe { - hb_paint_push_group(self.paint_funcs, self.paint_data); + hb_paint_push_group_for(self.paint_funcs, self.paint_data, mode); } } fn pop_layer_with_mode(&mut self, mode: CompositeMode) {