mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-09 20:31:29 +11:00
Merge pull request #292 from msiglreith/svg-transform
vello_svg: Use affine transformation
This commit is contained in:
commit
dccd59a217
|
@ -64,7 +64,10 @@ 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) => {
|
||||
|
@ -72,7 +75,7 @@ pub fn render_tree_with<F: FnMut(&mut SceneBuilder, &usvg::Node) -> Result<(), E
|
|||
// 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) {
|
||||
|
@ -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)?;
|
||||
}
|
||||
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue