diff --git a/crates/engine/src/cmd/fileio/access.rs b/crates/engine/src/cmd/fileio/access.rs index cb5b4e85cc..856656f564 100644 --- a/crates/engine/src/cmd/fileio/access.rs +++ b/crates/engine/src/cmd/fileio/access.rs @@ -149,7 +149,9 @@ pub(crate) const IMAGE_OUTSIDE: &str = "a linked image file is outside the read /// file with SVG Options › Images set to Link, and with Embed when the document holds no pixels for /// the image, for the images of the art each file draws (with chosen artboards, the art over each /// one; hidden layers and objects only with `hiddenLayers`, template layers and the opacity-mask -/// and symbol editing layers never) and of the symbols, patterns and brushes that art uses; with +/// and symbol editing layers never, opacity masks not with SVG Tiny 1.2, and objects with effects +/// SVG has no filters for as the images the file draws of them), of the art the file draws for each +/// placed document, and of the symbols, patterns and brushes that art uses; with /// Preserve Editing Capabilities, the native document the file carries names every linked file, the relative paths kept of them /// and each data set's image. The error names no file or folder. pub fn check_linked_images(cmd: &str, format: &str, st: &crate::DocState, d: &vectorcraft_doc::Document, p: &Value) -> Result<()> { @@ -162,21 +164,27 @@ pub(crate) fn check_images_in(cmd: &str, format: &str, d: &vectorcraft_doc::Docu if !matches!(format, "svg" | "svgz") || crate::file_access::current().is_none() { return Ok(()); } - // Options that don't read as the encoder's choices count as Link, Preserve Editing and hidden - // layers kept: the encoder refuses them anyway. - let (link, preserve, hidden) = match super::svg::options_map(p) { + // Options that don't read as the encoder's choices count as Link, Preserve Editing, hidden + // layers kept and SVG 1.1: the encoder refuses them anyway. + let (link, preserve, hidden, tiny) = match super::svg::options_map(p) { Ok(m) => { let on = |k: &str| m.get(k).is_some_and(|v| v.as_bool() != Some(false)); - (m.get("images").is_some_and(|v| v.as_str() != Some("embed")), on("preserveEditing"), on("hiddenLayers")) + let tiny = m.get("profile").and_then(Value::as_str) == Some("tiny12"); + (m.get("images").is_some_and(|v| v.as_str() != Some("embed")), on("preserveEditing"), on("hiddenLayers"), tiny) } - Err(_) => (true, true, true), + Err(_) => (true, true, true, false), }; // The opacity-mask and symbol editing layers are never written. let d = &*d.without_edit_modes(); - let names = |d: &vectorcraft_doc::Document| crate::cmd::links::svg_names_hidden_image(d, base, link, hidden); - if preserve && crate::cmd::links::names_hidden_file(d, base) - || names(d) && super::svg::drawn(d, p).is_none_or(|files| files.iter().any(|f| names(f))) - { + let names = |d: &vectorcraft_doc::Document| crate::cmd::links::svg_names_hidden_image(d, base, link, hidden, tiny); + // The SVG draws the objects with effects it has no filters for as images of them, as the + // encoder and the clipboard prepare them. + let drawing_names = || { + let flat = crate::cmd::rasterfx::flatten_pixel_effects_for(d, !tiny); + let d = flat.as_ref().unwrap_or(d); + names(d) && super::svg::drawn(d, p).is_none_or(|files| files.iter().any(|f| names(f))) + }; + if preserve && crate::cmd::links::names_hidden_file(d, base) || names(d) && drawing_names() { return Err(bad(cmd, IMAGE_OUTSIDE)); } Ok(()) diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs index b3fc65e8fc..522bd47817 100644 --- a/crates/engine/src/cmd/links.rs +++ b/crates/engine/src/cmd/links.rs @@ -1314,27 +1314,54 @@ pub(crate) fn file_hidden(path: &str, doc_path: Option<&str>) -> bool { /// gray or missing names none: the SVG writes gray pixels colorized and leaves out an image /// without pixels. The images of the art the SVG writes (opacity masks included) and of the /// symbols, patterns and brushes that art uses, as Copy follows them, are checked: the SVG writes -/// no other resource. Hidden layers and objects are written only with -/// SVG Options › hidden layers kept (`hidden`), and template layers never ([`svg_written`]). -/// Always `false` without read roots in force. -pub(crate) fn svg_names_hidden_image(d: &Document, base: LinkBase, link: bool, hidden: bool) -> bool { - if crate::file_access::current().is_none() || !names_hidden_image(d, base, link) { +/// no other resource. A placed document's images are those of the art the SVG draws for it. Hidden +/// layers and objects are written only with SVG Options › hidden layers kept (`hidden`), in the +/// layers and in the symbols, patterns and graph designs alike, and template layers never. SVG Tiny +/// 1.2 (`tiny`) writes no opacity masks ([`svg_written`]). Always `false` without read roots in +/// force. +pub(crate) fn svg_names_hidden_image(d: &Document, base: LinkBase, link: bool, hidden: bool, tiny: bool) -> bool { + if crate::file_access::current().is_none() { return false; } - let art = d.layers.iter().filter_map(|l| svg_written(l, hidden)).collect(); - names_hidden_image(&super::clipboard::Clipboard::gather(d, art).to_document(), base, link) + if !d.has_placed() && !names_hidden_image(d, base, link) { + return false; + } + // The writer draws placed documents' art with the pixels their files hold. + let placed = d.with_placed_art(); + let d = &*placed; + let art = d.layers.iter().filter_map(|l| svg_written(d, l, hidden, tiny)).collect(); + let mut out = super::clipboard::Clipboard::gather(d, art).to_document(); + let written = |n: &std::sync::Arc| { + let empty = || Node::new(n.id, NodeKind::Group { children: vec![], clip: false }); + std::sync::Arc::new(svg_written(d, n, hidden, tiny).unwrap_or_else(empty)) + }; + for s in &mut out.symbols { + s.art = written(&s.art); + } + for g in &mut out.graph_designs { + g.art = written(&g.art); + } + for p in &mut out.patterns { + p.art = p.art.iter().filter_map(|n| svg_written(d, n, hidden, tiny)).map(std::sync::Arc::new).collect(); + } + names_hidden_image(&out, base, link) } -/// `n` as the SVG writer writes it, or `None` when it writes none of it: a hidden layer or object -/// is left out unless `hidden`, a template layer's art always, and a disabled opacity mask's art. -/// Only layers and groups lose members; other objects keep theirs as they are. -fn svg_written(n: &Node, hidden: bool) -> Option { +/// `n` (an object of `d`) as the SVG writer writes it, or `None` when it writes none of it: a +/// hidden layer or object is left out unless `hidden`, a template layer's art always, a disabled +/// opacity mask's art, and with SVG Tiny 1.2 (`tiny`) every opacity mask's art. A placed document +/// is the art the writer draws for it. Only layers and groups lose members; other objects keep +/// theirs as they are. +fn svg_written(d: &Document, n: &Node, hidden: bool, tiny: bool) -> Option { if !(n.visible || hidden) { return None; } + if matches!(n.kind, NodeKind::PlacedDocument(_)) { + return svg_written(d, &vectorcraft_render::effects::expand_live_deep(Some(d), n), hidden, tiny); + } let mut n = n.clone(); - let mask = n.extras().mask.as_deref().filter(|m| !m.disabled).and_then(|m| { - let art = svg_written(&m.art, hidden)?; + let mask = n.extras().mask.as_deref().filter(|m| !m.disabled && !tiny).and_then(|m| { + let art = svg_written(d, &m.art, hidden, tiny)?; Some(Box::new(vectorcraft_doc::OpacityMask { art: std::sync::Arc::new(art), ..m.clone() })) }); if n.extras().mask.is_some() { @@ -1343,7 +1370,7 @@ fn svg_written(n: &Node, hidden: bool) -> Option { match &mut n.kind { NodeKind::Layer { template: true, children, .. } => children.clear(), NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } => { - *children = children.iter().filter_map(|c| svg_written(c, hidden)).map(std::sync::Arc::new).collect(); + *children = children.iter().filter_map(|c| svg_written(d, c, hidden, tiny)).map(std::sync::Arc::new).collect(); } _ => {} } diff --git a/crates/engine/src/tests/links.rs b/crates/engine/src/tests/links.rs index 57bb9e278e..931c011d40 100644 --- a/crates/engine/src/tests/links.rs +++ b/crates/engine/src/tests/links.rs @@ -2138,3 +2138,141 @@ fn confined_preserve_editing_svg_refuses_a_brush_library_entry_it_cannot_read() confine(roots.as_ref(), || s.execute("document.serialize", &json!({"format": "svg"}))).unwrap(); } } + +/// A confined caller's SVG of a placed document whose art links an image: the file draws that art +/// and names the image's file, so a file outside the read roots refuses it and one inside them is +/// written. Any output that names no file is written. +#[test] +fn confined_svg_output_checks_the_images_of_placed_documents() { + use crate::file_access::{AutomationRoots, confine}; + + let away = Folder::new("svg-placed-away"); + let home = Folder::new("svg-placed-home"); + let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap(); + for (photo, outside) in [(away.file("photo.png"), true), (home.file("photo.png"), false)] { + write(&photo, &png(60, 30, RED)); + let src = home.file("src.vectorcraft"); + let mut inner = session(); + place(&mut inner, &photo); + save(&mut inner, &src); + let mut s = session(); + place(&mut s, &src); + let link = json!({"format": "svg", "images": "link"}); + assert!(svg_text(&s.execute("document.serialize", &link).unwrap()).contains(&photo), "the file names the placed art's image"); + for format in ["svg", "svgz"] { + for images in ["link", "embed"] { + let p = json!({"format": format, "images": images}); + // Embed writes the pixels the placed file holds. + let names = svg_text(&s.execute("document.serialize", &p).unwrap()).contains(&photo); + assert_eq!(names, images == "link", "{p}"); + match confine(roots.as_ref(), || s.execute("document.serialize", &p)) { + Ok(r) => assert!(!outside || !svg_text(&r).contains(&photo), "{p}: {}", svg_text(&r)), + Err(e) => { + assert!(outside && names, "{p}: {e}"); + assert!(e.to_string().contains("a linked image file is outside the read roots"), "{p}: {e}"); + } + } + } + } + if outside { + let e = confine(roots.as_ref(), || s.execute("document.serialize", &link)).unwrap_err().to_string(); + assert!(e.contains("a linked image file is outside the read roots") && !e.contains("photo.png"), "{e}"); + } + } +} + +/// A confined caller's SVG of a symbol holding a visible rectangle and a hidden linked image outside +/// the read roots: the file leaves the hidden image out of the symbol and is written, unless hidden +/// layers are kept, which writes the image and refuses the file. +#[test] +fn confined_svg_output_leaves_hidden_symbol_art_unchecked() { + use crate::file_access::{AutomationRoots, confine}; + + let away = Folder::new("svg-symbol-hidden-away"); + let home = Folder::new("svg-symbol-hidden-home"); + let photo = away.file("photo.png"); + write(&photo, &png(60, 30, RED)); + let mut s = session(); + let r = s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 20})).unwrap()["id"].clone(); + let a = place(&mut s, &photo); + s.execute("object.hide", &json!({"ids": [a.0]})).unwrap(); + s.execute("select.set", &json!({"ids": [r, a.0]})).unwrap(); + s.execute("symbol.new", &json!({"name": "Mixed"})).unwrap(); + let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap(); + for format in ["svg", "svgz"] { + let p = json!({"format": format, "images": "link"}); + assert!(!svg_text(&s.execute("document.serialize", &p).unwrap()).contains(&photo), "{p}"); + let text = svg_text(&confine(roots.as_ref(), || s.execute("document.serialize", &p)).unwrap()); + assert!(!text.contains(&photo), "{p}: {text}"); + let kept = json!({"format": format, "images": "link", "hiddenLayers": true}); + assert!(svg_text(&s.execute("document.serialize", &kept).unwrap()).contains(&photo), "{kept}"); + let e = confine(roots.as_ref(), || s.execute("document.serialize", &kept)).unwrap_err().to_string(); + assert!(e.contains("a linked image file is outside the read roots"), "{kept}: {e}"); + } +} + +/// A confined caller's SVG Tiny 1.2 of an object whose opacity mask is a linked image outside the +/// read roots: the Tiny file leaves the mask out and is written; SVG 1.1 writes the mask and is +/// refused. +#[test] +fn confined_svg_tiny_output_leaves_opacity_mask_images_unchecked() { + use crate::file_access::{AutomationRoots, confine}; + + let away = Folder::new("svg-tiny-mask-away"); + let home = Folder::new("svg-tiny-mask-home"); + let photo = away.file("photo.png"); + write(&photo, &png(60, 30, RED)); + let mut s = session(); + let r = s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 20})).unwrap()["id"].clone(); + let a = place(&mut s, &photo); + s.execute("select.set", &json!({"ids": [r, a.0]})).unwrap(); + s.execute("transparency.makeOpacityMask", &json!({})).unwrap(); + let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap(); + for format in ["svg", "svgz"] { + let tiny = json!({"format": format, "images": "link", "profile": "tiny12"}); + assert!(!svg_text(&s.execute("document.serialize", &tiny).unwrap()).contains(&photo), "{tiny}"); + let text = svg_text(&confine(roots.as_ref(), || s.execute("document.serialize", &tiny)).unwrap()); + assert!(!text.contains(&photo), "{tiny}: {text}"); + let full = json!({"format": format, "images": "link"}); + assert!(svg_text(&s.execute("document.serialize", &full).unwrap()).contains(&photo), "{full}"); + let e = confine(roots.as_ref(), || s.execute("document.serialize", &full)).unwrap_err().to_string(); + assert!(e.contains("a linked image file is outside the read roots"), "{full}: {e}"); + } +} + +/// A confined caller's SVG of a linked image outside the read roots, without pixels in the +/// document, under Radial Blur: the file and the clipboard draw the rendered image in its place, +/// name no file, and are written. +#[test] +fn confined_svg_output_checks_the_images_drawn_for_pixel_effects() { + use crate::file_access::{AutomationRoots, confine}; + + let away = Folder::new("svg-flat-away"); + let home = Folder::new("svg-flat-home"); + let photo = away.file("photo.png"); + write(&photo, &png(60, 30, RED)); + let mut s = session(); + let a = place(&mut s, &photo); + s.execute("effect.apply", &json!({"effect": "blur.radial", "ids": [a.0], "params": {"amount": 30, "quality": "draft"}})).unwrap(); + without_pixels(&mut s, a); + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + s.execute("edit.copy", &json!({})).unwrap(); + let roots = AutomationRoots::new(&[home.0.as_path()], &[home.0.as_path()]).unwrap(); + let clip = + |s: &mut Session| confine(roots.as_ref(), || s.execute("clipboard.exportSvg", &json!({}))).unwrap()["svg"].as_str().unwrap().to_string(); + assert!(!clip(&mut s).contains(&photo)); + assert!(confine(roots.as_ref(), || s.clipboard_svg()).is_some_and(|svg| !svg.contains(&photo))); + for format in ["svg", "svgz"] { + for images in ["link", "embed"] { + let p = json!({"format": format, "images": images}); + let text = svg_text(&confine(roots.as_ref(), || s.execute("document.serialize", &p)).unwrap()); + assert!(!text.contains(&photo), "{p}: {text}"); + } + } + // Without the effect, the image names its file. + s.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + s.execute("effect.remove", &json!({"index": 0})).unwrap(); + assert!(s.doc().unwrap().doc.node(a).unwrap().appearance.effects.is_empty()); + let e = confine(roots.as_ref(), || s.execute("document.serialize", &json!({"format": "svg"}))).unwrap_err().to_string(); + assert!(e.contains("a linked image file is outside the read roots"), "{e}"); +} diff --git a/docs/mcp.md b/docs/mcp.md index 781e4a31c7..ce63a13274 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -255,9 +255,12 @@ the suite) keep the agent to the folders you give it: paths kept of them and each data set's image, in every symbol, pattern, graph design and brush, used or not, colorized or not, and a stored brush entry that does not read as a brush is refused too, since its links cannot be checked. Otherwise the images of the art the file writes, - in opacity masks and in the symbols, patterns and brushes that art uses, are checked: hidden layers and - objects only with `hiddenLayers` (a save keeps them unless it is `false`), and template layers and the - layer of opacity-mask or symbol editing mode never. `selectedOnly` and `document.exportSelection` check the + in opacity masks, in the art drawn for placed documents and in the symbols, patterns and brushes that art + uses, are checked: hidden layers and objects only with `hiddenLayers` (a save keeps them unless it is + `false`), also inside symbols, patterns and graph designs, and template layers and the layer of + opacity-mask or symbol editing mode never. With `profile: "tiny12"` the file leaves out opacity masks, and + their images are not checked. An object whose effect SVG has no filter for is checked as the image the file + draws of it. `selectedOnly` and `document.exportSelection` check the selected objects only, and `clipboard.exportSvg` checks the copied objects, following a relative path from the document they came from while it is open; in a frame a request drives, Copy then puts no SVG on the system clipboard. An image whose pixels the document holds exports embedded, and a URL is not checked. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 11350e47d4..d7e1c75ac6 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -879,7 +879,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Link replies under `--automation-read-root`: `links.list`, `links.check`, `links.info` and `document.open`'s link rows leave out the path, found path and folder of a linked file outside the read roots, and the stored size and date of it in `links.info`; each row keeps its id, file name and status, and the document's links are not changed. `crates/engine/src/tests/linkspanel.rs` (`link_paths_outside_the_read_roots_are_left_out`), `crates/engine/src/tests/placed_document.rs` (`link_info_leaves_out_a_placed_documents_path_outside_the_read_roots`). - Document replies under `--automation-read-root`: `document.inspect` gives `path` as null for a document file outside the read roots, and `document.json` names a linked image or placed file outside them by its file name alone, without its relative path, size or date, brush art included, leaves out a relative path that leads outside them and a stored brush entry that does not read as a brush, names a data set's image value outside them by its file name, and leaves an Export for Screens folder outside them out of `export_settings`; the document is not changed. `crates/engine/src/tests/placed_document.rs` (`document_replies_leave_out_paths_outside_the_read_roots`, `document_json_checks_brush_art_and_relative_paths_against_the_read_roots`). - SVG output under `--automation-read-root`: `document.serialize`, `document.export`, `document.exportSelection`, `document.exportForScreens`, `assets.export`, the SVG and SVGZ saves, `file.exportAs` and the SVG Options dialog's Show Code refuse an SVG or SVGZ of a document that links a JavaScript file outside the read roots, before any file or folder is written, with an error that names no file or folder; a URL, a file inside the roots and a relative path that leads inside them are written as stored, and the person at the keyboard exports every link as stored. `crates/engine/src/tests/interactivity.rs` (`confined_svg_output_refuses_a_linked_javascript_file_outside_the_read_roots`, `svg_output_keeps_linked_javascript_files_a_caller_may_read`), `crates/ui-egui/src/tests/automation.rs` (`control_svg_export_refuses_a_linked_javascript_file_outside_the_read_root`), `crates/ui-egui/src/dialogs/svg_options.rs` (`show_code_leaves_out_a_linked_javascript_file_outside_the_read_roots`). - - Linked images in SVG output under `--automation-read-root`: the same outputs, and `clipboard.exportSvg`, refuse an SVG or SVGZ that would name a linked image's file outside the read roots (`images: link`, an image whose pixels the document doesn't hold, or `preserveEditing`), before any file or folder is written, with an error that names no file or folder; Copy in a frame a request drives then puts no SVG on the system clipboard. Embedded pixels, a file inside the roots, a relative path that leads inside them and a URL are written as before, and the person at the keyboard exports every link as stored. `crates/engine/src/tests/links.rs` (`confined_svg_output_refuses_a_linked_image_file_outside_the_read_roots`, `svg_output_names_linked_image_files_a_caller_may_read`, `confined_clipboard_svg_refuses_a_linked_image_file_outside_the_read_roots`, `confined_preserve_editing_svg_refuses_a_brush_library_entry_it_cannot_read`, `confined_svg_output_checks_only_the_linked_images_it_writes`, `confined_svg_output_writes_a_colorized_gray_image_without_its_file`), `crates/ui-egui/src/tests/automation.rs` (`control_svg_export_refuses_a_linked_image_file_outside_the_read_root`), `crates/ui-egui/src/dialogs/svg_options.rs` (`show_code_leaves_out_a_linked_image_file_outside_the_read_roots`). + - Linked images in SVG output under `--automation-read-root`: the same outputs, and `clipboard.exportSvg`, refuse an SVG or SVGZ that would name a linked image's file outside the read roots (`images: link`, an image whose pixels the document doesn't hold, or `preserveEditing`), before any file or folder is written, with an error that names no file or folder; Copy in a frame a request drives then puts no SVG on the system clipboard. Embedded pixels, a file inside the roots, a relative path that leads inside them and a URL are written as before, and the person at the keyboard exports every link as stored. The check covers the art drawn for placed documents and leaves out what the file leaves out: hidden art in symbols, patterns and graph designs, opacity masks in SVG Tiny 1.2, and objects drawn as images for effects SVG has no filter for. `crates/engine/src/tests/links.rs` (`confined_svg_output_refuses_a_linked_image_file_outside_the_read_roots`, `svg_output_names_linked_image_files_a_caller_may_read`, `confined_clipboard_svg_refuses_a_linked_image_file_outside_the_read_roots`, `confined_preserve_editing_svg_refuses_a_brush_library_entry_it_cannot_read`, `confined_svg_output_checks_only_the_linked_images_it_writes`, `confined_svg_output_writes_a_colorized_gray_image_without_its_file`, `confined_svg_output_checks_the_images_of_placed_documents`, `confined_svg_output_leaves_hidden_symbol_art_unchecked`, `confined_svg_tiny_output_leaves_opacity_mask_images_unchecked`, `confined_svg_output_checks_the_images_drawn_for_pixel_effects`), `crates/ui-egui/src/tests/automation.rs` (`control_svg_export_refuses_a_linked_image_file_outside_the_read_root`), `crates/ui-egui/src/dialogs/svg_options.rs` (`show_code_leaves_out_a_linked_image_file_outside_the_read_roots`). - Linked-file and font-file searches under `--automation-read-root`: `links.findFiles` and `text.findFontFiles` replies, also later polls and stops of a search another client started, leave out the files found, a link's saved path and the folder searched outside the caller's read roots, and a failed search gives its reason without the path; `image.info` gives `link: null` for a linked file outside them; `text.addFontFiles` gives `folder: null` and the copies' file names when the Fonts folder is outside them. `crates/engine/src/tests/linkfiles.rs`, `crates/engine/src/tests/fontfiles.rs`, `crates/engine/tests/font_folder.rs`. - Swatch, brush, symbol and graphic style library lists under `--automation-read-root`: every library stays listed, the paths of library files and the user library folder outside the read roots are `null`, a library loaded from outside them is listed and found as `loaded/` and keeps that id for the session unless a library loaded later without a file shows that id itself, which moves it to the next free `loaded/ (N)`, and the app's own list is not changed. `crates/engine/src/tests/library_roots.rs`. - Preferences commands under `--automation-read-root`: `prefs.get`, `prefs.list`, `prefs.set` and `prefs.reset` show folder preferences outside the read roots as `null` and leave out an export preset's folder outside them, and the preferences are not changed. `crates/engine/src/tests/prefs_roots.rs`.