From 3d0e911c3e64a14ad4c6262e0faa46265ab047dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=B6ln?= Date: Sat, 10 Aug 2019 18:27:54 +0300 Subject: [PATCH] fix #219 (minimum stroke thickness) --- canvas/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index e87d4ecd..ad17c08b 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -168,7 +168,13 @@ impl CanvasRenderingContext2D { let paint_id = self.scene.push_paint(&paint); let mut stroke_style = self.current_state.resolve_stroke_style(); - stroke_style.line_width = f32::max(stroke_style.line_width, HAIRLINE_STROKE_WIDTH); + + // the smaller scale is relevant here, as we multiply by it and want to ensure it is always bigger than HAIRLINE_STROKE_WIDTH + let transform_scale = f32::min(self.current_state.transform.m11(), self.current_state.transform.m22()); + // avoid the division in the normal case of sufficient thickness + if stroke_style.line_width * transform_scale < HAIRLINE_STROKE_WIDTH { + stroke_style.line_width = HAIRLINE_STROKE_WIDTH / transform_scale; + } let mut outline = path.into_outline(); if !self.current_state.line_dash.is_empty() {