Skip to content

Read Illustrator EPS and .ai layers from their editing data - #715

Merged
bflatastic merged 15 commits into
storytold:mainfrom
DisasterAreaDesigns:eps-editing-data-pr
Oct 9, 2026
Merged

bflatastic merged 15 commits into
storytold:mainfrom
DisasterAreaDesigns:eps-editing-data-pr

Conversation

@DisasterAreaDesigns

Copy link
Copy Markdown
Contributor

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 .eps is a flattened PostScript page followed by the editing copy of the art after %%EOF. .ai files 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.rs reads 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.rs reads the text document (stories/frames, including hidden and off-page text).
  • Text objects are matched to the page's own type by letters, baseline and position; type the page draws in pieces is joined; outlined type that leaves an undrawn stub is left out.
  • Every import is compared against the flattened page. More than 5% difference → fall back to the page with a warning; more than 0.2% → imported with a note.
  • Overwrite guard: re-saving over a source file whose import left things out is refused unless the user confirms (acknowledgeLoss; CLI --replace-lossy).
  • family_style also 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

  • Everything about the format was learned only from files we own or have the right to use (our own Illustrator-saved artwork), by reading them.
  • No Adobe software was run or inspected, no Adobe SDK was used, and no Adobe specification was read.
  • No Adobe or GPL/AGPL code was read or translated. The only references are permissively licensed or public standards: RFC 8878 (Zstandard), the MIT-licensed ruzstd crate, the flate2 crate (zlib), and the standard ASCII85 encoding (decoded by the project's existing code). The PostScript is run by the project's own interpreter.
  • No real files are committed. All tests use small synthetic inputs written by hand.

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:

  • decompression is capped while streaming (Zstandard and zlib, MAX_DECODED 256 MiB); the .ai private data is inflated under its own cap because the PDF reader's decoded() has none, and only plain or single-Flate streams are read;
  • the text document: ASCII85 input is bounded before decoding, nesting depth 64, value budget 4M, a story is limited to 1 MiB and read once however many text objects name it, total text and the number of text objects/pairs compared are capped (over a cap the layers aren't used);
  • layers: at most 4096, nested at most 32 deep; a dictionary left open or deeper nesting makes the file come in as its page rather than silently dropping content;
  • malformed data → the page as the fallback plus a visible warning saying why, never a crash; import_fuzz.rs feeds truncated/corrupted/random data through import;
  • lossy_overwrite.rs covers 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, Xy transparency.

  • Type turned to outlines leaves an undrawn text stub in the file; those are left out when the page doesn't draw them (with a note). That isn't counted as a loss, or every file with outlined type would ask before being saved over.
  • Some older-format (zlib %AI9_DataStream) files still can't be decoded: they come in as their page with a warning (8 of our 1,712).

Notes

  • New dependency: ruzstd (MIT, pure Rust, builds for wasm32). Covered by the generic permissive-dependencies line in NOTICE.
  • New user-visible messages have es/fr/it/ru rows.
  • Locally: fmt, brands, layers and the tests of the eps, pdf, engine crates and the i18n completeness test pass. One ui-egui test, 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 on main too. Clippy fails on xtask/affinity with my toolchain (rustc 1.99, chunks_exact_to_as_chunks), in code this PR doesn't touch.

🤖 Generated with Claude Code

DisasterAreaDesigns and others added 10 commits October 9, 2026 03:49
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>
bflatastic and others added 5 commits October 9, 2026 14:57
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>
@bflatastic

Copy link
Copy Markdown
Member

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 cargo xtask ci merged with current main. I pushed four small commits on top of yours (your commits are untouched):

  • Zstandard window cap: unzstd now uses StreamingDecoder::new_with_max_window_size (64 MB, as the Affinity reader does). A hostile frame header could otherwise make the decoder allocate a huge window before the 256 MB output cap applies.
  • A confirmation for the overwrite guard in the app: in the UI the refusal surfaced as an error telling the user to "pass acknowledgeLoss: true". File › Save, Save As, Save a Copy, Save as Template and Export As now ask "Replace "a.eps", the file this document was opened from?", say what would be lost, and OK repeats the save with acknowledgeLoss. Closing a document (or Package) whose save asks keeps the document open. There's a test in tests_save.rs, and the texts are translated into every complete language.
  • French: "calque" rather than "couche" for a layer, matching the rest of the French UI.
  • Clippy: nonminimal_bool on the 1.96 toolchain (is_none_or instead of !is_some_and(!…)).

One thing worth knowing: RGB colours (Xa/XA), gradients (Bb/Bg/Bm/BB) and embedded images (XI) aren't in the operator list yet, so RGB documents, the default document type, all come in as their page with the "layers use …" warning. We have reader work for those operators (plus Xy opacity and blend, XR even-odd, names, lock and layer options, multiple artboards) and will build it on top of your PR once it's in, keeping your guard, page comparison and text matching.

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.

@DisasterAreaDesigns
DisasterAreaDesigns marked this pull request as ready for review October 9, 2026 08:21
@DisasterAreaDesigns

Copy link
Copy Markdown
Contributor Author

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

@bflatastic
bflatastic merged commit be47c41 into storytold:main Oct 9, 2026
3 checks passed
@bflatastic

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Illustrator EPS and .ai import: read layers, hidden objects and hidden text from the editing data

2 participants