From 046d4e67ff9facec11717a0de46dc043edbac7f1 Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Fri, 6 Nov 2026 20:50:28 -0500 Subject: [PATCH] EPS import: shadings not extended paint only between their ends shfill filled the whole clip with an axial or radial shading whatever its Extend. Without Extend (the default, PLRM 3rd ed. section 4.9.3) an axial shading now paints only between the lines through its ends across its axis, and a radial shading from a point only over its circles. --- crates/eps/src/import/graphics/ops.rs | 16 +++- crates/eps/src/import/graphics/paint.rs | 111 ++++++++++++++++++++++ crates/eps/src/import/tests_generators.rs | 28 ++++++ docs/file-format-parity.md | 5 +- 4 files changed, 155 insertions(+), 5 deletions(-) diff --git a/crates/eps/src/import/graphics/ops.rs b/crates/eps/src/import/graphics/ops.rs index 78a214b410..01731807d8 100644 --- a/crates/eps/src/import/graphics/ops.rs +++ b/crates/eps/src/import/graphics/ops.rs @@ -1,4 +1,4 @@ -use super::paint::is_mesh; +use super::paint::{is_mesh, polygon, shading_extent}; use super::state::{GState, Space}; use super::{ Affine, Color, FillRule, Interp, Key, LineCap, LineJoin, MAX_DASH_ENTRIES, MAX_DASHES, MAX_GSAVE, MAX_PATH, Obj, Op, Paint, Point, PsError, Rc, @@ -531,10 +531,20 @@ impl Interp<'_> { let m = self.xf(); if let Some(g) = self.gradient(&d, m)? { let area = self.clip_bounds()?; + // Not extended, it paints only between its ends. + let extent = shading_extent(&d, m, area); + let path = match &extent { + Some(pts) if pts.len() < 3 => return Ok(()), + Some(pts) => polygon(pts), + None => area.to_path(0.1), + }; let paint = Paint::Gradient(Box::new(g)); let clips = self.g.clips.clone(); - self.out.fill(area.to_path(0.1), FillRule::NonZero, paint, self.g.overprint, &clips); - if let Some((_, n)) = self.out.drawn.last() { + self.out.fill(path, FillRule::NonZero, paint, self.g.overprint, &clips); + // Only a fill of the whole clip can stand in for the clip's shape. + if extent.is_none() + && let Some((_, n)) = self.out.drawn.last() + { let id = n.id; self.out.shadings.insert(id); } diff --git a/crates/eps/src/import/graphics/paint.rs b/crates/eps/src/import/graphics/paint.rs index 8b0a729eef..d0f8cb6788 100644 --- a/crates/eps/src/import/graphics/paint.rs +++ b/crates/eps/src/import/graphics/paint.rs @@ -429,6 +429,117 @@ fn is_gradient(sh: &DictRef) -> bool { matches!(sh.borrow().get(&Key::name("ShadingType")).and_then(Obj::as_num), Some(2.0 | 3.0)) } +/// The part of `area` (in the document) that axial or radial shading `sh`, mapped into the +/// document by `m`, paints, as a convex polygon; `None` when it paints all of it. Without +/// `Extend` an axial shading paints only between the lines through its ends across its axis, and +/// a radial one only over its circles (PLRM 3rd ed. §4.9.3, shading types 2 and 3: `Extend` +/// defaults to `[false false]`). A radial shading extended at one end only, or starting from a +/// circle with a radius, is not bounded here (it paints all of `area`). +pub(super) fn shading_extent(sh: &DictRef, m: Affine, area: Rect) -> Option> { + let d = sh.borrow(); + let nums = |k: &str| -> Vec { + d.get(&Key::name(k)).and_then(Obj::items).map(|i| i.borrow().iter().filter_map(Obj::as_num).collect()).unwrap_or_default() + }; + let extend: Vec = d + .get(&Key::name("Extend")) + .and_then(Obj::items) + .map(|i| i.borrow().iter().map(|o| matches!(o, Obj::Bool(true))).collect()) + .unwrap_or_default(); + let (e0, e1) = (extend.first().copied().unwrap_or(false), extend.get(1).copied().unwrap_or(false)); + if (e0 && e1) || m.determinant().abs() < 1e-12 || !m.as_coeffs().iter().all(|v| v.is_finite()) { + return None; + } + let inv = m.inverse(); + // `area` in the shading's own space, where its axis and circles are. + let mut poly: Vec = + [(area.x0, area.y0), (area.x1, area.y0), (area.x1, area.y1), (area.x0, area.y1)].map(|(x, y)| inv * Point::new(x, y)).to_vec(); + let c = nums("Coords"); + let at = |i: usize| c.get(i).copied().filter(|v| v.is_finite()).unwrap_or(0.0); + match d.get(&Key::name("ShadingType")).and_then(Obj::as_num) { + Some(2.0) => { + let (p0, p1) = (Point::new(at(0), at(1)), Point::new(at(2), at(3))); + let axis = p1 - p0; + if axis.hypot2() < 1e-18 { + return None; + } + if !e0 { + poly = clip_half(&poly, |p| (p - p0).dot(axis)); + } + if !e1 { + poly = clip_half(&poly, |p| (p1 - p).dot(axis)); + } + } + Some(3.0) if !e0 && !e1 && at(2) <= 0.0 && at(5) > 0.0 => { + // The circles from a point to a circle cover the hull of that point and circle. + let (p0, c1, r1) = (Point::new(at(0), at(1)), Point::new(at(3), at(4)), at(5)); + let ring: Vec = (0..64).map(|i| c1 + Vec2::from_angle(i as f64 * std::f64::consts::TAU / 64.0) * r1).collect(); + for edge in hull(&[ring, vec![p0]].concat()).windows(2) { + if let [a, b] = edge { + let (a, b) = (*a, *b); + poly = clip_half(&poly, |p| (b - a).cross(p - a)); + } + } + } + _ => return None, + } + Some(poly.into_iter().map(|p| m * p).collect()) +} + +/// Convex polygon `poly` cut to where `f` (a linear function) is zero or more. +fn clip_half(poly: &[Point], f: impl Fn(Point) -> f64) -> Vec { + let mut out = Vec::with_capacity(poly.len() + 1); + for (i, &a) in poly.iter().enumerate() { + let Some(&b) = poly.get((i + 1) % poly.len()) else { continue }; + let (fa, fb) = (f(a), f(b)); + if fa >= 0.0 { + out.push(a); + } + if (fa >= 0.0) != (fb >= 0.0) { + out.push(a.lerp(b, fa / (fa - fb))); + } + } + out +} + +/// The convex hull of `pts`, counter-clockwise, its first point repeated at the end. +fn hull(pts: &[Point]) -> Vec { + let mut p = pts.to_vec(); + p.sort_by(|a, b| a.x.total_cmp(&b.x).then(a.y.total_cmp(&b.y))); + let mut h: Vec = Vec::with_capacity(p.len() * 2); + let turn = |h: &[Point], q: Point| match h { + [.., a, b] => (*b - *a).cross(q - *a) <= 0.0, + _ => false, + }; + for &q in &p { + while turn(&h, q) { + h.pop(); + } + h.push(q); + } + let lower = h.len() + 1; + for &q in p.iter().rev().skip(1) { + while h.len() >= lower && turn(&h, q) { + h.pop(); + } + h.push(q); + } + h +} + +/// A closed path through `pts`. +pub(super) fn polygon(pts: &[Point]) -> kurbo::BezPath { + let mut bp = kurbo::BezPath::new(); + for (i, p) in pts.iter().enumerate() { + if i == 0 { + bp.move_to(*p); + } else { + bp.line_to(*p); + } + } + bp.close_path(); + bp +} + /// Is shading `sh` one [`Interp::mesh_fill`] paints? pub(super) fn is_mesh(sh: &DictRef) -> bool { matches!(sh.borrow().get(&Key::name("ShadingType")).and_then(Obj::as_num), Some(1.0 | 4.0 | 5.0 | 6.0 | 7.0)) diff --git a/crates/eps/src/import/tests_generators.rs b/crates/eps/src/import/tests_generators.rs index 4337b9474c..75e4fd5d3d 100644 --- a/crates/eps/src/import/tests_generators.rs +++ b/crates/eps/src/import/tests_generators.rs @@ -1141,3 +1141,31 @@ fn filter_output_counts_against_the_memory_budget() { let Err(err) = many else { panic!("the budget ends the program") }; assert!(err.contains("too much memory"), "{err}"); } + +/// A shading painted with `shfill` and not extended paints only between its ends: an axial one +/// between the lines through them across its axis, a radial one from a point over its circles +/// (PLRM 3rd ed. §4.9.3: `Extend` is `[false false]` by default). Extended both ways it paints +/// the whole clip. +#[test] +fn shadings_not_extended_paint_only_between_their_ends() { + let shade = |kind: u8, coords: &str, extend: &str| { + let r = read(&format!( + "<< /ShadingType {kind} /ColorSpace /DeviceRGB /Coords [{coords}] {extend} \ + /Function << /FunctionType 2 /Domain [0 1] /C0 [1 0 0] /C1 [0 0 1] /N 1 >> >> shfill" + )); + let n = all(&r.document).into_iter().find(|n| matches!(fill(n), Some(Paint::Gradient(_)))).expect("a gradient fill"); + bounds(&n) + }; + // Axial, from x 10 to 90 (and its reflection in y: the document's y runs down). + let b = shade(2, "10 0 90 0", ""); + assert!(near(b, Rect::new(10.0, 0.0, 90.0, 100.0)), "{b:?}"); + let b = shade(2, "10 0 90 0", "/Extend [false true]"); + assert!(near(b, Rect::new(10.0, 0.0, 100.0, 100.0)), "{b:?}"); + let b = shade(2, "10 0 90 0", "/Extend [true true]"); + assert!(near(b, Rect::new(0.0, 0.0, 100.0, 100.0)), "{b:?}"); + // Radial from the centre point to a circle of radius 30. + let b = shade(3, "50 50 0 50 50 30", ""); + assert!((b.width() - 60.0).abs() < 0.5 && (b.height() - 60.0).abs() < 0.5 && (b.center().x - 50.0).abs() < 0.5, "{b:?}"); + let b = shade(3, "50 50 0 50 50 30", "/Extend [true true]"); + assert!(near(b, Rect::new(0.0, 0.0, 100.0, 100.0)), "{b:?}"); +} diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index d3e2f03031..f3484484c4 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-06 · **Change:** minor (SVG import: filter and mask regions clip, #5876, #5875; SVG import: Gaussian blurs keep `color-interpolation-filters`, #5877; PDF and `.ai` export: objects' URLs as links, #5785; SVG import: `color-interpolation="linearRGB"` gradients, #5878; `.ai` import: paths with a Calligraphic brush open brushed, #372) · **Target:** Adobe Illustrator 2026 (30.x) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-07 · **Change:** minor (EPS import: shadings not extended paint only between their ends; SVG import: filter and mask regions clip, #5876, #5875; SVG import: Gaussian blurs keep `color-interpolation-filters`, #5877; PDF and `.ai` export: objects' URLs as links, #5785; SVG import: `color-interpolation="linearRGB"` gradients, #5878; `.ai` import: paths with a Calligraphic brush open brushed, #372) · **Target:** Adobe Illustrator 2026 (30.x) Every format Illustrator opens, places, saves or exports, against VectorCraft's format table (`FORMATS`, `OPEN_EXTS`, `PLACE_EXTS` in `crates/engine/src/cmd/fileio/formats.rs`). Illustrator's list comes from its public @@ -153,7 +153,7 @@ the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPri | Illustrator template `.ait` | open, save | yes | PDF-compatible only, from Save as Template (`.vctemplate` stays its default) | New from Template opens a saved `.ait` untitled with its layers and art (`tests_pdfedit.rs`) | | Illustrator `.ai` | open, save | yes (PDF-compatible + editing-data structure with template layers and ruler guides, File Info) | PDF-compatible, or legacy version 7 (layers and groups) | see above; no real-file corpus | | PDF | open, place, save | yes (layers, masks, editable text, security, overprint, File Info from the XMP packet and the document information dictionary; Crop To › Trim takes the bleed box as the document's bleed) | yes (presets, PDF/X-1a/3/4, layers, marks and bleed, ICC, fast web view, 1.3+; objects' URLs as link annotations, not in PDF/X) | fuzzed import; shared guarded writer and windowed reader ([pdf-backend.md](pdf-backend.md)), metadata, incomplete-content and dependency-source regressions; PDF text opens where the file draws it, glyph by glyph (#722: kerning or none, spacing per character, text rise as baseline shift, vertical writing, justified text boxes); alpha soft masks drawn as images import with the mask (#1551); a clip only counts as covering the page when its shape does (#1542); a PDF another app copied pastes as editable vector art (#1499); letter-spaced type on a path keeps its length and its glyph-by-glyph stroke comes in as one text object (#1586, #1585); a crafted name tree with shared nodes no longer takes exponential time on open (#1781); fonts named with hyphens (`Noto-Sans-Bold`) or with a composite font's CMap (`Name-Identity-H`) find the installed family; invisible text (rendering mode 3: a scanned page's recognized text) opens as type with no fill or stroke and saves back as invisible, searchable text (#2675); PDF/X-1a and X-3 flattening in a CMYK document keeps CMYK inks where it rasterizes (#2160) | -| EPS | open, place, save | yes (own PostScript L3 interpreter, Illustrator EPS editing data structure) | yes (L2/L3, TIFF previews) | CID-keyed CJK type not read; #505; images encoded with `CCITTFaxDecode` (ITU-T T.4 Group 3 and T.6 Group 4, with `K`, `Columns`, `Rows`, `EndOfBlock`, `EndOfLine`, `EncodedByteAlign` and `BlackIs1`) draw, and damaged data keeps the rows decoded before its first damaged row; Type 42 (TrueType) fonts set type at its size (#1553); a clip only counts as covering the page when its shape does (#1542); an EPS another app copied pastes as editable vector art (`clipboard.importEps`, #1499); a stitched shading keeps its hard colour changes on import (#1654); CMYK images, CMYK JPEGs included, keep their ink amounts on import, as from PDF, and the pixels a `MaskColor` or `ImageType 3` mask hides become a grayscale opacity mask; ruzstd 0.9.1 for compressed editing data (#1807, RUSTSEC-2026-0344) | +| EPS | open, place, save | yes (own PostScript L3 interpreter, Illustrator EPS editing data structure) | yes (L2/L3, TIFF previews) | CID-keyed CJK type not read; #505; images encoded with `CCITTFaxDecode` (ITU-T T.4 Group 3 and T.6 Group 4, with `K`, `Columns`, `Rows`, `EndOfBlock`, `EndOfLine`, `EncodedByteAlign` and `BlackIs1`) draw, and damaged data keeps the rows decoded before its first damaged row; Type 42 (TrueType) fonts set type at its size (#1553); a clip only counts as covering the page when its shape does (#1542); an EPS another app copied pastes as editable vector art (`clipboard.importEps`, #1499); a stitched shading keeps its hard colour changes on import (#1654); an axial shading painted with `shfill` without `Extend` paints only between its ends, and a radial one from a point only over its circles; CMYK images, CMYK JPEGs included, keep their ink amounts on import, as from PDF, and the pixels a `MaskColor` or `ImageType 3` mask hides become a grayscale opacity mask; ruzstd 0.9.1 for compressed editing data (#1807, RUSTSEC-2026-0344) | | PostScript `.ps` | open, place | yes (the EPS reader reads its first page; `.epsf` files open and place as EPS) | via Print to PostScript | `tests_epsimport.rs` | | SVG / SVGZ | open, place, save | yes | yes (SVG Options, Preserve Editing, symbols, filters, rich text) | strongest format; tests in `crates/svg/tests`; text on a path follows basic shapes as their SVG 2 equivalent paths (#1527); CSS transforms and the `font` shorthand (#1565), percentage lengths in symbols (#1596), Inkscape flowed text as area type (#1568) and Inkscape pages as artboards (#1601) import; an unsupported filter is named in its warning (#1598); an artboard exported on its own (Export As with Use Artboards, Export for Screens, Asset Export) has the artboard's name as ``, Save the document's (#3544); attributes in other applications' XML namespaces (`plotter:pen="2"`) kept on their objects from import to export, as `data-*` attributes are (`crates/svg/tests/it/foreign_attributes.rs`); simple shapes export as `<rect>`, `<circle>`, `<ellipse>`, `<line>`, `<polygon>` and `<polyline>` where they draw the same as the path (#4652, `crates/svg/tests/it/basic_shapes.rs`) | | DXF | open, export | yes | yes (R12–2018) | R13–2018 closed SPLINE flags and control-point closure on import verified (#1299); circular cubic paths export as native CIRCLE/ARC where stroke semantics permit; R12 weighted strokes remain POLYLINE while non-circular curves keep the existing fallback (`crates/cad/src/tests.rs`); [Autodesk group 70](https://help.autodesk.com/cloudhelp/2024/ENU/AutoCAD-DXF/files/GUID-E1F884F8-AA90-4864-A215-3182D47A9C74.htm). DXF 2000–2018 LAYOUT objects write the paper image origin as 148/149 (was a stray 158), the shade plot codes (2004+) and the model type flag, and the plot style placeholder carries no subclass marker (#3085; structure test `r2000_and_later_files_have_the_structure_cad_apps_require`, checked with ezdxf's audit; not yet confirmed in Autodesk Fusion). CNC preset and VCarve QA remain open | @@ -191,6 +191,7 @@ the app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPri | Date | Change | Summary | |---|---|---| +| 2026-11-07 | minor | EPS import: an axial or radial shading painted with `shfill` filled the whole clip whatever its `Extend`, so one without it (the default, `[false false]`: PLRM 3rd ed. §4.9.3) painted its end colours past its ends. An axial shading not extended at an end now paints only up to the line through that end across its axis, and a radial one from a point (no starting radius) not extended at either end only over its circles. Test `shadings_not_extended_paint_only_between_their_ends`; a hand-written axial shading from x 10 to 190 is 0.5% from Ghostscript's render (it was 4.5%). Radial shadings extended at one end only or starting from a circle, and shadings through a shading pattern, still paint the whole area; scores unchanged | | 2026-11-06 | minor | SVG import: filter and mask regions clip (SVG 1.1 §15.5, §14.4). An object whose imported blur, shadow or glow reaches past its filter's region comes in inside a clip group cut to the region (#5876), and a mask's art is cut to the mask's region, in user space or the object's bounding box (#5875). Objects that fit their regions, and our own exports, are unchanged; primitive subregions are still ignored. Tests `import_live::a_blur_is_cut_at_its_filter_region`, `import_live::a_mask_counts_only_inside_its_region` (crate `vectorcraft-svg`); scores unchanged | | 2026-11-06 | minor | SVG import: a Gaussian blur keeps the colour space its filter asks for with `color-interpolation-filters` (initially `linearRGB`, SVG 1.1 §15.7.6): a linear-light blur becomes Gaussian Blur with the new `linear` parameter, which blurs the colours in linear light (black beside white meets at about 188/255 instead of 128), and SVG export writes it back on the `feGaussianBlur` (#5877). Blurs that ask for sRGB, and the blurs our own export writes, are as before. CSS export still writes `blur()`. Tests `pixel::tests::linear_light_blur_mixes_light_not_values` (crate `vectorcraft-effects`), `import_live::a_gaussian_blur_keeps_its_colour_space` (crate `vectorcraft-svg`); scores unchanged | | 2026-11-06 | minor | PDF export and PDF-compatible `.ai` saves write each object's URL (Attributes panel) as a link annotation with a URI action (web and mail URLs only) over the bounds of the object that shows, trimmed by its clipping groups (ISO 32000-1, 12.5.6.5 and 12.6.4.7); hidden objects, layers that don't print and prints have none, and PDF/X files leave them out with a warning (#5785). Own-fixture tests in `tests::links`; PDF import doesn't read links back as URLs yet; scores unchanged |