mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 08:15:29 +00:00
svg: pin transform composition and malformed-list parity
This commit is contained in:
1 parent
399ecc74de
commit
a6d5f86ee4
2 files changed
+41
No files matched your search
@@ -13,3 +13,6 @@ and its regression test preserve NetterSilver's
|
||||
`10e173c0e49696ad335e3da8a069889c089b09a6`; both contributors retain primary Git authorship
|
||||
for their respective port commits. Source and destination use MIT OR Apache-2.0.
|
||||
The shared adapter adds an aggregate 64 MiB stylesheet-text limit and idempotent indexing.
|
||||
|
||||
### Transform compatibility
|
||||
`transform_compat::parse_transform` preserves EffectCraft transform-list recovery and exact composition. It retains six numeric arguments per operation; scanning is not time/byte capped and matrix overflow behavior is unchanged. The strict geometry reader is unchanged. Source: Brandon Thomas, EffectCraft94e1c86d89a866771f80ad1610afda9aa12e85d8; bounded safe argument matching by Altynzhan Karybai,4035d181329e847d7a57bf3d059502ea2c91b560.
|
||||
@@ -35,3 +35,41 @@ pub fn parse_transform(s: &str) -> Affine {
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn operations_keep_composition_order() {
|
||||
let cases = [
|
||||
("matrix(1 2 3 4 5 6)", Affine::new([1., 2., 3., 4., 5., 6.])),
|
||||
("translate(2)", Affine::translate((2., 0.))),
|
||||
("translate(2,3)", Affine::translate((2., 3.))),
|
||||
("scale(2)", Affine::scale(2.)),
|
||||
("scale(2 3)", Affine::scale_non_uniform(2., 3.)),
|
||||
("rotate(30)", Affine::rotate(30f64.to_radians())),
|
||||
("rotate(30 2 3)", Affine::translate((2., 3.)) * Affine::rotate(30f64.to_radians()) * Affine::translate((-2., -3.))),
|
||||
("skewX(30)", Affine::new([1., 0., 30f64.to_radians().tan(), 1., 0., 0.])),
|
||||
("skewY(30)", Affine::new([1., 30f64.to_radians().tan(), 0., 1., 0., 0.])),
|
||||
];
|
||||
for (text, expected) in cases {
|
||||
assert_eq!(parse_transform(text).as_coeffs(), expected.as_coeffs());
|
||||
assert_eq!(parse_transform(&format!("translate(7,9), {text}")).as_coeffs(), (Affine::translate((7., 9.)) * expected).as_coeffs());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_and_oversized_operations_keep_accepted_prefix() {
|
||||
for text in ["", "unknown(1)", "translate()", "scale(1 2 3)", "matrix(1 2 3 4 5 6 7)", "rotate(2 3)"] {
|
||||
assert_eq!(parse_transform(text), Affine::IDENTITY);
|
||||
}
|
||||
for suffix in ["translate(", "unknown(1)", "matrix(1 2 3 4 5 6 7)"] {
|
||||
assert_eq!(parse_transform(&format!("translate(3,4){suffix}")), Affine::translate((3., 4.)));
|
||||
}
|
||||
assert_eq!(parse_transform("unknown(1) scale(2)"), Affine::scale(2.));
|
||||
assert_eq!(parse_transform("translate(3 4oops)"), Affine::translate((3., 4.)));
|
||||
let huge = format!("scale({}) translate(2)", "1 ".repeat(10_000));
|
||||
assert_eq!(parse_transform(&huge), Affine::translate((2., 0.)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user