From 9953ca314d264b62c11f87ccaea4de578482929d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 23:22:52 -0500 Subject: [PATCH 1/2] svg: consume shared compatibility transform-list parser --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- crates/svg/src/lib.rs | 29 +---------------------------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5b87bf7e..22e7a5427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1485,9 +1485,9 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d#e52cd9a889adbeeda447c75a546133960cf3382d" +source = "git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021#a6d5f86ee486eae446cb834559085f8ae1463021" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021)", "flate2", "kurbo", "quick-xml 0.41.0", @@ -1680,7 +1680,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" +source = "git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021#a6d5f86ee486eae446cb834559085f8ae1463021" dependencies = [ "quick-xml 0.41.0", "serde", @@ -1690,7 +1690,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e52cd9a889adbeeda447c75a546133960cf3382d#e52cd9a889adbeeda447c75a546133960cf3382d" +source = "git+https://github.com/storytold/craft-libs?rev=b3643af6477326e840f86be78c89357f5308ba1d#b3643af6477326e840f86be78c89357f5308ba1d" dependencies = [ "quick-xml 0.41.0", "serde", diff --git a/Cargo.toml b/Cargo.toml index 54158cd1c..ae1021969 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ce2ec507c2e6a6a078a5f450f641487f8931816d" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "e52cd9a889adbeeda447c75a546133960cf3382d" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "a6d5f86ee486eae446cb834559085f8ae1463021" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } diff --git a/crates/svg/src/lib.rs b/crates/svg/src/lib.rs index fd4baa543..8f18371bc 100644 --- a/crates/svg/src/lib.rs +++ b/crates/svg/src/lib.rs @@ -1668,34 +1668,7 @@ fn viewbox_transform(n: roxmltree::Node, w: f64, h: f64) -> Affine { } /// Parse a `transform` list. -pub fn parse_transform(s: &str) -> Affine { - let mut m = Affine::IDENTITY; - let mut rest = s; - while let Some(open) = rest.find('(') { - let name = rest[..open].trim().trim_start_matches(',').trim(); - let Some(close) = rest[open..].find(')') else { break }; - let (a, too_many) = pathdata::numbers_bounded(&rest[open + 1..open + close], 6); - rest = &rest[open + close + 1..]; - let t = if too_many { - Affine::IDENTITY - } else { - match (name, a.as_slice()) { - ("matrix", [a0, a1, a2, a3, a4, a5]) => Affine::new([*a0, *a1, *a2, *a3, *a4, *a5]), - ("translate", [x]) => Affine::translate((*x, 0.0)), - ("translate", [x, y]) => Affine::translate((*x, *y)), - ("scale", [scale]) => Affine::scale(*scale), - ("scale", [x, y]) => Affine::scale_non_uniform(*x, *y), - ("rotate", [angle]) => Affine::rotate(angle.to_radians()), - ("rotate", [angle, x, y]) => Affine::translate((*x, *y)) * Affine::rotate(angle.to_radians()) * Affine::translate((-*x, -*y)), - ("skewX", [angle]) => Affine::new([1.0, 0.0, angle.to_radians().tan(), 1.0, 0.0, 0.0]), - ("skewY", [angle]) => Affine::new([1.0, angle.to_radians().tan(), 0.0, 1.0, 0.0, 0.0]), - _ => Affine::IDENTITY, - } - }; - m *= t; - } - m -} +pub use craft_svg::transform_compat::parse_transform; /// The deepest element nesting accepted. The XML parser recurses per level and overflowed a /// 2 MiB thread's stack (aborting the app) at a few thousand levels; real documents stay far From ce2df07d5298e63890d2f225cabfcba311535939 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 02:16:35 -0500 Subject: [PATCH 2/2] svg: integrate merged transform parser with current main --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22e7a5427..e1e414649 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1485,9 +1485,9 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021#a6d5f86ee486eae446cb834559085f8ae1463021" +source = "git+https://github.com/storytold/craft-libs?rev=77686f24fe8665c21369f1b593f4d65a973e2a45#77686f24fe8665c21369f1b593f4d65a973e2a45" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=77686f24fe8665c21369f1b593f4d65a973e2a45)", "flate2", "kurbo", "quick-xml 0.41.0", @@ -1670,7 +1670,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" +source = "git+https://github.com/storytold/craft-libs?rev=77686f24fe8665c21369f1b593f4d65a973e2a45#77686f24fe8665c21369f1b593f4d65a973e2a45" dependencies = [ "quick-xml 0.41.0", "serde", @@ -1680,7 +1680,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a6d5f86ee486eae446cb834559085f8ae1463021#a6d5f86ee486eae446cb834559085f8ae1463021" +source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab" dependencies = [ "quick-xml 0.41.0", "serde", diff --git a/Cargo.toml b/Cargo.toml index ae1021969..4082dfd41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ce2ec507c2e6a6a078a5f450f641487f8931816d" } -craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "a6d5f86ee486eae446cb834559085f8ae1463021" } +craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "77686f24fe8665c21369f1b593f4d65a973e2a45" } craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" } craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", default-features = false, features = ["stl", "obj", "gltf", "fbx"] }