diff --git a/Cargo.lock b/Cargo.lock index 9819a923..d89d5ebd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1692,12 +1692,6 @@ dependencies = [ "cty", ] -[[package]] -name = "rctree" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b42e27ef78c35d3998403c1d26f3efd9e135d3e5121b0a4845cc5cc27547f4f" - [[package]] name = "rdrand" version = "0.4.0" @@ -2141,9 +2135,9 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "usvg" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b0a51b72ab80ca511d126b77feeeb4fb1e972764653e61feac30adc161a756" +checksum = "377f62b4a3c173de8654c1aa80ab1dac1154e6f13a779a9943e53780120d1625" dependencies = [ "base64", "log", @@ -2156,9 +2150,9 @@ dependencies = [ [[package]] name = "usvg-parser" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd4e3c291f45d152929a31f0f6c819245e2921bfd01e7bd91201a9af39a2bdc" +checksum = "351a05e6f2023d6b4e946f734240a3927aefdcf930d7d42587a2c8a8869814b0" dependencies = [ "data-url", "flate2", @@ -2174,9 +2168,9 @@ dependencies = [ [[package]] name = "usvg-text-layout" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d383a3965de199d7f96d4e11a44dd859f46e86de7f3dca9a39bf82605da0a37c" +checksum = "8c41888b9d5cf431fe852eaf9d047bbde83251b98f1749c2f08b1071e6db46e2" dependencies = [ "fontdb", "kurbo", @@ -2190,11 +2184,10 @@ dependencies = [ [[package]] name = "usvg-tree" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee3d202ebdb97a6215604b8f5b4d6ef9024efd623cf2e373a6416ba976ec7d3" +checksum = "18863e0404ed153d6e56362c5b1146db9f4f262a3244e3cf2dbe7d8a85909f05" dependencies = [ - "rctree", "strict-num", "svgtypes", "tiny-skia-path 0.11.4", diff --git a/examples/wgpu_svg/Cargo.toml b/examples/wgpu_svg/Cargo.toml index b1770d4b..cc901e4c 100644 --- a/examples/wgpu_svg/Cargo.toml +++ b/examples/wgpu_svg/Cargo.toml @@ -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" diff --git a/examples/wgpu_svg/src/main.rs b/examples/wgpu_svg/src/main.rs index ff1bac1b..7ef6c45e 100644 --- a/examples/wgpu_svg/src/main.rs +++ b/examples/wgpu_svg/src/main.rs @@ -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; @@ -498,6 +438,72 @@ fn main() { }); } +fn collect_geom(group: &Group, prev_transform: &mut Transform, transforms: &mut Vec, primitives: &mut Vec, fill_tess: &mut FillTessellator, mesh: &mut VertexBuffers, 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 {