Skip to content

Commit

Permalink
rsvg 0.38 : .descendants() no longer exists, recurse manually. transf…
Browse files Browse the repository at this point in the history
…orm is off again!
  • Loading branch information
hrydgard authored and nical committed Apr 20, 2024
1 parent bb01b63 commit debf1c5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 77 deletions.
23 changes: 8 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/wgpu_svg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lyon = { path = "../../crates/lyon", features = ["extra"] }
clap = "2.32.0"
wgpu = "0.13.1"
winit = "0.27.5"
usvg = { version = "0.37", features = []}
usvg = { version = "0.38", features = []}
tiny-skia-path = "0.11"
futures = "0.3.5"
bytemuck = "1.2.0"
Expand Down
128 changes: 67 additions & 61 deletions examples/wgpu_svg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,67 +93,7 @@ fn main() {
ty: f32::NAN,
};
let view_box = rtree.view_box;
for node in rtree.root.descendants() {
if let usvg::NodeKind::Path(ref p) = *node.borrow() {
let t = node.abs_transform();
if t != prev_transform {
transforms.push(GpuTransform {
data0: [t.sx, t.kx, t.ky, t.sy],
data1: [t.tx, t.ty, 0.0, 0.0],
});
}
prev_transform = t;

let transform_idx = transforms.len() as u32 - 1;

if let Some(ref fill) = p.fill {
// fall back to always use color fill
// no gradients (yet?)
let color = match fill.paint {
usvg::Paint::Color(c) => c,
_ => FALLBACK_COLOR,
};

primitives.push(GpuPrimitive::new(
transform_idx,
color,
fill.opacity.get() as f32,
));

fill_tess
.tessellate(
convert_path(p),
&FillOptions::tolerance(0.01),
&mut BuffersBuilder::new(
&mut mesh,
VertexCtor {
prim_id: primitives.len() as u32 - 1,
},
),
)
.expect("Error during tessellation!");
}

if let Some(ref stroke) = p.stroke {
let (stroke_color, stroke_opts) = convert_stroke(stroke);
primitives.push(GpuPrimitive::new(
transform_idx,
stroke_color,
stroke.opacity.get() as f32,
));
let _ = stroke_tess.tessellate(
convert_path(p),
&stroke_opts.with_tolerance(0.01),
&mut BuffersBuilder::new(
&mut mesh,
VertexCtor {
prim_id: primitives.len() as u32 - 1,
},
),
);
}
}
}
collect_geom(&rtree.root, &mut prev_transform, &mut transforms, &mut primitives, &mut fill_tess, &mut mesh, &mut stroke_tess);

if app.is_present("TESS_ONLY") {
return;
Expand Down Expand Up @@ -498,6 +438,72 @@ fn main() {
});
}

fn collect_geom(group: &Group, prev_transform: &mut Transform, transforms: &mut Vec<GpuTransform>, primitives: &mut Vec<GpuPrimitive>, fill_tess: &mut FillTessellator, mesh: &mut VertexBuffers<GpuVertex, u32>, stroke_tess: &mut StrokeTessellator) {
for node in &group.children {
if let usvg::Node::Group(group) = node {
collect_geom(group, prev_transform, transforms, primitives, fill_tess, mesh, stroke_tess)
} else if let usvg::Node::Path(ref p) = node {
let t = node.abs_transform();
if t != *prev_transform {
transforms.push(GpuTransform {
data0: [t.sx, t.kx, t.ky, t.sy],
data1: [t.tx, t.ty, 0.0, 0.0],
});
}
*prev_transform = t;

let transform_idx = transforms.len() as u32 - 1;

if let Some(ref fill) = p.fill {
// fall back to always use color fill
// no gradients (yet?)
let color = match fill.paint {
usvg::Paint::Color(c) => c,
_ => FALLBACK_COLOR,
};

primitives.push(GpuPrimitive::new(
transform_idx,
color,
fill.opacity.get() as f32,
));

fill_tess
.tessellate(
convert_path(p),
&FillOptions::tolerance(0.01),
&mut BuffersBuilder::new(
mesh,
VertexCtor {
prim_id: primitives.len() as u32 - 1,
},
),
)
.expect("Error during tessellation!");
}

if let Some(ref stroke) = p.stroke {
let (stroke_color, stroke_opts) = convert_stroke(stroke);
primitives.push(GpuPrimitive::new(
transform_idx,
stroke_color,
stroke.opacity.get(),
));
let _ = stroke_tess.tessellate(
convert_path(p),
&stroke_opts.with_tolerance(0.01),
&mut BuffersBuilder::new(
mesh,
VertexCtor {
prim_id: primitives.len() as u32 - 1,
},
),
);
}
}
}
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct GpuVertex {
Expand Down

0 comments on commit debf1c5

Please sign in to comment.