Skip to content

Commit

Permalink
Use Affine transforms for svg widget
Browse files Browse the repository at this point in the history
  • Loading branch information
fishrockz authored and cmyr committed Jan 13, 2020
1 parent 7eaa871 commit c87fecc
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions druid/src/widget/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,17 @@ impl SvgData {
/// Convert SvgData into Piet draw instructions
pub fn to_piet(&self, scale: f64, offset: Point, paint_ctx: &mut PaintCtx) {
let root = self.tree.root();

let offset_matrix = Affine::new([scale, 0., 0., scale, offset.x, offset.y]);
for n in root.children() {
match *n.borrow() {
usvg::NodeKind::Path(ref p) => {
let mut path = BezPath::new();
for segment in p.data.iter() {
match *segment {
usvg::PathSegment::MoveTo { x, y } => {
let x = (x * scale) + offset.x;
let y = (y * scale) + offset.y;
path.move_to((x, y));
}
usvg::PathSegment::LineTo { x, y } => {
let x = (x * scale) + offset.x;
let y = (y * scale) + offset.y;
path.line_to((x, y));
}
usvg::PathSegment::CurveTo {
Expand All @@ -157,20 +153,24 @@ impl SvgData {
x,
y,
} => {
let x1 = (x1 * scale) + offset.x;
let y1 = (y1 * scale) + offset.y;
let x2 = (x2 * scale) + offset.x;
let y2 = (y2 * scale) + offset.y;
let x = (x * scale) + offset.x;
let y = (y * scale) + offset.y;

path.curve_to((x1, y1), (x2, y2), (x, y));
}
usvg::PathSegment::ClosePath => {
path.close_path();
}
}
}

path.apply_affine(Affine::new([
p.transform.a,
p.transform.b,
p.transform.c,
p.transform.d,
p.transform.e,
p.transform.f,
]));
path.apply_affine(offset_matrix);

match &p.fill {
Some(fill) => {
let brush = color_from_usvg(&fill.paint, fill.opacity);
Expand Down

0 comments on commit c87fecc

Please sign in to comment.