mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 12:47:13 -06:00
M4.19: SVG text import fidelity — text keeps its place, group, clip and mask; textPath, per-character positions, weights, spacing, paints and CSS selectors survive
Each <text> is swapped for a placeholder group before usvg runs, so the text keeps its z-order, parent group, clip, mask, opacity, link and <use> instances, and usvg resolves its gradient and pattern paints (in text space). <textPath> becomes type on a path (startOffset, side, anchor), vertical writing-mode type on a vertical path. Per-character x/y/dx/dy/rotate lists become line breaks (bounded), kerning (absolute x measured against the layout), baseline shift and rotation; baseline-shift, numeric and relative weights (style names), letter/word spacing, kerning and the character stroke's cap, join, miter and dashes are kept. The style cascade supports type, #id, multiple-class, attribute, descendant and child selectors with !important and specificity. <pattern> paints become pattern swatches. The import fuzz covers the new attributes and CSS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bc17c1e635
commit
5c58ebcb32
@@ -117,6 +117,14 @@ fn arb_svg_attr() -> impl Strategy<Value = String> {
|
||||
"mask-type",
|
||||
"data-vectorcraft-mask",
|
||||
"href",
|
||||
"baseline-shift",
|
||||
"word-spacing",
|
||||
"kerning",
|
||||
"writing-mode",
|
||||
"font-weight",
|
||||
"text-anchor",
|
||||
"side",
|
||||
"path",
|
||||
]);
|
||||
let value = prop_oneof![
|
||||
arb_num(),
|
||||
@@ -203,6 +211,19 @@ proptest! {
|
||||
survive(&svg, || vectorcraft_svg::import(&svg).ok())?;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_hostile_css_never_panics(
|
||||
sheet in r#"[a-z#.>*\[\]=:;{}@ !"'/,-]{0,160}"#,
|
||||
decls in r#"[a-z0-9.%: ;!-]{0,60}"#,
|
||||
body in prop::collection::vec(arb_svg_element(1), 0..3),
|
||||
) {
|
||||
let svg = format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\"><style>{sheet}</style><g class=\"a b\"><text id=\"t\" class=\"a\" x=\"1 2 3\" y=\"9\" rotate=\"5\" style=\"{decls}\">ab<tspan dy=\"3\">c</tspan></text></g>{}</svg>",
|
||||
body.concat()
|
||||
);
|
||||
survive(&svg, || vectorcraft_svg::import(&svg).ok())?;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_mutated_export_never_panics(
|
||||
cut in 0usize..20_000,
|
||||
|
||||
Reference in New Issue
Block a user