From c72a556b8956aac216a99375928976fcf6be36e2 Mon Sep 17 00:00:00 2001 From: webdevtodayjason <115739170+webdevtodayjason@users.noreply.github.com> Date: Mon, 12 Oct 2026 03:20:15 +0000 Subject: [PATCH 1/2] Contributors: credit webdevtodayjason as Jason Brashear --- contributors/people.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contributors/people.toml b/contributors/people.toml index 03f8c667..4950f9aa 100644 --- a/contributors/people.toml +++ b/contributors/people.toml @@ -54,3 +54,6 @@ sync_github_name = false real_name = "Vikram Bhaskaran" display_name = "Vikram Bhaskaran" sync_github_name = false + +[people.webdevtodayjason] +display_name = "Jason Brashear" From d9f80ea76f6a73a023ab4555b5d40a806dbd48a2 Mon Sep 17 00:00:00 2001 From: webdevtodayjason <115739170+webdevtodayjason@users.noreply.github.com> Date: Mon, 12 Oct 2026 03:20:15 +0000 Subject: [PATCH 2/2] SVG: percentages inside a nested resolve against its own viewport --- crates/svg/src/lib.rs | 8 ++++---- crates/svg/src/tests.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/crates/svg/src/lib.rs b/crates/svg/src/lib.rs index 6bef8d63..75985fbd 100644 --- a/crates/svg/src/lib.rs +++ b/crates/svg/src/lib.rs @@ -794,10 +794,10 @@ impl<'a, 'i> Parser<'a, 'i> { let vb = viewbox_transform(n, w, h); let mut children = vec![]; let saved = (self.vw, self.vh); - if let Some((_, vw, vh)) = viewbox(n) { - self.vw = vw; - self.vh = vh; - } + // Percentages use this viewport's user space, even without a viewBox. + let (vw, vh) = viewbox(n).map_or((w, h), |(_, vw, vh)| (vw, vh)); + self.vw = vw; + self.vh = vh; for c in n.children() { self.node(c, &st, &mut children, depth + 1); } diff --git a/crates/svg/src/tests.rs b/crates/svg/src/tests.rs index a7a9bef3..3553205d 100644 --- a/crates/svg/src/tests.rs +++ b/crates/svg/src/tests.rs @@ -86,6 +86,39 @@ fn paths_gradients_css_use() { assert!(c[0] > 0.9 && c[3] > 0.9, "{c:?}"); } +#[test] +fn nested_svg_percentages_use_the_nearest_viewport() { + let d = parse( + br#" + + + + + + + + + + + "#, + ) + .unwrap(); + let shapes = d.flatten(); + assert_eq!(shapes.len(), 4); + for ((_, _, shape), (name, width, height)) in + shapes.iter().zip([("inner", 20.0, 10.0), ("deep", 10.0, 5.0), ("outer", 50.0, 10.0), ("viewbox", 100.0, 50.0)]) + { + assert_eq!(shape.name, name); + assert!(matches!(shape.geom, Geom::Rect { w, h, .. } if w == width && h == height), "{name}: {:?}", shape.geom); + } + let img = rasterize(&d, 100, 80, 1.0); + assert_eq!(px(&img, 15, 15), [1.0, 0.0, 0.0, 1.0]); + assert_eq!(px(&img, 35, 12), [0.0, 0.0, 1.0, 1.0]); + assert_eq!(px(&img, 35, 17)[3], 0.0); + assert_eq!(px(&img, 45, 65)[3], 1.0); + assert_eq!(px(&img, 55, 65)[3], 0.0); +} + #[test] fn malformed_input() { assert!(parse(b"").is_err());