Skip to content

Commit

Permalink
Merge pull request linebender#292 from msiglreith/svg-transform
Browse files Browse the repository at this point in the history
vello_svg: Use affine transformation
  • Loading branch information
msiglreith authored Mar 10, 2023
2 parents 2f268d4 + 6c41948 commit dccd59a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions integrations/vello_svg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ pub fn render_tree_with<F: FnMut(&mut SceneBuilder, &usvg::Node) -> Result<(), E
mut on_err: F,
) -> Result<(), E> {
for elt in svg.root.descendants() {
let transform = elt.abs_transform();
let transform = {
let usvg::Transform { a, b, c, d, e, f } = elt.abs_transform();
Affine::new([a, b, c, d, e, f])
};
match &*elt.borrow() {
usvg::NodeKind::Group(_) => {}
usvg::NodeKind::Path(path) => {
let mut local_path = BezPath::new();
// The semantics of SVG paths don't line up with `BezPath`; we must manually track initial points
let mut just_closed = false;
let mut most_recent_initial = (0., 0.);
for elt in usvg::TransformedPath::new(&path.data, transform) {
for elt in path.data.segments() {
match elt {
usvg::PathSegment::MoveTo { x, y } => {
if std::mem::take(&mut just_closed) {
Expand Down Expand Up @@ -112,7 +115,7 @@ pub fn render_tree_with<F: FnMut(&mut SceneBuilder, &usvg::Node) -> Result<(), E
if let Some(fill) = &path.fill {
if let Some(brush) = paint_to_brush(&fill.paint, fill.opacity) {
// FIXME: Set the fill rule
sb.fill(Fill::NonZero, Affine::IDENTITY, &brush, None, &local_path);
sb.fill(Fill::NonZero, transform, &brush, None, &local_path);
} else {
on_err(sb, &elt)?;
}
Expand All @@ -122,7 +125,7 @@ pub fn render_tree_with<F: FnMut(&mut SceneBuilder, &usvg::Node) -> Result<(), E
// FIXME: handle stroke options such as linecap, linejoin, etc.
sb.stroke(
&Stroke::new(stroke.width.get() as f32),
Affine::IDENTITY,
transform,
&brush,
None,
&local_path,
Expand Down

0 comments on commit dccd59a

Please sign in to comment.