Skip to content

Commit 35f4bb8

Browse files
authored
Merge pull request #30 from LaurenzV/stroke-width-fix
Fix bug where scaling wasn't properly applied to stroke widths
2 parents 29682b1 + 84e29b3 commit 35f4bb8

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/render.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ fn render_path_partial(
173173

174174
if stroke {
175175
if let Some(stroke) = &path.stroke {
176-
content.set_line_width(ctx.c.px_to_pt(stroke.width.get()));
176+
content.set_line_width(
177+
ctx.c.px_to_pt(stroke.width.get() * ctx.c.compute_scale()),
178+
);
177179

178180
match stroke.linecap {
179181
LineCap::Butt => content.set_line_cap(LineCapStyle::ButtCap),

src/scale.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ impl CoordToPdf {
184184
self.transform.apply(point.0, point.1)
185185
}
186186

187+
/// Compute the scale (e.g. to adapt the stroke width).
188+
pub fn compute_scale(&self) -> f64 {
189+
let mut complete_transform = Transform::new_scale(self.factor_x, self.factor_y);
190+
complete_transform.append(&self.transform);
191+
let (x_scale, y_scale) = complete_transform.get_scale();
192+
193+
if x_scale.is_finite() && y_scale.is_finite() {
194+
let scale = x_scale.max(y_scale);
195+
if scale > 0.0 {
196+
return scale;
197+
}
198+
}
199+
200+
1.0
201+
}
202+
187203
/// Set a pre-transformation, overriding the old one.
188204
pub fn concat_transform(&mut self, add_transform: Transform) -> Transform {
189205
let old = self.transform.clone();
Lines changed: 6 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)