Merge pull request #3801 from storytold/refactor/shared-svg-transform

svg: reuse shared permissive transform-list parsing
This commit is contained in:
Dylan M. Taylor
2026-11-17 03:16:41 -05:00
committed by GitHub
3 changed files with 6 additions and 33 deletions
Generated
+4 -4
View File
@@ -1485,9 +1485,9 @@ dependencies = [
[[package]]
name = "craft-svg"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=af9985523a079c9e25c638003dbd9aa09fa4d254#af9985523a079c9e25c638003dbd9aa09fa4d254"
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=af9985523a079c9e25c638003dbd9aa09fa4d254)",
"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=af9985523a079c9e25c638003dbd9aa09fa4d254#af9985523a079c9e25c638003dbd9aa09fa4d254"
source = "git+https://github.com/storytold/craft-libs?rev=82062077bba679ba5236e2d1a391f02d1533cbab#82062077bba679ba5236e2d1a391f02d1533cbab"
dependencies = [
"quick-xml 0.41.0",
"serde",
+1 -1
View File
@@ -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 = "af9985523a079c9e25c638003dbd9aa09fa4d254" }
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"] }
+1 -28
View File
@@ -1453,34 +1453,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