From 630b36eaa77d42d3e3c06805f533c7863f4b109e Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Fri, 13 Nov 2026 02:19:23 -0500 Subject: [PATCH 1/7] Twist: handles follow the rotation's derivative, so its pieces join without kinks (#7069) --- crates/doc/src/live.rs | 4 +++- crates/doc/src/live/warp.rs | 37 ++++++++++++++++++++++++++++++----- crates/effects/src/distort.rs | 10 ++++++---- crates/effects/src/tests.rs | 21 ++++++++++++++++++++ crates/effects/src/util.rs | 2 +- docs/effects-parity.md | 5 +++-- docs/target-app-parity.md | 3 ++- 7 files changed, 68 insertions(+), 14 deletions(-) diff --git a/crates/doc/src/live.rs b/crates/doc/src/live.rs index b4c0f9fdd8..1926d58b89 100644 --- a/crates/doc/src/live.rs +++ b/crates/doc/src/live.rs @@ -65,7 +65,9 @@ pub use expand::{ #[cfg(test)] use mesh::grid_eval; pub use mesh::{Coons, GradientMesh, MeshAppearance, MeshPiece, MeshPoint, MeshQuad, default_fidelity, grid_points, nodes_bounds}; -pub use warp::{WARP_NET, WarpNet, WarpStyle, fit_piece, map_nonlinear, map_nonlinear_within, pieces, uses_net, warp_point, warp_version}; +pub use warp::{ + WARP_NET, WarpNet, WarpStyle, fit_piece, map_nonlinear, map_nonlinear_within, map_smooth_within, pieces, uses_net, warp_point, warp_version, +}; #[cfg(test)] mod tests { diff --git a/crates/doc/src/live/warp.rs b/crates/doc/src/live/warp.rs index 08bef91140..2f33e670a5 100644 --- a/crates/doc/src/live/warp.rs +++ b/crates/doc/src/live/warp.rs @@ -497,6 +497,33 @@ pub fn map_nonlinear(path: &PathData, max_piece: f64, f: impl Fn(Point) -> Point /// where pieces of `max_piece` would make more, the pieces grow until they don't ([`fit_piece`]), /// a coarser approximation of the image curve. Geometry effects map within their anchor budget. pub fn map_nonlinear_within(path: &PathData, max_piece: f64, max: usize, f: impl Fn(Point) -> Point) -> PathData { + map_pieces_within(path, max_piece, max, &f, |_, h| f(h)) +} + +/// [`map_nonlinear_within`] with each handle mapped along `f`'s derivative at its point +/// ([`mapped_handle`]) rather than as a point of its own: where `f` turns quickly (Twist), handles +/// mapped as points point different ways on the two sides of a join and the curve kinks there +/// (#7069); along the derivative, the pieces on both sides leave each join in one direction. +pub fn map_smooth_within(path: &PathData, max_piece: f64, max: usize, f: impl Fn(Point) -> Point) -> PathData { + map_pieces_within(path, max_piece, max, &f, |p, h| mapped_handle(&f, p, h)) +} + +/// Handle `h` of point `p` mapped through `f`: `f(p)` plus `f`'s derivative at `p` along `h - p` +/// (a central difference), so the image curve leaves `f(p)` the way `f` takes the curve. +fn mapped_handle(f: &impl Fn(Point) -> Point, p: Point, h: Point) -> Point { + let v = h - p; + let len = v.hypot(); + // A retracted handle stays retracted, and a non-finite one has no direction to follow. + if len.is_nan() || len <= 0.0 || len.is_infinite() { + return f(p); + } + const STEP: f64 = 1e-3; + let d = (f(p + v * STEP) - f(p - v * STEP)) / (2.0 * STEP); + f(p) + d +} + +/// [`map_nonlinear_within`]'s pieces, with `handle(point, handle)` giving each mapped handle. +fn map_pieces_within(path: &PathData, max_piece: f64, max: usize, f: &impl Fn(Point) -> Point, handle: impl Fn(Point, Point) -> Point) -> PathData { let mut max_piece = max_piece.max(1e-3); // Each segment adds one anchor per piece past its first. let room = max.saturating_sub(path.anchor_count()); @@ -516,20 +543,20 @@ pub fn map_nonlinear_within(path: &PathData, max_piece: f64, max: usize, f: impl let mut pending_in: Option = None; for i in 0..n { let a = &sp.anchors[i]; - let h_in = pending_in.take().unwrap_or_else(|| f(a.h_in)); - res.push(Anchor { p: f(a.p), h_in, h_out: f(a.h_out), kind: a.kind }); + let h_in = pending_in.take().unwrap_or_else(|| handle(a.p, a.h_in)); + res.push(Anchor { p: f(a.p), h_in, h_out: handle(a.p, a.h_out), kind: a.kind }); if i < segs { let c = seg_cubic(sp, i); let k = pieces(poly_len(&c), max_piece, MAX_PIECES); for j in 0..k { let sub = c.subsegment((j as f64 / k as f64)..((j + 1) as f64 / k as f64)); if let Some(last) = res.last_mut() { - last.h_out = f(sub.p1); + last.h_out = handle(sub.p0, sub.p1); } if j + 1 < k { - res.push(Anchor { p: f(sub.p3), h_in: f(sub.p2), h_out: f(sub.p3), kind: Default::default() }); + res.push(Anchor { p: f(sub.p3), h_in: handle(sub.p3, sub.p2), h_out: f(sub.p3), kind: Default::default() }); } else { - pending_in = Some(f(sub.p2)); + pending_in = Some(handle(sub.p3, sub.p2)); } } } diff --git a/crates/effects/src/distort.rs b/crates/effects/src/distort.rs index a5bc941b16..7a03a2f3aa 100644 --- a/crates/effects/src/distort.rs +++ b/crates/effects/src/distort.rs @@ -5,7 +5,9 @@ use vectorcraft_geom::kurbo::ParamCurveArclen; use vectorcraft_geom::{Affine, Anchor, ParamCurve, PathData, Point, Rect, SubPath, Vec2}; use vectorcraft_pathops::addons::pathtools::insert_at; -use crate::util::{catmull_rom, fit_piece, flag, map_nonlinear_within, mean_size, noise, normal_at, num, pieces, seed, seg_cubic, smooth_points}; +use crate::util::{ + catmull_rom, fit_piece, flag, map_nonlinear_within, map_smooth_within, mean_size, noise, normal_at, num, pieces, seed, seg_cubic, smooth_points, +}; fn diag(b: Rect) -> f64 { b.width().hypot(b.height()).max(1e-6) @@ -325,8 +327,8 @@ pub fn tweak(path: &PathData, b: Rect, p: &Value) -> PathData { } /// Twist: rotation that is strongest at the centre and fades to zero at the bounding circle, -/// clockwise on the page for a positive `angle`, making at most `max` anchors -/// ([`map_nonlinear_within`]). +/// clockwise on the page for a positive `angle`, making at most `max` anchors. Its handles follow +/// the rotation's derivative ([`map_smooth_within`]), so the pieces join without kinks (#7069). pub fn twist(path: &PathData, b: Rect, angle: f64, max: usize) -> PathData { let ang = angle.clamp(-3600.0, 3600.0).to_radians(); if ang == 0.0 { @@ -343,7 +345,7 @@ pub fn twist(path: &PathData, b: Rect, angle: f64, max: usize) -> PathData { c + Vec2::new(d.x * co - d.y * s, d.x * s + d.y * co) }; let piece = (r / 8.0).min(r / (1.0 + ang.abs() * 2.0)); - map_nonlinear_within(path, piece, max, f) + map_smooth_within(path, piece, max, f) } const ZIGZAG_ARCLEN_ACCURACY: f64 = 1e-4; diff --git a/crates/effects/src/tests.rs b/crates/effects/src/tests.rs index 56f9d40633..3c333cd0a0 100644 --- a/crates/effects/src/tests.rs +++ b/crates/effects/src/tests.rs @@ -1662,6 +1662,27 @@ fn twist_turns_clockwise_for_positive_angles() { assert!(turned(-45.0).y < 49.5, "{:?}", turned(-45.0)); } +/// Twist turns a line into a smooth spiral: the points it adds join their pieces without a kink, +/// however far it turns (#7069). +#[test] +fn twist_joins_its_pieces_smoothly() { + let line = PathData::single(SubPath::polyline(&[Point::new(40.0, 30.0), Point::new(60.0, 30.0)], false)); + let bounds = Rect::new(40.0, 30.0, 60.0, 30.0); + for angle in [90.0, 400.0, -720.0] { + let out = apply_geometry(&[fx("distort.twist", json!({"angle": angle}))], &line, bounds); + let anchors = &out.subpaths[0].anchors; + assert!(anchors.len() > 8, "{angle}°: {} anchors", anchors.len()); + for a in &anchors[1..anchors.len() - 1] { + let (into, out) = (a.p - a.h_in, a.h_out - a.p); + if into.hypot() < 1e-9 || out.hypot() < 1e-9 { + continue; + } + let kink = (into.x * out.y - into.y * out.x).atan2(into.dot(out)).to_degrees().abs(); + assert!(kink < 1.0, "{angle}°: a kink of {kink:.1}° at {:?}", a.p); + } + } +} + #[test] fn twist_fixes_the_outer_circle_and_rotates_inside() { let out = run("distort.twist", json!({"angle": 0}), &square()); diff --git a/crates/effects/src/util.rs b/crates/effects/src/util.rs index ec8cb4cba8..de203b4955 100644 --- a/crates/effects/src/util.rs +++ b/crates/effects/src/util.rs @@ -71,7 +71,7 @@ pub fn seg_cubic(sp: &SubPath, i: usize) -> CubicBez { /// Non-linear path mapping (shared with live envelopes in `vectorcraft-doc`), and the split of /// segments into pieces within an anchor budget. -pub use vectorcraft_doc::live::{fit_piece, map_nonlinear_within, pieces}; +pub use vectorcraft_doc::live::{fit_piece, map_nonlinear_within, map_smooth_within, pieces}; /// About how many lines the renderer flattens `path` into at 1 px/pt: one for a straight /// segment, and for a curve the count Wang's formula gives at vello's tolerance of 0.25 px, diff --git a/docs/effects-parity.md b/docs/effects-parity.md index 0eb68c7e25..b4ed0f41c8 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -1,6 +1,6 @@ # Effects parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-10 · **Change:** minor (Effect Gallery: a thumbnail for each filter and an in-dialog preview on an original drawing; the 1–2 h for those is done; Extrude & Bevel, Inflate and Rotate merge contours that cross, touch or overlap, as type often draws a glyph, before building a solid; previously: Extrude & Bevel, Inflate and Rotate apply to groups and layers, their objects turning about one shared axis (#4506); the Transform effect's copies of a path with a fill and a stroke (or several fills and strokes, an even-odd fill, or a partly transparent one) are drawn each above the one before, as Expand Appearance makes them (#5920); Expand Appearance makes each copy of a path's Transform effect an object of its own (#5612); previously: Pixelate › Color Halftone: Max Radius in pixels of the Document Raster Effects resolution, 4–127 px, with older documents converted on opening and radii written back in points for older app versions (#3260); Effect dialogs clamp bounded length inputs immediately on commit and flash rejection on invalid input (#4638); previously: Drop Shadow Darkness uses fixed RGB subtraction and CMYK black addition; scores unchanged; Pathfinder › Trap: the Pathfinder panel's Trap… and Effect › Pathfinder › Trap… add an overprinting strip of the lighter colour where two solid colours meet; recounted with Hard Mix (#3061) and Soft Mix already in the catalogue: Pathfinder 13/13, Illustrator effects 49/50) · **Target:** Adobe Illustrator 2026 (30.x) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-13 · **Change:** minor (Twist: a strongly twisted path joins its pieces without kinks, #7069; scores and estimates unchanged; previously: Effect Gallery: a thumbnail for each filter and an in-dialog preview on an original drawing; the 1–2 h for those is done; Extrude & Bevel, Inflate and Rotate merge contours that cross, touch or overlap, as type often draws a glyph, before building a solid; previously: Extrude & Bevel, Inflate and Rotate apply to groups and layers, their objects turning about one shared axis (#4506); the Transform effect's copies of a path with a fill and a stroke (or several fills and strokes, an even-odd fill, or a partly transparent one) are drawn each above the one before, as Expand Appearance makes them (#5920); Expand Appearance makes each copy of a path's Transform effect an object of its own (#5612); previously: Pixelate › Color Halftone: Max Radius in pixels of the Document Raster Effects resolution, 4–127 px, with older documents converted on opening and radii written back in points for older app versions (#3260); Effect dialogs clamp bounded length inputs immediately on commit and flash rejection on invalid input (#4638); previously: Drop Shadow Darkness uses fixed RGB subtraction and CMYK black addition; scores unchanged; Pathfinder › Trap: the Pathfinder panel's Trap… and Effect › Pathfinder › Trap… add an overprinting strip of the lighter colour where two solid colours meet; recounted with Hard Mix (#3061) and Soft Mix already in the catalogue: Pathfinder 13/13, Illustrator effects 49/50) · **Target:** Adobe Illustrator 2026 (30.x) Every entry of Illustrator's Effect menu, by its public feature name, against VectorCraft's effects catalogue (`effect_catalog()` in `crates/effects/src/lib.rs`) and the Effect menu built from it @@ -22,7 +22,7 @@ Part of [target-app-parity.md](target-app-parity.md); open work is in [gaps.md]( |---|---|---:|---| | Convert to Shape | Rectangle, Rounded Rectangle, Ellipse | 3/3 | — | | Crop Marks | Crop Marks | 1/1 | — | -| Distort & Transform | Free Distort, Pucker & Bloat, Roughen, Transform, Tweak, Twist, Zig Zag | 7/7 | Free Distort's dialog has a handle on each corner of the object's bounds, moved by dragging or with the arrow keys; Zig Zag's ridges are evenly spaced along each segment (#1558), and Smooth points make a continuous wave whose peaks and valleys have handles along the path (#2343); Roughen with Smooth keeps turn-backs smooth instead of cusps that draw as spikes (#1646); Expand Appearance of a path whose Transform effect makes copies gives a group of one object per copy, each painted as the path, and a second Transform effect's copies nest in a group per copy of the first (#5612); drawn, each copy of a path with a fill and a stroke (or several, an even-odd fill or a partly transparent one) paints below the one before, the fills above covering the strokes of the copies below, instead of one path of every copy (#5920), and a group's copies each hold all its members except guides, the original group on top (#6316); a clipping group, a group with a fill or stroke of its own, a group whose type is kept as type, and a group with a member that carries a geometry, Pathfinder or 3D effect copy each member in its place | +| Distort & Transform | Free Distort, Pucker & Bloat, Roughen, Transform, Tweak, Twist, Zig Zag | 7/7 | Free Distort's dialog has a handle on each corner of the object's bounds, moved by dragging or with the arrow keys; Zig Zag's ridges are evenly spaced along each segment (#1558), and Smooth points make a continuous wave whose peaks and valleys have handles along the path (#2343); Roughen with Smooth keeps turn-backs smooth instead of cusps that draw as spikes (#1646); Expand Appearance of a path whose Transform effect makes copies gives a group of one object per copy, each painted as the path, and a second Transform effect's copies nest in a group per copy of the first (#5612); drawn, each copy of a path with a fill and a stroke (or several, an even-odd fill or a partly transparent one) paints below the one before, the fills above covering the strokes of the copies below, instead of one path of every copy (#5920), and a group's copies each hold all its members except guides, the original group on top (#6316); a clipping group, a group with a fill or stroke of its own, a group whose type is kept as type, and a group with a member that carries a geometry, Pathfinder or 3D effect copy each member in its place; Twist's handles follow the rotation's derivative, so a strongly twisted path is a smooth spiral without kinks where its pieces join (#7069, `twist_joins_its_pieces_smoothly`). | | Path | Offset Path, Outline Object, Outline Stroke | 3/3 | With Use Preview Bounds on, Align, Distribute and the Transform panel still measure type that carries Outline Object by its layout box (preview bounds leave out effects) | | Pathfinder | Add, Intersect, Exclude, Subtract, Minus Back, Divide, Trim, Merge, Crop, Outline, Hard Mix, Soft Mix, Trap | 13/13 | Trap traps only solid fills (gradients and patterns hide what is below them but don't trap) and spreads each colour's visible area as a whole; the public page gives no default values, so Trap's 0.25 pt, 100% and 40% are VectorCraft's own | | Rasterize | Rasterize… (as a live effect) | 1/1 | — | @@ -193,6 +193,7 @@ angular cut caps, exact visibility, the rest of 3D Classic (Map Art), Turntable) | Date | Change | Summary | |---|---|---| +| 2026-11-13 | minor | Distort & Transform › Twist: handles follow the rotation's derivative, so a strongly twisted path is a smooth spiral instead of pieces meeting at kinks (#7069; `twist_joins_its_pieces_smoothly` in `crates/effects/src/tests.rs`). Scores and estimates unchanged. | | 2026-11-10 | minor | Effect Gallery: each filter has a thumbnail, and the dialog has a preview of the visible stack (or the browsed filter when the stack is empty). Both are an original landscape drawing passed through the filter ([Filter Gallery overview](https://helpx.adobe.com/photoshop/desktop/effects-filters/get-started-with-filters/filter-gallery.html)). The canvas preview and one-undo OK are unchanged. Remaining hours for the gallery's thumbnails and in-dialog preview: 1–2 → none. Counts unchanged (57/57). | | 2026-11-08 | minor | Extrude & Bevel, Inflate and Rotate merge contours that cross, touch or overlap (a glyph's arm across its stem) before building a solid, so the solid follows the shape as it is filled; others are built as drawn ([three-d.md](three-d.md)); scores and estimates unchanged | | 2026-11-06 | minor | Extrude & Bevel, Inflate and Rotate apply to a group or layer: a solid for every path, compound path and type in it, all turned about one shared axis as the public documentation describes for groups ([three-d.md](three-d.md#groups), #4506); scores and estimates unchanged | diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3984b49491..7dc426fce8 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1,6 +1,6 @@ # Parity with Adobe Illustrator -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-13 · **Change:** minor (library panels' lists fill a taller panel, #2992; scores and estimates unchanged; previously: Swatches list fills a taller panel, #1638; scores and estimates unchanged; previously minor: Object › Rasterize with the Grayscale or Bitmap colour model makes a grayscale image, #6969; scores and estimates unchanged; previously minor: `.ai` and EPS import: type in an envelope with Distort Appearance is also tried mapped from the box of what it paints, miter tips and moved strokes included, after its glyphs grown by half its strokes' weight (#6824; #6617: Swatches panel menu: Show Recent Colors; scores unchanged; previously minor: icon-strip flyouts also resize from the top edge and the canvas-side top corner, keeping the moved top in workspaces (storytold/craft-libs#1094); scores and estimates unchanged; previously: #6865: explicitly requested oversized editing artboard; macOS: the canvas cursor stays after the pointer moves, #6362; scores and estimates unchanged; previously minor: Type tool: kerning at a caret at the start of a line moves the character after it, #5111; scores and estimates unchanged; previously minor: Rulers: the zero point dragged out of the rulers' corner snaps as a drawn point does; previously minor: Live Paint Bucket fills faces crossed in one drag (#6373); previously: #6404: transform-aware Eyedropper character copying; scores and estimates unchanged; previously: Envelopes: with Distort Appearance, type's strokes paint along the bent glyph outlines at their own weight, as users' `.ai` files draw them, which changes how VectorCraft's own envelopes of stroked type draw (#6644; scores and estimates unchanged); previously minor: G5: Energy Beams brush library; bundled content ~44% → ~46%; previously minor: G5: Skill Icons symbol library; bundled content ~42% → ~44%; previously minor: `.ai` and EPS import: an envelope saved in Edit Contents whose mesh lies away from its drawn art by a move opens live on that art (#6570; scores and estimates unchanged); previously minor: ruler double-click adds a guide at the pointer, #5239; G5: Status Effects graphic style library; bundled content ~40% → ~42%; MCP symbol libraries list UI Frames and Map Markers; previously minor: G5: Inventory Icons built-in symbol library; bundled content ~38% → ~40%; previously minor: `.ai` and EPS import: stroked type in an envelope maps from its glyphs grown by half its stroke (#3179; scores and estimates unchanged); previously minor: `.ai` and EPS import: warps of type open as mesh envelopes on their saved grid where VectorCraft's warp doesn't draw as their drawn art (#3179; scores and estimates unchanged); G5: Game Trails brush library; bundled content ~36% → ~38%; previously minor: Edit › Edit Custom Dictionary…: its dialog adds, deletes and changes the custom dictionary's words, #4936; previously minor: `.ai` and EPS import: envelopes of type open live where they draw as their drawn art and the layers with them draw as the page (#3179; scores and estimates unchanged); G5: Game HUD graphic style library; bundled content ~34% → ~36%; previously minor: Line Arrow arrowhead (#5421; scores and estimates unchanged); G5: Map Markers built-in symbol library; bundled content ~32% → ~34%; previously minor: right-click on type: Spelling › Auto Spell Check, with its check mark, #4936; previously minor: right-click on a word Auto Spell Check underlined: its suggestions, Ignore All and Add to Dictionary, #4936; previously minor: Canvas: a 3D effect changed on type or a group redraws where its solid was; Fit to Artwork Bounds and per-artboard SVG export build each solid once for all artboards; previously minor: Effect Gallery: a thumbnail for each filter and a preview area inside the dialog, on an original drawing; Raster effects 52% → 55%, hours 1–2 → none; headline numbers unchanged; Auto Spell Check: `edit.autoSpellCheck` underlines the unknown words, #4936; previously minor: PDF editable import preserves authored ActualText once, including empty/nested spans and authored ordering (#6165); cross-line/style layout remains approximate; scores and estimates unchanged; PDF marked-text export (#6309): compatible glyphs stay on one layout line with per-glyph offsets; scores and estimates unchanged; G5: UI Frames built-in symbol library with default 9-slice; bundled content ~32%; previously minor: G5: dynamic symbol part on-canvas opacity/blend/gradient/pattern; strokes remaining no longer lists Overlap/auto corners; symbols ~88%; previously minor: interim macOS cursor delivery, #2292; native validation pending; scores and estimates unchanged; previously minor: harakat paint fallback clarified; previously minor: current Guides feature-area rows consolidated using existing ruler evidence; scores and estimates unchanged; previously minor: Control bar › Snapping includes the existing Snap to Glyph and Alignment Guides toggles (#6164); scores and estimates unchanged; previously minor: G5 docs: Art brush Overlap and Pattern brush auto corners removed from strokes remaining; symbols remaining lists dynamic on-canvas beyond solid and guides outside the art; previously minor: custom dictionary and Ignore All: `text.spelling.addWord`, `removeWord`, `changeWord`, `dictionary` and `ignoreAll`, #4936; previously minor: EPS import: embedded fonts (composite, Type 42, CID-keyed, Type 1, CFF FontSet) draw their glyphs; spell check engine: `text.spelling.check` and `text.spelling.suggest` on craft-proof, #4936; previously minor: floating tab groups collapse into the side icon rail and opened rail panels fold back into it, #5925 in part; `.ai`/EPS type keeps its tab stops, and right-aligned lines with tabs lay out as the file's page, #6147; `.ai`/EPS type from the text document lays its lines out closer to the file's page, within limits, #6137; `.ai` and EPS import: older Art brush objects read; numeric fields step on wheel hover without taking keyboard focus, and a panel wheel turn cannot seed a canvas zoom glide, #5949; Character Styles panel: a double-click on a style's row opens its Character Style Options; the dialog keeps a fixed width and scrolls its sections, so its buttons stay on screen; Tools stays beside the canvas with left-side panels; new gradients follow document color mode; Selection QoL: marquee modes and visible feedback, #5313; SVG CSS classes survive export and repeated import in all four styling modes (#2480); current-main integration retains event attributes and scripts; #3380 deletion-only review follow-up: independent survivors keep gradient placement, owned subpaths avoid discarded copies, and contracts/status/evidence are clarified; endpoint highlighting remains open; scores and estimates unchanged; the canvas keeps selection outlines and anchors between frames; Indian-language hyphenation review and license allowlist, #4947; Stroke gradients: an arrowhead aligned to the tip is painted to the corners of its base, #5964; Drop Shadow and glow dialogs: spinner arrows, #5367, #5368; Stroke Weight Up and Down shortcuts, #5797; Hindi catalog and contributor loanword preferences; full wording review in progress; Properties in Edit Artboards: a Transform section with the reference point above the Artboards section, #5219; the Control bar's Stroke: and Opacity: links scrub their fields, #4088; an image zoomed in on is separated, colorized or proofed only where it shows (#4155); a document's first frame renders on the render worker, so opening a heavy file no longer freezes the window, #4155; Control bar Paragraph section with type selected, #5372; translating unchanged type reuses its glyph and character-stroke outlines; scores and estimates unchanged) · **Target:** Adobe Illustrator 2026 (30.x; public release notes through 30.7, August 2026; Units › East Asian Type acts, with Q and Ha units; scores unchanged) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-13 · **Change:** minor (Twist: a strongly twisted path joins its pieces without kinks, #7069; scores and estimates unchanged; previously: library panels' lists fill a taller panel, #2992; scores and estimates unchanged; previously: Swatches list fills a taller panel, #1638; scores and estimates unchanged; previously minor: Object › Rasterize with the Grayscale or Bitmap colour model makes a grayscale image, #6969; scores and estimates unchanged; previously minor: `.ai` and EPS import: type in an envelope with Distort Appearance is also tried mapped from the box of what it paints, miter tips and moved strokes included, after its glyphs grown by half its strokes' weight (#6824; #6617: Swatches panel menu: Show Recent Colors; scores unchanged; previously minor: icon-strip flyouts also resize from the top edge and the canvas-side top corner, keeping the moved top in workspaces (storytold/craft-libs#1094); scores and estimates unchanged; previously: #6865: explicitly requested oversized editing artboard; macOS: the canvas cursor stays after the pointer moves, #6362; scores and estimates unchanged; previously minor: Type tool: kerning at a caret at the start of a line moves the character after it, #5111; scores and estimates unchanged; previously minor: Rulers: the zero point dragged out of the rulers' corner snaps as a drawn point does; previously minor: Live Paint Bucket fills faces crossed in one drag (#6373); previously: #6404: transform-aware Eyedropper character copying; scores and estimates unchanged; previously: Envelopes: with Distort Appearance, type's strokes paint along the bent glyph outlines at their own weight, as users' `.ai` files draw them, which changes how VectorCraft's own envelopes of stroked type draw (#6644; scores and estimates unchanged); previously minor: G5: Energy Beams brush library; bundled content ~44% → ~46%; previously minor: G5: Skill Icons symbol library; bundled content ~42% → ~44%; previously minor: `.ai` and EPS import: an envelope saved in Edit Contents whose mesh lies away from its drawn art by a move opens live on that art (#6570; scores and estimates unchanged); previously minor: ruler double-click adds a guide at the pointer, #5239; G5: Status Effects graphic style library; bundled content ~40% → ~42%; MCP symbol libraries list UI Frames and Map Markers; previously minor: G5: Inventory Icons built-in symbol library; bundled content ~38% → ~40%; previously minor: `.ai` and EPS import: stroked type in an envelope maps from its glyphs grown by half its stroke (#3179; scores and estimates unchanged); previously minor: `.ai` and EPS import: warps of type open as mesh envelopes on their saved grid where VectorCraft's warp doesn't draw as their drawn art (#3179; scores and estimates unchanged); G5: Game Trails brush library; bundled content ~36% → ~38%; previously minor: Edit › Edit Custom Dictionary…: its dialog adds, deletes and changes the custom dictionary's words, #4936; previously minor: `.ai` and EPS import: envelopes of type open live where they draw as their drawn art and the layers with them draw as the page (#3179; scores and estimates unchanged); G5: Game HUD graphic style library; bundled content ~34% → ~36%; previously minor: Line Arrow arrowhead (#5421; scores and estimates unchanged); G5: Map Markers built-in symbol library; bundled content ~32% → ~34%; previously minor: right-click on type: Spelling › Auto Spell Check, with its check mark, #4936; previously minor: right-click on a word Auto Spell Check underlined: its suggestions, Ignore All and Add to Dictionary, #4936; previously minor: Canvas: a 3D effect changed on type or a group redraws where its solid was; Fit to Artwork Bounds and per-artboard SVG export build each solid once for all artboards; previously minor: Effect Gallery: a thumbnail for each filter and a preview area inside the dialog, on an original drawing; Raster effects 52% → 55%, hours 1–2 → none; headline numbers unchanged; Auto Spell Check: `edit.autoSpellCheck` underlines the unknown words, #4936; previously minor: PDF editable import preserves authored ActualText once, including empty/nested spans and authored ordering (#6165); cross-line/style layout remains approximate; scores and estimates unchanged; PDF marked-text export (#6309): compatible glyphs stay on one layout line with per-glyph offsets; scores and estimates unchanged; G5: UI Frames built-in symbol library with default 9-slice; bundled content ~32%; previously minor: G5: dynamic symbol part on-canvas opacity/blend/gradient/pattern; strokes remaining no longer lists Overlap/auto corners; symbols ~88%; previously minor: interim macOS cursor delivery, #2292; native validation pending; scores and estimates unchanged; previously minor: harakat paint fallback clarified; previously minor: current Guides feature-area rows consolidated using existing ruler evidence; scores and estimates unchanged; previously minor: Control bar › Snapping includes the existing Snap to Glyph and Alignment Guides toggles (#6164); scores and estimates unchanged; previously minor: G5 docs: Art brush Overlap and Pattern brush auto corners removed from strokes remaining; symbols remaining lists dynamic on-canvas beyond solid and guides outside the art; previously minor: custom dictionary and Ignore All: `text.spelling.addWord`, `removeWord`, `changeWord`, `dictionary` and `ignoreAll`, #4936; previously minor: EPS import: embedded fonts (composite, Type 42, CID-keyed, Type 1, CFF FontSet) draw their glyphs; spell check engine: `text.spelling.check` and `text.spelling.suggest` on craft-proof, #4936; previously minor: floating tab groups collapse into the side icon rail and opened rail panels fold back into it, #5925 in part; `.ai`/EPS type keeps its tab stops, and right-aligned lines with tabs lay out as the file's page, #6147; `.ai`/EPS type from the text document lays its lines out closer to the file's page, within limits, #6137; `.ai` and EPS import: older Art brush objects read; numeric fields step on wheel hover without taking keyboard focus, and a panel wheel turn cannot seed a canvas zoom glide, #5949; Character Styles panel: a double-click on a style's row opens its Character Style Options; the dialog keeps a fixed width and scrolls its sections, so its buttons stay on screen; Tools stays beside the canvas with left-side panels; new gradients follow document color mode; Selection QoL: marquee modes and visible feedback, #5313; SVG CSS classes survive export and repeated import in all four styling modes (#2480); current-main integration retains event attributes and scripts; #3380 deletion-only review follow-up: independent survivors keep gradient placement, owned subpaths avoid discarded copies, and contracts/status/evidence are clarified; endpoint highlighting remains open; scores and estimates unchanged; the canvas keeps selection outlines and anchors between frames; Indian-language hyphenation review and license allowlist, #4947; Stroke gradients: an arrowhead aligned to the tip is painted to the corners of its base, #5964; Drop Shadow and glow dialogs: spinner arrows, #5367, #5368; Stroke Weight Up and Down shortcuts, #5797; Hindi catalog and contributor loanword preferences; full wording review in progress; Properties in Edit Artboards: a Transform section with the reference point above the Artboards section, #5219; the Control bar's Stroke: and Opacity: links scrub their fields, #4088; an image zoomed in on is separated, colorized or proofed only where it shows (#4155); a document's first frame renders on the render worker, so opening a heavy file no longer freezes the window, #4155; Control bar Paragraph section with type selected, #5372; translating unchanged type reuses its glyph and character-stroke outlines; scores and estimates unchanged) · **Target:** Adobe Illustrator 2026 (30.x; public release notes through 30.7, August 2026; Units › East Asian Type acts, with Q and Ha units; scores unchanged) > > Oversized artboard import update (2026-11-12): Explicit editing-data import retains a single artboard beyond a capped 14,400 pt PDF page (#6865). > @@ -53,6 +53,7 @@ Artboard Options forwards the active Artboard tool's Scale Artwork with Artboard | Date | Change | Summary | |---|---|---| +| 2026-11-13 | minor | Distort & Transform › Twist: handles follow the rotation's derivative, so a strongly twisted path is a smooth spiral instead of pieces meeting at kinks (#7069; `twist_joins_its_pieces_smoothly` in `crates/effects/src/tests.rs`). Scores and estimates unchanged. | | 2026-11-13 | minor | Library panels (swatch, Color Book, brush, symbol and graphic style libraries): in a panel made taller the list fills the space above the footer instead of scrolling inside 220 or 280 pt (#2992; `the_list_fills_a_tall_panel_above_its_footer` in `crates/ui-egui/src/panels/library_panel/tests.rs`). Scores and estimates unchanged. | | 2026-11-13 | minor | Swatches: in a panel made taller the swatch list fills the space above the footer instead of scrolling inside 150 or 200 pt (#1638; `the_list_fills_a_tall_panel_above_its_footer` in `crates/ui-egui/src/panels/swatches/tests.rs`). Scores and estimates unchanged. | | 2026-11-13 | minor | Swatches panel: its menu's Show Recent Colors hides and shows the panel's Recent Colors row, checked by default and kept between sessions apart from the Color panel's (#6617); scores unchanged. | From 128ba86be3c147e28d9dcc98d3e62d6f2a826b94 Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Fri, 13 Nov 2026 03:25:35 -0500 Subject: [PATCH 2/7] Twist (#7069): the derivative's step grows with the coordinates so it doesn't round away --- crates/doc/src/live.rs | 24 ++++++++++++++++++++++++ crates/doc/src/live/warp.rs | 8 ++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/doc/src/live.rs b/crates/doc/src/live.rs index 5768d26cac..946f1534c7 100644 --- a/crates/doc/src/live.rs +++ b/crates/doc/src/live.rs @@ -90,6 +90,30 @@ mod tests { } } + /// The smooth map takes each handle along the map's derivative, also far from the origin, + /// where a fixed sampling step would round away (#7069): the identity map keeps a curve's + /// handles there. + #[test] + fn map_smooth_within_keeps_handles_far_from_the_origin() { + for at in [0.0, 1e13] { + let o = Point::new(at, at); + let curve = PathData::single(vectorcraft_geom::SubPath::new( + vec![ + vectorcraft_geom::Anchor::with_handles(o, o, o + vectorcraft_geom::Vec2::new(0.2, 0.0)), + vectorcraft_geom::Anchor::with_handles( + o + vectorcraft_geom::Vec2::new(1.0, 0.5), + o + vectorcraft_geom::Vec2::new(0.8, 0.5), + o + vectorcraft_geom::Vec2::new(1.0, 0.5), + ), + ], + false, + )); + let out = map_smooth_within(&curve, 10.0, usize::MAX, |p| p); + let (a, b) = (&curve.subpaths[0].anchors, &out.subpaths[0].anchors); + assert!(a[0].h_out.distance(b[0].h_out) < 0.01 && a[1].h_in.distance(b[1].h_in) < 0.01, "at {at}: {:?} {:?}", b[0].h_out, b[1].h_in); + } + } + /// #3578: a non-linear map within an anchor budget splits its segments into longer pieces, /// down to one a segment, and matches the plain map where the budget leaves room. #[test] diff --git a/crates/doc/src/live/warp.rs b/crates/doc/src/live/warp.rs index 2f33e670a5..dd48e8ef65 100644 --- a/crates/doc/src/live/warp.rs +++ b/crates/doc/src/live/warp.rs @@ -517,8 +517,12 @@ fn mapped_handle(f: &impl Fn(Point) -> Point, p: Point, h: Point) -> Point { if len.is_nan() || len <= 0.0 || len.is_infinite() { return f(p); } - const STEP: f64 = 1e-3; - let d = (f(p + v * STEP) - f(p - v * STEP)) / (2.0 * STEP); + // A thousandth of the handle, or more where the coordinates are so large that so short a + // step would round away (#7069): the samples stay a billionth of the coordinates apart, and + // at most at the handle's own end. + let size = p.x.abs().max(p.y.abs()).max(1.0); + let step = (1e-3f64).max(size * 1e-9 / len).min(1.0); + let d = (f(p + v * step) - f(p - v * step)) / (2.0 * step); f(p) + d } From 7fa3ceb635b2475e9208df772265f32d095a01df Mon Sep 17 00:00:00 2001 From: el-j Date: Mon, 16 Nov 2026 11:33:39 +0100 Subject: [PATCH 3/7] Save PDF: show rasterization DPI and prompt confirmation when flattening transparency (#8097) --- crates/ui-egui/src/dialogs.rs | 1 + crates/ui-egui/src/dialogs/save_pdf.rs | 77 +++++++++++++++++++- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 46 ++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index da1062838f..89b10f12c5 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -378,6 +378,7 @@ registry! { WarichuSettings: [warichu::KIND] => warichu::SPEC, CompositeFonts: [composite_fonts::KIND] => composite_fonts::SPEC, SavePdf: [save_pdf::KIND] => save_pdf::SPEC, + ConfirmFlattenPdf: [save_pdf::CONFIRM_FLATTEN] => save_pdf::CONFIRM_FLATTEN_SPEC, SvgOptions: [svg_options::KIND] => svg_options::SPEC, JavaScriptFiles: [javascript_files::KIND] => javascript_files::SPEC, SvgFilter: [svg_filter::KIND] => svg_filter::SPEC, diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 4f8bdf7667..ef9bf097a6 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -44,6 +44,61 @@ pub(super) const PRESET_SPEC: DialogSpec = DialogSpec { ..DialogSpec::FORM }; +/// The dialog kind of the confirmation prompt when saving with transparency reduction. +pub(crate) const CONFIRM_FLATTEN: &str = "confirmFlattenPdf"; + +pub(crate) const CONFIRM_FLATTEN_SPEC: DialogSpec = DialogSpec { + heading: |d| d.str("message"), + body: |_, ui, d| { + let detail = d.str("detail"); + if !detail.is_empty() { + ui.label(egui::RichText::new(detail).color(Tokens::get(ui.ctx()).text_dim)); + } + false + }, + confirm: confirm_flatten, + ok: Some("Continue"), + max_width: Some(440.0), + ..DialogSpec::FORM +}; + +fn confirm_flatten(app: &mut VectorcraftApp, d: &Dialog) -> Result { + let mut parent = super::parent(d).filter(|p| p.kind == KIND).ok_or("the Save PDF dialog is no longer open")?; + parent.fields.insert("__confirmed_flatten".into(), json!(true)); + app.ui.dialog = Some(parent.clone()); + confirm(app, &parent) +} + +fn ask_confirm_flatten(app: &mut VectorcraftApp, d: &Dialog) { + let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER); + let preset_opts = FlattenOptions::preset(name) + .or_else(|| app.session.prefs.flattener_presets.iter().find(|p| p.name.eq_ignore_ascii_case(name)).map(|p| p.options.clone())) + .unwrap_or_default(); + let line_ppi = preset_opts.line_art_ppi.round() as u32; + let grad_ppi = preset_opts.gradient_ppi.round() as u32; + let message = tl!("The document contains transparency which will be flattened. Do you want to continue?"); + let detail = crate::i18n::fmt( + tl!( + "Transparent objects will be reduced into opaque paths and images at {line_ppi} ppi (line art and text) and {grad_ppi} ppi (gradients and meshes). Reopening the PDF may not restore separate transparent objects." + ), + &[("line_ppi", &line_ppi.to_string()), ("grad_ppi", &grad_ppi.to_string())], + ); + let under = serde_json::to_value(d).ok(); + let fields = json!({ + "message": message, + "detail": detail, + super::PARENT: under, + }); + app.ui.dialog = Some(Dialog::new(CONFIRM_FLATTEN, fields)); +} + +fn doc_has_transparency(doc: &vectorcraft_doc::Document) -> bool { + fn check_node(n: &vectorcraft_doc::Node) -> bool { + !n.has_default_transparency() || n.shows_transparency() || n.children().into_iter().flatten().any(|c| check_node(c)) + } + doc.layers.iter().any(|l| check_node(l)) +} + /// The preset editor's field holding the name of the saved preset it edits (empty: a new one). const EDITING: &str = "__editing"; /// Save PDF's field holding the name typed for Save Preset… (present while that row shows). @@ -153,6 +208,13 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { app.ui.dialog = Some(d); return r; } + let flat = choice::(d, "compatibility") == Some(Compatibility::Pdf13) + || choice::(d, "standard").is_some_and(Standard::flattens); + let has_transparency = app.session.active().is_some_and(|st| doc_has_transparency(&st.doc)); + if flat && has_transparency && !d.bool("__confirmed_flatten") { + ask_confirm_flatten(app, d); + return Ok(Value::Null); + } let r = match SaveMode::of(&d.str("__save")) { Some(mode) => io::save_pdf(app, mode, params(d)), None if d.bool(ART_BOUNDS) => export_art(app, d), @@ -732,7 +794,20 @@ fn advanced(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { } }); }); - if !flat { + if flat { + let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER); + let preset_opts = FlattenOptions::preset(name) + .or_else(|| app.session.prefs.flattener_presets.iter().find(|p| p.name.eq_ignore_ascii_case(name)).map(|p| p.options.clone())) + .unwrap_or_default(); + let line_ppi = preset_opts.line_art_ppi.round() as u32; + let grad_ppi = preset_opts.gradient_ppi.round() as u32; + note( + ui, + &crate::i18n::fmt( + tl!("Raster resolution: {line_ppi} ppi line art and text, {grad_ppi} ppi gradient and mesh"), + &[("line_ppi", &line_ppi.to_string()), ("grad_ppi", &grad_ppi.to_string())], + ), + ); note(ui, tl!("PDF 1.3 files have no transparency: the preset flattens it.")); } } diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index dbceed5881..c758b8bae8 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -507,3 +507,49 @@ fn pdf_1_3_takes_a_flattener_preset_in_advanced() { let saved = app.session.prefs.pdf_presets.iter().find(|p| p.name == "Old").unwrap(); assert_eq!((saved.settings.compatibility, saved.settings.flattener_preset.as_str()), (Compatibility::Pdf13, "Low Resolution")); } + +#[test] +fn save_pdf_prompts_confirmation_when_document_has_transparency_and_is_flattened() { + let (mut app, written, _) = app(); + // Add transparent artwork to the document + app.run("transparency.set", json!({"opacity": 50})).unwrap(); + + app.run("ui.savePdfDialog", json!({"path": "/tmp/transparent.pdf", "compatibility": "1.3"})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND); + + // Clicking Save PDF triggers the confirmFlattenPdf modal prompt + super::super::confirm(&mut app).unwrap(); + let prompt = app.ui.dialog.as_ref().expect("confirm dialog open"); + assert_eq!(prompt.kind, CONFIRM_FLATTEN); + assert!(prompt.str("message").contains("transparency which will be flattened")); + assert!(prompt.str("detail").contains("1200 ppi")); + assert!(prompt.str("detail").contains("300 ppi")); + + // Cancel on confirmation modal restores the Save PDF dialog + crate::dialogs::cancel(&mut app); + assert_eq!(app.ui.dialog.as_ref().expect("Save PDF restored").kind, KIND); + assert!(written.borrow().is_empty(), "nothing written on cancel"); + + // Click Save PDF again, then confirm the prompt + super::super::confirm(&mut app).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none(), "dialog closed after save"); + assert_eq!(written.borrow().len(), 1); + assert!(written.borrow()[0].1.starts_with(b"%PDF-1.3")); +} + +#[test] +fn save_pdf_does_not_prompt_when_compatibility_is_not_flattened() { + let (mut app, written, _) = app(); + app.run("transparency.set", json!({"opacity": 50})).unwrap(); + + app.run("ui.savePdfDialog", json!({"path": "/tmp/live.pdf", "compatibility": "1.7"})).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND); + + // Saving with PDF 1.7 (supports live transparency) does not prompt confirmation + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(written.borrow().len(), 1); + assert!(written.borrow()[0].1.starts_with(b"%PDF-1.7")); +} From 6a9b61e7585753fb71aaf938681a3d2efc1ee1dd Mon Sep 17 00:00:00 2001 From: el-j Date: Mon, 16 Nov 2026 11:57:38 +0100 Subject: [PATCH 4/7] Address review comments: detect see-through images and clear flatten approval on write failure --- crates/engine/src/cmd/flatten.rs | 3 +- crates/engine/src/cmd/flatten/analysis.rs | 4 +- crates/ui-egui/src/dialogs/save_pdf.rs | 25 ++++++-- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 66 ++++++++++++++++++++ 4 files changed, 90 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/flatten.rs b/crates/engine/src/cmd/flatten.rs index 399f2ec4bd..773b9cb992 100644 --- a/crates/engine/src/cmd/flatten.rs +++ b/crates/engine/src/cmd/flatten.rs @@ -51,7 +51,8 @@ mod options; mod presets; mod report; -pub(crate) use analysis::{carry, outlined_text, see_through_images}; +pub(crate) use analysis::{carry, outlined_text}; +pub use analysis::{draws_image, see_through_images}; pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded, has_transparent_tile_images}; #[cfg(test)] pub(crate) use apply::{with_clips_ignored, with_every_region}; diff --git a/crates/engine/src/cmd/flatten/analysis.rs b/crates/engine/src/cmd/flatten/analysis.rs index 9771d18ef9..da8f33f3d5 100644 --- a/crates/engine/src/cmd/flatten/analysis.rs +++ b/crates/engine/src/cmd/flatten/analysis.rs @@ -69,7 +69,7 @@ pub(crate) fn carry(from: &Node, mut to: Node) -> Node { /// The keys of `doc`'s images that have see-through pixels (an alpha channel that isn't opaque /// everywhere). -pub(crate) fn see_through_images(doc: &Document) -> BTreeSet { +pub fn see_through_images(doc: &Document) -> BTreeSet { let see_through = |b: &ImageBlob| { b.mime != "image/jpeg" && image::load_from_memory(&b.bytes).is_ok_and(|i| i.color().has_alpha() && i.to_rgba8().pixels().any(|p| p[3] < 255)) }; @@ -78,7 +78,7 @@ pub(crate) fn see_through_images(doc: &Document) -> BTreeSet { /// `n` shows an image of `keys` (itself or inside), a color-masked image's masked pixels counted as /// what it shows. -pub(super) fn draws_image(n: &Node, keys: &BTreeSet) -> bool { +pub fn draws_image(n: &Node, keys: &BTreeSet) -> bool { !keys.is_empty() && n.visible && match &n.kind { diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index ef9bf097a6..85d63e2189 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -92,11 +92,21 @@ fn ask_confirm_flatten(app: &mut VectorcraftApp, d: &Dialog) { app.ui.dialog = Some(Dialog::new(CONFIRM_FLATTEN, fields)); } -fn doc_has_transparency(doc: &vectorcraft_doc::Document) -> bool { - fn check_node(n: &vectorcraft_doc::Node) -> bool { - !n.has_default_transparency() || n.shows_transparency() || n.children().into_iter().flatten().any(|c| check_node(c)) +fn doc_has_transparency(doc: &vectorcraft_doc::Document, include_non_printing: bool) -> bool { + let see_through = vectorcraft_engine::cmd::flatten::see_through_images(doc); + fn check_node(n: &vectorcraft_doc::Node, see_through: &std::collections::BTreeSet, include_non_printing: bool) -> bool { + if !n.visible { + return false; + } + if matches!(n.kind, vectorcraft_doc::NodeKind::Layer { printable: false, .. }) && !include_non_printing { + return false; + } + !n.has_default_transparency() + || n.shows_transparency() + || vectorcraft_engine::cmd::flatten::draws_image(n, see_through) + || n.children().into_iter().flatten().any(|c| check_node(c, see_through, include_non_printing)) } - doc.layers.iter().any(|l| check_node(l)) + doc.layers.iter().any(|l| check_node(l, &see_through, include_non_printing)) } /// The preset editor's field holding the name of the saved preset it edits (empty: a new one). @@ -210,7 +220,8 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { } let flat = choice::(d, "compatibility") == Some(Compatibility::Pdf13) || choice::(d, "standard").is_some_and(Standard::flattens); - let has_transparency = app.session.active().is_some_and(|st| doc_has_transparency(&st.doc)); + let include_non_printing = d.bool("includeNonPrinting") || d.bool("createLayers"); + let has_transparency = app.session.active().is_some_and(|st| doc_has_transparency(&st.doc, include_non_printing)); if flat && has_transparency && !d.bool("__confirmed_flatten") { ask_confirm_flatten(app, d); return Ok(Value::Null); @@ -224,6 +235,10 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { if r.is_ok() && app.ui.dialog.as_ref().is_some_and(|o| o.kind == KIND) { app.ui.dialog = None; } + // A failed write keeps the dialog open. Drop the approval so the next OK asks again. + if let Some(open) = app.ui.dialog.as_mut().filter(|o| o.kind == KIND && r.is_err()) { + open.fields.remove("__confirmed_flatten"); + } r } diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index c758b8bae8..9b0007242b 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -553,3 +553,69 @@ fn save_pdf_does_not_prompt_when_compatibility_is_not_flattened() { assert_eq!(written.borrow().len(), 1); assert!(written.borrow()[0].1.starts_with(b"%PDF-1.7")); } + +#[test] +fn save_pdf_clears_confirmed_flatten_when_save_fails() { + let (mut app, _, _) = app(); + app.services.write = Some(Box::new(|_, _| Err("disk full".into()))); + app.run("transparency.set", json!({"opacity": 50})).unwrap(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/fail.pdf", "compatibility": "1.3"})).unwrap(); + super::super::confirm(&mut app).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); + + // Confirming write when disk write fails keeps Save PDF dialog open without confirmed marker + let err = super::super::confirm(&mut app); + assert!(err.is_err()); + let open = app.ui.dialog.as_ref().expect("Save PDF dialog stays open on failure"); + assert_eq!(open.kind, KIND); + assert!(!open.bool("__confirmed_flatten")); +} + +#[test] +fn save_pdf_prompts_confirmation_for_see_through_image() { + let (mut app, written, _) = app(); + let img_bytes = { + let mut buf = std::io::Cursor::new(Vec::new()); + image::RgbaImage::from_pixel(2, 2, image::Rgba([255, 0, 0, 128])).write_to(&mut buf, image::ImageFormat::Png).unwrap(); + buf.into_inner() + }; + let blob = vectorcraft_doc::ImageBlob::png(img_bytes); + let key = "see_through_img".to_string(); + app.session + .edit("add see-through image", |d, _| { + d.images.insert(key.clone(), blob); + let id = d.alloc_id(); + let im = vectorcraft_doc::ImageObject { + key, + width: 2, + height: 2, + xf: vectorcraft_geom::Affine::IDENTITY, + link: None, + placement: Default::default(), + pixels: None, + }; + d.insert(d.default_layer(), 0, vectorcraft_doc::Node::new(id, vectorcraft_doc::NodeKind::Image(Box::new(im))))?; + Ok(()) + }) + .unwrap(); + + app.run("ui.savePdfDialog", json!({"path": "/tmp/img.pdf", "compatibility": "1.3"})).unwrap(); + super::super::confirm(&mut app).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(written.borrow().len(), 1); +} + +#[test] +fn save_pdf_does_not_prompt_for_non_printing_layer_transparency() { + let (mut app, written, _) = app(); + let layer_id = app.session.active().unwrap().doc.layers[0].id; + app.run("transparency.set", json!({"opacity": 50})).unwrap(); + app.run("layer.setProps", json!({"id": layer_id.0, "printable": false})).unwrap(); + + app.run("ui.savePdfDialog", json!({"path": "/tmp/nonprint.pdf", "compatibility": "1.3"})).unwrap(); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(written.borrow().len(), 1); +} From 7234b26ec69baa991e0a2c586f0f05dae3aea3f1 Mon Sep 17 00:00:00 2001 From: el-j Date: Tue, 17 Nov 2026 12:21:37 +0100 Subject: [PATCH 5/7] Address review comments: check pattern tile transparency and skip image scan when unflattened --- crates/engine/src/cmd/flatten.rs | 3 +- crates/engine/src/cmd/flatten/apply.rs | 2 +- crates/ui-egui/src/dialogs/save_pdf.rs | 45 +++++++++++++------- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 22 ++++++++++ 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/crates/engine/src/cmd/flatten.rs b/crates/engine/src/cmd/flatten.rs index 773b9cb992..b9cec002c6 100644 --- a/crates/engine/src/cmd/flatten.rs +++ b/crates/engine/src/cmd/flatten.rs @@ -53,7 +53,8 @@ mod report; pub(crate) use analysis::{carry, outlined_text}; pub use analysis::{draws_image, see_through_images}; -pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded, has_transparent_tile_images}; +pub use apply::has_transparent_tile_images; +pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded}; #[cfg(test)] pub(crate) use apply::{with_clips_ignored, with_every_region}; pub use commands::specs; diff --git a/crates/engine/src/cmd/flatten/apply.rs b/crates/engine/src/cmd/flatten/apply.rs index b8aebf8324..67fff9b0ff 100644 --- a/crates/engine/src/cmd/flatten/apply.rs +++ b/crates/engine/src/cmd/flatten/apply.rs @@ -723,7 +723,7 @@ pub(super) fn opaque(n: &mut Node) { /// Whether `doc` has pattern fills whose image tiles need transparency flattening with `o` /// ([`expand_transparent_tile_images`]). -pub(crate) fn has_transparent_tile_images(doc: &Document, o: &FlattenOptions) -> bool { +pub fn has_transparent_tile_images(doc: &Document, o: &FlattenOptions) -> bool { let keys = o.no_transparency.clone().unwrap_or_default(); let colorize = |d: &Document, n: &Node| o.counts_colorize(d, n); !doc.patterns.is_empty() && crate::cmd::expand::has_transparent_image_patterns(doc, &keys, &colorize) diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index 85d63e2189..dd5d33ed9d 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -69,13 +69,9 @@ fn confirm_flatten(app: &mut VectorcraftApp, d: &Dialog) -> Result bool { - let see_through = vectorcraft_engine::cmd::flatten::see_through_images(doc); +fn doc_has_transparency(doc: &vectorcraft_doc::Document, include_non_printing: bool, o: &vectorcraft_engine::cmd::flatten::FlattenOptions) -> bool { + let mut with_images; + let o = match &o.no_transparency { + Some(_) => o, + None => { + with_images = o.clone(); + with_images.no_transparency = Some(vectorcraft_engine::cmd::flatten::see_through_images(doc)); + &with_images + } + }; + if vectorcraft_engine::cmd::flatten::has_transparent_tile_images(doc, o) { + return true; + } + let empty = std::collections::BTreeSet::new(); + let see_through = o.no_transparency.as_ref().unwrap_or(&empty); fn check_node(n: &vectorcraft_doc::Node, see_through: &std::collections::BTreeSet, include_non_printing: bool) -> bool { if !n.visible { return false; @@ -106,7 +115,7 @@ fn doc_has_transparency(doc: &vectorcraft_doc::Document, include_non_printing: b || vectorcraft_engine::cmd::flatten::draws_image(n, see_through) || n.children().into_iter().flatten().any(|c| check_node(c, see_through, include_non_printing)) } - doc.layers.iter().any(|l| check_node(l, &see_through, include_non_printing)) + doc.layers.iter().any(|l| check_node(l, see_through, include_non_printing)) } /// The preset editor's field holding the name of the saved preset it edits (empty: a new one). @@ -220,11 +229,17 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { } let flat = choice::(d, "compatibility") == Some(Compatibility::Pdf13) || choice::(d, "standard").is_some_and(Standard::flattens); - let include_non_printing = d.bool("includeNonPrinting") || d.bool("createLayers"); - let has_transparency = app.session.active().is_some_and(|st| doc_has_transparency(&st.doc, include_non_printing)); - if flat && has_transparency && !d.bool("__confirmed_flatten") { - ask_confirm_flatten(app, d); - return Ok(Value::Null); + if flat && !d.bool("__confirmed_flatten") { + let include_non_printing = d.bool("includeNonPrinting") || d.bool("createLayers"); + let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER); + let mut o = FlattenOptions::for_export(Some(name), d.fields.get("flattener"), &app.session.prefs.flattener_presets).unwrap_or_default(); + if let Some(st) = app.session.active() { + o.no_transparency = Some(vectorcraft_engine::cmd::flatten::see_through_images(&st.doc)); + if doc_has_transparency(&st.doc, include_non_printing, &o) { + ask_confirm_flatten(app, d, &o); + return Ok(Value::Null); + } + } } let r = match SaveMode::of(&d.str("__save")) { Some(mode) => io::save_pdf(app, mode, params(d)), diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index c7c8939da6..3564a4d601 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -651,3 +651,25 @@ fn save_pdf_does_not_prompt_for_non_printing_layer_transparency() { assert!(app.ui.dialog.is_none()); assert_eq!(written.borrow().len(), 1); } + +#[test] +fn save_pdf_prompts_confirmation_for_transparent_pattern_tile_image() { + let (mut app, written, _) = app(); + let img_bytes = { + let mut buf = std::io::Cursor::new(Vec::new()); + image::RgbaImage::from_pixel(2, 2, image::Rgba([255, 0, 0, 128])).write_to(&mut buf, image::ImageFormat::Png).unwrap(); + buf.into_inner() + }; + let href = format!("data:image/png;base64,{}", vectorcraft_format::base64_encode(&img_bytes)); + let svg = format!( + r##""## + ); + app.run("document.open", json!({"name": "pat.svg", "dataBase64": vectorcraft_format::base64_encode(svg.as_bytes())})).unwrap(); + + app.run("ui.savePdfDialog", json!({"path": "/tmp/pat.pdf", "compatibility": "1.3"})).unwrap(); + super::super::confirm(&mut app).unwrap(); + assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); + super::super::confirm(&mut app).unwrap(); + assert!(app.ui.dialog.is_none()); + assert_eq!(written.borrow().len(), 1); +} From b84f06f463dcdc8783c1745fed33a138bc81e1db Mon Sep 17 00:00:00 2001 From: Don Omondi <282319807+mockydevs@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:39:39 -0500 Subject: [PATCH 6/7] Twist test: walk the anchors through Anchors::iter after the merge Main now keeps a subpath's anchors in shared chunks, which can't be sliced. --- crates/effects/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/effects/src/tests.rs b/crates/effects/src/tests.rs index d48b91223e..52b38f986d 100644 --- a/crates/effects/src/tests.rs +++ b/crates/effects/src/tests.rs @@ -1697,7 +1697,7 @@ fn twist_joins_its_pieces_smoothly() { let out = apply_geometry(&[fx("distort.twist", json!({"angle": angle}))], &line, bounds); let anchors = &out.subpaths[0].anchors; assert!(anchors.len() > 8, "{angle}°: {} anchors", anchors.len()); - for a in &anchors[1..anchors.len() - 1] { + for a in anchors.iter().skip(1).take(anchors.len() - 2) { let (into, out) = (a.p - a.h_in, a.h_out - a.p); if into.hypot() < 1e-9 || out.hypot() < 1e-9 { continue; From 5665114718fc421d854563b52b25b90937665988 Mon Sep 17 00:00:00 2001 From: el-j Date: Tue, 17 Nov 2026 15:00:11 +0100 Subject: [PATCH 7/7] Save PDF: include flattener resolutions in Summary warning and Advanced section --- crates/engine/src/cmd/fileio/pdf.rs | 16 +- crates/engine/src/cmd/flatten.rs | 6 +- crates/engine/src/cmd/flatten/analysis.rs | 4 +- crates/engine/src/cmd/flatten/apply.rs | 2 +- crates/ui-egui/src/dialogs.rs | 1 - crates/ui-egui/src/dialogs/save_pdf.rs | 96 +----------- crates/ui-egui/src/dialogs/save_pdf/tests.rs | 152 +++++-------------- 7 files changed, 55 insertions(+), 222 deletions(-) diff --git a/crates/engine/src/cmd/fileio/pdf.rs b/crates/engine/src/cmd/fileio/pdf.rs index 75e2dba02b..36b0845aa1 100644 --- a/crates/engine/src/cmd/fileio/pdf.rs +++ b/crates/engine/src/cmd/fileio/pdf.rs @@ -417,9 +417,13 @@ fn encode_carrying_at( } let (flat, flattened) = flatten_for(cmd, doc, set, p)?; vectorcraft_doc::cancel::check()?; - if flattened { + if let Some(o) = flattened { let kind = if set.standard.flattens() { set.standard.label() } else { set.compatibility.label() }; - notes.push(Note::loss(format!("transparency is flattened into opaque art and images ({kind} files have none): see the flattener preset"))); + let line_ppi = o.line_art_ppi.round() as u32; + let grad_ppi = o.gradient_ppi.round() as u32; + notes.push(Note::loss(format!( + "transparency is flattened into opaque art and images ({kind} files have none) at {line_ppi} ppi line art and text, {grad_ppi} ppi gradients and meshes: see the flattener preset" + ))); } let r = super::super::rasterfx::export_pdf_with_report(flat.as_ref().unwrap_or(doc), &opts).map_err(|e| pdf_error(cmd, e))?; notes.extend(r.warnings.into_iter().map(Note::loss)); @@ -438,9 +442,9 @@ pub const DEFAULT_FLATTENER: &str = "High Resolution"; /// discarded overprints are dropped. Layers the pages leave out (non-printing ones, unless asked /// for) are left out of the flattening, hidden. → the document to write (`None`: `doc` as it is) /// and whether its transparency was flattened. -fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Result<(Option, bool)> { +fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Result<(Option, Option)> { if !set.pdf13() { - return Ok((None, false)); + return Ok((None, None)); } let printed = if set.include_non_printing || set.create_layers { None } else { without_non_printing(&doc.layers) }; let shown = printed.map(|layers| { @@ -456,8 +460,8 @@ fn flatten_for(cmd: &str, doc: &Document, set: &PdfSettings, p: &Value) -> Resul // its art: it is clipped to its regions (opaque inside them). o.clip_complex_regions = true; Ok(match flatten_document(shown.as_ref().unwrap_or(doc), &o)? { - Some(flat) => (Some(flat), true), - None => (shown, false), + Some(flat) => (Some(flat), Some(o)), + None => (shown, None), }) } diff --git a/crates/engine/src/cmd/flatten.rs b/crates/engine/src/cmd/flatten.rs index b9cec002c6..399f2ec4bd 100644 --- a/crates/engine/src/cmd/flatten.rs +++ b/crates/engine/src/cmd/flatten.rs @@ -51,10 +51,8 @@ mod options; mod presets; mod report; -pub(crate) use analysis::{carry, outlined_text}; -pub use analysis::{draws_image, see_through_images}; -pub use apply::has_transparent_tile_images; -pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded}; +pub(crate) use analysis::{carry, outlined_text, see_through_images}; +pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded, has_transparent_tile_images}; #[cfg(test)] pub(crate) use apply::{with_clips_ignored, with_every_region}; pub use commands::specs; diff --git a/crates/engine/src/cmd/flatten/analysis.rs b/crates/engine/src/cmd/flatten/analysis.rs index ea6e350eda..70eab3c3e5 100644 --- a/crates/engine/src/cmd/flatten/analysis.rs +++ b/crates/engine/src/cmd/flatten/analysis.rs @@ -69,14 +69,14 @@ pub(crate) fn carry(from: &Node, mut to: Node) -> Node { /// The keys of `doc`'s images that have see-through pixels (an alpha channel that isn't opaque /// everywhere). -pub fn see_through_images(doc: &Document) -> BTreeSet { +pub(crate) fn see_through_images(doc: &Document) -> BTreeSet { let see_through = |b: &ImageBlob| b.mime != "image/jpeg" && b.has_transparency(); doc.images.iter().filter(|(_, b)| see_through(b)).map(|(k, _)| k.clone()).collect() } /// `n` shows an image of `keys` (itself or inside), a color-masked image's masked pixels counted as /// what it shows. -pub fn draws_image(n: &Node, keys: &BTreeSet) -> bool { +pub(super) fn draws_image(n: &Node, keys: &BTreeSet) -> bool { !keys.is_empty() && n.visible && match &n.kind { diff --git a/crates/engine/src/cmd/flatten/apply.rs b/crates/engine/src/cmd/flatten/apply.rs index 67fff9b0ff..b8aebf8324 100644 --- a/crates/engine/src/cmd/flatten/apply.rs +++ b/crates/engine/src/cmd/flatten/apply.rs @@ -723,7 +723,7 @@ pub(super) fn opaque(n: &mut Node) { /// Whether `doc` has pattern fills whose image tiles need transparency flattening with `o` /// ([`expand_transparent_tile_images`]). -pub fn has_transparent_tile_images(doc: &Document, o: &FlattenOptions) -> bool { +pub(crate) fn has_transparent_tile_images(doc: &Document, o: &FlattenOptions) -> bool { let keys = o.no_transparency.clone().unwrap_or_default(); let colorize = |d: &Document, n: &Node| o.counts_colorize(d, n); !doc.patterns.is_empty() && crate::cmd::expand::has_transparent_image_patterns(doc, &keys, &colorize) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index df2016241a..30b02e4380 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -379,7 +379,6 @@ registry! { WarichuSettings: [warichu::KIND] => warichu::SPEC, CompositeFonts: [composite_fonts::KIND] => composite_fonts::SPEC, SavePdf: [save_pdf::KIND] => save_pdf::SPEC, - ConfirmFlattenPdf: [save_pdf::CONFIRM_FLATTEN] => save_pdf::CONFIRM_FLATTEN_SPEC, SvgOptions: [svg_options::KIND] => svg_options::SPEC, JavaScriptFiles: [javascript_files::KIND] => javascript_files::SPEC, SvgFilter: [svg_filter::KIND] => svg_filter::SPEC, diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs index dd5d33ed9d..d8d73c79eb 100644 --- a/crates/ui-egui/src/dialogs/save_pdf.rs +++ b/crates/ui-egui/src/dialogs/save_pdf.rs @@ -44,80 +44,6 @@ pub(super) const PRESET_SPEC: DialogSpec = DialogSpec { ..DialogSpec::FORM }; -/// The dialog kind of the confirmation prompt when saving with transparency reduction. -pub(crate) const CONFIRM_FLATTEN: &str = "confirmFlattenPdf"; - -pub(crate) const CONFIRM_FLATTEN_SPEC: DialogSpec = DialogSpec { - heading: |d| d.str("message"), - body: |_, ui, d| { - let detail = d.str("detail"); - if !detail.is_empty() { - ui.label(egui::RichText::new(detail).color(Tokens::get(ui.ctx()).text_dim)); - } - false - }, - confirm: confirm_flatten, - ok: Some("Continue"), - max_width: Some(440.0), - ..DialogSpec::FORM -}; - -fn confirm_flatten(app: &mut VectorcraftApp, d: &Dialog) -> Result { - let mut parent = super::parent(d).filter(|p| p.kind == KIND).ok_or("the Save PDF dialog is no longer open")?; - parent.fields.insert("__confirmed_flatten".into(), json!(true)); - app.ui.dialog = Some(parent.clone()); - confirm(app, &parent) -} - -fn ask_confirm_flatten(app: &mut VectorcraftApp, d: &Dialog, o: &FlattenOptions) { - let line_ppi = o.line_art_ppi.round() as u32; - let grad_ppi = o.gradient_ppi.round() as u32; - let message = tl!("The document contains transparency which will be flattened. Do you want to continue?"); - let detail = crate::i18n::fmt( - tl!( - "Transparent objects will be reduced into opaque paths and images at {line_ppi} ppi (line art and text) and {grad_ppi} ppi (gradients and meshes). Reopening the PDF may not restore separate transparent objects." - ), - &[("line_ppi", &line_ppi.to_string()), ("grad_ppi", &grad_ppi.to_string())], - ); - let under = serde_json::to_value(d).ok(); - let fields = json!({ - "message": message, - "detail": detail, - super::PARENT: under, - }); - app.ui.dialog = Some(Dialog::new(CONFIRM_FLATTEN, fields)); -} - -fn doc_has_transparency(doc: &vectorcraft_doc::Document, include_non_printing: bool, o: &vectorcraft_engine::cmd::flatten::FlattenOptions) -> bool { - let mut with_images; - let o = match &o.no_transparency { - Some(_) => o, - None => { - with_images = o.clone(); - with_images.no_transparency = Some(vectorcraft_engine::cmd::flatten::see_through_images(doc)); - &with_images - } - }; - if vectorcraft_engine::cmd::flatten::has_transparent_tile_images(doc, o) { - return true; - } - let empty = std::collections::BTreeSet::new(); - let see_through = o.no_transparency.as_ref().unwrap_or(&empty); - fn check_node(n: &vectorcraft_doc::Node, see_through: &std::collections::BTreeSet, include_non_printing: bool) -> bool { - if !n.visible { - return false; - } - if matches!(n.kind, vectorcraft_doc::NodeKind::Layer { printable: false, .. }) && !include_non_printing { - return false; - } - !n.has_default_transparency() - || n.shows_transparency() - || vectorcraft_engine::cmd::flatten::draws_image(n, see_through) - || n.children().into_iter().flatten().any(|c| check_node(c, see_through, include_non_printing)) - } - doc.layers.iter().any(|l| check_node(l, see_through, include_non_printing)) -} - /// The preset editor's field holding the name of the saved preset it edits (empty: a new one). const EDITING: &str = "__editing"; /// Save PDF's field holding the name typed for Save Preset… (present while that row shows). @@ -227,20 +153,6 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { app.ui.dialog = Some(d); return r; } - let flat = choice::(d, "compatibility") == Some(Compatibility::Pdf13) - || choice::(d, "standard").is_some_and(Standard::flattens); - if flat && !d.bool("__confirmed_flatten") { - let include_non_printing = d.bool("includeNonPrinting") || d.bool("createLayers"); - let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER); - let mut o = FlattenOptions::for_export(Some(name), d.fields.get("flattener"), &app.session.prefs.flattener_presets).unwrap_or_default(); - if let Some(st) = app.session.active() { - o.no_transparency = Some(vectorcraft_engine::cmd::flatten::see_through_images(&st.doc)); - if doc_has_transparency(&st.doc, include_non_printing, &o) { - ask_confirm_flatten(app, d, &o); - return Ok(Value::Null); - } - } - } let r = match SaveMode::of(&d.str("__save")) { Some(mode) => io::save_pdf(app, mode, params(d)), None if d.bool(ART_BOUNDS) => export_art(app, d), @@ -250,10 +162,6 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { if r.is_ok() && app.ui.dialog.as_ref().is_some_and(|o| o.kind == KIND) { app.ui.dialog = None; } - // A failed write keeps the dialog open. Drop the approval so the next OK asks again. - if let Some(open) = app.ui.dialog.as_mut().filter(|o| o.kind == KIND && r.is_err()) { - open.fields.remove("__confirmed_flatten"); - } r } @@ -826,9 +734,7 @@ fn advanced(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) { }); if flat { let name = get(d, "flattenerPreset").as_str().map(str::trim).filter(|n| !n.is_empty()).unwrap_or(pdf::DEFAULT_FLATTENER); - let preset_opts = FlattenOptions::preset(name) - .or_else(|| app.session.prefs.flattener_presets.iter().find(|p| p.name.eq_ignore_ascii_case(name)).map(|p| p.options.clone())) - .unwrap_or_default(); + let preset_opts = FlattenOptions::for_export(Some(name), d.fields.get("flattener"), &app.session.prefs.flattener_presets).unwrap_or_default(); let line_ppi = preset_opts.line_art_ppi.round() as u32; let grad_ppi = preset_opts.gradient_ppi.round() as u32; note( diff --git a/crates/ui-egui/src/dialogs/save_pdf/tests.rs b/crates/ui-egui/src/dialogs/save_pdf/tests.rs index 3564a4d601..b8a0704e28 100644 --- a/crates/ui-egui/src/dialogs/save_pdf/tests.rs +++ b/crates/ui-egui/src/dialogs/save_pdf/tests.rs @@ -541,7 +541,7 @@ fn pdf_1_3_takes_a_flattener_preset_in_advanced() { } #[test] -fn save_pdf_prompts_confirmation_when_document_has_transparency_and_is_flattened() { +fn save_pdf_flattens_transparent_document_without_modal_prompt() { let (mut app, written, _) = app(); // Add transparent artwork to the document app.run("transparency.set", json!({"opacity": 50})).unwrap(); @@ -549,127 +549,53 @@ fn save_pdf_prompts_confirmation_when_document_has_transparency_and_is_flattened app.run("ui.savePdfDialog", json!({"path": "/tmp/transparent.pdf", "compatibility": "1.3"})).unwrap(); assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND); - // Clicking Save PDF triggers the confirmFlattenPdf modal prompt + // Clicking Save PDF goes ahead without stopping at a confirmation prompt super::super::confirm(&mut app).unwrap(); - let prompt = app.ui.dialog.as_ref().expect("confirm dialog open"); - assert_eq!(prompt.kind, CONFIRM_FLATTEN); - assert!(prompt.str("message").contains("transparency which will be flattened")); - assert!(prompt.str("detail").contains("1200 ppi")); - assert!(prompt.str("detail").contains("300 ppi")); - - // Cancel on confirmation modal restores the Save PDF dialog - crate::dialogs::cancel(&mut app); - assert_eq!(app.ui.dialog.as_ref().expect("Save PDF restored").kind, KIND); - assert!(written.borrow().is_empty(), "nothing written on cancel"); - - // Click Save PDF again, then confirm the prompt - super::super::confirm(&mut app).unwrap(); - assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); - super::super::confirm(&mut app).unwrap(); - assert!(app.ui.dialog.is_none(), "dialog closed after save"); + assert!(app.ui.dialog.is_none(), "Save PDF closes without a modal prompt"); assert_eq!(written.borrow().len(), 1); assert!(written.borrow()[0].1.starts_with(b"%PDF-1.3")); } #[test] -fn save_pdf_does_not_prompt_when_compatibility_is_not_flattened() { - let (mut app, written, _) = app(); - app.run("transparency.set", json!({"opacity": 50})).unwrap(); - - app.run("ui.savePdfDialog", json!({"path": "/tmp/live.pdf", "compatibility": "1.7"})).unwrap(); - assert_eq!(app.ui.dialog.as_ref().unwrap().kind, KIND); - - // Saving with PDF 1.7 (supports live transparency) does not prompt confirmation - super::super::confirm(&mut app).unwrap(); - assert!(app.ui.dialog.is_none()); - assert_eq!(written.borrow().len(), 1); - assert!(written.borrow()[0].1.starts_with(b"%PDF-1.7")); -} - -#[test] -fn save_pdf_clears_confirmed_flatten_when_save_fails() { +fn summary_warnings_include_flattener_resolutions_when_flattening_transparency() { let (mut app, _, _) = app(); - app.services.write = Some(Box::new(|_, _| Err("disk full".into()))); app.run("transparency.set", json!({"opacity": 50})).unwrap(); - app.run("ui.savePdfDialog", json!({"path": "/tmp/fail.pdf", "compatibility": "1.3"})).unwrap(); - super::super::confirm(&mut app).unwrap(); - assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); - // Confirming write when disk write fails keeps Save PDF dialog open without confirmed marker - let err = super::super::confirm(&mut app); - assert!(err.is_err()); - let open = app.ui.dialog.as_ref().expect("Save PDF dialog stays open on failure"); - assert_eq!(open.kind, KIND); - assert!(!open.bool("__confirmed_flatten")); -} - -#[test] -fn save_pdf_prompts_confirmation_for_see_through_image() { - let (mut app, written, _) = app(); - let img_bytes = { - let mut buf = std::io::Cursor::new(Vec::new()); - image::RgbaImage::from_pixel(2, 2, image::Rgba([255, 0, 0, 128])).write_to(&mut buf, image::ImageFormat::Png).unwrap(); - buf.into_inner() - }; - let blob = vectorcraft_doc::ImageBlob::png(img_bytes); - let key = "see_through_img".to_string(); - app.session - .edit("add see-through image", |d, _| { - d.images.insert(key.clone(), blob); - let id = d.alloc_id(); - let im = vectorcraft_doc::ImageObject { - key, - width: 2, - height: 2, - xf: vectorcraft_geom::Affine::IDENTITY, - link: None, - placement: Default::default(), - pixels: None, - }; - d.insert(d.default_layer(), 0, vectorcraft_doc::Node::new(id, vectorcraft_doc::NodeKind::Image(Box::new(im))))?; - Ok(()) - }) - .unwrap(); - - app.run("ui.savePdfDialog", json!({"path": "/tmp/img.pdf", "compatibility": "1.3"})).unwrap(); - super::super::confirm(&mut app).unwrap(); - assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); - super::super::confirm(&mut app).unwrap(); - assert!(app.ui.dialog.is_none()); - assert_eq!(written.borrow().len(), 1); -} - -#[test] -fn save_pdf_does_not_prompt_for_non_printing_layer_transparency() { - let (mut app, written, _) = app(); - let layer_id = app.session.active().unwrap().doc.layers[0].id; - app.run("transparency.set", json!({"opacity": 50})).unwrap(); - app.run("layer.setProps", json!({"id": layer_id.0, "printable": false})).unwrap(); - - app.run("ui.savePdfDialog", json!({"path": "/tmp/nonprint.pdf", "compatibility": "1.3"})).unwrap(); - super::super::confirm(&mut app).unwrap(); - assert!(app.ui.dialog.is_none()); - assert_eq!(written.borrow().len(), 1); -} - -#[test] -fn save_pdf_prompts_confirmation_for_transparent_pattern_tile_image() { - let (mut app, written, _) = app(); - let img_bytes = { - let mut buf = std::io::Cursor::new(Vec::new()); - image::RgbaImage::from_pixel(2, 2, image::Rgba([255, 0, 0, 128])).write_to(&mut buf, image::ImageFormat::Png).unwrap(); - buf.into_inner() - }; - let href = format!("data:image/png;base64,{}", vectorcraft_format::base64_encode(&img_bytes)); - let svg = format!( - r##""## + app.run("ui.savePdfDialog", json!({"path": "/tmp/out.pdf", "compatibility": "1.3"})).unwrap(); + let p = params(app.ui.dialog.as_ref().unwrap()); + let v = summary_of(&mut app, &egui::Context::default(), &p).unwrap(); + let warnings = v["warnings"].as_array().unwrap(); + assert!( + warnings.iter().any(|w| { + let s = w.as_str().unwrap(); + s.contains("transparency is flattened into opaque art and images") + && s.contains("at 1200 ppi line art and text, 300 ppi gradients and meshes") + }), + "{warnings:?}" ); - app.run("document.open", json!({"name": "pat.svg", "dataBase64": vectorcraft_format::base64_encode(svg.as_bytes())})).unwrap(); - app.run("ui.savePdfDialog", json!({"path": "/tmp/pat.pdf", "compatibility": "1.3"})).unwrap(); - super::super::confirm(&mut app).unwrap(); - assert_eq!(app.ui.dialog.as_ref().unwrap().kind, CONFIRM_FLATTEN); - super::super::confirm(&mut app).unwrap(); - assert!(app.ui.dialog.is_none()); - assert_eq!(written.borrow().len(), 1); + // With a custom flattener override, the resolution in the warning reflects the options + set_field(&mut app, "flattener.lineArtPpi", json!(600)); + set_field(&mut app, "flattener.gradientPpi", json!(200)); + let p2 = params(app.ui.dialog.as_ref().unwrap()); + let v2 = summary_of(&mut app, &egui::Context::default(), &p2).unwrap(); + let warnings2 = v2["warnings"].as_array().unwrap(); + assert!( + warnings2.iter().any(|w| { + let s = w.as_str().unwrap(); + s.contains("at 600 ppi line art and text, 200 ppi gradients and meshes") + }), + "{warnings2:?}" + ); +} + +#[test] +fn advanced_section_shows_raster_resolution_note() { + let (mut app, _, _) = app(); + app.run("ui.savePdfDialog", json!({"path": "/tmp/out.pdf", "compatibility": "1.3"})).unwrap(); + set_field(&mut app, "__section", json!("Advanced")); + set_field(&mut app, "flattener.lineArtPpi", json!(600)); + set_field(&mut app, "flattener.gradientPpi", json!(200)); + frame(&mut app); + assert!(app.ui.dialog.is_some()); }