From d0bd9336c08ea2a0f0ab2f942ec398cc0b3a1949 Mon Sep 17 00:00:00 2001 From: Walter Kalata Date: Thu, 11 Jun 2026 20:29:34 -0700 Subject: [PATCH] Clip text groups in `tiny_skia` backend --- tiny_skia/src/layer.rs | 14 ++++++++++---- tiny_skia/src/lib.rs | 12 +++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 04c930e7ec..103bf6d914 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -109,8 +109,11 @@ impl Layer { clip_bounds: Rectangle, transformation: Transformation, ) { - self.text - .push(Item::Group(text, clip_bounds, transformation)); + self.text.push(Item::Group( + text, + clip_bounds * transformation, + transformation, + )); } pub fn draw_text_cache( @@ -119,8 +122,11 @@ impl Layer { clip_bounds: Rectangle, transformation: Transformation, ) { - self.text - .push(Item::Cached(text, clip_bounds, transformation)); + self.text.push(Item::Cached( + text, + clip_bounds * transformation, + transformation, + )); } pub fn draw_image(&mut self, image: Image, transformation: Transformation) { diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index e72702c83a..382b35f619 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -166,15 +166,25 @@ impl Renderer { let render_span = debug::render(debug::Primitive::Image); for group in &layer.text { + let Some(group_bounds) = + (group.clip_bounds() * scale_factor).intersection(&layer_bounds) + else { + continue; + }; + + engine::adjust_clip_mask(clip_mask, group_bounds); + for text in group.as_slice() { self.engine.draw_text( text, Transformation::scale(scale_factor) * group.transformation(), pixels, clip_mask, - layer_bounds, + group_bounds, ); } + + engine::adjust_clip_mask(clip_mask, layer_bounds); } render_span.finish();