From 2c01a42b358f9f7d1335c6fa7c826214dce2aaa5 Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Tue, 13 Oct 2026 03:14:10 +0200 Subject: [PATCH] SVG import: CSS transforms in CSS syntax move objects; the font shorthand styles type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit usvg takes a `transform` CSS property as a presentation attribute that overrides the element's own, but reads its value as SVG: CSS units (`translate(100px, 0)`, `rotate(45deg)`) don't parse, and the object was left with no transform at all. Before usvg runs, transform declarations in `style` attributes and `transform: rotate(9deg)"#; + let xml = roxmltree::Document::parse(svg).unwrap(); + let found = rewrites(svg, &xml); + let r: Vec<(&str, &str)> = found.iter().map(|(r, v)| (&svg[r.clone()], v.as_str())).collect(); + assert_eq!(r, vec![(" rotate(45deg) ", " rotate(45)"), ("translate(3px,4px)", " translate(3 4)")]); + } +} diff --git a/crates/svg/tests/import_details.rs b/crates/svg/tests/import_details.rs index b6cbf72c..3890aa59 100644 --- a/crates/svg/tests/import_details.rs +++ b/crates/svg/tests/import_details.rs @@ -181,3 +181,24 @@ fn reflect_and_repeat_match_resvg() { assert_similar(&render_artboard(&d), &resvg_render(&svg(&body), 200, 120), 24.0, 0.01); } } + +/// #1557: `transform` as a CSS property, in CSS syntax, moves the object (and wins over the +/// attribute, as in CSS), from a `style` attribute or a ` + + + "#), + &ImportOptions::default(), + ) + .unwrap() + .0; + let b: Vec = art(&d).iter().map(|n| n.geometric_bounds().unwrap()).collect(); + let near = + |r: Rect, x0: f64, y0: f64, x1: f64, y1: f64| [(r.x0, x0), (r.y0, y0), (r.x1, x1), (r.y1, y1)].iter().all(|(a, b)| (a - b).abs() < 1e-6); + assert!(near(b[0], 100.0, 100.0, 150.0, 150.0), "{:?}", b[0]); + assert!(near(b[1], 100.0, 0.0, 150.0, 50.0), "{:?}", b[1]); + assert!(near(b[2], -20.0, 0.0, 0.0, 50.0), "{:?}", b[2]); +} diff --git a/crates/svg/tests/import_text.rs b/crates/svg/tests/import_text.rs index ce68fd65..56ec8636 100644 --- a/crates/svg/tests/import_text.rs +++ b/crates/svg/tests/import_text.rs @@ -583,3 +583,14 @@ fn text_path_to_an_empty_shape_still_falls_back_to_point_type() { assert!(matches!(only_text(&d).kind, TextKind::Point)); assert!(w.iter().any(|w| w.contains("textPath")), "{w:?}"); } + +/// #1557: the `font` shorthand sets the type's size, weight and style. +#[test] +fn the_font_shorthand_styles_type() { + let d = open(r#"Deco"#); + let t = only_text(&d); + let st = &t.runs[0].style; + assert!(close(st.size * t.xf.determinant().abs().sqrt(), 30.0, 1e-6), "{}", st.size); + let style = st.font_style.to_ascii_lowercase(); + assert!(style.contains("bold") && style.contains("italic"), "{style}"); +}