mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
svg: consume shared compatibility transform-list parser
This commit is contained in:
1 parent
41da144555
commit
9953ca314d
3 files changed
+6
-33
No files matched your search
Generated
+4
-4
@@ -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",
|
||||
|
||||
+1
-1
@@ -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"] }
|
||||
|
||||
+1
-28
@@ -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
|
||||
|
||||
Reference in new issue
Block a user