diff --git a/crates/engine/src/cmd/place.rs b/crates/engine/src/cmd/place.rs index e787899cd2..73dc4e3603 100644 --- a/crates/engine/src/cmd/place.rs +++ b/crates/engine/src/cmd/place.rs @@ -85,7 +85,7 @@ pub fn specs() -> Vec { "Place…", ["File"], Some("Cmd+Shift+P"), - "{path | name | dataBase64 (a file's path, or its name with its bytes), link?: true (a raster image keeps its file's path; a VectorCraft document at path becomes one locked placed document showing artboard `page`, linked to the file and read again when it changes (links.update; saving it in this app updates it at once), drawn as vectors in every output; so does a PDF/.ai page at path, showing its `crop` box, unless password or textAs: \"outlines\" is given, and an EPS file, a PostScript file or a PostScript .ai at path, showing the art false gives; false: an editable copy of its art, as from dataBase64; other files are embedded), text?: {characterSet?: \"unicode\" (UTF-8, or UTF-16 with a byte-order mark, or without one by dataset.import's rule: an even length, at least half of its two-byte units holding a NUL byte, the byte order that reads a line break, valid UTF-16 with no NUL character; other bytes as the platform's 8-bit set) | \"ansi\" (the platform's 8-bit set) | \"shiftJis\" | \"gb2312\" (read as GBK) | \"chineseBig5\" | \"cyrillic\" (windows-1251, x-mac-cyrillic on mac) | \"gb18030\" | \"greek\" (windows-1253) | \"turkish\" (windows-1254) | \"baltic\" (windows-1257) | \"centralEuropean\" (windows-1250) (the WHATWG Encoding Standard's decoders: a byte-order mark is read as ordinary bytes, a malformed sequence as U+FFFD), platform?: \"windows\" (ANSI is Windows-1252) | \"mac\" (ANSI is Mac Roman), removeLineReturns?: false (each block of lines becomes one paragraph; blank lines end paragraphs), removeParagraphReturns?: false (drop blank lines), replaceSpaces?: n (runs of n ≥ 2 spaces become a tab)} (a .txt file, placed as area type filling rect, the replaced object's bounds, or else the artboard less a 36 pt margin), template?: false (onto a new locked template layer below the current layer), replace?: false (swap the one selected object, keeping its stacking place and transform; no at/rect; refused while an object of a symbol instance's art is selected), at?: [x, y] centre (default: the first artboard's centre), rect?: [x, y, width, height] fit inside; aspect kept (wins over at), page?: 1 (PDF/.ai page, or a native document's artboard), crop?: \"crop\" (clipped to that page or artboard, default; an SVG, only when given: framed and clipped by its viewBox, else by its art's bounds) | \"bounding\" (the bounds of the art that shows, with its strokes and effects, as an export measures them: hidden objects and guides left out) | \"art\" | \"trim\" | \"bleed\" | \"media\" (a PDF page's boxes), password? (an encrypted PDF), layers?: false (a PSD or PSB file: true embeds its layers as one group named after the file, read as document.open reads them: an image for each layer and a group for each layer group, with the layer's name, visibility, opacity, blend mode and opacity mask, at the place its merged image would take and clipped to the canvas when layers, hidden ones included, reach past it; never linked: link is then false unless given, and link: true is refused; a file without layers is embedded as its merged image, and so are one whose layers are all left out and one whose layers can't be read, with a warning), hiddenLayers?: false (with layers: true, the hidden layers come in hidden instead of being left out; refused without it), importSlices?: bool (a PSD or PSB file: its slices become user slices, moved and scaled with the placed art, in the same undo step; default true when the file is embedded, false when it is linked, and true with link is refused; slices the file generated automatically are left out), dxf?: {…the DXF options of document.open} (a .dxf drawing: fit fills the artboard under at, else the first; fitted or uncentred art lands with its drawing's artboard on that artboard, else it is centred on at), showImportOptions?: true (in the app, a text file without text, a DXF drawing without dxf, a PSD or PSB file embedded without layers (with two layers or more, or with slices) and a PDF with several pages or a password and no page ask for those options first, and an encrypted PDF given page and no password asks for its password; false places them with the options last confirmed, a PDF on page 1 (or page), and asks only an encrypted PDF's password), importer?: \"plugin.\" (an importer plug-in whose manifest sets place, see document.formats: it reads the file, which must have an extension it lists, also one a built-in format reads; without importer, a file no built-in format reads, by its content or its extension, is read by the first such importer by id that lists its extension; it is given the file, at most 128 MiB, with _context.mode \"place\", and its objects, guides left out, are placed as one group named after the file, in the order it returned them, embedded whatever link says), params?: {…} (the importer's own parameters, see plugin.info)} → {ids, name, format, linked, width, height, warnings, image?: the id of the image of a DCS file or PSD/PSB file placed in a clip group, which the Links commands take, slices?: [the ids of the user slices a PSD file brought in]}. A PSD or PSB file that names a clipping path places in a clip group of that path (even-odd), as does its merged image in document.open. Raster images come in at 100% of their physical size (the file's ppi, else 72); SVG, DXF, HP-GL (.plt, .hpgl, .hgl, .hpg), PDF/.ai, EMF/WMF and PICT (.pct, .pic, .pict; clipped to the picture's frame), EPS (clipped to its bounding box; as document.open reads it), a .ai saved without PDF compatibility (from its editing data, as document.open reads it: the art of the layers that show on artboard `page`, clipped to that artboard unless crop is \"bounding\") and native documents as one group, with the images, symbols, patterns, swatches and brushes they use. A DCS file (an EPS file with one program per printing plate, DCS 1.0 or 2.0) is placed only from its path with link (else an error, as are document.open and links.embed): one linked image of its plates mixed into CMYK, clipped by the clipping path its composite is drawn through, its spot plates added as spot swatches in the process equivalents the file gives (a swatch of the same name is kept, with a warning); print separations and Separations Preview show each plate on its own ink, and plate files of their own are read from its folder. One undo step; selects what it placed (unless on a template layer); never touches the clipboard. A PNG, JPEG, GIF or WebP image whose pixels can't be read (a file cut short) is an error, and nothing is placed", + "{path | name | dataBase64 (a file's path, or its name with its bytes), link?: true (a raster image keeps its file's path; a VectorCraft document at path becomes one locked placed document showing artboard `page`, linked to the file and read again when it changes (links.update; saving it in this app updates it at once), drawn as vectors in every output; so does a PDF/.ai page at path, showing its `crop` box, unless password or textAs: \"outlines\" is given, and an EPS file, a PostScript file or a PostScript .ai at path, showing the art false gives; false: an editable copy of its art, as from dataBase64; other files are embedded), text?: {characterSet?: \"unicode\" (UTF-8, or UTF-16 with a byte-order mark, or without one by dataset.import's rule: an even length, at least half of its two-byte units holding a NUL byte, the byte order that reads a line break, valid UTF-16 with no NUL character; other bytes as the platform's 8-bit set) | \"ansi\" (the platform's 8-bit set) | \"shiftJis\" | \"gb2312\" (read as GBK) | \"chineseBig5\" | \"cyrillic\" (windows-1251, x-mac-cyrillic on mac) | \"gb18030\" | \"greek\" (windows-1253) | \"turkish\" (windows-1254) | \"baltic\" (windows-1257) | \"centralEuropean\" (windows-1250) (the WHATWG Encoding Standard's decoders: a byte-order mark is read as ordinary bytes, a malformed sequence as U+FFFD), platform?: \"windows\" (ANSI is Windows-1252) | \"mac\" (ANSI is Mac Roman), removeLineReturns?: false (each block of lines becomes one paragraph; blank lines end paragraphs), removeParagraphReturns?: false (drop blank lines), replaceSpaces?: n (runs of n ≥ 2 spaces become a tab)} (a .txt file, placed as area type filling rect, the replaced object's bounds, or else the artboard less a 36 pt margin), template?: false (onto a new locked template layer below the current layer), replace?: false (swap the one selected object, keeping its stacking place and transform; no at/rect; refused while an object of a symbol instance's art is selected), at?: [x, y] center (default: the first artboard's center; transformed art must stay within ±4,000,000 pt on either axis, including template placement), rect?: [x, y, width, height] fit inside; aspect kept (wins over at), page?: 1 (PDF/.ai page, or a native document's artboard), crop?: \"crop\" (clipped to that page or artboard, default; an SVG, only when given: framed and clipped by its viewBox, else by its art's bounds) | \"bounding\" (the bounds of the art that shows, with its strokes and effects, as an export measures them: hidden objects and guides left out) | \"art\" | \"trim\" | \"bleed\" | \"media\" (a PDF page's boxes), password? (an encrypted PDF), layers?: false (a PSD or PSB file: true embeds its layers as one group named after the file, read as document.open reads them: an image for each layer and a group for each layer group, with the layer's name, visibility, opacity, blend mode and opacity mask, at the place its merged image would take and clipped to the canvas when layers, hidden ones included, reach past it; never linked: link is then false unless given, and link: true is refused; a file without layers is embedded as its merged image, and so are one whose layers are all left out and one whose layers can't be read, with a warning), hiddenLayers?: false (with layers: true, the hidden layers come in hidden instead of being left out; refused without it), importSlices?: bool (a PSD or PSB file: its slices become user slices, moved and scaled with the placed art, in the same undo step; default true when the file is embedded, false when it is linked, and true with link is refused; slices the file generated automatically are left out), dxf?: {…the DXF options of document.open} (a .dxf drawing: fit fills the artboard under at, else the first; fitted or uncentred art lands with its drawing's artboard on that artboard, else it is centred on at), showImportOptions?: true (in the app, a text file without text, a DXF drawing without dxf, a PSD or PSB file embedded without layers (with two layers or more, or with slices) and a PDF with several pages or a password and no page ask for those options first, and an encrypted PDF given page and no password asks for its password; false places them with the options last confirmed, a PDF on page 1 (or page), and asks only an encrypted PDF's password), importer?: \"plugin.\" (an importer plug-in whose manifest sets place, see document.formats: it reads the file, which must have an extension it lists, also one a built-in format reads; without importer, a file no built-in format reads, by its content or its extension, is read by the first such importer by id that lists its extension; it is given the file, at most 128 MiB, with _context.mode \"place\", and its visible layers' objects (all objects without layers), guides left out, are placed as one group named after the file, in the order it returned them, embedded whatever link says), params?: {…} (the importer's own parameters, see plugin.info)} → {ids, name, format, linked, width, height, warnings, image?: the id of the image of a DCS file or PSD/PSB file placed in a clip group, which the Links commands take, slices?: [the ids of the user slices a PSD file brought in]}. A PSD or PSB file that names a clipping path places in a clip group of that path (even-odd), as does its merged image in document.open. Raster images come in at 100% of their physical size (the file's ppi, else 72); SVG, DXF, HP-GL (.plt, .hpgl, .hgl, .hpg), PDF/.ai, EMF/WMF and PICT (.pct, .pic, .pict; clipped to the picture's frame), EPS (clipped to its bounding box; as document.open reads it), a .ai saved without PDF compatibility (from its editing data, as document.open reads it: the art of the layers that show on artboard `page`, clipped to that artboard unless crop is \"bounding\") and native documents as one group, with the images, symbols, patterns, swatches and brushes they use. A DCS file (an EPS file with one program per printing plate, DCS 1.0 or 2.0) is placed only from its path with link (else an error, as are document.open and links.embed): one linked image of its plates mixed into CMYK, clipped by the clipping path its composite is drawn through, its spot plates added as spot swatches in the process equivalents the file gives (a swatch of the same name is kept, with a warning); print separations and Separations Preview show each plate on its own ink, and plate files of their own are read from its folder. One undo step; selects what it placed (unless on a template layer); never touches the clipboard. A PNG, JPEG, GIF or WebP image whose pixels can't be read (a file cut short) is an error, and nothing is placed", has_doc, place ), @@ -864,6 +864,9 @@ fn apply(s: &mut Session, read: PlaceRead) -> Result { Affine::translate(c - natural.center()) } }; + if !crate::sanity::rect_in_range(m.transform_rect_bbox(natural)) { + return Err(bad(PLACE, "placed art lies outside the canvas")); + } let parent = st.insertion_parent(); let below = st.current_layer().or_else(|| parent.and_then(|p| st.doc.layer_of(p))); let link = loaded.link.take().filter(|_| bool_or(p, "link", true)); diff --git a/crates/engine/tests/plugin_import.rs b/crates/engine/tests/plugin_import.rs index b64dde61bf..8bac66a4d3 100644 --- a/crates/engine/tests/plugin_import.rs +++ b/crates/engine/tests/plugin_import.rs @@ -472,9 +472,13 @@ fn rich_output() -> Value { } /// The active document's layers (name, shown, locked, kinds of its objects), its artboards (name -/// and rectangle), its type (text, family, size, fill) and the RGBA of its first image. +/// and rectangle), its type (text, family, size, fill), the RGBA of its first image, and the transforms +/// of its text and images. #[allow(clippy::type_complexity)] -fn structure(s: &Session) -> (Vec<(String, bool, bool, Vec<&'static str>)>, Vec<(String, [f64; 4])>, Vec<(String, String, f64, String)>, Vec) { +fn structure( + s: &Session, +) -> (Vec<(String, bool, bool, Vec<&'static str>)>, Vec<(String, [f64; 4])>, Vec<(String, String, f64, String)>, Vec, Vec<(&'static str, [f64; 6])>) +{ let d = &s.doc().unwrap().doc; let kind = |n: &vectorcraft_doc::Node| match &n.kind { vectorcraft_doc::NodeKind::Text(_) => "type", @@ -488,21 +492,25 @@ fn structure(s: &Session) -> (Vec<(String, bool, bool, Vec<&'static str>)>, Vec< .map(|l| (l.name.clone().unwrap_or_default(), l.visible, l.locked, l.children().unwrap().iter().map(|c| kind(c)).collect())) .collect(); let boards = d.artboards.iter().map(|a| (a.name.clone(), [a.rect.x0, a.rect.y0, a.rect.x1, a.rect.y1])).collect(); - let (mut types, mut pixels) = (Vec::new(), Vec::new()); + let (mut types, mut pixels, mut transforms) = (Vec::new(), Vec::new(), Vec::new()); d.walk(|n| match &n.kind { vectorcraft_doc::NodeKind::Text(t) => { + transforms.push(("type", t.xf.as_coeffs())); let st = &t.runs[0].style; let text: String = t.runs.iter().map(|r| r.text.as_str()).collect(); types.push((text, st.font_family.clone(), st.size, serde_json::to_string(&st.fill).unwrap())); } - vectorcraft_doc::NodeKind::Image(_) if pixels.is_empty() => { + vectorcraft_doc::NodeKind::Image(im) => { + transforms.push(("image", im.xf.as_coeffs())); // Read back through the filter input's own decoder, not the importer's. - let o = vectorcraft_plugins::objects::encode_read_only(d, n).unwrap(); - pixels = vectorcraft_format::base64_decode(o["pixelsBase64"].as_str().unwrap()).unwrap(); + if pixels.is_empty() { + let o = vectorcraft_plugins::objects::encode_read_only(d, n).unwrap(); + pixels = vectorcraft_format::base64_decode(o["pixelsBase64"].as_str().unwrap()).unwrap(); + } } _ => {} }); - (layers, boards, types, pixels) + (layers, boards, types, pixels, transforms) } /// An importer at API level 4 that lists every output kind opens editable type, an embedded image, @@ -525,6 +533,7 @@ fn an_api_4_importer_opens_type_images_layers_and_artboards() { assert_eq!(opened.1, [("Front".to_string(), [0.0, 0.0, 200.0, 100.0]), ("Back".to_string(), [220.0, 0.0, 420.0, 100.0])]); assert_eq!(opened.2, [("Hello\nWorld".to_string(), "No Such Family Q9617".to_string(), 24.0, blue)]); assert_eq!(opened.3, PIXELS); + assert_eq!(opened.4, [("image", [10.0, 0.0, 0.0, 10.0, 0.0, 100.0]), ("type", [1.0, 0.0, 0.0, 1.0, 10.0, 40.0])]); // The type is laid out at the place the transform gives: its first baseline starts at (10, 40). let d = &s.doc().unwrap().doc; let words = d.layers[1].children().unwrap()[0].clone(); @@ -571,7 +580,7 @@ fn rich_output_that_fails_its_checks_changes_nothing() { rich_echo(&mut s, "test.richboards", r#"["artboard"]"#); let blank = json!({"objects": [], "artboards": [{"name": "Only", "rect": [0, 0, 50, 60]}]}); open(&mut s, "Blank.trc", blank.to_string().as_bytes(), json!({"importer": "plugin.test.richboards"})).unwrap(); - let (layers, boards, types, _) = structure(&s); + let (layers, boards, types, _, _) = structure(&s); assert_eq!((layers.len(), layers[0].3.len(), boards, types.len()), (1, 0, vec![("Only".to_string(), [0.0, 0.0, 50.0, 60.0])], 0)); } diff --git a/crates/engine/tests/plugin_place.rs b/crates/engine/tests/plugin_place.rs index d164219cdb..0319595ced 100644 --- a/crates/engine/tests/plugin_place.rs +++ b/crates/engine/tests/plugin_place.rs @@ -58,6 +58,38 @@ fn state(s: &mut Session) -> (usize, usize, usize, Value) { (d.history.undo.len(), d.history.redo.len(), d.doc.layers.len(), content) } +#[test] +fn placing_importer_checks_the_transformed_bounds_before_editing() { + let image = json!({"objects": [{ + "type": "image", "pixelSize": [1, 1], "pixelsBase64": vectorcraft_format::base64_encode(&[255, 0, 0, 255]), + "transform": [20, 0, 0, 10, 0, 0], + }]}) + .to_string(); + for (index, output, half_width) in [(0, ART, 50.0), (1, image.as_str(), 10.0)] { + let mut s = with_document(); + let mut manifest: Value = serde_json::from_str(&placing(&format!("test.place.canvas{index}"), r#"["tpc"]"#)).unwrap(); + if index == 1 { + manifest["api"] = json!(4); + manifest["outputKinds"] = json!(["image"]); + } + install(&mut s, &tpl::returning(&manifest.to_string(), output)); + let importer = format!("plugin.test.place.canvas{index}"); + let before = state(&mut s); + for at in [[4_000_000.0, 400.0], [-4_000_000.0, 400.0], [400.0, 4_000_000.0], [400.0, -4_000_000.0]] { + for template in [false, true] { + assert!( + place(&mut s, "Art.tpc", b"?", json!({"at": at, "template": template, "importer": importer})).is_err(), + "{index}: {at:?}, template: {template}" + ); + assert_eq!(state(&mut s), before); + } + } + let inside = place(&mut s, "Art.tpc", b"?", json!({"at": [4_000_000.0 - half_width, 400.0], "importer": importer})); + assert!(inside.is_ok(), "{index}: {inside:?}"); + assert_eq!(s.doc().unwrap().history.undo.len(), before.0 + 1); + } +} + /// A placed group: its name, the names of its children, and its bounds as `(x0, y0, x1, y1)`. type Placed = (Option, Vec>, (f64, f64, f64, f64)); diff --git a/crates/plugins/src/import.rs b/crates/plugins/src/import.rs index 03e853d879..97784d6b01 100644 --- a/crates/plugins/src/import.rs +++ b/crates/plugins/src/import.rs @@ -298,6 +298,17 @@ pub fn decode_with(bytes: &[u8], kinds: &[OutputKind]) -> Result { }; (objects, layers, artboards) }; + for (i, object) in objects.iter().enumerate() { + if let ImportObject::Path(path) = object { + let at = format!("objects[{i}]"); + if path.id.is_some() { + return Err(out_err(&at, "an importer returns new paths without `id`")); + } + if path.path.is_none() { + return Err(out_err(&at, "an imported path must include its geometry in `path`")); + } + } + } if objects.is_empty() && layers.is_empty() && artboards.is_empty() { return Err(Error::Output("the importer returned no objects".into())); } @@ -581,11 +592,12 @@ fn decode_artboards(v: &Value) -> Result> { let r = o.get("rect").and_then(Value::as_array).filter(|r| r.len() == 4).ok_or_else(wrong)?; let n: Vec = r.iter().map(Value::as_f64).collect::>().ok_or_else(wrong)?; let (x, y, w, h) = (n[0], n[1], n[2], n[3]); + let (x1, y1) = (x + w, y + h); let inside = |v: f64| v.is_finite() && v.abs() <= MAX_COORD; - if !(w > 0.0 && h > 0.0 && inside(x) && inside(y) && inside(x + w) && inside(y + h)) { + if !(w > 0.0 && h > 0.0 && x1 > x && y1 > y && inside(x) && inside(y) && inside(x1) && inside(y1)) { return Err(wrong()); } - boards.push(OutArtboard { name, rect: Rect::new(x, y, x + w, y + h) }); + boards.push(OutArtboard { name, rect: Rect::new(x, y, x1, y1) }); } Ok(boards) } @@ -668,6 +680,35 @@ mod tests { decode_with(v.to_string().as_bytes(), ALL) } + #[test] + fn importer_output_rejects_filter_only_path_updates() { + let square: Value = serde_json::from_str(SQUARE).unwrap(); + let mut identified = square.clone(); + identified["id"] = json!(3); + for object in [json!({"id": 3}), json!({"type": "path"}), identified] { + let output = json!({"objects": [object]}); + for kinds in [&[OutputKind::Type][..], &[][..]] { + assert!(decode_with(output.to_string().as_bytes(), kinds).is_err(), "{kinds:?}: {output}"); + } + } + let mut untyped = square.clone(); + untyped.as_object_mut().unwrap().remove("type"); + for object in [square, untyped] { + let output = json!({"objects": [object]}); + for kinds in [&[OutputKind::Type][..], &[][..]] { + assert!(decode_with(output.to_string().as_bytes(), kinds).is_ok(), "{kinds:?}: {output}"); + } + } + } + + #[test] + fn importer_output_rejects_artboards_with_collapsed_endpoints() { + for rect in [[1_000_000.0, 0.0, 1e-12, 10.0], [0.0, 1_000_000.0, 10.0, 1e-12]] { + assert!(rich_with(|v| v["artboards"][0]["rect"] = json!(rect)).is_err(), "{rect:?}"); + } + assert!(rich_with(|v| v["artboards"][0]["rect"] = json!([3_999_999.0, 3_999_999.0, 1.0, 1.0])).is_ok()); + } + /// An importer listing every output kind returns type, an embedded image, paths, layers and /// artboards, each read as it was given. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 9798427845..3c8aa304bd 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -13944,9 +13944,13 @@ and `file.place.queue` take `importer?: "plugin."` (one that sets `place` an `params?`, and without `importer` a file no built-in format reads goes to the first such importer by id that lists its extension. The importer is given at most 128 MiB of the file (a larger file is refused from its size, with `importer` before any of it is read or decoded, and without it after its first 64 KiB are read or decoded) -and `_context.mode` `"place"`; its objects, guides left out, are placed as one group named after the file, in the order -it returned them, as one undo step, embedded whatever `link` says (`linked: false`). `plugin.run` of an importer is -an error that names `document.open`. In the app, File › Open With lists the installed importers, and +and `_context.mode` `"place"`; its visible layers' objects, or all objects when it returns no layers, are placed +as one group named after the file, in the order it returned them, with guides omitted, as one undo step, +embedded whatever `link` says (`linked: false`). `plugin.run` of an importer is +an error that names `document.open`. Placement rejects transformed art beyond ±4,000,000 pt on either axis, +including template placement, before changing the document. An importer returns new paths with geometry and +without object IDs. An artboard's positive width and height must produce distinct finite endpoints within the canvas. +In the app, File › Open With lists the installed importers, and `file.openWith {importer, path?, params?}` opens `path`, or a file picked among the importer's extensions, with one (on the web it opens File › Open's picker) and adds it to Open Recent. With `path` the reply is `document.open`'s result; on the desktop a picked file is read off the UI thread and the reply is `{background: true, status}`, and diff --git a/docs/plugins.md b/docs/plugins.md index 631a341654..74a7b74bda 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -1243,12 +1243,15 @@ error names the kind. An importer that lists no kinds is read as before, and the `locked` (default `false`) and `objects`, the indexes of its objects in `objects` in increasing order. Every object is in exactly one layer, and a layer may hold none. Without `layers`, every object goes in one layer. - `artboards` (kind `artboard`): 1–100 artboards, each with a `name` used once and a `rect`, `[x, y, width, height]` - with a width and height above 0, within ±4,000,000. They replace the one artboard around the art. + with a width and height above 0. Each computed endpoint must differ from its origin and remain within + ±4,000,000. They replace the one artboard around the art. - A `name` (of type, an image, a layer or an artboard) and a font's family and style are each 1–256 characters, not only spaces, without control characters or characters that change the direction of text. - An output whose `objects` is empty opens as a blank document when it has `layers` or `artboards`. - To place (`_context.mode` `"place"`), the objects of the visible layers are placed in one group with their type and - images, the objects of hidden layers are left out, and `artboards` are left out. + images, the objects of hidden layers are left out, and `artboards` are left out. Without layers, all objects are + placed. Transformed art beyond ±4,000,000 pt on either axis is rejected before the edit, including template placement. +- Imported paths require `path` geometry and cannot include an `id`, at every plug-in API level. ## Writing a plug-in in Rust diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index db3cf048e3..2187c300b8 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2706,8 +2706,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Exporter plug-ins (G17):** a WebAssembly plug-in of kind `exporter` adds a write-only file format. File › Export › Export As lists it after the built-in formats, with Use Artboards greyed out (the plug-in writes the whole document) and its parameters in a generated dialog once the file is picked; `document.export` writes it by its format id, `plugin.`, or by one of its extensions, and built-in formats keep theirs. The plug-in is given the native file's JSON (large images without their data) and `_context` (`mode`, `extension`, `name`), with 10 G instructions plus 4,000 per byte of input and 300 s, and Background Export's Cancel stops it between two slices of that budget. A decline or invalid output writes nothing; its warnings come back with the export's. Regressions: `crates/engine/tests/plugin_export.rs`, `crates/plugins/tests/abi.rs`, `crates/ui-egui/src/dialogs/tests_plugin_export.rs`. Scores and hours unchanged. - **Importer plug-ins (G17):** a WebAssembly plug-in of kind `importer` adds a read-only file format, as [the help page](https://ai-sdk-2020.84.nz/html/struct_a_i_file_format_suite) describes for file format plug-ins that read: File › Open lists its files under "All readable files" and its own filter, and File › Open With lists each importer by name. `document.open` uses it for a file whose extension no built-in format reads, by content or extension (the importer whose id sorts first, when several list the extension), or the one `importer` names, also for an extension a built-in format reads; a damaged file of a built-in format reports that format's error. The plug-in is given at most 128 MiB of the file and `_context` (`mode: "import"`, `extension`, `name`), and returns paths and compound paths in the filters' object JSON, checked as a filter's output is; they become a new document whose artboard is their bounds, which Save asks a name for. A decline, invalid output, a trap or Cancel opens nothing. The routing rule, the limit and Open With are VectorCraft's own. Regressions: `crates/engine/tests/plugin_import.rs`, `crates/plugins/src/import.rs`, `crates/ui-egui/src/dialogs/tests_plugin_import.rs`. Scores and hours unchanged. -- **Importer output kinds (G17, VectorCraft's own contract):** an importer at plug-in API level 4 lists in its manifest's `outputKinds` which of `type`, `image`, `layer` and `artboard` it returns besides paths. Its output may then hold point type (text, font family and style, size, fill, transform), embedded RGBA images (stored as PNG in the document), top-level layers with their names, visibility, lock and objects, and named artboards that replace the one around the art; output of artboards or layers alone opens as a blank document. The host checks the whole output before it makes the document: a kind the manifest doesn't list, an image whose bytes aren't 4 × width × height, a name with control or text direction characters, or output past the limits on objects, layers, artboards, text and pixels opens nothing, and the error names the kind or the limit. Importers below level 4 read paths alone, as before. Regressions: `crates/engine/tests/plugin_import.rs`, `crates/plugins/src/import.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged. -- **Importer plug-ins place their files (G17):** an importer whose manifest has `"place": true` also reads its files for File › Place, which lists them under "All placeable files" and a filter named after the importer. `file.place`, `file.place.info` and `file.place.queue` use the importer `importer` names, which must set `place`, or, for a file no built-in format reads, the first such importer by id that lists its extension. It is given at most 128 MiB of the file (a larger file is refused from its size, before any of it is read when `importer` names the importer) and `_context.mode` `"place"`, and its objects are placed as one group named after the file, in the order it returned them, at `at`, in `rect`, over the object Replace swaps or on a template layer, as one undo step, embedded whatever `link` says. A decline, invalid output, a trap or Cancel places nothing and leaves the undo steps as they were; an importer without `place` is not used by File › Place. These rules are VectorCraft's own. Regressions: `crates/engine/tests/plugin_place.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged. +- **Importer output kinds (G17, VectorCraft's own contract):** an importer at plug-in API level 4 lists in its manifest's `outputKinds` which of `type`, `image`, `layer` and `artboard` it returns besides paths. Its output may then hold point type (text, font family and style, size, fill, transform), embedded RGBA images (stored as PNG in the document), top-level layers with their names, visibility, lock and objects, and named artboards that replace the one around the art; output of artboards or layers alone opens as a blank document. The host checks the whole output before it makes the document: a kind the manifest doesn't list, an image whose bytes aren't 4 × width × height, a name with control or text direction characters, or output past the limits on objects, layers, artboards, text and pixels opens nothing, and the error names the kind or the limit. Imported paths require geometry and cannot name existing object IDs. Positive artboard sizes must produce distinct finite endpoints within the canvas. Importers below level 4 read paths alone, as before. Regressions: `crates/engine/tests/plugin_import.rs`, `crates/plugins/src/import.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged. +- **Importer plug-ins place their files (G17):** an importer whose manifest has `"place": true` also reads its files for File › Place, which lists them under "All placeable files" and a filter named after the importer. `file.place`, `file.place.info` and `file.place.queue` use the importer `importer` names, which must set `place`, or, for a file no built-in format reads, the first such importer by id that lists its extension. It is given at most 128 MiB of the file (a larger file is refused from its size, before any of it is read when `importer` names the importer) and `_context.mode` `"place"`. Its visible layers' objects, or all objects when it returns no layers, are placed as one group named after the file, with guides omitted, in the order it returned them, at `at`, in `rect`, over the object Replace swaps or on a template layer, as one undo step, embedded whatever `link` says. Transformed art beyond ±4,000,000 pt on either axis is rejected before an edit, including on a template layer. A decline, invalid output, a trap or Cancel places nothing and leaves the undo steps as they were; an importer without `place` is not used by File › Place. These rules are VectorCraft's own. Regressions: `crates/engine/tests/plugin_place.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged. - **Plug-in parameters as their manifest presents them (G17):** each parameter may have a `label`, a `unit` shown after its value, `help` on its label and a `helpUrl` page opened from a button, a `group` (sections that fold, after the parameters outside any group) and a `visibleWhen` that shows it only while the checkboxes and choices it names have one of the listed values (a hidden parameter still goes to the plug-in). `string` and `numberList` parameters join number, int, bool and choice, and a plug-in declares up to 256 parameters, at most 64 outside groups. The filter, live-effect and exporter dialogs use these keys, and the Appearance panel's effect editor the labels, units, help and conditions; hosts from before them ignore them. Regressions: `crates/plugins/src/dialog.rs`, `crates/plugins/src/manifest.rs`, `crates/ui-egui/src/dialogs/tests_plugin_fields.rs`, `crates/ui-egui/src/panels/appearance.rs`. Scores and hours unchanged. - **Plug-in int parameters as sliders (G17):** an `int` parameter with `"widget": "slider"` shows a slider over its range with its number field, in the filter, live-effect and exporter dialogs and in the Appearance panel's effect editor; the manifest is refused at install when the parameter cannot have one. Regressions: `crates/plugins/src/dialog.rs`, `crates/ui-egui/src/dialogs/tests_plugin_fields.rs`. Scores and hours unchanged.