diff --git a/crates/doc/src/placed_document.rs b/crates/doc/src/placed_document.rs index cd423658d7..1d6b3e4f11 100644 --- a/crates/doc/src/placed_document.rs +++ b/crates/doc/src/placed_document.rs @@ -1,5 +1,5 @@ -//! Placed documents: another VectorCraft file, or a page of a PDF or `.ai` file, placed linked -//! ([`PlacedDocument`]). +//! Placed documents: another VectorCraft file, a page of a PDF or `.ai` file, or an EPS file, +//! placed linked ([`PlacedDocument`]). //! //! The object keeps the link to the file and the file's bytes, stored like image data in //! [`Document::images`] (with a small preview a save writes instead, as for linked images), so the @@ -7,9 +7,9 @@ //! joins the object tree, so editing can't reach it: it is locked by design. Drawing and exporting //! expand it like a live object ([`crate::live::expanded`]). //! -//! The file is read by the engine's loader (native documents, PDF and `.ai` pages), which lives -//! above this crate and registers itself ([`set_loader`]); the art read is kept in a small cache -//! by content. Before exporting, +//! The file is read by the engine's loader (native documents, PDF and `.ai` pages, EPS files), +//! which lives above this crate and registers itself ([`set_loader`]); the art read is kept in a +//! small cache by content. Before exporting, //! every exporter calls [`Document::with_placed_art`], which adds the resources the art uses //! (images, symbols, patterns) under names of their own ([`RESOURCE_PREFIX`]) to a temporary copy //! of the document, so they never meet the user's or show in panels. Placed documents inside a @@ -27,8 +27,8 @@ use vectorcraft_color::Paint; use crate::{AppearanceItem, Document, ImageBlob, ImageObject, LinkInfo, Node, NodeKind, PatternDef, PlacementOptions, Symbol}; -/// A placed document: an artboard of another VectorCraft file, or a page of a PDF or `.ai` file, -/// shown as one locked object. +/// A placed document: an artboard of another VectorCraft file, a page of a PDF or `.ai` file, or +/// an EPS file's art, shown as one locked object. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct PlacedDocument { /// The file (its `page` is the artboard or page shown, 1-based). diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs index 1ec0f7ceaa..3c517c006a 100644 --- a/crates/engine/src/cmd/links.rs +++ b/crates/engine/src/cmd/links.rs @@ -509,7 +509,16 @@ pub(crate) fn linked_files(d: &Document, base: LinkBase) -> Vec { .filter(|g| seen.insert(g.link.path.clone())) .map(|g| { let named = fileio::format_for_name(g.link.name()).or_else(|| fileio::readable_format_for_name(g.link.name())); - let own = |b: &&ImageBlob| !b.is_proxy() && named.is_some_and(|f| f.mime == b.mime); + // A placed document's PostScript bytes are its file's own only when its name is one that + // PostScript is read from (`.eps`, `.epsf`, `.ps`, a PostScript `.ai` or `.ait`). + let postscript_name = matches!(fileio::extension(g.link.name()).as_str(), "eps" | "epsf" | "ps" | "ai" | "ait"); + let postscript = |b: &ImageBlob| { + g.document.is_some() + && postscript_name + && b.mime == super::place::document::POSTSCRIPT + && super::place::document::is_postscript(&b.bytes) + }; + let own = |b: &&ImageBlob| !b.is_proxy() && (named.is_some_and(|f| f.mime == b.mime) || postscript(b)); let found = locate(&g.link, base); let found_path = found.as_ref().map(|f| f.path.clone()); let bytes = found.and_then(|mut f| f.read().ok()).or_else(|| d.images.get(&g.key).filter(own).map(|b| b.bytes.to_vec())); @@ -2361,12 +2370,20 @@ fn format_label(d: &Document, im: &ImageObject) -> &'static str { .map_or("Image", |f| f.label) } -/// A placed document's `links.list` fields: `format` (`VectorCraft`, or the PDF or `.ai` file's -/// format), `document: true` and its artboard's or page's size (`pageWidth`, `pageHeight`, pt) -/// instead of pixels. -fn document_row(p: &PlacedDocument) -> Value { - let pdf = fileio::format_for_name(p.link.name()).filter(|f| matches!(f.id, "pdf" | "ai" | "ait")); - json!({ "format": pdf.map_or("VectorCraft", |f| f.label), "document": true, "pageWidth": p.width, "pageHeight": p.height }) +/// A placed document's `links.list` fields (of `d`): `format` (`VectorCraft`, the PDF or `.ai` +/// file's format, or for an EPS or PostScript file `EPS` or `PostScript`), `document: true` and its +/// artboard's or page's size (`pageWidth`, `pageHeight`, pt) instead of pixels. A PostScript `.ai` +/// is told by its stored bytes or, when a save kept only its preview, by its key. +fn document_row(d: &Document, p: &PlacedDocument) -> Value { + use super::place::document::{POSTSCRIPT, is_postscript_ai_key}; + let postscript = d.images.get(&p.key).is_some_and(|b| b.mime == POSTSCRIPT) || is_postscript_ai_key(&p.key); + let format = match fileio::format_for_name(p.link.name()) { + Some(f) if matches!(f.id, "eps" | "ps") => f.label, + _ if postscript => "PostScript", + Some(f) if matches!(f.id, "pdf" | "ai" | "ait") => f.label, + _ => "VectorCraft", + }; + json!({ "format": format, "document": true, "pageWidth": p.width, "pageHeight": p.height }) } /// The size in bytes of the file that link `l` (of `st`) names, as Link Info shows it: the file's @@ -2488,7 +2505,7 @@ fn list(s: &mut Session, p: &Value) -> Result { } (im.link.as_ref(), row) } - NodeKind::PlacedDocument(p) => (Some(&p.link), document_row(p)), + NodeKind::PlacedDocument(p) => (Some(&p.link), document_row(&doc, p)), _ => continue, }; let name = link.map_or_else(|| n.display_name(), |l| l.name().to_string()); @@ -2766,7 +2783,7 @@ fn placed_info(st: &crate::DocState, doc: &Document, id: NodeId) -> Result 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; 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), platform?: \"windows\" (Windows-1252) | \"mac\" (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)} → {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), platform?: \"windows\" (Windows-1252) | \"mac\" (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)} → {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 ), @@ -125,8 +126,8 @@ enum Art { /// A text file's, an RTF file's or a Word document's text, placed as area type filling the /// natural box. Text(text::Story), - /// A VectorCraft document or a PDF/.ai page placed linked: the file read, the link, and - /// whether the art's bounds (not the artboard or page) are shown. + /// A VectorCraft document, a PDF/.ai page or an EPS file placed linked: the file read, the + /// link, and whether the art's bounds (not the artboard or page) are shown. Document(document::Source, LinkInfo, bool), /// A DCS file: one linked image of its plates, clipped by its clipping path ([`dcs`]). Dcs(Box), @@ -158,6 +159,16 @@ struct Loaded { /// of its art, and their options. type Slices = Vec<(Rect, SliceOptions)>; +/// The most bytes [`head_is_dcs`] reads from the start of a file. +pub const DCS_HEAD_BYTES: usize = dcs::HEAD_BYTES; + +/// Does `head`, the start of a file `size` bytes long (at most [`DCS_HEAD_BYTES`] of it, or all of +/// it), name DCS plates? `file.place` places such a file as a linked image, never as a placed +/// document. `None` when `head` can't tell. +pub fn head_is_dcs(head: &[u8], size: u64) -> Option { + dcs::head_is_dcs(head, size) +} + /// Points per pixel of a raster image at the resolution it declares (72 ppi when none). pub(crate) fn pt_per_px(ppi: Option<(f64, f64)>) -> (f64, f64) { let (x, y) = ppi.unwrap_or((72.0, 72.0)); @@ -177,9 +188,9 @@ fn load_sliced(p: &Value, cmd: &str, board: Option, link_pdf: bool) -> Res } /// The file `p` names, read into placeable art; a DXF drawing's Fit to Artboard fills `board` -/// (unless the params name their own box). A PDF/.ai page read from a path is placed linked with -/// Link when `link_pdf` (false for the queries, which read it embedded). A PSD or PSB file's slices -/// go to `slices`. +/// (unless the params name their own box). A PDF/.ai page or an EPS file read from a path is placed +/// linked with Link when `link_pdf` (false for the queries, which read it embedded). A PSD or PSB +/// file's slices go to `slices`. fn load_into(p: &Value, cmd: &str, board: Option, link_pdf: bool, slices_out: &mut Slices) -> Result { let src = fileio::source(p, cmd)?; let name = fileio::file_name(src.name); @@ -324,6 +335,14 @@ fn load_into(p: &Value, cmd: &str, board: Option, link_pdf: bool, slices_o let art = Art::Vector { src: Box::new(a.doc), nodes: a.nodes, clip: a.clip }; return Ok(Loaded { name, format, art, natural: a.frame, warnings: a.warnings, link: None, board: None }); } + // An EPS file (or a PostScript .ai) with Link: placed like a PDF page, its art read as below. + if let Some(path) = src.path.filter(|_| link_pdf && bool_or(p, "link", true) && document::is_postscript(&src.bytes)) { + let page = page as u32; + let s = document::source(src.name, &src.bytes, Some(path), page, !crop, PageBox::Crop, cmd)?; + let link = LinkInfo { page: Some(page), ..super::links::link_info(path, &src.bytes) }; + let (natural, warnings) = (s.frame, s.warnings.clone()); + return Ok(Loaded { name, format, art: Art::Document(s, link.clone(), !crop), natural, warnings, link: Some(link), board: None }); + } let anchored = format.id == "dxf" && (opts.dxf.fit || !opts.dxf.center); let (mut doc, warnings) = { // Of the open options, only a DXF drawing's apply (the colour mode stays the file's). diff --git a/crates/engine/src/cmd/place/document.rs b/crates/engine/src/cmd/place/document.rs index 454f7302a8..31ab486a80 100644 --- a/crates/engine/src/cmd/place/document.rs +++ b/crates/engine/src/cmd/place/document.rs @@ -1,6 +1,6 @@ -//! Placed documents (`file.place` of a VectorCraft document, a PDF or a `.ai` file from a file, -//! with `link`): one locked object showing an artboard of the document or a page of the PDF, a -//! [`PlacedDocument`]. +//! Placed documents (`file.place` of a VectorCraft document, a PDF, a `.ai` file or an EPS file +//! from a file, with `link`): one locked object showing an artboard of the document, a page of the +//! PDF or the EPS file's art, a [`PlacedDocument`]. //! //! The object keeps the file's bytes (in the document's images, like image data) and the link; the //! art it shows is read from them the way placing the file without Link reads it @@ -33,6 +33,16 @@ pub(crate) const MAX_FILE: usize = 256 << 20; const NATIVE: [&str; 2] = ["vectorcraft", "template"]; /// The type a placed VectorCraft document's bytes are stored with (a PDF's: its format's). const MIME: &str = "application/json"; +/// The type a placed EPS or PostScript file's bytes are stored with. +pub(crate) const POSTSCRIPT: &str = "application/postscript"; +/// What follows the hash in the key of a placed PostScript `.ai` file ([`key_for`]). +const AI_MARK: &str = "-ai"; + +/// Is `key` (of a placed document) a PostScript `.ai` file's ([`AI_MARK`])? Hashes are hex, so +/// only the mark puts `-ai-` in a key. +pub(crate) fn is_postscript_ai_key(key: &str) -> bool { + key.contains(&format!("{AI_MARK}-")) +} /// Is `name` with `bytes` a VectorCraft document? pub(crate) fn is_native(name: &str, bytes: &[u8]) -> bool { @@ -44,6 +54,12 @@ pub(crate) fn is_pdf(name: &str, bytes: &[u8]) -> bool { fileio::detect(name, bytes).is_some_and(|f| matches!(f.id, "pdf" | "ai" | "ait")) && !vectorcraft_pdf::is_postscript(bytes) } +/// Is `bytes` an EPS file, a PostScript file or a PostScript `.ai` or `.ait` file, read by the EPS +/// importer (not a DCS file, which is placed as a linked image)? +pub(crate) fn is_postscript(bytes: &[u8]) -> bool { + vectorcraft_pdf::is_postscript(bytes) && !super::dcs::is_dcs(bytes) +} + /// The editing data of the `.ai` file `name` (`bytes`) when its PDF part is only a placeholder, or /// can't be read: /// the document its pages are read from ([`super::pdf_art`]), with the files it links. `None` for @@ -60,9 +76,12 @@ pub(crate) fn editing_data(name: &str, bytes: &[u8]) -> Option { } } -/// The type the bytes of placed file `name` (`bytes`) are stored with: a PDF's format's, else -/// [`MIME`]. +/// The type the bytes of placed file `name` (`bytes`) are stored with: a PDF's format's, +/// [`POSTSCRIPT`] for an EPS or PostScript file, else [`MIME`]. fn mime(name: &str, bytes: &[u8]) -> &'static str { + if is_postscript(bytes) { + return POSTSCRIPT; + } fileio::detect(name, bytes).filter(|_| is_pdf(name, bytes)).map_or(MIME, |f| f.mime) } @@ -108,7 +127,9 @@ pub(crate) struct DocumentArt { /// Artboard `page` (1-based) of the VectorCraft document `name` (`bytes`, read from `path` when /// there is one, so its linked images are found), clipped to the artboard unless `bounding`; or /// page `page` of the PDF or `.ai` file `name`, clipped to its box `page_box` unless `bounding` -/// ([`super::pdf_art`]). +/// ([`super::pdf_art`]); or the art of the EPS or PostScript file `name` ([`is_postscript`]) on +/// its page `page`, clipped to its bounding box unless `bounding`, as placing it without Link reads +/// it. pub(crate) fn document_art( name: &str, bytes: &[u8], @@ -135,7 +156,7 @@ fn opened_document_art( ) -> Result { let file = fileio::file_name(name); let pdf = is_pdf(name, bytes); - if !pdf && !is_native(name, bytes) { + if !pdf && !is_native(name, bytes) && !is_postscript(bytes) { return Err(bad(cmd, format!("`{file}` isn't a VectorCraft document, a PDF or a PDF-compatible .ai file"))); } if bytes.len() > MAX_FILE { @@ -145,6 +166,8 @@ fn opened_document_art( let o = fileio::LoadOptions { crop: crop_to(page_box), ..Default::default() }; return super::pdf_art(name, (bytes, opened), path, page as usize, o, bounding, cmd); } + // A VectorCraft document, or an EPS or PostScript file: the document our EPS files carry, else + // what its PostScript draws. let mut l = fileio::load(name, bytes)?; // Its linked images show their files; its placed documents stay as they are, unless their // stored bytes are lost, when resolving reads their files, which can place this one again. @@ -292,6 +315,10 @@ fn read_source( let hash = shared.map_or_else(|| hash_bytes(bytes), |f| f.hash.to_string()); let opened = shared.map(|f| f.opened); let shared = shared.map(|f| f.bytes); + // A PostScript `.ai` is read with the artboard its header gives, an EPS file on its page: the + // same bytes under the two names show different art, so they have keys of their own. + let ai = is_postscript(bytes) && fileio::detect(name, bytes).is_some_and(|f| matches!(f.id, "ai" | "ait")); + let hash = if ai { format!("{hash}{AI_MARK}") } else { hash }; // The same document placed the same way is read once (placing it again is free). let key = key_for(&hash, page, bounding, page_box); // Resolving its links depends on where the file is and on what the caller may read, so a hit diff --git a/crates/engine/src/tests/package.rs b/crates/engine/src/tests/package.rs index 218434eb8a..64d333df76 100644 --- a/crates/engine/src/tests/package.rs +++ b/crates/engine/src/tests/package.rs @@ -746,6 +746,87 @@ fn package_copies_a_linked_pdf_page_as_it_is() { assert!(s.doc().unwrap().doc.has_placed()); } +#[test] +fn package_copies_a_linked_eps_file_as_it_is() { + let dir = Folder::new("package-placed-eps"); + let eps = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 50\n%%EndComments\n1 0 0 setrgbcolor\nnewpath 0 0 moveto 100 0 lineto 100 50 lineto 0 50 lineto closepath fill\nshowpage\n%%EOF\n"; + let src = dir.file("art/seal.eps"); + write(&src, eps); + let mut s = session(); + let placed = run(&mut s, "file.place", json!({"path": src})); + assert_eq!(placed["linked"], true, "{placed}"); + save(&mut s, &dir.file("poster.vectorcraft")); + let r = run(&mut s, "file.package", json!({"folder": dir.file("out")})); + assert_eq!((r["links"].as_u64(), r["missingLinks"].clone(), r["warnings"].clone()), (Some(1), json!([]), json!([])), "{r}"); + let root = dir.0.join("out/poster Folder"); + assert_eq!(std::fs::read(root.join("Links/seal.eps")).unwrap(), eps, "copied as it is"); + // The packaged document shows the copy. + std::fs::remove_dir_all(dir.0.join("art")).unwrap(); + let opened = open(&mut s, &root.join("poster.vectorcraft").to_string_lossy()); + assert_eq!(opened["missingLinks"], json!([]), "{opened}"); + assert!(s.doc().unwrap().doc.has_placed()); +} + +#[test] +fn package_copies_a_linked_postscript_ai_file_the_document_holds_after_it_is_gone() { + let dir = Folder::new("package-placed-ps-ai"); + let ai = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 50\n%%EndComments\n0 0 1 setrgbcolor\nnewpath 0 0 moveto 100 0 lineto 100 50 lineto 0 50 lineto closepath fill\nshowpage\n%%EOF\n"; + let src = dir.file("art/badge.ai"); + write(&src, ai); + let mut s = session(); + let placed = run(&mut s, "file.place", json!({"path": src})); + assert_eq!(placed["linked"], true, "{placed}"); + save(&mut s, &dir.file("poster.vectorcraft")); + std::fs::remove_dir_all(dir.0.join("art")).unwrap(); + let r = run(&mut s, "file.package", json!({"folder": dir.file("out")})); + assert_eq!((r["links"].as_u64(), r["missingLinks"].clone()), (Some(1), json!([])), "{r}"); + let root = dir.0.join("out/poster Folder"); + assert_eq!(std::fs::read(root.join("Links/badge.ai")).unwrap(), ai, "the bytes the document holds"); +} + +/// The PostScript bytes a document holds are copied for a placed document whose file name is one +/// PostScript is read from, and not under any other name or for a linked image. +#[test] +fn package_copies_held_postscript_only_for_a_placed_document_with_a_postscript_name() { + let dir = Folder::new("package-placed-ps-names"); + let eps = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 50\n%%EndComments\n1 0 0 setrgbcolor\nnewpath 0 0 moveto 100 0 lineto 100 50 lineto 0 50 lineto closepath fill\nshowpage\n%%EOF\n"; + let ai = b"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 50\n%%EndComments\n0 0 1 setrgbcolor\nnewpath 0 0 moveto 100 0 lineto 100 50 lineto 0 50 lineto closepath fill\nshowpage\n%%EOF\n"; + write(&dir.file("art/seal.eps"), eps); + write(&dir.file("art/badge.ai"), ai); + write(&dir.file("art/logo.png"), &png(8, 8, RED)); + let mut s = session(); + let seal = run(&mut s, "file.place", json!({"path": dir.file("art/seal.eps")})); + assert_eq!(seal["linked"], true, "{seal}"); + let seal = vectorcraft_doc::NodeId(seal["ids"][0].as_u64().unwrap()); + run(&mut s, "file.place", json!({"path": dir.file("art/badge.ai")})); + let logo = place(&mut s, &dir.file("art/logo.png")); + let (tool, logo_ai) = (dir.file("art/tool.exe"), dir.file("art/logo.ai")); + s.edit("names", |d, _| { + let vectorcraft_doc::NodeKind::PlacedDocument(p) = &mut d.node_mut(seal).unwrap().kind else { panic!("not a placed document") }; + p.link.path = tool.clone(); + p.link.relative = None; + let vectorcraft_doc::NodeKind::Image(im) = &mut d.node_mut(logo).unwrap().kind else { panic!("not an image") }; + im.link.as_mut().unwrap().path = logo_ai.clone(); + im.link.as_mut().unwrap().relative = None; + let key = im.key.clone(); + d.images + .insert(key, vectorcraft_doc::ImageBlob { mime: "application/postscript".into(), bytes: std::sync::Arc::new(eps.to_vec()), proxy: None }); + Ok(()) + }) + .unwrap(); + save(&mut s, &dir.file("poster.vectorcraft")); + std::fs::remove_dir_all(dir.0.join("art")).unwrap(); + let r = run(&mut s, "file.package", json!({"folder": dir.file("out")})); + assert_eq!(r["links"].as_u64(), Some(1), "{r}"); + let mut missing: Vec<&str> = r["missingLinks"].as_array().unwrap().iter().filter_map(Value::as_str).collect(); + missing.sort_unstable(); + assert_eq!(missing, ["logo.ai", "tool.exe"], "{r}"); + let links = dir.0.join("out/poster Folder/Links"); + assert_eq!(std::fs::read(links.join("badge.ai")).unwrap(), ai, "a PostScript .ai under its own name"); + assert!(!links.join("tool.exe").exists(), "PostScript under a name it isn't read from"); + assert!(!links.join("logo.ai").exists(), "PostScript held for a linked image"); +} + #[test] fn package_copies_the_fonts_of_the_type_on_a_linked_pdf_page() { let dir = Folder::new("package-placed-pdf-type"); diff --git a/crates/engine/src/tests/placed_document.rs b/crates/engine/src/tests/placed_document.rs index 8c2d4a7e19..e1b4f6aad0 100644 --- a/crates/engine/src/tests/placed_document.rs +++ b/crates/engine/src/tests/placed_document.rs @@ -926,6 +926,190 @@ fn a_pdf_compatible_ai_file_places_linked_like_a_pdf() { assert_eq!(images, 0); } +/// An EPS file written by hand at `path`: a 100×50 bounding box holding a 40×20 rectangle of `rgb` +/// from (20, 10), and `extra` comment lines (which change the file's size). +fn eps_source(path: &str, rgb: [u8; 3], extra: usize) { + let [r, g, b] = rgb.map(|c| c as f64 / 255.0); + let mut ps = format!( + "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 50\n%%EndComments\n{r} {g} {b} setrgbcolor\nnewpath 20 10 moveto 60 10 lineto 60 30 lineto 20 30 lineto closepath fill\n" + ); + for i in 0..extra { + ps.push_str(&format!("% line {i}\n")); + } + ps.push_str("showpage\n%%EOF\n"); + write(path, ps.as_bytes()); +} + +/// An EPS file at `path` written by VectorCraft's EPS export: a 100×50 artboard filled with `rgb` +/// (`extra` more rectangles change the file's size). +fn exported_eps(path: &str, rgb: [u8; 3], extra: usize) { + let mut d = Document::new(100.0, 50.0); + let layer = d.layers[0].id; + for _ in 0..=extra { + let id = d.alloc_id(); + d.insert(Some(layer), usize::MAX, Node::path(id, shapes::rectangle(Rect::new(0.0, 0.0, 100.0, 50.0)), look(rgb))).unwrap(); + } + write(path, &cmd::fileio::encode_all(&d, "eps", &json!({})).unwrap().files[0].1); +} + +/// The kinds of `n` and everything inside it, in order. +fn kinds(n: &Node) -> Vec<&'static str> { + let mut k = vec![]; + n.walk(&mut |c| k.push(c.kind_label())); + k +} + +#[test] +fn with_link_an_eps_file_places_linked_framed_as_without_link() { + let dir = Folder::new("placed-eps-linked"); + let src = dir.file("badge.eps"); + eps_source(&src, RED, 0); + let mut s = session(); + let embedded = |s: &mut Session, crop: &str| { + let r = s.execute("file.place", &json!({"path": src, "link": false, "crop": crop, "at": [200, 150]})).unwrap(); + assert_eq!(r["linked"], false, "{r}"); + let n = s.doc().unwrap().doc.node(NodeId(r["ids"][0].as_u64().unwrap())).unwrap().clone(); + s.execute("edit.undo", &json!({})).unwrap(); + n + }; + let copy = embedded(&mut s, "crop"); + let id = place(&mut s, &src); + let p = placed(&s, id); + assert_eq!((p.link.path.as_str(), p.link.page, p.bounding), (src.as_str(), Some(1), false), "{p:?}"); + assert!((p.width - 100.0).abs() < 1e-6 && (p.height - 50.0).abs() < 1e-6, "{p:?}"); + assert_eq!(Some(bounds(&s, id)), copy.geometric_bounds(), "the bounding box, as without Link"); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED)); + let row = &s.execute("links.list", &json!({})).unwrap()["links"][0]; + assert_eq!((row["format"].as_str(), row["document"].as_bool(), row["status"].as_str()), (Some("EPS"), Some(true), Some("ok")), "{row}"); + assert_eq!(s.doc().unwrap().doc.images[&p.key].mime, "application/postscript"); + // Break Link gives the group placing it without Link gives. + let r = s.execute("links.embed", &json!({"ids": [id.0]})).unwrap(); + assert_eq!(r["embedded"], json!([id.0]), "{r}"); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + assert_eq!((kinds(&n), n.geometric_bounds()), (kinds(©), copy.geometric_bounds())); + assert!(!s.doc().unwrap().doc.has_placed() && near(centre_colour(&s.doc().unwrap().doc), RED)); + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("edit.undo", &json!({})).unwrap(); + // Bounding Box: the art's bounds, as without Link. + let copy = embedded(&mut s, "bounding"); + let r = s.execute("file.place", &json!({"path": src, "crop": "bounding", "at": [200, 150]})).unwrap(); + assert_eq!(r["linked"], true, "{r}"); + let id = NodeId(r["ids"][0].as_u64().unwrap()); + let p = placed(&s, id); + assert!(p.bounding && (p.width - 40.0).abs() < 1e-6 && (p.height - 20.0).abs() < 1e-6, "{p:?}"); + assert_eq!(Some(bounds(&s, id)), copy.geometric_bounds()); + // Object › Expand gives it too (the placed object is selected). + let r = s.execute("object.expand", &json!({})).unwrap(); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + assert_eq!((kinds(&n), n.geometric_bounds()), (kinds(©), copy.geometric_bounds()), "{r}"); + // Placed from its bytes, it is embedded. + let data = vectorcraft_format::base64_encode(&std::fs::read(&src).unwrap()); + let r = s.execute("file.place", &json!({"name": "badge.eps", "dataBase64": data})).unwrap(); + assert_eq!(r["linked"], false, "{r}"); +} + +#[test] +fn a_changed_eps_file_is_modified_and_update_links_reads_it_again() { + let dir = Folder::new("placed-eps-update"); + let src = dir.file("flyer.eps"); + exported_eps(&src, RED, 0); + let mut s = session(); + let id = place(&mut s, &src); + exported_eps(&src, BLUE, 1); + assert_eq!(s.execute("links.check", &json!({})).unwrap()["links"][0]["status"], "modified"); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED), "shows the file as it read it"); + let u = s.execute("links.update", &json!({})).unwrap(); + assert_eq!(u["updated"], json!([id.0]), "{u}"); + assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE)); + assert_eq!(s.execute("links.check", &json!({})).unwrap()["modified"], 0); + // Relinked to another EPS file, it shows that file's art. + let other = dir.file("other.eps"); + eps_source(&other, RED, 0); + let r = s.execute("links.relink", &json!({"ids": [id.0], "path": other})).unwrap(); + assert_eq!(r["relinked"], json!([id.0]), "{r}"); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED)); + // A file it can't show is refused. + let notes = dir.file("notes.txt"); + write(¬es, b"not a page"); + let e = s.execute("links.relink", &json!({"ids": [id.0], "path": notes})).unwrap_err().to_string(); + assert!(e.contains("isn't a VectorCraft document"), "{e}"); + assert_eq!(placed(&s, id).link.path, other); + // Its file replaced by one that isn't PostScript: updating keeps the art it shows. + write(&other, b"not a page"); + let _ = s.execute("links.update", &json!({})); + assert_eq!(placed(&s, id).link.path, other); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED)); +} + +#[test] +fn a_linked_eps_file_outputs_as_vectors_and_shows_its_preview_without_its_file() { + let dir = Folder::new("placed-eps-outputs"); + let src = dir.file("seal.eps"); + // Content of its own: files read are cached by content, and this one is removed. + eps_source(&src, RED, 3); + let bytes = std::fs::read(&src).unwrap(); + let mut s = session(); + let id = place(&mut s, &src); + let doc_path = dir.file("poster.vectorcraft"); + save(&mut s, &doc_path); + // Without its file: missing, shown and output as its preview, and not embedded. + std::fs::remove_file(&src).unwrap(); + open(&mut s, &doc_path); + let key = placed(&s, id).key; + assert!(s.doc().unwrap().doc.images[&key].is_proxy(), "opened with the preview only"); + let row = &s.execute("links.list", &json!({})).unwrap()["links"][0]; + assert_eq!((row["format"].as_str(), row["status"].as_str()), (Some("EPS"), Some("missing")), "{row}"); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED), "the preview"); + let pdf = s.execute("document.serialize", &json!({"format": "pdf"})).unwrap(); + assert!(pdf["warnings"].to_string().contains("1 placed document output as its preview"), "{}", pdf["warnings"]); + let r = s.execute("links.embed", &json!({"ids": [id.0]})).unwrap(); + assert_eq!((r["embedded"].clone(), r["missing"].clone()), (json!([]), json!([id.0])), "{r}"); + assert!(s.doc().unwrap().doc.has_placed()); + // The file back: output reads it again, its paths and not the preview. + write(&src, &bytes); + assert_eq!(s.execute("links.check", &json!({})).unwrap()["links"][0]["status"], "ok"); + let pdf = s.execute("document.serialize", &json!({"format": "pdf"})).unwrap(); + assert_eq!(pdf["warnings"], json!([]), "{}", pdf["warnings"]); + let (images, paths) = pdf_contents(&decode(&pdf)); + assert_eq!(images, 0, "no image in the PDF"); + assert!(paths > 0); + // Include Linked Files keeps the EPS file itself. + let full = file_json(&decode(&s.execute("document.serialize", &json!({"format": "vectorcraft", "includeLinked": true})).unwrap())); + assert_eq!((full["images"][&key]["proxy"].clone(), full["images"][&key]["mime"].as_str()), (Value::Null, Some("application/postscript"))); +} + +#[test] +fn a_postscript_ai_file_places_linked_like_an_eps_file() { + let dir = Folder::new("placed-ps-ai-linked"); + let src = dir.file("badge.ai"); + eps_source(&src, RED, 0); + let mut s = session(); + let id = place(&mut s, &src); + assert_eq!(placed(&s, id).link.path, src); + assert!(near(centre_colour(&s.doc().unwrap().doc), RED)); + let row = &s.execute("links.list", &json!({})).unwrap()["links"][0]; + assert_eq!(row["format"], "PostScript", "{row}"); + eps_source(&src, BLUE, 5); + let u = s.execute("links.update", &json!({})).unwrap(); + assert_eq!(u["updated"], json!([id.0]), "{u}"); + assert!(near(centre_colour(&s.doc().unwrap().doc), BLUE)); + // Saved with its preview only and reopened without its file, it is still listed as PostScript. + let bytes = std::fs::read(&src).unwrap(); + let doc_path = dir.file("poster.vectorcraft"); + save(&mut s, &doc_path); + std::fs::remove_file(&src).unwrap(); + open(&mut s, &doc_path); + assert!(s.doc().unwrap().doc.images[&placed(&s, id).key].is_proxy(), "opened with the preview only"); + let row = &s.execute("links.list", &json!({})).unwrap()["links"][0]; + assert_eq!((row["format"].as_str(), row["status"].as_str()), (Some("PostScript"), Some("missing")), "{row}"); + write(&src, &bytes); + // The same bytes named .eps are read as an EPS file: a file of their own, not the .ai's art. + let eps = dir.file("badge.eps"); + write(&eps, &std::fs::read(&src).unwrap()); + let other = place(&mut s, &eps); + assert_ne!(placed(&s, other).key, placed(&s, id).key); +} + #[test] fn a_placed_document_inside_a_placed_document_outputs_from_its_own_file() { let dir = Folder::new("placed-nested"); diff --git a/crates/ui-egui/src/place.rs b/crates/ui-egui/src/place.rs index 6485cafd8c..c87e906d4d 100644 --- a/crates/ui-egui/src/place.rs +++ b/crates/ui-egui/src/place.rs @@ -305,14 +305,36 @@ fn open_dialog(app: &mut VectorcraftApp, files: Vec) { } /// Is dialog file entry `file` a VectorCraft document on disk (what Link places as one locked -/// object), or a PDF or `.ai` file on disk? A `.ai` saved without PDF compatibility is PostScript, -/// which `file.place` embeds whether Link is on or not. +/// object), or a PDF, `.ai`, EPS or PostScript file on disk? A DCS file (an EPS file naming its +/// plates) is placed as a linked image instead. Where the platform reads part of a file, only the +/// file's start is read; a file longer than that is taken to be at least as long as its binary EPS +/// header says, and one whose header can't be told from it counts as a document. fn is_vectorcraft_file(app: &VectorcraftApp, file: &Value) -> bool { + use vectorcraft_engine::cmd::place::{DCS_HEAD_BYTES, head_is_dcs}; let Some(path) = file.get("path").and_then(Value::as_str) else { return false }; let native = ["vectorcraft", vectorcraft_format::LEGACY_EXTENSION, "vctemplate"]; + // The file's start, and the file's length when that is all of it. + let bytes = || match (&app.services.read_head, &app.services.read) { + (Some(read_head), _) => read_head(path, DCS_HEAD_BYTES + 1).ok().map(|mut b| { + let whole = b.len() <= DCS_HEAD_BYTES; + b.truncate(DCS_HEAD_BYTES); + let size = if whole { b.len() as u64 } else { u64::MAX }; + (b, size) + }), + (None, Some(read)) => read(path).ok().map(|b| { + let size = b.len() as u64; + (b, size) + }), + (None, None) => None, + }; + let dcs = |(b, size): &(Vec, u64)| { + let head = b.get(..DCS_HEAD_BYTES).unwrap_or(b); + vectorcraft_pdf::is_postscript(head) && head_is_dcs(head, *size).unwrap_or(false) + }; match fileio::extension(path).as_str() { e if native.contains(&e) => true, - "pdf" | "ai" | "ait" => app.services.read.as_ref().and_then(|r| r(path).ok()).is_none_or(|b| !vectorcraft_pdf::is_postscript(&b)), + "pdf" | "ai" | "ait" => bytes().is_none_or(|b| !dcs(&b)), + "eps" | "epsf" | "ps" => bytes().is_some_and(|b| vectorcraft_pdf::is_postscript(&b.0) && !dcs(&b)), _ => false, } } diff --git a/crates/ui-egui/src/tests/place.rs b/crates/ui-egui/src/tests/place.rs index 58af75a1d2..c0bdf16ea2 100644 --- a/crates/ui-egui/src/tests/place.rs +++ b/crates/ui-egui/src/tests/place.rs @@ -756,21 +756,61 @@ fn the_place_dialog_links_a_pdf_page_and_embeds_it_with_link_off() { } #[test] -fn the_place_dialog_does_not_offer_a_postscript_ai_as_a_locked_object() { +fn the_place_dialog_offers_a_postscript_ai_and_an_eps_file_as_a_locked_object() { let mut app = app(); let ps = b"%!PS-Adobe-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n1 0 0 setrgbcolor 10 10 50 50 rectfill\nshowpage\n%%EOF\n"; let dir = Folder::new("ui-place-postscript"); - let path = dir.file("legacy.ai", ps); - // file.place embeds a .ai saved without PDF compatibility, even with Link on. - let r = app.session.execute("file.place", &json!({"path": path, "link": true})).unwrap(); - assert_eq!(r["linked"], json!(false), "{r}"); - let st = app.session.active().unwrap(); - assert!(!matches!(st.doc.node(st.selection.objects[0]).unwrap().kind, NodeKind::PlacedDocument(_))); - // So Link's tooltip does not promise one locked object for it. + for name in ["legacy.ai", "legacy.eps", "legacy.ps"] { + let path = dir.file(name, ps); + // With Link, file.place places a .ai saved without PDF compatibility, an EPS file and a + // PostScript file as one locked placed document. + let r = app.session.execute("file.place", &json!({"path": path, "link": true})).unwrap(); + assert_eq!(r["linked"], json!(true), "{name}: {r}"); + let st = app.session.active().unwrap(); + assert!(matches!(st.doc.node(st.selection.objects[0]).unwrap().kind, NodeKind::PlacedDocument(_)), "{name}"); + // So Link's tooltip promises one locked object for it. + place_picked(&mut app, &path); + let d = app.ui.dialog.as_ref().expect("the Place dialog"); + assert!(d.bool("__documents") && !d.bool("__others"), "{name}: {:?}", d.fields); + assert!(crate::dialogs::place::link_tip(d).contains("locked object"), "{name}"); + app.ui.dialog = None; + } + // Where the platform reads part of a file, only the file's start is read to tell. + let asked = std::rc::Rc::new(std::cell::Cell::new(0)); + let seen = asked.clone(); + app.services.read_head = Some(Box::new(move |p: &str, max: usize| { + seen.set(max); + std::fs::read(p).map(|b| b[..b.len().min(max)].to_vec()).map_err(|e| e.to_string()) + })); + place_picked(&mut app, &dir.file("headed.eps", ps)); + assert!(app.ui.dialog.as_ref().expect("the Place dialog").bool("__documents")); + assert_eq!(asked.get(), vectorcraft_engine::cmd::place::DCS_HEAD_BYTES + 1); + app.ui.dialog = None; + // A DCS file is placed as a linked image, from its start alone too: past the start the + // PostScript goes on longer than what is read. + let mut dcs = b"%!PS-Adobe-2.0 EPSF-1.2\n%%BoundingBox: 0 0 20 10\n%%CyanPlate: pic.C\n%%EndComments\n".to_vec(); + dcs.resize(vectorcraft_engine::cmd::place::DCS_HEAD_BYTES + 100, b'\n'); + // The same PostScript behind a binary EPS header (no preview). + let mut binary = vec![0xC5, 0xD0, 0xD3, 0xC6]; + binary.extend(30u32.to_le_bytes()); + binary.extend((dcs.len() as u32).to_le_bytes()); + binary.resize(30, 0); + binary.extend(&dcs); + let files = [("plates.eps", &dcs, true), ("plates.ai", &dcs, true), ("binary.eps", &binary, true), ("binary.eps", &binary, false)]; + for (name, bytes, head) in files { + if !head { + app.services.read_head = None; + } + place_picked(&mut app, &dir.file(name, bytes)); + let d = app.ui.dialog.as_ref().expect("the Place dialog"); + assert!(!d.bool("__documents") && d.bool("__others"), "{name}, head {head}: {:?}", d.fields); + app.ui.dialog = None; + } + // A file named .eps that isn't PostScript gets the tooltip for other files. + let path = dir.file("notes.eps", b"not PostScript"); place_picked(&mut app, &path); let d = app.ui.dialog.as_ref().expect("the Place dialog"); assert!(!d.bool("__documents") && d.bool("__others"), "{:?}", d.fields); - assert!(!crate::dialogs::place::link_tip(d).contains("locked object")); } /// Tool key `key` as the Control bar's Apply (Enter) and Cancel (Escape) send it. diff --git a/docs/mcp.md b/docs/mcp.md index 7c45340f2b..4939de86ba 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -7452,7 +7452,9 @@ artboard `page` (or, with `crop: "bounding"`, its art's bounds), linked to the f (see Linked images), and vectors in every output; with `link: false` (or from `dataBase64`) it is an editable copy of its art, as one clipped group. A PDF, `.ai` or `.ait` page read from `path` (with neither `password` nor `textAs: "outlines"`) is a placed document the same way, showing page `page` clipped to its `crop` box (or its -art's bounds); with `link: false` it is placed as one clipped group. EPS and PostScript `.ai` files are embedded. `at` centres it, `rect` fits it, `replace` +art's bounds); with `link: false` it is placed as one clipped group. An EPS file, a PostScript file or a PostScript `.ai` read from `path` is a placed document +too, showing the art `link: false` places (clipped to its bounding box, or its art's bounds with `crop: "bounding"`); +with `link: false` or from `dataBase64` it is one group. `at` centres it, `rect` fits it, `replace` swaps the selected object (keeping its place and transform), `template` puts it on a new template layer. A DCS file (Desktop Color Separation, version 1.0 or 2.0: an EPS file whose header names one EPS program per printing plate, ) is placed only from its `path` with link, as one linked image @@ -8073,13 +8075,13 @@ that includes a placed document fails and relinks nothing; placed documents are files are. Find in Folder… in the Linked File Not Found dialog and in the Links panel menu (`ui.findLinksInFolder`) runs both. The web build has no folder search. -Placed documents (a `.vectorcraft` file, or a PDF or `.ai` page, placed linked) +Placed documents (a `.vectorcraft` file, a PDF or `.ai` page, or an EPS or PostScript file, placed linked) work the same way: the document keeps the file's bytes and a preview (JPEG or PNG, 1 px per point, at most 1024 px a side), and a save writes the preview (Include Linked Files: the file); output reads the file again, or uses the preview with a warning when it is gone or changed. `links.list` and `links.info` give them `document: true`, the file's `format` (`VectorCraft`, `PDF`, -`PDF-compatible .ai`) and the artboard's or page's `pageWidth` and `pageHeight` (pt). A relinked PDF shows the same -page and box of the new file. File › Package copies a placed PDF or `.ai` file as it is. For a `.ai` file read from +`PDF-compatible .ai`, `EPS`, `PostScript`) and the artboard's or page's `pageWidth` and `pageHeight` (pt). A relinked +PDF shows the same page and box of the new file. File › Package copies a placed PDF, `.ai` or EPS file as it is. For a `.ai` file read from its editing data, Package also copies the files its art places into the same folder. That file finds them by name, and Package warns when one is copied under another name: the copy then shows the file of that name, or its preview. Saving the file in the app updates the open documents that place it. `links.embed` (the Links panel's Break Link) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 423881e73c..bbddec5b39 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1984,7 +1984,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Affinity documents in (AF.1–AF.4): `.af` (Affinity 3) and `.afdesign`/`.afphoto`/`.afpub` (Affinity 1 and 2, container versions 8–12) open and place as editable art: layers and sublayers, groups (pass-through or isolated), artboards (with their names and backgrounds) and Publisher pages side by side, curves with live corners, parametric shapes (rectangles with corner radii, ellipses, polygons, stars, pies, triangles, trapezoids), compound shapes, solid/linear/elliptical gradient fills and strokes (weight, dashes, alignment, scale-with-object), clipping by nesting, vector and pixel masks, artistic and frame text with fonts, sizes, tracking, leading and alignment, placed images (their original JPEG/PNG) and pixel layers (8/16-bit RGB, CMYK), opacity, visibility, locking and blend modes, at the document's resolution in points. Effects, adjustments, brushes and pressure profiles, transparency gradients, master pages, symbol instances (imported as their cached picture), special shapes (cloud, heart, cog…, imported as ellipses) and Affinity-only blend modes are named in the import warning. A file whose native data can't be read opens as its embedded preview with the reason, and that preview can't be placed. Save never writes back over the Affinity file and there is no Affinity export. AF.5 (from DesignCraft's import, storytold/designcraft#291) adds master pages (on a locked layer behind the pages that show them), tables (area type per cell and a line per edge), each paragraph's alignment, indents, spacing and leading, horizontal text scale, outlined text, frame text sized by its text scale, drop shadows and outer glows as live effects (inner shadows as inner glows), outline effects as strokes, colour and gradient overlays baked into the paint, embedded Affinity documents as editable content (their artboards don't become artboards), pixel layers over 64 MP at a reduced resolution and HEIC photos from their stored pixels; automatic leading (size plus the font's line gap) fitted on thumbnails; underlines and strikethrough; strokes whose style is None (every shape stores one) left out, which also brings 6 public files closer to their thumbnails; line breaks inside a paragraph; table cell text centred as Affinity centres it, also where it is taller than its cell; CMYK pixel layers converted through the document's embedded CMYK profile (relative colorimetric with black-point compensation, as each layer's colour settings name), or kept as CMYK images when there is none; outline effects on stroked shapes around their stroke; artistic text whose paragraphs align differently aligned within its longest line, a frame's first baseline at cap height, and frames whose last lines' descenders hang out made tall enough to show them (all measured on a local document's own PDF export: baselines match to 0.1 pt); a local 56-artboard document's mean thumbnail difference went from 16.2 to 11.4, and its pages' mean difference from the owner's PDF export from 12.9 to 9.3. AF.4 adds Affinity 3 artboard recognition and actual-outline clipping, source-backed JPEG/PNG raster tiles, Unicode text-run recovery, stored fallback/exact installed fonts, OpenType feature flags and compound-geometry limits. 51 public CC0/MIT/Apache-2.0 files (33 current `.af`), pinned and sha256-verified (`cargo xtask corpus --affinity`), test native retention and every-board native/SVG/PDF/PSD output for current files; selected files compare their saved thumbnails. No Affinity reopen or independent paired PSD oracle was available; [source audit and complex-font gaps](affinity-validation.md); [scope, provenance and limits](../crates/affinity/README.md). - Placed documents: File › Place of a `.vectorcraft` file links to it by default (`file.place`'s `link`): one locked object showing an artboard of the document (or its art's bounds), read the way placing it without Link reads it, its symbols, patterns and images kept apart from the document's; without Link (or from bytes, not a file) it is an editable copy as before. It stays vectors in every output (SVG, PDF, EPS, EMF, DXF), and so do placed documents inside it, read from their own files up to 8 levels deep (documents that place each other stop there). On screen they draw from bitmaps cached per file and zoom step, shared by every copy and made in the background (a placeholder until ready), so a sheet of them redraws in about a millisecond; exports and prints draw them exactly. Like linked images, a save keeps only a preview of each (JPEG when opaque) unless Include Linked Files; output, and zooming past the preview, read the file again, falling back to the preview with a warning when it is gone or changed. Saves for older versions write them as plain art. Links check, update, relink, Update Links on open, Link Info (the artboard's size), Placement Options, Break Link (also Embed, Object › Expand: the editable copy placing without Link gives, its resources joining the document), Edit Original (the document in a new tab) and the Links panel cover them; saving a document updates the open documents that place it. The native format (v4) keeps data of 8 KB or more after the JSON instead of base64 in it. - Placed documents' bitmaps on screen: when a bitmap made in the background is ready, the desktop app renders the canvas again only where the objects that show its file are, when the frame shown was rendered on the UI thread and that part is at most half the canvas. Bitmaps drawn or made since a frame began are kept for that frame past the 512 MiB budget, up to 2 GiB, so a view showing more than the budget does not make them again in every frame. A bitmap that would take them past 2 GiB is not kept, and its file draws exactly at that zoom. A bitmap that can't be made (the file can't be read and there is no preview) shows the light placeholder and is not asked for again. Each ready bitmap used to render the whole canvas again, and bitmaps past the budget and bitmaps that could not be made were asked for again in every frame (`crates/render/src/tests/placed_document.rs`). - - Linked PDF and `.ai` pages: File › Place with Link (the default) places a page of a PDF, `.ai` or `.ait` file read as PDF pages as a placed document, as it links an image, the page and its box (`crop`) kept with the link: Links check, update and relink it, Break Link and Object › Expand give the group placing it without Link gives, every output draws the page's vectors, and Package copies the file. Without Link, or with a password or `textAs: "outlines"`, the page is embedded. EPS and PostScript `.ai` files are still embedded (`crates/engine/src/tests/placed_document.rs`). + - Linked PDF and `.ai` pages: File › Place with Link (the default) places a page of a PDF, `.ai` or `.ait` file read as PDF pages as a placed document, as it links an image, the page and its box (`crop`) kept with the link: Links check, update and relink it, Break Link and Object › Expand give the group placing it without Link gives, every output draws the page's vectors, and Package copies the file. Without Link, or with a password or `textAs: "outlines"`, the page is embedded. An EPS file, a PostScript file or a PostScript `.ai` placed from a file with Link is a placed document the same way, showing the art placing it without Link gives (clipped to its bounding box, or its art's bounds with `crop: "bounding"`); Links lists it as `EPS` or `PostScript`, and a save, Package, Break Link and Object › Expand treat it as they treat a placed PDF page. Placing one keeps the file linked rather than embedding it, as [the help page](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/eps-and-dcs-file-import-in-illustrator.html) describes; a DCS file stays a linked image (`crates/engine/src/tests/placed_document.rs`, `crates/engine/src/tests/package.rs`). - The place cursor keeps an encrypted PDF, `.ai` or `.ait` file, at a letter page's size (VectorCraft's own size) and without a thumbnail, and a click or drag on it asks for its password, with the Place dialog's Show Import Options on or off; such a file was left out of the cursor before (`crates/engine/src/tests/place.rs`, `crates/ui-egui/src/tests/place.rs`). - File › Place with Bounding Box (`file.place {crop: "bounding"}`) measures the art that shows, with its strokes and effects, as an export does: hidden objects, guides and template layers do not count, a group whose only part on the page or artboard is hidden is not placed, and symbol instances are measured by their art, for `at`, `rect`, the place cursor and `file.place.info` (`crates/engine/src/tests/place.rs`). - The Place dialog has a Show Import Options checkbox after Link, Template and Replace ([Place multiple files in a document](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/place-multiple-files-in-a-document.html)). On (VectorCraft's default, saved with the preferences), each PDF, DXF or text file asks for its import options before it is placed, also in the place cursor; off (`file.place {showImportOptions: false}`), it is placed with the options last confirmed for its format, and only an encrypted PDF asks, for its password. Text Import Options now starts from the options confirmed last (`crates/ui-egui/src/tests/place.rs`).