From 500f583110fcde5a2e7d6e79777cefb49d78de37 Mon Sep 17 00:00:00 2001 From: jmverges Date: Tue, 17 Nov 2026 06:56:24 +0000 Subject: [PATCH] .ai import: the reads of a file apart from its layers spend none of the layers' checks Besides the reader of its layers, a file whose layers come from its PDF part is read again over all of its data for its artboards (once more for the page scale), its variable library, its swatches, brushes, graphic styles and symbols. Each of those readers started with every envelope check (`MAX_CHECKED`) and every aligned-dash check (`MAX_DASH_CHECKS`) an import has, so such a file could draw several times the strokes the limit allows. - The artboard and variable-library readers start with no checks (`reader_aside`): neither depends on how a stroke or an envelope draws. - The swatch, brush, style and symbol readers, which need only what comes before the first layer, make no more checks once they reach it (`Reader::defs_only`). What they read is unchanged in files that write their definitions before their layers, as saved files do (symbols after the first layer aren't read at all). A pattern tile or brush art defined after the first layer is still read, without checks: it draws the same, and keeps its drawn art where it could have come in live. Definitions read before the layers (pattern tiles, brush art, symbols) are still checked by each of those readers within the limit. Test `the_reads_apart_from_the_layers_check_no_aligned_dashes`, which counts the checks made (`DASH_CHECKS_MADE`, in tests only). Co-Authored-By: Claude Opus 5.5 --- crates/eps/src/import/ai.rs | 2 ++ crates/eps/src/import/ai/envelope.rs | 7 ++++++ crates/eps/src/import/ai/read.rs | 5 +++++ crates/eps/src/import/ai/read/containers.rs | 3 +++ crates/eps/src/import/ai/read/document.rs | 18 +++++++++++++-- crates/eps/src/import/ai/read/ops.rs | 2 ++ crates/eps/src/import/tests_native.rs | 25 +++++++++++++++++++++ docs/file-format-parity.md | 2 +- 8 files changed, 61 insertions(+), 3 deletions(-) diff --git a/crates/eps/src/import/ai.rs b/crates/eps/src/import/ai.rs index 09f553ad2f..649b7fc096 100644 --- a/crates/eps/src/import/ai.rs +++ b/crates/eps/src/import/ai.rs @@ -36,6 +36,8 @@ use crate::ps; pub(crate) use blend::{MAX_BLEND_OBJECTS, MAX_KEYS as MAX_BLEND_KEYS, PLUGIN as BLEND_PLUGIN, blend_reads}; pub(crate) use brush::{BrushesRead, MANAGER_NAME as BRUSH_MANAGER, brushes_kept, plugin_name as brush_plugin_name, read_brush_object}; +#[cfg(test)] +pub(crate) use envelope::DASH_CHECKS_MADE; pub(crate) use envelope::DRAWN as ENVELOPE_DRAWN; pub(crate) use envelope::TYPE_DRAWN as ENVELOPE_TYPE_DRAWN; pub(crate) use envelope::{GridPoint as EnvelopeGridPoint, PLUGIN as DEFORM_PLUGIN, outline as envelope_outline, upright as envelope_upright}; diff --git a/crates/eps/src/import/ai/envelope.rs b/crates/eps/src/import/ai/envelope.rs index b70329ae11..6fc5fbad5d 100644 --- a/crates/eps/src/import/ai/envelope.rs +++ b/crates/eps/src/import/ai/envelope.rs @@ -62,6 +62,13 @@ pub(crate) const MAX_CHECKED: usize = 256; /// The most strokes with dashes aligned to corners one import draws to check against their drawn /// looks (apart from [`MAX_CHECKED`]); more keep their drawn looks. pub(crate) const MAX_DASH_CHECKS: usize = 256; + +#[cfg(test)] +thread_local! { + /// How many strokes with dashes aligned to corners have been drawn on this thread to check them + /// against their looks. + pub(crate) static DASH_CHECKS_MADE: std::cell::Cell = const { std::cell::Cell::new(0) }; +} /// The most rows or columns of a mesh read (Make with Mesh's own limit). const MAX_GRID: u32 = 50; /// How far, in points over width and height together, a saved size may lie from the contents' diff --git a/crates/eps/src/import/ai/read.rs b/crates/eps/src/import/ai/read.rs index 6c2071c0d0..3d4c3122e4 100644 --- a/crates/eps/src/import/ai/read.rs +++ b/crates/eps/src/import/ai/read.rs @@ -596,6 +596,10 @@ struct Reader<'a> { /// How many more strokes with dashes aligned to corners this import may draw to check /// ([`super::MAX_DASH_CHECKS`]). dash_checks: usize, + /// Whether this reader reads only what comes before the first layer (swatches, brushes, styles, + /// symbols) for a file whose layers another reader reads: it makes no more checks once it + /// reaches the layers, so it spends none of theirs. + defs_only: bool, /// The text objects read with a Warp ([`super::envelope::WarpedType`]). warped_type: Vec, /// The envelopes of type read with their drawn art, settled once the type is laid out @@ -826,6 +830,7 @@ impl<'a> Reader<'a> { envelope_checks: super::envelope::MAX_CHECKED, envelope_spent: super::envelope::Spent::default(), dash_checks: super::MAX_DASH_CHECKS, + defs_only: false, warped_type: Vec::new(), typed_envelopes: Vec::new(), envelopes_drawn: Vec::new(), diff --git a/crates/eps/src/import/ai/read/containers.rs b/crates/eps/src/import/ai/read/containers.rs index 9db1470093..7e0fe615d4 100644 --- a/crates/eps/src/import/ai/read/containers.rs +++ b/crates/eps/src/import/ai/read/containers.rs @@ -16,6 +16,9 @@ impl<'a> Reader<'a> { if matches!(kind, Kind::Layer(_)) { self.ensure_space(); self.check_symbols(); + if self.defs_only { + (self.envelope_checks, self.dash_checks) = (0, 0); + } } let base = if matches!(kind, Kind::Obj(_)) { self.stack.len() } else { self.frames.last().map_or(0, |f| f.base) }; self.frames.push(Frame { diff --git a/crates/eps/src/import/ai/read/document.rs b/crates/eps/src/import/ai/read/document.rs index 258d7d584b..5432cb554e 100644 --- a/crates/eps/src/import/ai/read/document.rs +++ b/crates/eps/src/import/ai/read/document.rs @@ -336,6 +336,7 @@ fn repoint(n: &mut Node, renamed: &std::collections::BTreeMap) { /// those the swatches take. pub fn palette(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) -> Option { let mut r = Reader::with_names(data, names.encoding); + r.defs_only = true; // The palette, the gradients and the patterns it names come before the art, so an error in the // art leaves them read. let _ = r.run(); @@ -396,6 +397,7 @@ pub fn brushes(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) -> // Brush objects are plug-in objects: data without one isn't read again. memchr::memmem::find(data, b"BeginPluginObject")?; let mut r = Reader::with_names(data, names.encoding); + r.defs_only = true; // The brushes come before the art, so an error in the art leaves them read. let _ = r.run(); let (mut lib, unread) = r.brush_library()?; @@ -449,6 +451,7 @@ pub fn graphic_styles(data: &[u8], large_canvas: bool, names: &mut obj::Names) - return (vec![], 1.0); } let mut r = Reader::with_names(data, names.encoding); + r.defs_only = true; r.large_canvas = large_canvas.then_some(1.0); // The styles come before the art, so an error in the art leaves them read. let _ = r.run(); @@ -482,6 +485,7 @@ pub struct Symbols { pub fn symbols(data: &[u8], names: &mut obj::Names) -> Option { crate::import::ai::find(data, b"BeginSymbol")?; let mut r = Reader::with_names(data, names.encoding); + r.defs_only = true; // The symbols come before the art, so an error in the art leaves them read. let _ = r.run(); r.check_symbols(); @@ -536,10 +540,20 @@ pub fn symbols(data: &[u8], names: &mut obj::Names) -> Option { Some(Symbols { symbols, images, swatches, canvas_scale: r.canvas_scale, own_size: r.symbols_own_size }) } +/// A reader of all of `data` for what doesn't depend on how its art draws (its artboards, its +/// variable library): it checks no envelope and no stroke with aligned dashes against its drawn +/// look, so it spends none of the import's checks ([`super::MAX_CHECKED`], +/// [`super::MAX_DASH_CHECKS`]), which are the layers' reader's. +fn reader_aside(data: &[u8]) -> Reader<'_> { + let mut r = Reader::new(data); + (r.envelope_checks, r.dash_checks) = (0, 0); + r +} + /// [`artboards`] as far as reading `data` from its start gets: those read before an error, and /// those of a `/Document` still open when it stopped (its art can be what stopped it). fn artboards_read(data: &[u8], names: &mut obj::Names) -> (Vec<(String, Rect)>, Option) { - let mut r = Reader::new(data); + let mut r = reader_aside(data); r.names = obj::Names::new(names.encoding); let _ = r.run(); let open: Vec = r.frames.iter().filter_map(|f| if let Kind::Obj(o) = &f.kind { Some((**o).clone()) } else { None }).collect(); @@ -608,7 +622,7 @@ pub fn variables(data: &[u8], names: &mut obj::Names) -> VariableRead { if crate::import::ai::find(data, b"variableSets").is_none() { return VariableRead::default(); } - let mut r = Reader::new(data); + let mut r = reader_aside(data); r.names = obj::Names::new(names.encoding); let _ = r.run(); if r.variables.present { diff --git a/crates/eps/src/import/ai/read/ops.rs b/crates/eps/src/import/ai/read/ops.rs index 60bf922c63..de7817062d 100644 --- a/crates/eps/src/import/ai/read/ops.rs +++ b/crates/eps/src/import/ai/read/ops.rs @@ -855,6 +855,8 @@ impl<'a> Reader<'a> { Some(ap) if aligns_dashes(&ap) => { let alike = self.dash_checks > 0 && { self.dash_checks -= 1; + #[cfg(test)] + crate::import::ai::DASH_CHECKS_MADE.set(crate::import::ai::DASH_CHECKS_MADE.get() + 1); let layer = self.doc.alloc_id(); let shared = crate::import::ai::envelope::Shared { patterns: &self.doc.patterns, images: &self.doc.images }; let mut spent = crate::import::ai::envelope::Spent::default(); diff --git a/crates/eps/src/import/tests_native.rs b/crates/eps/src/import/tests_native.rs index c88a071d42..27081f8b45 100644 --- a/crates/eps/src/import/tests_native.rs +++ b/crates/eps/src/import/tests_native.rs @@ -7289,6 +7289,31 @@ fn dashes_aligned_to_corners_past_their_checks_keep_the_look() { assert_eq!(looks, 1); } +/// The reads of a file apart from its layers check no stroke with dashes aligned to corners in its +/// layers against its look: the import's checks ([`crate::import::ai::MAX_DASH_CHECKS`]) are its +/// layers' reader's, though those reads go over all of the data. Its artboards and variable library +/// are read with no checks at all, and its swatches (and so its brushes, styles and symbols, read +/// the same way) with none once their reader reaches the layers. The layers' reader still checks +/// the one such stroke. +#[test] +fn the_reads_apart_from_the_layers_check_no_aligned_dashes() { + use vectorcraft_testkit::ai::{sample_variable_sets, variable_library_data}; + let library = variable_library_data(&sample_variable_sets("variableAndTypes", &[])); + let own = "%_0 0 0 1 0 0 0 XA\n%_2 w\n%_20 80 m\n%_80 80 L\n%_80 30 L\n%_S\n"; + let one = format!("u\n{}\nU\n9 () XW\n{own}1 (Dashed) XW\n", aligned_dash_look(true)); + let data = native(&(library + &aligned_dash_style() + &layer("Art", true, &one))); + let checks = |f: &dyn Fn()| { + crate::import::ai::DASH_CHECKS_MADE.set(0); + f(); + crate::import::ai::DASH_CHECKS_MADE.get() + }; + let names = crate::import::ai::Names::default; + assert_eq!(checks(&|| drop(crate::ai_alone(&private(&data)))), 1); + assert_eq!(checks(&|| drop(crate::import::ai::artboards(data.as_bytes(), &mut names()))), 0); + assert_eq!(checks(&|| assert!(crate::import::ai::variables(data.as_bytes(), &mut names()).present)), 0); + assert_eq!(checks(&|| drop(crate::import::ai::palette(data.as_bytes(), &[], &mut names()))), 0); +} + /// Type under a style with dashes aligned to corners keeps its drawn look, as before, and takes no /// such stroke: the look check isn't made for type. #[test] diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index ffd4342700..efb50988b3 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -361,7 +361,7 @@ Stop opacity on translated artboards remains outside this regression coverage. | Date | Change | Summary | |---|---|---| -| 2026-11-16 | minor | `.ai` and EPS import (#8196): a stroke from an art style with dashes aligned to corners and path ends (`BSDashAdj` in its dictionary) is read with `Dash::align_corners` instead of refused, and the object takes it where it draws as its drawn look (the check images with a Warp use, renamed `look_alike`), within 256 checks of its own per import that leave the envelopes' checks and share of the page check alone; elsewhere, past those checks and on type, the drawn look stays. The reason #1439 kept the look (the style's dash array doesn't hold the fitted pattern) still holds, hence the check. The check draws at min(400 / the longer side, 4) pixels per point with a threshold of 48 levels, so dots below a pixel on a long path can sit elsewhere and still pass. A Graphic Styles panel style with the switch now comes in with aligned dashes (no check: there is no look to compare with; before, the style was left out), and a stroke with the switch and no dash array comes in as a solid stroke. Before, every such object came in as its drawn look. In 200 garment files we own (used locally, never committed), such objects come in live in 12 files (23 fewer objects kept as their drawn look), and in another 224 in 23 files (78 fewer); one file whose dots VectorCraft fits elsewhere keeps its look; no file opens another way, no live envelope comes or goes, and no render changes by more than 0.005% of its pixels past the threshold. Tests `dashes_aligned_to_corners_that_draw_as_the_look_come_in_live`, `dashes_aligned_to_corners_that_draw_apart_from_the_look_keep_it`, `dashes_aligned_to_corners_past_their_checks_keep_the_look`, `type_with_dashes_aligned_to_corners_keeps_its_drawn_look` in `crates/eps/src/import/tests_native.rs`, `a_stroke_offset_with_dashes_aligned_to_corners_unlike_its_look_keeps_the_look` in `crates/eps/src/import/ai/tests.rs` and `dashes_aligned_to_corners_read_as_aligned_dashes` in `crates/eps/src/import/ai/style/tests.rs`. Scores and estimates unchanged. | +| 2026-11-16 | minor | `.ai` and EPS import (#8196): a stroke from an art style with dashes aligned to corners and path ends (`BSDashAdj` in its dictionary) is read with `Dash::align_corners` instead of refused, and the object takes it where it draws as its drawn look (the check images with a Warp use, renamed `look_alike`), within 256 checks of its own per import that leave the envelopes' checks and share of the page check alone; elsewhere, past those checks and on type, the drawn look stays. The reason #1439 kept the look (the style's dash array doesn't hold the fitted pattern) still holds, hence the check. The check draws at min(400 / the longer side, 4) pixels per point with a threshold of 48 levels, so dots below a pixel on a long path can sit elsewhere and still pass. A Graphic Styles panel style with the switch now comes in with aligned dashes (no check: there is no look to compare with; before, the style was left out), and a stroke with the switch and no dash array comes in as a solid stroke. Before, every such object came in as its drawn look. In 200 garment files we own (used locally, never committed), such objects come in live in 12 files (23 fewer objects kept as their drawn look), and in another 224 in 23 files (78 fewer); one file whose dots VectorCraft fits elsewhere keeps its look; no file opens another way, no live envelope comes or goes, and no render changes by more than 0.005% of its pixels past the threshold. Tests `dashes_aligned_to_corners_that_draw_as_the_look_come_in_live`, `dashes_aligned_to_corners_that_draw_apart_from_the_look_keep_it`, `dashes_aligned_to_corners_past_their_checks_keep_the_look`, `the_reads_apart_from_the_layers_check_no_aligned_dashes`, `type_with_dashes_aligned_to_corners_keeps_its_drawn_look` in `crates/eps/src/import/tests_native.rs`, `a_stroke_offset_with_dashes_aligned_to_corners_unlike_its_look_keeps_the_look` in `crates/eps/src/import/ai/tests.rs` and `dashes_aligned_to_corners_read_as_aligned_dashes` in `crates/eps/src/import/ai/style/tests.rs`. Scores and estimates unchanged. | | 2026-11-15 | minor | PDF import: stroked type (text rendering modes 1, 2, 5 and 6, and glyphs under `ActualText`) came in with butt caps, miter joins and a miter limit of 10 whatever the file stroked it with, while paths kept the graphics state's. The characters' stroke now takes the line cap (`J`), line join (`j`) and miter limit (`M`) of the graphics state, as a path's stroke does, and glyphs stroked with other ones start a run of their own, also a glyph filled and then stroked otherwise than the run its fill joined, so the glyphs before it keep their stroke (#7741). Test `imported_stroked_type_keeps_the_files_cap_join_and_miter_limit` in `crates/pdf/src/tests/textstroke.rs`. Scores and estimates unchanged. | | 2026-11-13 | minor | `.ai` and EPS import: layers that don't draw as the page, even with the drawn art of every live envelope put back, no longer put back the drawn art of every envelope of type. Each live envelope of type is weighed in the page check's own drawing of the pages it lies on, on the pixels that it and its drawn art ink there (the two drawn together on a layer of their own, without the rest of the layers; a pixel inks with an alpha above 8 of 255): it keeps its drawn art and its type, hidden, with the note, where the layers with it differ from the page in more of those pixels than its own check allows against its drawn art (10% of them, or 3% differing with all their neighbours, away from type), or where the envelopes of type that stay live, in the order they were read, would together differ there in more of a page than half of what the page check allows (a budget of the same size as the one their own checks share, kept apart from it). Art that differs elsewhere on the page no longer costs them their editable type; art that differs on their pixels still does. An envelope of type that a clip group or a clipping sublayer clips, an opacity mask masks, or a group with an appearance of its own, another envelope, a repeat or a blend holds keeps its drawn art as before, wherever it lies: drawn on its own it would be weighed elsewhere than it draws, and what holds it can draw it onto the page from off it. An envelope on no page stays live, as the page check doesn't see it, unless the page holds all the art that prints (an EPS's page that is its art's box, where art past the page is compared too): there one reaching past the page keeps its drawn art. Past 12 of them on the pages, all keep it. This holds where the editing data is trusted, where the objects that differ come in as the page's art (the placed files' other placement weighed on its own, as it draws them elsewhere under or over the envelopes; layers that draw as the page with only the envelopes the page holds put back are used as they are; where none of the objects that differ can then come in as the page's art, because an object holds type, the drawn art of every envelope of type is put back and that is tried again, as before), and for a `.ai` whose layers would open alone, which still opens alone: its envelopes of type are all settled again as they were with the page, in the same order and with the same checks, so each that opens live draws as it was weighed, and those the page held get their drawn art back. Where putting the drawn art of every live envelope back makes the layers draw as the page, it is still put back (#5065). In 224 users' files (used locally, never committed): envelopes of type that open live go from 174 to 186, in 8 files, none fewer in any file; no file changes between its layers and its PDF part; 7 renders change, by at most 0.7% of their pixels at 40 ppi (1 closer to the page, 1 alike, 5 further, by at most 0.7 of a percentage point, where VectorCraft's own envelope draws a little apart from the drawn art, within its check); the note for type in an envelope goes from 6 files. Of the 14 envelopes of type that had opened live and lost it to the page check, 2 keep their drawn art: one where the page draws something else where it is, and one in a file that comes in as its PDF part (#7141). Tests `build::candidate_tests::the_page_holds_back_only_envelopes_of_type_where_it_differs_from_them`, `envelopes_of_type_stay_live_within_half_of_what_the_page_check_allows`, `an_envelope_of_type_differing_in_more_of_its_pixels_than_its_check_allows_is_held_back`, `envelopes_of_type_the_layers_dont_draw_in_place_are_held_back`, `on_a_page_that_holds_all_the_art_an_envelope_of_type_past_it_is_held_back`, `objects_come_in_as_the_page_art_with_every_envelope_of_type_put_back_where_a_live_one_holds_a_difference`, `tests_native::layers_that_would_open_alone_keep_an_envelope_of_type_live_where_other_art_differs_from_the_page`, `layers_that_would_open_alone_keep_live_only_the_envelopes_of_type_the_page_doesnt_hold`, `trusted_layers_that_would_open_alone_open_alone_with_an_envelope_of_type_the_page_doesnt_hold_live`, `layers_with_objects_that_come_in_as_the_page_art_keep_an_envelope_of_type_that_draws_as_the_page_live`, `trusted_layers_keep_an_envelope_of_type_live_where_other_art_differs_from_the_page`, `trusted_layers_leave_an_envelope_of_type_the_page_draws_otherwise_its_drawn_art`, `build::candidate_tests::the_other_placement_of_placed_files_is_weighed_on_its_own`, `layers_that_draw_as_the_page_with_the_held_envelopes_of_type_put_back_are_used_so` | | 2026-11-13 | minor | PDF import: glyphs inside a marked-content span with an empty `ActualText` come in as outlines in their fill and stroke instead of being left out, adding no text (#6971; `empty_actual_text_keeps_the_glyphs_art` in `crates/pdf/src/tests/actual_text.rs`). Scores and estimates unchanged. |