diff --git a/ROADMAP.md b/ROADMAP.md index 5827ed8e..d33c80e5 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -4,7 +4,7 @@ VectorCraft is a clean-room, open-source, pure-Rust reimplementation of the Adob This file tracks **how far we are and what's left**. Time estimates are wall-clock hours of continuous Claude Opus 5.5 agent work (including builds and the CI gate), given both for **one agent** and for **4–6 parallel agents** on disjoint crates. They are counted from the remaining work (see [Parity estimate](#parity-estimate)), calibrated against measured throughput, and updated as work lands. -_Last updated: 2026-10-09 (after placed documents (File › Place of a `.vectorcraft` file, linked), M4.14–M4.98, M8.1–M8.20, M14.4–M14.7, the MCP prompts, resource templates, completions and logging, the 2026-10-07 issue fixes, the Layers panel rework and the 2026-10-08 community contributions: Pen and shape-tool modifiers, path editing, Layers, Artboards, Swatches/Brushes and dialogs, Japanese composition and PDF text, Hebrew/Arabic type, interface languages (Spanish among them), the font menu, saved selections, MCP and EPS, the missing-font export warning (#319), open paths in the Shape Builder (#374), PDF/`.ai` import keeping strokes live and hidden and nested layers (#372), per-corner Live Corners (#381), SVG type opening at the size it draws at (#396), the Wayland clipboard with copied-file paste (#398), ruler guides that can be selected, moved and deleted (#414), two batches of Preferences options that were stored but unused (#394), skeleton reads with `document.find` for large documents over MCP (#416) and anchors dragged with Direct Selection snapping to points, segments and smart guides, clipped SVG layers opening as clipping layers (#420), PDF/`.ai` layers read on pages of tens of millions of operators (#419), Document Color Mode putting RGB greys on the black plate on request and converting pattern tiles (#421) and movable dialogs with Offset Path's Joins dropdown (#423) and numeric fields scrubbed by dragging their label (#400), stroke weight presets in the stroke unit (#426), the Appearance panel's Opacity popup (#430), type on a path brackets, flip and Type on a Path Options that keep the type in place (#429), Layers rows dragged with a ghost and dropped on the trash or New Layer (#435), tool flyouts opening on a right or corner press (#436), tool flyouts torn off into floating toolbars (#437), the Shape Builder's erase mode deleting edges too (#439), installed fonts registered outside the font folders and fonts installed while the app runs listed in the font menus (#443), alike circular corners on rectangles that aren't square (#442), tool cursors as OS cursors so the pointer no longer trails over the canvas (#444), artboards copied and pasted with their art (#446), guides dragged out of the rulers snapping to the art's side midpoints and the artboards, artboard guides (#451), the toolbar's double arrow and Window › Toolbars › Double Column switching between one and two columns in any window height (#455), the Smart Guides display options and Snapping Tolerance (#394), Font Size and Leading combo boxes with preset lists in the Character and Properties panels and the Control bar (#458), screenshots pasted from the clipboard on macOS, Windows and the web (#457), the Properties panel's Fill and Stroke matching the Control bar's, Illustrator's Window menu panel keys (Shift+F7 for Align…) and Alt-wheel zoom whatever the wheel preference (Discord feedback), the point/area type widget (Discord feedback), groups in legacy Illustrator .ai files (Discord feedback), a rotating desktop log file (#465), image controls in the Control bar and Properties panel: Image Trace with its presets, Mask, Crop Image, Embed/Unembed, and an Image Trace object's preset, Expand and Release (Discord feedback), the Pen working as the Anchor Point tool with Alt held over a selected path's handles and anchors, and anchor buttons that convert, connect and cut paths at the selected anchors (Discord feedback), Japanese hanging punctuation (burasagari, #463), Escape leaving Presentation Mode with no screen mode saved across restarts, documents dropped on the desktop app opening as tabs of their own and a note that an `.ai` file's art off its artboards isn't in the part read (#472), Add/Delete Anchor Point tool icons drawn from the Pen tool's (#479), EPS import running more of PostScript Level 3 (patterns, Type 3 fonts, mesh shadings, masked images, VM and resource probes), and a preview that stands in saying why (Discord feedback, #466, #469, #474), chords with modifiers recorded in Edit › Keyboard Shortcuts (#487), Type Object Selection by Path Only (#394), Anti-aliased Artwork (#394), Show Pixel Grid (#394), pen and touch taps pressed and lifted within one frame clicking where they tapped and the Linux/Wayland pen-tablet workaround (#491), bounding-box resizes landing on the other objects' anchors and centres with labels, and the Rotate, Scale, Shear and Reflect tools snapping their drags (#482), Shift-drag marquees that toggle the objects or anchors they reach and a Lasso whose Alt subtraction keeps the rest of the selection (#483), the mouse wheel stepping the focused numeric field, the dialogs' and preferences' drag values made such fields (#485), Show The Home Screen When No Documents Are Open (#394), Numbers Without Units Are Points (#394), Auto-Collapse Iconic Panels (#394), the Contextual Task Bar moved by its handle and its More Options menu pinning and resetting its position, a designed macOS DMG window (#493), panels, panel groups and the Tools panel undocking into floating panels that move, stack and dock again (#495), the 0.5.0 startup crash on dual-GPU Linux desktops under Wayland fixed: the desktop's own GPU by default and a restart on the next GPU when one can't show the window (#502), path editing while drawing: Cmd/Ctrl with the Pen borrowing Direct Selection and drawing on afterwards, Pen+Alt reshaping segments, handles of a whole selected path dragging, and handle drags no longer re-gathering snap targets every move (#494), the Control bar's and Properties panel's Convert buttons for a path selected as a whole with Direct Selection, the Pen and the anchor tools (#504), the Pen closing a path dragged out of its first anchor every time, without flicker (#501), the Paste menu checking the system clipboard on a background thread on Linux so an X11 clipboard owner that never answers no longer freezes the window (#510), PDF/`.ai` import keeping a type object's outline stroke on the type, wrapped lines as area type, barcode digits in place and layers in the file's stacking order (#508), the Italian interface (#514), EPS images with several data sources read in turn (#498), `restore` undoing dictionary changes in EPS import (part of #505), the macOS menu bar laid out as a Mac app's (the VectorCraft menu with Settings, Language and Appearance, the system's Hide, Services and Window items; owner's request), Object › Image Trace › Make tracing with the Default preset instead of asking for a preset's name (#543), the rulers' unit menu (#528), Live Corners on stars, polygons and pen paths (#511), the drawing tools snapping to Smart Guides as the Selection tool does, with Construction Guides (#506), the in-window menus' Select All, Cut, Copy and Paste acting on the text field they were opened from (#516), Windows rendering through DX12 before Vulkan (#545), Image Trace tracing colour layers in parallel and refusing traces too large for memory, with the canvas outlining huge selections by their bounds (#525), SVGs of chosen artboards holding only the art over each artboard (#550), the font menu scrolling only its list, under a search field and filters that stay put (#555), a click on an object of a selection making it the key object that Align aligns to and Distribute Spacing spaces from, drawn with a thicker outline (#541), Shape Builder merges taken from the planar map itself, so merged regions leave no inner edge, hairline gap or spur in their outline (#569), `.ai` written by the exports and the CLI (`--export`, `convert`) as Save As writes it (#526), SVG round trips keeping hidden objects and `data-*` attributes (#522), the gradient stop popover staying open after the click that opens it from the Gradient panel (#577), standard ligatures kept under small tracking and dropped only past about −8% / +22% of a word space or when the character asks for them (#583), the Color panel keeping its height as warnings come and go so a drag on its spectrum no longer flickers near white (#578), fonts that font services such as Adobe Fonts load on Windows, listed through DirectWrite (#579), `.ai` files writing their layers and sublayers as PDF layers, hidden ones with their art, and PDF layers nested in layers importing as sublayers (#372), file dialogs on Linux shown off the UI thread so the compositor no longer finds the window not responding, and parented to the window on Linux and Windows (#592), anchors and handle ends picked from 2 px past their drawn size before the segments through them (#593), an image copied in a browser pasting as the picture, not its address (#597), the Free Transform widget with Constrain, Free Transform, Perspective Distort and Free Distort (#598), touch gestures: a two-finger tap undoes and a three-finger tap redoes (#585), the font menus' live preview staying on the text instead of flickering on and off every frame (#563), Edit Artboards showing the active artboard in the Properties panel with New Artboard, Delete Artboard and Exit (#530), the same DirectWrite fonts in `vectorcraft-cli` and its MCP server (#579), SVG layers keeping their names when wrapped and sublayers round-tripping through SVG (#372), a Layers panel that lays out only the rows in view and keeps a document's open rows in its file (#638), a panel dropped on the dock lights up the icon column it goes back to and pops out of its icon (#649); see [Honest assessment](#honest-assessment-2026-10-05))._ +_Last updated: 2026-10-09 (after placed documents (File › Place of a `.vectorcraft` file, linked), M4.14–M4.98, M8.1–M8.20, M14.4–M14.7, the MCP prompts, resource templates, completions and logging, the 2026-10-07 issue fixes, the Layers panel rework and the 2026-10-08 community contributions: Pen and shape-tool modifiers, path editing, Layers, Artboards, Swatches/Brushes and dialogs, Japanese composition and PDF text, Hebrew/Arabic type, interface languages (Spanish among them), the font menu, saved selections, MCP and EPS, the missing-font export warning (#319), open paths in the Shape Builder (#374), PDF/`.ai` import keeping strokes live and hidden and nested layers (#372), per-corner Live Corners (#381), SVG type opening at the size it draws at (#396), the Wayland clipboard with copied-file paste (#398), ruler guides that can be selected, moved and deleted (#414), two batches of Preferences options that were stored but unused (#394), skeleton reads with `document.find` for large documents over MCP (#416) and anchors dragged with Direct Selection snapping to points, segments and smart guides, clipped SVG layers opening as clipping layers (#420), PDF/`.ai` layers read on pages of tens of millions of operators (#419), Document Color Mode putting RGB greys on the black plate on request and converting pattern tiles (#421) and movable dialogs with Offset Path's Joins dropdown (#423) and numeric fields scrubbed by dragging their label (#400), stroke weight presets in the stroke unit (#426), the Appearance panel's Opacity popup (#430), type on a path brackets, flip and Type on a Path Options that keep the type in place (#429), Layers rows dragged with a ghost and dropped on the trash or New Layer (#435), tool flyouts opening on a right or corner press (#436), tool flyouts torn off into floating toolbars (#437), the Shape Builder's erase mode deleting edges too (#439), installed fonts registered outside the font folders and fonts installed while the app runs listed in the font menus (#443), alike circular corners on rectangles that aren't square (#442), tool cursors as OS cursors so the pointer no longer trails over the canvas (#444), artboards copied and pasted with their art (#446), guides dragged out of the rulers snapping to the art's side midpoints and the artboards, artboard guides (#451), the toolbar's double arrow and Window › Toolbars › Double Column switching between one and two columns in any window height (#455), the Smart Guides display options and Snapping Tolerance (#394), Font Size and Leading combo boxes with preset lists in the Character and Properties panels and the Control bar (#458), screenshots pasted from the clipboard on macOS, Windows and the web (#457), the Properties panel's Fill and Stroke matching the Control bar's, Illustrator's Window menu panel keys (Shift+F7 for Align…) and Alt-wheel zoom whatever the wheel preference (Discord feedback), the point/area type widget (Discord feedback), groups in legacy Illustrator .ai files (Discord feedback), a rotating desktop log file (#465), image controls in the Control bar and Properties panel: Image Trace with its presets, Mask, Crop Image, Embed/Unembed, and an Image Trace object's preset, Expand and Release (Discord feedback), the Pen working as the Anchor Point tool with Alt held over a selected path's handles and anchors, and anchor buttons that convert, connect and cut paths at the selected anchors (Discord feedback), Japanese hanging punctuation (burasagari, #463), Escape leaving Presentation Mode with no screen mode saved across restarts, documents dropped on the desktop app opening as tabs of their own and a note that an `.ai` file's art off its artboards isn't in the part read (#472), Add/Delete Anchor Point tool icons drawn from the Pen tool's (#479), EPS import running more of PostScript Level 3 (patterns, Type 3 fonts, mesh shadings, masked images, VM and resource probes), and a preview that stands in saying why (Discord feedback, #466, #469, #474), chords with modifiers recorded in Edit › Keyboard Shortcuts (#487), Type Object Selection by Path Only (#394), Anti-aliased Artwork (#394), Show Pixel Grid (#394), pen and touch taps pressed and lifted within one frame clicking where they tapped and the Linux/Wayland pen-tablet workaround (#491), bounding-box resizes landing on the other objects' anchors and centres with labels, and the Rotate, Scale, Shear and Reflect tools snapping their drags (#482), Shift-drag marquees that toggle the objects or anchors they reach and a Lasso whose Alt subtraction keeps the rest of the selection (#483), the mouse wheel stepping the focused numeric field, the dialogs' and preferences' drag values made such fields (#485), Show The Home Screen When No Documents Are Open (#394), Numbers Without Units Are Points (#394), Auto-Collapse Iconic Panels (#394), the Contextual Task Bar moved by its handle and its More Options menu pinning and resetting its position, a designed macOS DMG window (#493), panels, panel groups and the Tools panel undocking into floating panels that move, stack and dock again (#495), the 0.5.0 startup crash on dual-GPU Linux desktops under Wayland fixed: the desktop's own GPU by default and a restart on the next GPU when one can't show the window (#502), path editing while drawing: Cmd/Ctrl with the Pen borrowing Direct Selection and drawing on afterwards, Pen+Alt reshaping segments, handles of a whole selected path dragging, and handle drags no longer re-gathering snap targets every move (#494), the Control bar's and Properties panel's Convert buttons for a path selected as a whole with Direct Selection, the Pen and the anchor tools (#504), the Pen closing a path dragged out of its first anchor every time, without flicker (#501), the Paste menu checking the system clipboard on a background thread on Linux so an X11 clipboard owner that never answers no longer freezes the window (#510), PDF/`.ai` import keeping a type object's outline stroke on the type, wrapped lines as area type, barcode digits in place and layers in the file's stacking order (#508), the Italian interface (#514), EPS images with several data sources read in turn (#498), `restore` undoing dictionary changes in EPS import (part of #505), the macOS menu bar laid out as a Mac app's (the VectorCraft menu with Settings, Language and Appearance, the system's Hide, Services and Window items; owner's request), Object › Image Trace › Make tracing with the Default preset instead of asking for a preset's name (#543), the rulers' unit menu (#528), Live Corners on stars, polygons and pen paths (#511), the drawing tools snapping to Smart Guides as the Selection tool does, with Construction Guides (#506), the in-window menus' Select All, Cut, Copy and Paste acting on the text field they were opened from (#516), Windows rendering through DX12 before Vulkan (#545), Image Trace tracing colour layers in parallel and refusing traces too large for memory, with the canvas outlining huge selections by their bounds (#525), SVGs of chosen artboards holding only the art over each artboard (#550), the font menu scrolling only its list, under a search field and filters that stay put (#555), a click on an object of a selection making it the key object that Align aligns to and Distribute Spacing spaces from, drawn with a thicker outline (#541), Shape Builder merges taken from the planar map itself, so merged regions leave no inner edge, hairline gap or spur in their outline (#569), `.ai` written by the exports and the CLI (`--export`, `convert`) as Save As writes it (#526), SVG round trips keeping hidden objects and `data-*` attributes (#522), the gradient stop popover staying open after the click that opens it from the Gradient panel (#577), standard ligatures kept under small tracking and dropped only past about −8% / +22% of a word space or when the character asks for them (#583), the Color panel keeping its height as warnings come and go so a drag on its spectrum no longer flickers near white (#578), fonts that font services such as Adobe Fonts load on Windows, listed through DirectWrite (#579), `.ai` files writing their layers and sublayers as PDF layers, hidden ones with their art, and PDF layers nested in layers importing as sublayers (#372), file dialogs on Linux shown off the UI thread so the compositor no longer finds the window not responding, and parented to the window on Linux and Windows (#592), anchors and handle ends picked from 2 px past their drawn size before the segments through them (#593), an image copied in a browser pasting as the picture, not its address (#597), the Free Transform widget with Constrain, Free Transform, Perspective Distort and Free Distort (#598), touch gestures: a two-finger tap undoes and a three-finger tap redoes (#585), the font menus' live preview staying on the text instead of flickering on and off every frame (#563), Edit Artboards showing the active artboard in the Properties panel with New Artboard, Delete Artboard and Exit (#530), the same DirectWrite fonts in `vectorcraft-cli` and its MCP server (#579), SVG layers keeping their names when wrapped and sublayers round-tripping through SVG (#372), a Layers panel that lays out only the rows in view and keeps a document's open rows in its file (#638), a panel dropped on the dock lights up the icon column it goes back to and pops out of its icon (#649), Image Trace's View modes and an Advanced section that stays as it was left (part of #641); see [Honest assessment](#honest-assessment-2026-10-05))._ ## Where we are @@ -143,7 +143,7 @@ grade by behaviour against `plan/illustrator/`, not by whether a menu item exist - **Type:** Text Wrap, Type on a Path effects (Rainbow/Skew/3D Ribbon/Stair Step/Gravity) and Options (Flip, Align to Path, Spacing; OK keeps the type where it is), type on a path's start, centre and end brackets (Selection and Direct Selection drag them to set where the type runs, slide it along its path and, across the path, flip it: #429), Character and Paragraph Styles (override-preserving redefine), paragraph attributes per paragraph (alignment, indents, spacing, hyphenation, hanging punctuation, tab stops, paragraph style, direction, mojikumi and leading model; the Paragraph, Tabs and Paragraph Styles panels act on the paragraphs the Type tool's selection or caret touches, Return continues the paragraph's style, threads and SVG keep them), Area Type Options (rows/columns/inset/first baseline, vertical Align Top/Center/Bottom/Justify per row/column, reflowing non-rectangular frames and text wrap), threaded text across any closed shapes, Fit Headline, the Every-line Composer for justified and ragged text (paragraph-wide breaks for an even rag, Single-line per object from the Paragraph panel menu or `text.setFormat {composer}`). Area type resizes like Illustrator's type areas: a bounding-box handle drag (Selection tool) or Area Type Options Width/Height size the frame and the text reflows at its size (threads too); Direct Selection drags a frame corner or edge (`text.reshapeArea`). Point type still scales. Auto Size: the frame height follows the text after every edit, in the same undo step (rectangular frames of horizontal type in one row; columns get the least height that holds them; a height set by hand or threading turns it off), and the "Auto Size New Area Type" preference gives it to new area type. Shrink Text to Fit (beyond Illustrator): overflowing area type scales its sizes, leading and baseline shifts down by the largest factor (in 0.1 pt steps of the first run, down to a minimum percentage) that fits, at layout time so every export sees it. `text.areaOptions` and `document.inspect` report overflow and the shrink factor. The Selection tool shows the type widget beside selected type's bounding box (hollow on point type, filled on area type); double-clicking it converts between them (Type › Convert To Area Type / Convert To Point Type), keeping the text and its styles in place. Variable fonts list every named instance as a style of their family (Figtree Light to Black and their italics, Bahnschrift, Segoe UI Variable), and the instance chosen is shaped, drawn, outlined and measured at its axis settings; PDF and SVG embed it as that instance. Variation axis sliders are not done. Beyond Illustrator: inline graphics (`text.insertInline`, Type ▸ Insert Inline Symbol) set a document symbol in a run of type as one character that flows, wraps and justifies like a glyph (InDesign-style inline objects, e.g. mana symbols in card rules text): sized to a multiple of the font size, centred on the cap height, opening up tall lines, following Redefine Symbol; a character of its run's size for Character Alignment and Top-to-Top leading, placed by the bidi reordering in right-to-left text (a neutral U+FFFC); drawn on the canvas, kept as live text plus a `` in SVG and as vector art in PDF; Backspace removes it whole. Hebrew and Arabic are laid out right to left with the Unicode bidirectional algorithm (embedded Latin and numbers keep their direction, lines put in visual order after wrapping) in point, area and path type, with caret, selection and arrow keys in visual order; each paragraph's direction comes from its first strong character unless Paragraph Direction sets it (Paragraph panel with Show Indic Options, `text.setFormat {direction}`), and new type aligns to the start of its direction. SVG export outlines right-to-left text. Font Size and Leading are combo boxes in the Character and Properties panels (Font Size in the Control bar too, beside the Character link, font family and style): type, step with ↑/↓ or the spinner, scrub the label, or pick a preset (6–72 pt, shown in the type unit; Leading also Auto), each pick one undo step; Kerning and Tracking list -100…200; a size, leading, kerning or tracking the selected text doesn't share shows blank (#458). - **Interface languages, vertical type:** VectorCraft ▸ Language (or Preferences ▸ User Interface) picks Automatic (the system locale) or a registered language, persisted as `interfaceLanguage`. Translations come from per-language catalogs (`i18n/*.tsv`): Traditional and Simplified Chinese, Japanese, Spanish (neutral international Spanish, for every `es-*` locale), French (every `fr-*` locale), Italian (every `it-*` locale) and Russian (every `ru-*` locale) cover the whole interface, Czech and Brazilian Portuguese every menu label, Brazilian Portuguese the shell's `tl!` literals too (tested); Spanish, French, Italian and Russian also translate status-bar and error messages as they are shown (`@msg` templates, every message literal tested; the messages themselves stay English for agents); untranslated text stays English. Japanese and Chinese glyphs come from the craft-fonts build input (release builds) or the installed fonts, Czech, Spanish, French, Italian and Russian ones from the bundled UI fonts. The web app follows the browser's languages (or `?lang=`). The Basic toolbar's Type button holds Vertical Type in its flyout. Vertical Type, Vertical Area Type and Vertical Type on a Path create vertical text (columns right to left, upright CJK glyphs and marks with `vert` alternates, Latin and longer numbers on their side, two- and three-digit numbers set as tate-chu-yoko in one em of the column (kept whole when justified), upright glyphs centred on the column (tracked or justified too), point type's anchor on the first column's centre line); kinsoku (the strict set) applies to horizontal and vertical Japanese, and justified Japanese lines spread their room between characters (not inside Latin words); Paragraph panel › Mojikumi Set (shown with Preferences › Type › Show East Asian Options, `text.setFormat {mojikumi}`): None or Line-end Punctuation Half Width (new type's default, as in Illustrator; older documents and imported text keep None) shares one half-em space between consecutive punctuation, sets a closing mark ending a line half width and an opening bracket starting a wrapped line flush with its start, and puts a quarter em between Japanese and Latin letters or digits; Paragraph panel menu › Top-to-Top / Bottom-to-Bottom Leading measures leading from em box top to top (area type's first line touches the frame) or from baseline to baseline (new type in a Japanese interface starts top to top, with em box centre character alignment, #432); Paragraph panel menu › Burasagari None / Regular / Force (`text.setFormat {burasagari: "none"|"standard"|"forced"}`) hangs an East Asian comma or full stop (、。,.、。) ending an area type line outside it, Regular (new type's default) when it doesn't fit and Force always (the rest of the line then fills the measure; closing brackets and Latin punctuation don't hang); Character panel menu › Character Alignment (with the East Asian options; `text.setFormat` or `text.setRangeStyle {charAlign}`) lines characters smaller than the largest on their line up on the Roman baseline, the em box top/right, centre or bottom/left, or the ICF (ideographic character face) top/right or bottom/left, from the font's BASE table or, without one, the average ink box of some ideographs and kana; Type ▸ Type Orientation switches existing text; caret, selection, hit testing and arrow keys follow the writing direction. Vertical text exports to PDF as real text and to SVG as outlines. - **Transparency:** opacity masks (clip/invert/disable/link), exported as SVG `` and PDF soft masks. -- **Advanced art:** live Blends (steps/distance/smooth colour, editable spine, anchor-targeted Blend tool, faithful interpolation, knockout), Envelope Distort (warp/mesh/top object, Reset, full Envelope Options, mesh handles, Edit Contents; type, images, symbols, gradients, patterns and appearance distorted everywhere), Liquify tools with options and pen pressure, Puppet Warp with rotating pins, Perspective Grid with presets, movable planes and projected type (choosing a perspective tool shows the grid; Hide Grid hides it with the tool still chosen), Gradient Mesh, Shape Builder (stroke-only open paths and lines cut the regions they cross and enclose regions of their own; filled open paths count as closed; erase mode while Alt/Option is held: a minus pointer, red highlights of what will go, a click or drag deletes the regions touched, the pieces of open lines and the edges (outline pieces between the points where paths meet, opening their paths there) it passes over, one undo step, `shapeBuilder.merge {erase}` and `shapeBuilder.regions` edges over MCP), Live Paint (every path an edge, open lines included), Image Trace (12 presets, colour layers traced in parallel; a trace past two million anchor points or an image over 64 megapixels is refused with advice rather than running out of memory, and a selection too large to outline shows its bounds (#525); Object › Image Trace › Make and Make and Expand trace at once with the Default preset, #543; with an image selected the Control bar and the Properties panel show Image Trace, whose arrow traces with any preset, Mask (`object.maskImage`: a clipping path on the image's outline, selected so its handles crop), Crop Image and Embed or Unembed in place of Fill and Stroke; with an Image Trace object selected, its Preset (choosing another traces again), the Image Trace panel and Expand, plus Release in Properties; the View modes are not done), pattern swatches with pattern editing mode, live Repeat (radial/grid/mirror). +- **Advanced art:** live Blends (steps/distance/smooth colour, editable spine, anchor-targeted Blend tool, faithful interpolation, knockout), Envelope Distort (warp/mesh/top object, Reset, full Envelope Options, mesh handles, Edit Contents; type, images, symbols, gradients, patterns and appearance distorted everywhere), Liquify tools with options and pen pressure, Puppet Warp with rotating pins, Perspective Grid with presets, movable planes and projected type (choosing a perspective tool shows the grid; Hide Grid hides it with the tool still chosen), Gradient Mesh, Shape Builder (stroke-only open paths and lines cut the regions they cross and enclose regions of their own; filled open paths count as closed; erase mode while Alt/Option is held: a minus pointer, red highlights of what will go, a click or drag deletes the regions touched, the pieces of open lines and the edges (outline pieces between the points where paths meet, opening their paths there) it passes over, one undo step, `shapeBuilder.merge {erase}` and `shapeBuilder.regions` edges over MCP), Live Paint (every path an edge, open lines included), Image Trace (12 presets, colour layers traced in parallel; a trace past two million anchor points or an image over 64 megapixels is refused with advice rather than running out of memory, and a selection too large to outline shows its bounds (#525); Object › Image Trace › Make and Make and Expand trace at once with the Default preset, #543; with an image selected the Control bar and the Properties panel show Image Trace, whose arrow traces with any preset, Mask (`object.maskImage`: a clipping path on the image's outline, selected so its handles crop), Crop Image and Embed or Unembed in place of Fill and Stroke; with an Image Trace object selected, its Preset (choosing another traces again), View, the Image Trace panel and Expand, plus Release in Properties; the five View modes (Tracing Result, with Outlines, Outlines, Outlines with Source Image, Source Image) redraw a trace on screen without tracing again, are saved with it and `imageTrace.setView` sets them, while exports and Expand keep the result; the panel's Advanced section is a header that stays open or closed as it was left (part of #641); Palette (Full Tone, Automatic, Document Library) and Create Strokes are not done), pattern swatches with pattern editing mode, live Repeat (radial/grid/mirror). - **Paint and appearance (M3):** - **Swatches:** names follow the colour model and are unique; Swatch Options (process/spot, Global, Gray/RGB/HSB/CMYK/Web, live preview); editing a global or spot swatch recolours every linked fill, stroke and text run in one undo step; multi-select and delete with confirmation; New Swatch and New Color Group dialogs (a group from the selected artwork's colours); swatches in colour groups convert, separate and count like any other. The Swatches panel selects ranges and whole groups, has a find field, and drags swatches to reorder, regroup or paint art; Add Used Colors, Select All Unused, Merge, Ungroup and Sort by Kind; a CMYK document keeps applied colours in CMYK. Swatch libraries: nine generated colour libraries and five gradient libraries in a library panel, saved as `.vcswatches`, `.gpl` or CSS, and loaded from `.vcswatches`, `.gpl` and swatch exchange (`.ase`) files (RGB, CMYK, Lab and Gray; global, spot and process; groups). Tints of global and spot colours ("Name 40%") stay linked and separate as a percentage of their plate. Spot colours can be defined in Lab (Spot Colors options). A built-in [Registration] swatch prints on every plate. - **Colour:** a Color Picker (colour field, H/S/B/R/G/B channel slider, HSB/RGB/Lab/CMYK fields, hex, web-only snapping, out-of-gamut correction); the Color panel follows each colour's own model and Alt-click paints the other proxy; proxies look through groups and show "?" for mixed paint; Invert, Complement, Apply Last Color (`,`) and Apply Last Gradient (`.`) keep the colour model; every paint command feeds the recent colours. The Color Guide has 21 harmony rules, Steps and Variation options and Limit to Library. Adjust Color Balance (its Global mode shifts tints) and Saturate preview live; Edit Colors and Recolor also reach meshes, images and patterns. Recolor Artwork has colour reduction, five recolour methods, presets, Limit to Library, a colour-wheel Edit tab and Edit Color Group; a local Color Themes panel saves five-colour themes. Fill/Stroke chips open swatch and mixer popovers (the Properties panel has the Control bar's Fill and Stroke chips, Stroke link and weight spinner, with nothing selected too), panels have Illustrator's Window menu keys (Align Shift+F7, Transform Shift+F8, Pathfinder Cmd+Shift+F9, Layers F7, Character Cmd+T…; every panel can be given one in Edit › Keyboard Shortcuts), and Eyedropper Options pick up and apply chosen attributes (Alt and Shift+Alt, image pixels). Fills and strokes can overprint (Attributes panel, Overprint Black options), and CMYK documents blend in inks on screen, in PDF and when flattening. Document Color Mode converts the art, symbols, pattern tiles and swatches through the colour settings: Gray stays Gray, RGB greys separate into four-colour greys and a rich black as Illustrator does, or go on the black plate only with `grays: "black"` (also for `document.open {colorMode}`). @@ -215,7 +215,7 @@ about 1–1.5 agent-hours each, so the other rows (estimated on the older scale) | Type core | 9 | 80% | Middle Eastern features beyond bidi layout and Paragraph Direction (Character Direction, digit types, kashidas, the Middle Eastern composers, editable bidirectional SVG text, a split caret where directions meet); Hyphenation… and Justification… options (Every-line Composer for justified and ragged text, per object, is done; it is tuned by eye, not yet compared side by side with Illustrator; mixed type sizes in a paragraph still break single-line), Optical Margin Alignment, paragraph spacing limit for vertically justified area type, hidden characters, paragraph attributes in the Type tool's copy and paste (the characters keep their styles, the paragraphs take the destination's), mixed-value display in the Paragraph panel for a selection across differing paragraphs, Transform Again after a type-area resize (it scales the type), partial selection of type-area anchors by marquee | 14–19 | | Type advanced | 4 | 50% | CJK composition for vertical type (ruby, mojikumi beyond Line-end Punctuation Half Width — the other sets (and their paragraph-start bracket and indent rules), kinsoku sets and the Mojikumi Settings dialog —, proportional vertical metrics, manual tate-chu-yoko), variable font axis sliders (named instances are styles), tab leaders, spell check (open dictionary), Touch Type, Retype; vertical point/area/path type and Type Orientation have initial support (beyond parity, not scored: inline symbols in text) | 20–28 | | Symbols, blends, envelopes, Repeat, perspective | 5 | 88% | symbol libraries (original), dynamic symbols, envelope Anti-Alias/Preserve Shape output and warp point editing, brush interpolation in blends (M8 fidelity pass done) | 5–8 | -| Image Trace, graphs, image tools | 3 | 70% | graph Design/Column/Marker, Create Object Mosaic, Crop Image polish (an on-canvas crop box), Image Trace View modes (Outlines, Source Image) (Vector Halftone is done) | 6–10 | +| Image Trace, graphs, image tools | 3 | 70% | graph Design/Column/Marker, Create Object Mosaic, Crop Image polish (an on-canvas crop box), Image Trace Palette (Full Tone, Automatic, Document Library) and Create Strokes (Vector Halftone and the Image Trace View modes are done) | 6–10 | | Layers, artboards, document setup | 5 | 82% | Layers panel: a confirmation before deleting layers that hold art, Collect for Export, row context menus, the Layer Options dialog for several rows with mixed values, Paste Remembers Layers for sublayers, drag-scrolling a long panel while dragging rows; artboard presets/rearrange polish (Document Setup, New Document and the rest of the Layers panel are done) | 4–7 | | View & navigation | 3 | 70% | New View/Edit Views, multiple windows/arrange, Snap to Pixel/Glyph (print tiling is done) | 9–14 | | Guides, grids, smart guides, snapping, rulers | 3 | 84% | global/video rulers, Spacing Guides, Smart Guides' angle and distance readouts while drawing, Alt swapping a ruler guide's orientation, ruler guides selected together with art (marquee, Shift-click), ruler guides as Layers rows with their own lock and hide (#451: Lock Guides locks them all; Make Guides paths are Layers rows already) (dragging existing guides is done, #414; new guides snapping to side midpoints and artboards, and artboard guides, #451; the drawing tools snapping, with Construction Guides, #506) | 2–4 | diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index 372a8ae9..9dd9b076 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -40,6 +40,7 @@ pub mod slices; pub mod style_libs; pub mod swatches; pub mod text; +pub mod trace; use std::collections::BTreeMap; use std::sync::Arc; @@ -89,6 +90,7 @@ pub use text::{ ParaDirection, ParaStyle, PathAlign, PathEffect, ScriptMetrics, TabAlign, TabStop, TextKind, TextObject, TextRun, TextStyleDef, TextWrap, VerticalAlign, WrapShape, }; +pub use trace::TraceView; pub use vectorcraft_color as color; pub use vectorcraft_geom as geom; diff --git a/crates/doc/src/node.rs b/crates/doc/src/node.rs index c6b69904..665279b6 100644 --- a/crates/doc/src/node.rs +++ b/crates/doc/src/node.rs @@ -463,7 +463,8 @@ pub struct Node { /// Opacity mask (Transparency panel). Its art lives here, outside the layer tree. #[serde(default, skip_serializing_if = "Option::is_none")] pub mask: Option>, - /// Image Trace object: `{preset, params}` it was traced with (the Image Trace panel shows them). + /// Image Trace object: `{preset, params, view?}` it was traced with (the Image Trace panel shows + /// them; `view` is its [`crate::TraceView`] id, absent for the tracing result). #[serde(default, skip_serializing_if = "Option::is_none")] pub trace: Option>, /// Object → Text Wrap: area type below this object (in the same layer) flows around it. diff --git a/crates/doc/src/trace.rs b/crates/doc/src/trace.rs new file mode 100644 index 00000000..72dc470c --- /dev/null +++ b/crates/doc/src/trace.rs @@ -0,0 +1,92 @@ +//! Image Trace objects' View: how a live trace draws on screen. +//! +//! An Image Trace object is a group whose `trace` holds `{preset, params, view}` (see +//! `imageTrace.make`). The view is a viewing aid only: exports, printing and Expand always use the +//! tracing result, whatever it is set to. + +use crate::node::Node; + +/// Image Trace › View. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum TraceView { + /// The traced shapes as they are filled. + #[default] + Result, + /// The traced shapes, with their outlines over them. + ResultWithOutlines, + /// Only the traced shapes' outlines. + Outlines, + /// The source image, with the traced shapes' outlines over it. + OutlinesWithSource, + /// Only the source image. + Source, +} + +impl TraceView { + /// Panel order. + pub const ALL: [Self; 5] = [Self::Result, Self::ResultWithOutlines, Self::Outlines, Self::OutlinesWithSource, Self::Source]; + + /// The id used in command params and in the saved `trace` object. + pub fn id(self) -> &'static str { + match self { + Self::Result => "tracingResult", + Self::ResultWithOutlines => "tracingResultWithOutlines", + Self::Outlines => "outlines", + Self::OutlinesWithSource => "outlinesWithSourceImage", + Self::Source => "sourceImage", + } + } + + /// The view an id names (any case). + pub fn from_id(id: &str) -> Option { + Self::ALL.into_iter().find(|v| v.id().eq_ignore_ascii_case(id)) + } + + /// The view an Image Trace object's `trace` settings ask for (the tracing result when they + /// name none, or an unknown one). + pub fn of(trace: &serde_json::Value) -> Self { + trace.get("view").and_then(serde_json::Value::as_str).and_then(Self::from_id).unwrap_or_default() + } + + /// Whether the source image shows. + pub fn shows_source(self) -> bool { + matches!(self, Self::OutlinesWithSource | Self::Source) + } + + /// Whether the traced shapes show filled. + pub fn shows_result(self) -> bool { + matches!(self, Self::Result | Self::ResultWithOutlines) + } + + /// Whether the traced shapes' outlines show. + pub fn shows_outlines(self) -> bool { + matches!(self, Self::ResultWithOutlines | Self::Outlines | Self::OutlinesWithSource) + } +} + +impl Node { + /// The View of an Image Trace object (the tracing result for anything else, or an unknown id). + pub fn trace_view(&self) -> TraceView { + self.trace.as_deref().map(TraceView::of).unwrap_or_default() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ids_round_trip_and_unknown_views_show_the_result() { + for v in TraceView::ALL { + assert_eq!(TraceView::from_id(v.id()), Some(v)); + assert_eq!(TraceView::from_id(&v.id().to_ascii_uppercase()), Some(v)); + assert!(v.shows_result() || v.shows_outlines() || v.shows_source(), "{v:?} shows something"); + } + let mut g = Node::group(crate::NodeId(1), vec![]); + assert_eq!(g.trace_view(), TraceView::Result); + g.trace = Some(Box::new(serde_json::json!({"view": "outlines"}))); + assert_eq!(g.trace_view(), TraceView::Outlines); + g.trace = Some(Box::new(serde_json::json!({"view": "sepia"}))); + assert_eq!(g.trace_view(), TraceView::Result); + } +} diff --git a/crates/engine/src/cmd/buildcmds.rs b/crates/engine/src/cmd/buildcmds.rs index 921d1e84..80783dca 100644 --- a/crates/engine/src/cmd/buildcmds.rs +++ b/crates/engine/src/cmd/buildcmds.rs @@ -15,7 +15,7 @@ use std::sync::Arc; use serde_json::{Value, json}; use vectorcraft_color::{Color, Paint}; use vectorcraft_doc::appearance::{AppearanceItem, FillLayer, StrokeLayer}; -use vectorcraft_doc::{Appearance, Document, Node, NodeId, NodeKind, Selection}; +use vectorcraft_doc::{Appearance, Document, Node, NodeId, NodeKind, Selection, TraceView}; use vectorcraft_geom::{FillRule, PathData, Point, Rect, SubPath}; use vectorcraft_pathops as po; use vectorcraft_tools::builder::{ @@ -120,7 +120,7 @@ pub fn specs() -> Vec { "Make", ["Object", "Image Trace"], None, - "{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\", threshold: 0-255, colors: 2-256, paths: 0-100, corners: 0-100, noise: px, method: \"abutting\"|\"overlapping\", ignoreWhite, snapCurvesToLines}} → {id, paths, anchors, colors}", + "{id?: image or Image Trace group (default: selection), preset?: name (imageTrace.presets), params?: {mode: \"blackAndWhite\"|\"grayscale\"|\"color\", threshold: 0-255, colors: 2-256, paths: 0-100, corners: 0-100, noise: px, method: \"abutting\"|\"overlapping\", ignoreWhite, snapCurvesToLines}, view?: as imageTrace.setView (default: the traced object's own, else tracingResult)} → {id, paths, anchors, colors}", has_selection_or_ids, |s, p| trace_make(s, p, false) ), @@ -151,6 +151,15 @@ pub fn specs() -> Vec { has_selection_or_ids, trace_expand ), + cmd!( + "imageTrace.setView", + "Image Trace View", + [], + None, + "{id?|ids?: Image Trace objects (default: selection), view: \"tracingResult\"|\"tracingResultWithOutlines\"|\"outlines\"|\"outlinesWithSourceImage\"|\"sourceImage\"} how they draw on screen; exports, printing and Expand keep the tracing result → {ids, view}", + has_selection_or_ids, + trace_set_view + ), cmd!(query "imageTrace.presets", "Image Trace Presets", [], None, "{} → {presets: [{name, params}]}", always, |_, _| { Ok(json!({ "presets": tr::presets().into_iter().map(|(n, p)| json!({ "name": n, "params": p })).collect::>() })) }), @@ -639,6 +648,13 @@ fn is_trace_group(n: &Node) -> bool { && n.children().is_some_and(|c| c.first().is_some_and(|i| matches!(i.kind, NodeKind::Image(_)))) } +/// The `view` param ([`TraceView`] id), if given. +fn view_param(cmd: &str, p: &Value) -> Result> { + let Some(v) = p.get("view").filter(|v| !v.is_null()) else { return Ok(None) }; + let ids = || TraceView::ALL.map(TraceView::id).join(", "); + v.as_str().and_then(TraceView::from_id).map(Some).ok_or_else(|| bad(cmd, format!("view must be one of {}", ids()))) +} + fn trace_params(p: &Value) -> Result { let name = str_param(p, "preset").unwrap_or("Default"); let base = tr::preset(name).ok_or_else(|| bad("imageTrace.make", format!("unknown preset `{name}` (see imageTrace.presets)")))?; @@ -659,6 +675,7 @@ pub const MAX_TRACE_ANCHORS: usize = 2_000_000; fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result { const C: &str = "imageTrace.make"; let params = trace_params(p)?; + let view = view_param(C, p)?; let params_json = serde_json::to_value(¶ms).map_err(|e| EngineError::Other(e.to_string()))?; // The preset's name if the parameters are exactly that preset's, else "Custom". let named = str_param(p, "preset").unwrap_or("Default"); @@ -721,7 +738,9 @@ fn trace_make(s: &mut Session, p: &Value, expand: bool) -> Result { let mut g = Node::group(gid, children); g.name = if expand { None } else { Some(TRACE_NAME.into()) }; if !expand { - g.trace = Some(Box::new(json!({ "preset": preset_label, "params": params_json }))); + // Tracing again keeps the object's view unless another is asked for. + let view = view.unwrap_or_else(|| src.trace_view()); + g.trace = Some(Box::new(json!({ "preset": preset_label, "params": params_json, "view": view.id() }))); } let (par, idx, _) = d.position(target).ok_or(EngineError::NoNode(target))?; d.remove(target)?; @@ -741,6 +760,28 @@ fn trace_targets(s: &Session, p: &Value) -> Result> { Ok(v) } +fn trace_set_view(s: &mut Session, p: &Value) -> Result { + const C: &str = "imageTrace.setView"; + let view = view_param(C, p)?.ok_or_else(|| bad(C, "view is required"))?; + let targets = trace_targets(s, p)?; + let d = &s.doc()?.doc; + if targets.iter().all(|g| d.node(*g).is_some_and(|n| n.trace_view() == view)) { + return Ok(json!({ "ids": ids_json(&targets), "view": view.id() })); + } + s.edit("Image Trace View", |d, _| { + for g in &targets { + let n = d.node_mut(*g).ok_or(EngineError::NoNode(*g))?; + if let Some(t) = n.trace.as_deref_mut().and_then(Value::as_object_mut) { + t.insert("view".into(), json!(view.id())); + } else { + n.trace = Some(Box::new(json!({ "preset": "Custom", "view": view.id() }))); + } + } + Ok(()) + })?; + Ok(json!({ "ids": ids_json(&targets), "view": view.id() })) +} + fn trace_release(s: &mut Session, p: &Value) -> Result { let targets = trace_targets(s, p)?; let ids = s.edit("Release Image Trace", |d, sel| { diff --git a/crates/engine/src/tests_build.rs b/crates/engine/src/tests_build.rs index e077ff02..0bff63c1 100644 --- a/crates/engine/src/tests_build.rs +++ b/crates/engine/src/tests_build.rs @@ -705,6 +705,85 @@ fn image_trace_object_remembers_its_settings() { assert!(st.doc.node(id).unwrap().trace.is_none()); } +/// A black disc (r = 30 px) on light blue, 100 × 100 px, placed at 2× from (50, 50): traced in +/// Black and White with Ignore White, the blue drops out and one disc (r = 60 pt at (150, 150)) +/// remains. +fn disc_on_blue(s: &mut Session) -> NodeId { + let r = vectorcraft_trace::Raster::from_fn(100, 100, |x, y| { + let (dx, dy) = (x as f64 + 0.5 - 50.0, y as f64 + 0.5 - 50.0); + if dx * dx + dy * dy <= 900.0 { [0, 0, 0, 255] } else { [170, 210, 255, 255] } + }); + add_image(s, &r, Affine::translate((50.0, 50.0)) * Affine::scale(2.0)); + let r = s.execute("imageTrace.make", &json!({"params": {"ignoreWhite": true}})).unwrap(); + assert_eq!(r["paths"], 1); + NodeId(r["id"].as_u64().unwrap()) +} + +/// The document rendered as the canvas draws it (`trace_views`) or as exports do. +fn render_doc(s: &Session, trace_views: bool) -> vectorcraft_render::Rendered { + let opts = vectorcraft_render::RenderOptions { background: Some([255, 255, 255, 255]), trace_views, ..Default::default() }; + vectorcraft_render::Renderer::new().render(&s.doc().unwrap().doc, 300, 300, Affine::IDENTITY, &opts) +} + +#[test] +fn image_trace_view_is_stored_kept_and_validated() { + let mut s = session(); + let g = disc_on_blue(&mut s); + assert_eq!(node(&s, g).trace.unwrap()["view"], "tracingResult"); + let r = s.execute("imageTrace.setView", &json!({"view": "outlinesWithSourceImage"})).unwrap(); + assert_eq!((ids(&r), r["view"].as_str()), (vec![g], Some("outlinesWithSourceImage"))); + assert_eq!(node(&s, g).trace_view(), vectorcraft_doc::TraceView::OutlinesWithSource); + // Setting the view it has already adds no undo step. + let steps = s.doc().unwrap().history.undo.len(); + s.execute("imageTrace.setView", &json!({"id": g.0, "view": "outlinesWithSourceImage"})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), steps); + // Tracing again keeps it, unless another one is asked for; it survives save and open. + let g = NodeId(s.execute("imageTrace.make", &json!({"id": g.0, "params": {"ignoreWhite": true, "noise": 30}})).unwrap()["id"].as_u64().unwrap()); + assert_eq!(node(&s, g).trace_view(), vectorcraft_doc::TraceView::OutlinesWithSource); + let g = NodeId(s.execute("imageTrace.make", &json!({"id": g.0, "view": "SourceImage"})).unwrap()["id"].as_u64().unwrap()); + let back = vectorcraft_format::load(&vectorcraft_format::save(&s.doc().unwrap().doc, false)).unwrap(); + assert_eq!(back.node(g).unwrap().trace_view(), vectorcraft_doc::TraceView::Source); + // Bad views and other objects are refused. + assert!(s.execute("imageTrace.setView", &json!({"view": "sepia"})).is_err()); + assert!(s.execute("imageTrace.setView", &json!({})).is_err()); + assert!(s.execute("imageTrace.make", &json!({"view": 3})).is_err()); + let a = rect(&mut s, 0.0, 0.0, 10.0, 10.0); + assert!(s.execute("imageTrace.setView", &json!({"id": a.0, "view": "outlines"})).is_err()); +} + +#[test] +fn image_trace_views_draw_on_screen_only_and_expand_to_the_result() { + let mut s = session(); + let g = disc_on_blue(&mut s); + let dark = |p: [u8; 4]| p[0] < 60 && p[1] < 60 && p[2] < 60; + let white = |p: [u8; 4]| p[0] > 245 && p[1] > 245 && p[2] > 245; + let blue = |p: [u8; 4]| p[0] < 200 && p[2] > 245; + let (centre, beside) = ((150, 150), (70, 70)); + let at = |img: &vectorcraft_render::Rendered, (x, y): (u32, u32)| img.pixel(x, y); + // The outline is a 1 px line where the disc's right side is (x = 210, anti-aliased). + let outlined = |img: &vectorcraft_render::Rendered| (205..=215).any(|x| img.pixel(x, 150)[0] < 128); + let mut expanded = None; + for view in vectorcraft_doc::TraceView::ALL { + s.execute("imageTrace.setView", &json!({"id": g.0, "view": view.id()})).unwrap(); + let screen = render_doc(&s, true); + let (c, b) = (at(&screen, centre), at(&screen, beside)); + assert_eq!(dark(c), view.shows_result() || view.shows_source(), "{view:?}: the disc's middle {c:?}"); + assert_eq!(blue(b), view.shows_source(), "{view:?}: the image's background {b:?}"); + assert!(view.shows_source() || white(b), "{view:?}: nothing beside the disc {b:?}"); + if view == vectorcraft_doc::TraceView::Outlines { + assert!(outlined(&screen), "{view:?}: the disc's outline"); + } + // Exports draw the tracing result whatever the view. + let export = render_doc(&s, false); + assert!(dark(at(&export, centre)) && white(at(&export, beside)), "{view:?}: export"); + // Expand keeps the traced shapes, as traced, whatever the view. + s.execute("imageTrace.expand", &json!({"id": g.0})).unwrap(); + let shapes: Vec<_> = node(&s, g).children().unwrap().iter().map(|c| (c.path_data().cloned(), c.appearance.clone())).collect(); + assert_eq!(*expanded.get_or_insert_with(|| shapes.clone()), shapes, "{view:?}: expanded"); + s.execute("edit.undo", &json!({})).unwrap(); + } +} + /// #569: merging the regions of a rosette of unfilled ellipses (each off the centre, petals /// overlapping) merges every region the drags touch into one shape whose outline is only the /// merged area's border: no edge between merged regions stays in, as a stray line or a spur. diff --git a/crates/mcp/src/prompts.rs b/crates/mcp/src/prompts.rs index 737fc144..bde8fac8 100644 --- a/crates/mcp/src/prompts.rs +++ b/crates/mcp/src/prompts.rs @@ -298,7 +298,8 @@ Method: color, then threshold, colors, paths, corners, noise, method abutting or overlapping, ignoreWhite, snapCurvesToLines. Run imageTrace.presets to see every preset with its numbers. Lower paths and higher corners give the clean, logo-like result; high fidelity needs paths - near 90. + near 90. imageTrace.setView {view: \"outlinesWithSourceImage\"} draws the traced outlines + over the image on screen to compare them (screenshots show it; exports keep the result). 3. apply_effect {effect} on the traced shapes. Call apply_effect with no `effect` for the catalogue and each effect's parameters. 4. set_paint over the traced shapes to give the artwork its own colours. diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 52597243..dd039a13 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -21,7 +21,7 @@ pub mod proof; use std::collections::HashMap; use std::sync::Arc; -use vectorcraft_doc::{AppearanceItem, Document, Node, NodeId, NodeKind, StrokeAlign, StrokeLayer, TextObject}; +use vectorcraft_doc::{AppearanceItem, Document, Node, NodeId, NodeKind, StrokeAlign, StrokeLayer, TextObject, TraceView}; use vectorcraft_geom::{Affine, BezPath, FillRule, Rect, Shape}; use vello_cpu::kurbo; use vello_cpu::peniko::{self, BlendMode, Compose, Mix}; @@ -100,6 +100,9 @@ pub struct RenderOptions { /// Screen view: placed documents draw from cached bitmaps made in the background (see /// [`placed_document`]); off, they draw exactly, read when needed. pub progressive_placed: bool, + /// Screen view: Image Trace objects draw as their View asks (outlines, the source image…); + /// off, they draw their tracing result, as exports and printing do. + pub trace_views: bool, } /// How edges are rasterized (raster export option). @@ -165,6 +168,7 @@ impl Default for RenderOptions { highlight_substitutions: false, anti_alias: AntiAlias::Art, progressive_placed: false, + trace_views: false, } } } @@ -646,8 +650,10 @@ impl Renderer { let b = match &a.kind { NodeKind::Layer { children, clip: false, .. } | NodeKind::Group { children, clip: false } if !fx::has_object_fx(a) => { let mut acc: Option = None; + // An Image Trace object's hidden source image shows in some of its views. + let source = a.trace.is_some().then(|| children.first()).flatten(); for c in children { - if c.visible { + if c.visible || source.is_some_and(|s| Arc::ptr_eq(s, c)) { acc = vectorcraft_geom::union_opt(acc, self.bounds_of(c)); } } @@ -883,6 +889,9 @@ impl Renderer { /// What `n` draws inside its transparency group (`knockout`: its children knock each other out). fn draw_content(&mut self, ctx: &mut RenderContext, f: &Frame, n: &Node, knockout: bool) { match &n.kind { + NodeKind::Group { children, clip: false } if f.opts.trace_views && !f.opts.outline && n.trace_view() != TraceView::Result => { + self.draw_trace_view(ctx, f, children, n.trace_view(), knockout) + } NodeKind::Layer { children, clip: false, .. } | NodeKind::Group { children, clip: false } => { self.draw_children(ctx, f, children, knockout) } @@ -955,6 +964,25 @@ impl Renderer { } } + /// An Image Trace object's `children` (the hidden source image, then the traced shapes) as + /// `view` shows them on screen. + fn draw_trace_view(&mut self, ctx: &mut RenderContext, f: &Frame, children: &[Arc], view: TraceView, knockout: bool) { + let Some((source, shapes)) = children.split_first() else { return }; + if view.shows_source() && matches!(source.kind, NodeKind::Image(_)) { + self.draw_node(ctx, f, source, true); + } + if view.shows_result() { + self.draw_children(ctx, f, shapes, knockout); + } + if view.shows_outlines() { + let opts = RenderOptions { outline: true, ..f.opts.clone() }; + let frame = Frame { opts: &opts, ..*f }; + for c in shapes { + self.draw_node(ctx, &frame, c, false); + } + } + } + /// The children of a group: as the elements of a knockout group when `knockout`. fn draw_children(&mut self, ctx: &mut RenderContext, f: &Frame, children: &[Arc], knockout: bool) { if knockout { diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 19eb2ad6..161db60f 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -284,6 +284,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // pattern tiles stay smooth), as in Illustrator. anti_alias: if app.session.prefs.anti_aliased_artwork { vectorcraft_render::AntiAlias::Art } else { vectorcraft_render::AntiAlias::None }, progressive_placed: true, + trace_views: true, ..opts }; // Light documents render synchronously (no lag vs overlays); heavy ones go to the worker. diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index 7604be04..7939b963 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -441,17 +441,8 @@ fn choice(ui: &mut egui::Ui, d: &mut Dialog, key: &str, options: &[(Value, Strin /// The collapsible Advanced Options: Color Mode, Raster Effects and Preview Mode. fn advanced(ui: &mut egui::Ui, d: &mut Dialog, label: f32, field: f32) { - let t = Tokens::get(ui.ctx()); let open = d.bool("advanced"); - let resp = ui - .horizontal(|ui| { - let (r, _) = ui.allocate_exact_size(egui::vec2(14.0, 18.0), egui::Sense::hover()); - crate::icons::paint(ui, if open { "chevron-down" } else { "chevron-right" }, r, t.icon); - ui.label(egui::RichText::new(tl!("Advanced Options")).color(t.text)); - }) - .response - .interact(egui::Sense::click()); - if resp.clicked() { + if widgets::section_toggle(ui, tl!("Advanced Options"), open) { d.fields.insert("advanced".into(), json!(!open)); } if !open { diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index d6ee0e1c..9a11a035 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -2487,6 +2487,13 @@ Smooth Color Color suavizado Smooth Tool Herramienta Suavizar Snap Curves To Lines Ajustar curvas a líneas + View: Vista: + Tracing Result Resultado de calco + Tracing Result with Outlines Resultado de calco con contornos + Outlines Contornos + Outlines with Source Image Contornos con imagen de origen + Source Image Imagen de origen + Image Trace View Vista del calco de imagen Snap Options Opciones de ajuste Snap to Glyph Ajustar a glifo Snap to Grid Ajustar a cuadrícula diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 135d3eec..5e4bc114 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -2484,6 +2484,13 @@ Smooth Color Couleur lissée Smooth Tool Outil Arrondi Snap Curves To Lines Aimanter les courbes aux lignes + View: Affichage : + Tracing Result Résultat de la vectorisation + Tracing Result with Outlines Résultat de la vectorisation avec contours + Outlines Contours + Outlines with Source Image Contours avec l’image source + Source Image Image source + Image Trace View Affichage de la vectorisation de l’image Snap Options Options de magnétisme Snap to Glyph Aimanter au glyphe Snap to Grid Aimanter à la grille diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 39f0e052..20224024 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -2487,6 +2487,13 @@ Smooth Color Colore graduale Smooth Tool Strumento Smussa Snap Curves To Lines Aggancia curve a linee + View: Vista: + Tracing Result Risultato ricalco + Tracing Result with Outlines Risultato ricalco con contorni + Outlines Contorni + Outlines with Source Image Contorni con immagine di origine + Source Image Immagine di origine + Image Trace View Vista del ricalco immagine Snap Options Opzioni di aggancio Snap to Glyph Aggancia a glifo Snap to Grid Aggancia alla griglia diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 29667b31..fb9ed568 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -2314,6 +2314,13 @@ Smooth スムーズ Smooth Tool スムーズツール Snap Curves To Lines 曲線を直線にスナップ + View: 表示: + Tracing Result トレース結果 + Tracing Result with Outlines トレース結果(アウトライン付き) + Outlines アウトライン + Outlines with Source Image アウトライン(元画像付き) + Source Image 元画像 + Image Trace View 画像トレースの表示 Snap Options スナップオプション Snapping Tolerance スナップ許容値 Soft Light ソフトライト diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 607911a1..2cfbbbe4 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -2483,6 +2483,13 @@ Smooth Color Сглаженный цвет Smooth Tool Инструмент «Сглаживание» Snap Curves To Lines Привязывать кривые к линиям + View: Просмотр: + Tracing Result Результат трассировки + Tracing Result with Outlines Результат трассировки с контурами + Outlines Контуры + Outlines with Source Image Контуры с исходным изображением + Source Image Исходное изображение + Image Trace View Просмотр трассировки изображения Snap Options Параметры привязки Snap to Glyph Привязать к глифу Snap to Grid Привязать к сетке diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index a2fe75d6..2404890f 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -2424,6 +2424,13 @@ Smooth Color 平滑颜色 Smooth Tool 平滑工具 Snap Curves To Lines 将曲线对齐到直线 + View: 视图: + Tracing Result 描摹结果 + Tracing Result with Outlines 描摹结果(带轮廓) + Outlines 轮廓 + Outlines with Source Image 轮廓(带源图像) + Source Image 源图像 + Image Trace View 图像描摹视图 Snap Options 对齐选项 Snap to Glyph 靠齐字符 Snap to Grid 对齐网格 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index b23c0fd5..3f0985b3 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -2507,6 +2507,13 @@ Smooth Color 平滑顏色 Smooth Tool 平滑工具 Snap Curves To Lines 將曲線靠齊線條 + View: 檢視: + Tracing Result 描圖結果 + Tracing Result with Outlines 描圖結果(含外框) + Outlines 外框 + Outlines with Source Image 外框(含來源影像) + Source Image 來源影像 + Image Trace View 影像描圖檢視 Snap Options 靠齊選項 Snap to Glyph 靠齊字符 Snap to Grid 靠齊格點 diff --git a/crates/ui-egui/src/panels/image_trace.rs b/crates/ui-egui/src/panels/image_trace.rs index bda45ab0..41c60892 100644 --- a/crates/ui-egui/src/panels/image_trace.rs +++ b/crates/ui-egui/src/panels/image_trace.rs @@ -1,10 +1,12 @@ -//! Image Trace panel: preset, mode, threshold or colour count, and the advanced fidelity options. -//! With an Image Trace object selected, changing a setting re-traces it (one undo step per change; -//! sliders apply when released). With an image selected, Trace makes a new Image Trace object. +//! Image Trace panel: preset, view, mode, threshold or colour count, and the Advanced section's +//! fidelity options (open or closed as it was last left). With an Image Trace object selected, +//! changing a setting re-traces it (one undo step per change; sliders apply when released) and +//! changing the view redraws it without tracing again. With an image selected, Trace makes a new +//! Image Trace object. use egui::Ui; use serde_json::{Value, json}; -use vectorcraft_doc::{Node, NodeKind}; +use vectorcraft_doc::{Node, NodeKind, TraceView}; use super::{first_selected, pstate, set_pstate}; use crate::VectorcraftApp; @@ -12,11 +14,12 @@ use crate::widgets::{self, menu_item}; const MODES: [(&str, &str); 3] = [("blackAndWhite", "Black and White"), ("grayscale", "Grayscale"), ("color", "Color")]; -/// Panel state: the preset name, the current parameters and the last result's counts. +/// Panel state: the preset name, the current parameters, the view and the last result's counts. #[derive(Clone, Default)] struct TraceUi { preset: String, params: Value, + view: TraceView, info: Option<(u64, u64, u64)>, /// The selected Image Trace object's stored settings last adopted (so edits in progress /// aren't overwritten until the object changes). @@ -44,12 +47,44 @@ fn target(app: &VectorcraftApp) -> (bool, bool, Option) { (is_trace(&n), matches!(n.kind, NodeKind::Image(_)), n.trace.map(|t| *t)) } -/// The preset of the one selected Image Trace object ("Custom" once its settings were changed). -pub(crate) fn selected_preset(app: &VectorcraftApp) -> Option { +/// The one selected Image Trace object's preset ("Custom" once its settings were changed) and view. +pub(crate) fn selected_trace(app: &VectorcraftApp) -> Option<(String, TraceView)> { let st = app.session.active()?; let [id] = st.selection.objects[..] else { return None }; let n = st.doc.node(id).filter(|n| is_trace(n))?; - Some(n.trace.as_ref().and_then(|t| t["preset"].as_str()).unwrap_or("Custom").to_string()) + Some((n.trace.as_ref().and_then(|t| t["preset"].as_str()).unwrap_or("Custom").to_string(), n.trace_view())) +} + +/// Image Trace › View, in the UI language. +fn view_label(v: TraceView) -> &'static str { + match v { + TraceView::Result => tl!("Tracing Result"), + TraceView::ResultWithOutlines => tl!("Tracing Result with Outlines"), + TraceView::Outlines => tl!("Outlines"), + TraceView::OutlinesWithSource => tl!("Outlines with Source Image"), + TraceView::Source => tl!("Source Image"), + } +} + +/// The View dropdown showing `current` → the view chosen. +fn view_dropdown(ui: &mut Ui, current: TraceView, width: f32) -> Option { + let labels = TraceView::ALL.map(view_label); + widgets::dropdown_names(ui, "trace-view", view_label(current), &labels, width).and_then(|i| TraceView::ALL.get(i).copied()) +} + +/// Show the selected Image Trace objects with `view` (no new trace). +fn set_view(app: &mut VectorcraftApp, view: TraceView) { + if let Err(e) = app.run("imageTrace.setView", json!({ "view": view.id() })) { + app.ui.status = e; + } +} + +/// The selected Image Trace object's View row (Control bar, Properties). +pub(crate) fn view_row(app: &mut VectorcraftApp, ui: &mut Ui, current: TraceView, width: f32) { + widgets::dim_label(ui, tl!("View:")); + if let Some(v) = view_dropdown(ui, current, width) { + set_view(app, v); + } } /// Trace the selected image, or trace the selected Image Trace object again, with built-in `preset`. @@ -94,12 +129,13 @@ pub(crate) fn preset_dropdown(app: &mut VectorcraftApp, ui: &mut Ui, current: &s } } -/// The Control bar for one selected Image Trace object: its preset, the Image Trace panel and -/// Expand. Whether it is one. +/// The Control bar for one selected Image Trace object: its preset, view, the Image Trace panel +/// and Expand. Whether it is one. pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { - let Some(preset) = selected_preset(app) else { return false }; + let Some((preset, view)) = selected_trace(app) else { return false }; widgets::dim_label(ui, tl!("Preset:")); preset_dropdown(app, ui, &preset, 150.0); + view_row(app, ui, view, 190.0); if widgets::icon_button(ui, "image", tl!("Image Trace"), false, 24.0).clicked() { app.ui.open_panel = Some("imageTrace".into()); } @@ -112,7 +148,7 @@ pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { fn trace(app: &mut VectorcraftApp, st: &mut TraceUi) { let preset = if st.preset == "Custom" { "Default" } else { st.preset.as_str() }; - match app.run("imageTrace.make", json!({ "preset": preset, "params": st.params })) { + match app.run("imageTrace.make", json!({ "preset": preset, "params": st.params, "view": st.view.id() })) { Ok(r) => st.info = Some((r["paths"].as_u64().unwrap_or(0), r["anchors"].as_u64().unwrap_or(0), r["colors"].as_u64().unwrap_or(0))), Err(e) => app.ui.status = e, } @@ -143,6 +179,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if let Some(t) = stored.filter(|t| *t != st.synced) { st.preset = t["preset"].as_str().unwrap_or("Custom").to_string(); st.params = t["params"].clone(); + st.view = TraceView::of(&t); st.synced = t; } let mut retrace = false; @@ -156,6 +193,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { retrace = true; } }); + ui.horizontal(|ui| { + widgets::dim_label(ui, tl!("View:")); + if let Some(v) = view_dropdown(ui, st.view, 170.0) { + st.view = v; + if is_trace { + set_view(app, v); + } + } + }); ui.horizontal(|ui| { widgets::dim_label(ui, tl!("Mode:")); let mode = st.params["mode"].as_str().unwrap_or("blackAndWhite").to_string(); @@ -181,9 +227,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { } retrace |= release; - let open: bool = !pstate::(ui.ctx(), "it-advanced-closed"); - if ui.add(egui::Button::new(format!("{} {}", if open { "▾" } else { "▸" }, tl!("Advanced"))).frame(false)).clicked() { - set_pstate(ui.ctx(), "it-advanced-closed", open); + ui.add_space(4.0); + let open = app.ui.image_trace_advanced; + if widgets::section_toggle(ui, tl!("Advanced"), open) { + app.ui.image_trace_advanced = !open; } if open { for (key, label, range, suffix) in @@ -258,6 +305,73 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) { #[cfg(test)] mod tests { use super::*; + use egui::{Event, PointerButton, Pos2, Rect, vec2}; + + /// One headless frame of the panel (and its menu) with `events`: the texts drawn, with where. + fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> Vec<(String, Rect)> { + let screen = Rect::from_min_size(Pos2::ZERO, vec2(280.0, 700.0)); + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + crate::tests_removeanchors::shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::>()) + } + + /// Click the panel's `label` (the first one drawn). + fn click(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) { + let texts = frame(app, ctx, vec![]); + let at = texts.iter().find(|(t, _)| t == label).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("no `{label}` in {texts:?}")); + let press = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Default::default() }; + frame(app, ctx, vec![Event::PointerMoved(at), press(true)]); + frame(app, ctx, vec![press(false)]); + } + + fn traced_app() -> VectorcraftApp { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap(); + let img = image::RgbaImage::from_fn(20, 20, |x, _| image::Rgba(if x < 10 { [0, 0, 0, 255] } else { [255, 255, 255, 255] })); + let mut png = vec![]; + img.write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png).unwrap(); + let data = vectorcraft_format::base64_encode(&png); + app.run("file.place", json!({"name": "half.png", "dataBase64": data, "link": false})).unwrap(); + app.run("imageTrace.make", json!({"preset": "Default"})).unwrap(); + app + } + + #[test] + fn advanced_is_a_section_that_stays_as_it_was_left() { + let mut app = traced_app(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let has = |texts: &[(String, Rect)], s: &str| texts.iter().any(|(t, _)| t == s); + let texts = frame(&mut app, &ctx, vec![]); + assert!(app.ui.image_trace_advanced && has(&texts, "Advanced") && has(&texts, "Corners"), "open at first: {texts:?}"); + click(&mut app, &ctx, "Advanced"); + assert!(!app.ui.image_trace_advanced, "the header closes it"); + assert!(!has(&frame(&mut app, &ctx, vec![]), "Corners")); + // Remembered with the UI preferences, across launches. + let saved: crate::state::UiState = serde_json::from_value(serde_json::to_value(&app.ui).unwrap()).unwrap(); + assert!(!saved.image_trace_advanced); + let old: crate::state::UiState = serde_json::from_value(json!({})).unwrap(); + assert!(old.image_trace_advanced, "open for preferences saved before the section existed"); + click(&mut app, &ctx, "Advanced"); + assert!(app.ui.image_trace_advanced && has(&frame(&mut app, &ctx, vec![]), "Corners")); + } + + #[test] + fn the_view_dropdown_shows_and_sets_the_objects_view() { + let mut app = traced_app(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let texts = frame(&mut app, &ctx, vec![]); + assert!(texts.iter().any(|(t, _)| t == "View:") && texts.iter().any(|(t, _)| t == "Tracing Result"), "{texts:?}"); + let steps = app.session.active().unwrap().history.undo.len(); + click(&mut app, &ctx, "Tracing Result"); + click(&mut app, &ctx, "Source Image"); + assert_eq!(selected_trace(&app).map(|t| t.1), Some(TraceView::Source)); + assert_eq!(app.session.active().unwrap().history.undo.len(), steps + 1, "one undo step, no new trace"); + // Another object's view is shown when it is selected. + app.run("imageTrace.setView", json!({"view": "outlines"})).unwrap(); + assert!(frame(&mut app, &ctx, vec![]).iter().any(|(t, _)| t == "Outlines")); + } #[test] fn panel_and_menu_draw_headless() { @@ -266,6 +380,7 @@ mod tests { app.session.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); for _ in 0..2 { let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { show(&mut app, ui); menu(&mut app, ui); diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index b74bc2ba..e24c9c9f 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -44,8 +44,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { image_section(app, ui); divider(ui); } - if let Some(preset) = crate::panels::image_trace::selected_preset(app) { - trace_section(app, ui, &preset); + if let Some((preset, view)) = crate::panels::image_trace::selected_trace(app) { + trace_section(app, ui, &preset, view); divider(ui); } if matches!(first.as_ref().map(|n| &n.kind), Some(NodeKind::Text(_))) { @@ -162,13 +162,14 @@ fn image_section(app: &mut VectorcraftApp, ui: &mut Ui) { } /// The one selected Image Trace object: its preset (choosing another traces it again with that -/// one), Expand and Release. -fn trace_section(app: &mut VectorcraftApp, ui: &mut Ui, preset: &str) { +/// one), view, Expand and Release. +fn trace_section(app: &mut VectorcraftApp, ui: &mut Ui, preset: &str, view: vectorcraft_doc::TraceView) { section_header(ui, tl!("Image Trace")); ui.horizontal(|ui| { dim_label(ui, tl!("Preset:")); crate::panels::image_trace::preset_dropdown(app, ui, preset, ui.available_width()); }); + ui.horizontal(|ui| crate::panels::image_trace::view_row(app, ui, view, ui.available_width())); let w = (ui.available_width() - 6.0) / 2.0; ui.horizontal(|ui| { for (label, id) in [(tl!("Expand"), "imageTrace.expand"), (tl!("Release"), "imageTrace.release")] { diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index b6af00be..be105654 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -365,6 +365,9 @@ pub struct UiState { /// Layers panel › Panel Options… (row size, thumbnails, Show Layers Only). #[serde(default)] pub layers_panel: crate::panels::layers::PanelOptions, + /// The Image Trace panel's Advanced section is open (as it was last left). + #[serde(default = "yes")] + pub image_trace_advanced: bool, /// The desktop window's size, position and maximized state, saved when the app quits and /// restored at the next launch (the desktop host reads and writes it; none on the web). #[serde(default, skip_serializing_if = "Option::is_none")] @@ -518,6 +521,7 @@ impl Default for UiState { dxf_import: Value::Null, home: None, layers_panel: Default::default(), + image_trace_advanced: true, window: None, } } diff --git a/crates/ui-egui/src/tests_place.rs b/crates/ui-egui/src/tests_place.rs index f23ea87c..dc3bc806 100644 --- a/crates/ui-egui/src/tests_place.rs +++ b/crates/ui-egui/src/tests_place.rs @@ -308,7 +308,8 @@ fn click_label(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) { #[test] fn the_control_bar_and_properties_trace_a_selected_image() { - use crate::panels::image_trace::{TRACE_BUTTON_W, selected_preset}; + use crate::panels::image_trace::{TRACE_BUTTON_W, selected_trace}; + let selected_preset = |app: &VectorcraftApp| selected_trace(app).map(|t| t.0); use crate::tests_removeanchors::{at, click_control, control_frame, has, properties_frame}; let mut app = app(); let data = vectorcraft_format::base64_encode(&png(30, 30, 72.0)); @@ -332,19 +333,27 @@ fn the_control_bar_and_properties_trace_a_selected_image() { app.run("edit.undo", json!({})).unwrap(); click_label(&mut app, &ctx, "Image Trace"); assert_eq!(selected_preset(&app).as_deref(), Some("Default")); - // An Image Trace object: its preset (another traces it again), the panel and Expand. + // An Image Trace object: its preset (another traces it again), view, the panel and Expand. let bar = control_frame(&mut app, &ctx, vec![]); - for s in ["Image Tracing", "Preset:", "Default", "Expand"] { + for s in ["Image Tracing", "Preset:", "Default", "View:", "Tracing Result", "Expand"] { assert!(has(&bar, s), "{s}"); } - assert!(has(&properties_frame(&mut app, 260.0), "Release")); + let props = properties_frame(&mut app, 260.0); + assert!(has(&props, "Release") && has(&props, "View:")); + // Another view redraws it without tracing again. + let traced = app.session.active().unwrap().selection.objects.clone(); + click_control(&mut app, &ctx, at(&bar, "Tracing Result")); + click_label(&mut app, &ctx, "Outlines with Source Image"); + assert_eq!(selected_trace(&app).map(|t| t.1), Some(vectorcraft_doc::TraceView::OutlinesWithSource)); + assert_eq!(app.session.active().unwrap().selection.objects, traced, "the same object"); + let bar = control_frame(&mut app, &ctx, vec![]); click_control(&mut app, &ctx, at(&bar, "Default")); click_label(&mut app, &ctx, "3 Colors"); assert_eq!(selected_preset(&app).as_deref(), Some("3 Colors")); click_label(&mut app, &ctx, "Expand"); let st = app.session.active().unwrap(); let g = st.doc.node(st.selection.objects[0]).unwrap(); - assert!(selected_preset(&app).is_none() && g.children().unwrap().iter().all(|c| !matches!(c.kind, NodeKind::Image(_))), "expanded"); + assert!(selected_trace(&app).is_none() && g.children().unwrap().iter().all(|c| !matches!(c.kind, NodeKind::Image(_))), "expanded"); } #[test] diff --git a/crates/ui-egui/src/tests_removeanchors.rs b/crates/ui-egui/src/tests_removeanchors.rs index 0baee6c3..80a7dcc3 100644 --- a/crates/ui-egui/src/tests_removeanchors.rs +++ b/crates/ui-egui/src/tests_removeanchors.rs @@ -37,7 +37,7 @@ fn labels(items: &[Item]) -> Vec<&'static str> { .collect() } -fn shapes_text(shapes: &[Shape]) -> Vec<(String, Rect)> { +pub(crate) fn shapes_text(shapes: &[Shape]) -> Vec<(String, Rect)> { fn walk(s: &Shape, v: &mut Vec<(String, Rect)>) { match s { Shape::Text(t) => v.push((t.galley.text().to_string(), Rect::from_min_size(t.pos, t.galley.size()))), diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 78f45b48..58be7f37 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -121,6 +121,21 @@ pub fn section_header(ui: &mut Ui, text: &str) { ui.add_space(2.0); } +/// A collapsible section's header across the panel: a chevron (down while `open`) and `text`; +/// a click anywhere on it toggles the section. Whether it was clicked. +pub fn section_toggle(ui: &mut Ui, text: &str, open: bool) -> bool { + let t = Tokens::get(ui.ctx()); + let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click()); + if resp.hovered() { + ui.painter().rect_filled(rect, 3.0, t.hover); + } + let chevron = Rect::from_center_size(pos2(rect.left() + 8.0, rect.center().y), vec2(12.0, 12.0)); + icons::paint(ui, if open { "chevron-down" } else { "chevron-right" }, chevron, if resp.hovered() { t.text_strong } else { t.icon }); + ui.painter().text(pos2(rect.left() + 18.0, rect.center().y), egui::Align2::LEFT_CENTER, tl!(text), theme::semibold(12.5), t.text); + resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, true, open, tl!(text))); + resp.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() +} + /// Full-width 1 px divider with vertical margins. pub fn divider(ui: &mut Ui) { let t = Tokens::get(ui.ctx());