From ec39390c23cd46a115bb0528abdb2c5527f1272a Mon Sep 17 00:00:00 2001 From: Vlad-Stefan Harbuz Date: Fri, 21 Jun 2024 10:41:17 +0100 Subject: Add stroke_rectangle This method should be able to leverage performance improvements in lyon's `tessellate_rectangle` over `tessellate_path`. --- tiny_skia/src/geometry.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tiny_skia') diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs index 659612d1..532a53cd 100644 --- a/tiny_skia/src/geometry.rs +++ b/tiny_skia/src/geometry.rs @@ -168,6 +168,31 @@ impl geometry::frame::Backend for Frame { }); } + fn stroke_rectangle<'a>( + &mut self, + top_left: Point, + size: Size, + stroke: impl Into>, + ) { + let Some(path) = convert_path(&Path::rectangle(top_left, size)) + .and_then(|path| path.transform(self.transform)) + else { + return; + }; + + let stroke = stroke.into(); + let skia_stroke = into_stroke(&stroke); + + let mut paint = into_paint(stroke.style); + paint.shader.transform(self.transform); + + self.primitives.push(Primitive::Stroke { + path, + paint, + stroke: skia_stroke, + }); + } + fn fill_text(&mut self, text: impl Into) { let text = text.into(); -- cgit