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