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);