Skip to content

Commit

Permalink
Correctly capture and use stroke properties when rendering SVG paths (l…
Browse files Browse the repository at this point in the history
…inebender#1647)

* Use correct LineJoin and LineCap behavior in svg widget

* Correctly set miter limit and dash array properties when rendering SVG paths with stroke

* Update changelog
  • Loading branch information
SecondFlight authored and richard-uk1 committed Apr 6, 2021
1 parent da452bf commit b2e7e3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can find its changes [documented below](#070---2021-01-01).

- Fixed docs of derived Lens ([#1523] by [@Maan2003])
- Use correct fill rule when rendering SVG paths ([#1606] by [@SecondFlight])
- Correctly capture and use stroke properties when rendering SVG paths ([#1647] by [@SecondFlight])

### Visual

Expand Down Expand Up @@ -635,6 +636,7 @@ Last release without a changelog :(
[#1634]: https://github.com/linebender/druid/pull/1634
[#1635]: https://github.com/linebender/druid/pull/1635
[#1641]: https://github.com/linebender/druid/pull/1641
[#1647]: https://github.com/linebender/druid/pull/1647

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
19 changes: 17 additions & 2 deletions druid/src/widget/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tracing::{instrument, trace};

use crate::{
kurbo::BezPath,
piet::{self, FixedLinearGradient, GradientStop},
piet::{self, FixedLinearGradient, GradientStop, LineCap, LineJoin, StrokeStyle},
widget::common::FillStrat,
widget::prelude::*,
Affine, Color, Data, Point, Rect,
Expand Down Expand Up @@ -309,7 +309,22 @@ impl SvgRenderer {
match &p.stroke {
Some(stroke) => {
let brush = self.brush_from_usvg(&stroke.paint, stroke.opacity, ctx);
ctx.stroke(path, &*brush, stroke.width.value());
let mut stroke_style = StrokeStyle::new()
.line_join(match stroke.linejoin {
usvg::LineJoin::Miter => LineJoin::Miter,
usvg::LineJoin::Round => LineJoin::Round,
usvg::LineJoin::Bevel => LineJoin::Bevel,
})
.line_cap(match stroke.linecap {
usvg::LineCap::Butt => LineCap::Butt,
usvg::LineCap::Round => LineCap::Round,
usvg::LineCap::Square => LineCap::Square,
})
.miter_limit(stroke.miterlimit.value());
if let Some(dash_array) = &stroke.dasharray {
stroke_style.set_dash(dash_array.clone(), stroke.dashoffset as f64);
}
ctx.stroke_styled(path, &*brush, stroke.width.value(), &stroke_style);
}
None => {}
}
Expand Down

0 comments on commit b2e7e3b

Please sign in to comment.