Files
vectorcraft/crates/ui-egui/src/tests_svgsave.rs
T
bflatasticandClaude Opus 5.5 370c6e2fc0 M4.39: SVG symbols as <symbol>/<use>, hidden layers on Save, Dublin Core metadata
Symbol instances export as one <symbol> def per symbol and a <use> per
instance. An instance the def can't stand for exactly (stained by its fill,
or a transform under which the canvas paints differently: scaling with
strokes, effects or live objects, turning with effects or brushes, any move
with pattern paints or unlinked masks) is written as its own art, now
stained like the canvas and with its patterns and unlinked masks left on
the page. Symbols nested in themselves stop at a fixed depth.

New SVG option hiddenLayers keeps hidden layers as display:none groups;
document.save (and Save As / Save a Copy) turns it on unless told
otherwise, exports leave hidden layers out. Import shows display:none
layer groups to usvg and marks them hidden, so they reopen hidden
(groups a <use> refers to stay templates). File Info metadata goes through
one Dublin Core list. The symbol stain helper moves to vectorcraft-brush
so the renderer and the SVG writer share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 09:03:52 +07:00

29 lines
1.5 KiB
Rust

//! SVG Options and hidden layers: Save As SVG keeps them (hidden), Export As leaves them out, and
//! a save with Preserve Editing Capabilities reopens as the document.
use serde_json::{Value, json};
use crate::tests_svg::app;
#[test]
fn save_as_svg_keeps_hidden_layers_and_export_as_leaves_them_out() {
let (mut app, written) = app("/tmp/layers.svg");
let notes = app.run("layer.new", json!({"name": "Notes"})).unwrap()["id"].clone();
app.run("shape.ellipse", json!({"x": 50, "y": 40, "width": 20, "height": 20})).unwrap();
app.run("layer.setProps", json!({"id": notes, "visible": false})).unwrap();
app.run("file.export.svg", Value::Null).unwrap();
crate::dialogs::confirm(&mut app).unwrap();
app.run("file.saveAs", Value::Null).unwrap();
let d = app.ui.dialog.as_mut().expect("SVG Options");
d.fields.insert("preserveEditing".into(), json!(true));
crate::dialogs::confirm(&mut app).unwrap();
let text = |i: usize| String::from_utf8(written.borrow()[i].1.clone()).unwrap();
assert!(!text(0).contains("Notes"), "exported: {}", text(0));
assert!(text(1).contains("id=\"Notes\"") && text(1).contains("display:none"), "saved: {}", text(1));
// Reopened, the saved SVG is the document again.
let before = app.session.doc().unwrap().doc.layers.clone();
let saved = text(1);
app.session.execute("document.open", &json!({"name": "layers.svg", "dataBase64": vectorcraft_format::base64_encode(saved.as_bytes())})).unwrap();
assert_eq!(app.session.doc().unwrap().doc.layers, before);
}