Repository navigation
Read Illustrator EPS and .ai layers from their editing data - #715
Conversation
An Illustrator EPS is a flattened page plus, after %%EOF, an editing copy of the document; a PDF-compatible .ai carries the same in its private data. Importing only the page lost layer names, order, visibility, hidden layers and hidden objects and hidden text. - eps: read the editing copy (Zstandard %AI24_DataStream, older zlib %AI9_DataStream) into layers, sublayers, groups, compound paths, clip groups and hidden objects, run by the existing PostScript interpreter. Falls back to the page, with a warning, when a shown layer uses an operator that isn't read or the art differs from the page by over 5%. - eps: read the text document (ate.rs) to place type on hidden layers and objects; the page's type is matched to the file's text objects by position (pieces of a line included) and kept with the nearest one when none claims it. Area type and type on a path are left out with a note. - pdf/engine: .ai files go through the same reader. - engine/cli: a file whose import left things out isn't overwritten unless asked (acknowledgeLoss, --replace-lossy). - eps: font names re-encoded with a *<n> suffix resolve to their family. - i18n: es/it/ru for the new import messages; ROADMAP updated. Container and text-document formats were inferred from user-owned files; the Adobe file format specification was not read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n't another object Some files write a text object twice, once plainly and once as comments (and others only as comments). Reading both made a second copy of the type, built from the text document, over the page's own (wrong size and place). The commented copy is now skipped when its story has a plain text object. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…aws in pieces as one text
- A PostScript font name's shortened style words (Md, Lt, Bd, XBd, Cn, It, ...)
weren't matched to installed faces, so AkzidenzGroteskPro-Md came in as
the condensed face. They are spelled out before the face is looked up.
- A line the page draws in pieces (around kerning) came in as several text
objects ("swe", "ep"); the pieces that add up to one line of the file's
text object now join into one, with the line's spaces between them.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The pieces joined into one text kept the layout cached for the first piece, so the selection box covered only that piece. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Type turned to outlines leaves its text object in the file, which the app that wrote it doesn't draw (it paints every shown text object on the page). A text object made from the file's text document that shows on the page's area where the page has no type, and without which the layers look no worse against the page, is left out, with a note. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… the wrappers Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… can't be read - a story is read once however many text objects name it; the text objects, their pairs with the page's type, the pieces of a line and a story's size are capped, and over a cap the layers aren't used - the ASCII85 of the text document is bounded before it is decoded - joining the pieces of lines that interleave no longer removes the wrong pieces - a run length too large for the text saturates instead of overflowing - a dictionary left open at the end of a layer, and layers nested deeper than are read, make the file one that comes in as its page (they were silently dropped) - a file whose editing data can't be decoded says so, and the notes about art that was too much or too far away count as losses, so writing over the source asks first - the private data of a .ai is inflated under a cap of its own (the PDF reader's decoder has none) - the other writers (PDF, selection, office, print) ask before replacing a source that lost things, and a recovered copy remembers that Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The engine refuses to write over the file a document was read from when
reading it left something out, unless acknowledgeLoss is passed. In the
app that surfaced as an error naming a parameter. File > Save, Save As,
Save a Copy, Save as Template and Export As now ask instead ("Replace
'a.eps', the file this document was opened from?", with what would be
lost), and OK repeats the command with acknowledgeLoss. Closing a
document whose save asks keeps it open, and so does Package.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @DisasterAreaDesigns, this is a big, careful piece of work: the hostile-input bounds, the page comparison as a safety net and the overwrite guard are exactly the right instincts for an importer. It's reviewed and passes full
One thing worth knowing: RGB colours ( It's still marked as a draft, so I haven't merged it. Is it ready from your side? If so, mark it ready for review (or tell me to) and I'll merge. |
|
Thank you for the review and for the four commits on top, @bflatastic. This is ready from my side: I've marked it ready for review. The Zstandard window cap and the confirmation dialog are both welcome. The RFC 8878 and operator notes are useful too; we only need compatibility with our daily EPS files, so I'm glad the RGB, gradient and image operators will be built on this reader. 🤖 Generated with Claude Code |
|
Merged, thanks @DisasterAreaDesigns! Layers, sublayers, nested groups and hidden objects now come back from the editing data, and the overwrite guard means nobody loses what an import couldn't read yet. The RGB, gradient and image work builds on this next; I'll link those PRs in #637. |
Read Illustrator EPS and .ai layers from their editing data
Closes #637 (first part: layers, visibility, hidden objects, text). Opened as discussed in the issue.
What it does
An Illustrator-saved
.epsis a flattened PostScript page followed by the editing copy of the art after%%EOF..aifiles carry the same copy in their PDF private data. Until now VectorCraft read only the flattened page, so layer names, order, visibility, hidden layers/objects and hidden text were lost on re-save.crates/eps/src/import/native.rsreads the editing copy (Zstandard%AI24_DataStream, zlib%AI9_DataStream), translates the drawing operators it understands into plain PostScript that the existing interpreter runs, one run per layer.ate.rsreads the text document (stories/frames, including hidden and off-page text).acknowledgeLoss; CLI--replace-lossy).family_stylealso expands abbreviated style words (Cn,Bd, …); the*<digits>suffix fix is a separate small PR.Why we're doing this
We aren't Illustrator power users, but we use EPS files every day (our printer only takes EPS). Interoperability and compatibility are what we care about here, not vector effects or filters: opening our files with their layers, hidden items and type intact, and saving them back without loss.
Clean-room statement
ruzstdcrate, theflate2crate (zlib), and the standard ASCII85 encoding (decoded by the project's existing code). The PostScript is run by the project's own interpreter.Untrusted input
EPS/AI files are untrusted. The reader is bounded and must not panic. Before opening this PR it was reviewed for hostile input and the findings were fixed:
MAX_DECODED256 MiB); the.aiprivate data is inflated under its own cap because the PDF reader'sdecoded()has none, and only plain or single-Flate streams are read;import_fuzz.rsfeeds truncated/corrupted/random data through import;lossy_overwrite.rscovers the overwrite guard on save, export, PDF, selection, office export and print; a crash-recovered copy keeps the guard.Results on our corpus (1,712 EPS files, our own artwork)
1,224 read with layers (210 of them have hidden type that can't be read yet, which the overwrite guard protects); 487 fall back to the page with a warning (mostly images and gradients); 1 fails in the existing page reader.
Known gaps
Area type and type on a path (come in as page text only), images/gradients in layers (page fallback), kerning/tracking,
Xytransparency.%AI9_DataStream) files still can't be decoded: they come in as their page with a warning (8 of our 1,712).Notes
ruzstd(MIT, pure Rust, builds for wasm32). Covered by the generic permissive-dependencies line in NOTICE.save_a_copy_and_template_suggest_their_names(expects/templates, gets/), fails here; it is about the Templates folder (New from Template… opens Documents/VectorCraft Templates and errors when that path is missing (non-English $HOME) #703) and nothing in this PR touches it, but I haven't confirmed it fails onmaintoo. Clippy fails onxtask/affinitywith my toolchain (rustc 1.99,chunks_exact_to_as_chunks), in code this PR doesn't touch.🤖 Generated with Claude Code