Compare commits

..

No commits in common. "contrib/pr-303-original" and "docs/roadmap-catch-up" have entirely different histories.

67 changed files with 441 additions and 6654 deletions

5
NOTICE
View File

@ -31,7 +31,6 @@ WebAssembly plug-ins run in the wasmi interpreter (MIT OR Apache-2.0); its wasmp
under the Apache License 2.0 with the LLVM exception.
Builds made with craft-fonts (the CRAFT_FONTS_DIR build option; all official releases) embed the
fonts listed in https://github.com/storytold/craft-fonts/blob/main/ATTRIBUTION.md (BIZ UDPGothic,
Shippori Mincho, BIZ UDMincho, Noto Sans CJK SC and Noto Sans Arabic in the current manifest;
web builds BIZ UDPGothic Regular only) under the SIL
fonts listed in https://github.com/storytold/craft-fonts/blob/main/ATTRIBUTION.md (today BIZ
UDPGothic, Shippori Mincho and BIZ UDMincho; web builds BIZ UDPGothic Regular only) under the SIL
Open Font License 1.1. Their license texts ship with the release packages as OFL-<family>.txt.

View File

@ -142,12 +142,6 @@ exposes to agents, and exported by VectorCraft's own renderer. The source files
## Quick start
Simplified Chinese (`zh-hans`) is available in the language menu and Preferences.
Legacy `locale: "zh-Hans"` preferences migrate without overriding an explicit language choice.
Horizontal Chinese text supports punctuation compression and inter-character justification.
Build desktop releases with `CRAFT_FONTS_DIR` set to include Noto Sans CJK SC from craft-fonts;
without that optional input, Chinese falls back to installed system fonts.
```sh
cargo run --release -p vectorcraft # desktop app
cargo run --release -p vectorcraft -- examples/dusk-poster.vectorcraft

View File

@ -84,19 +84,18 @@ When a task lands, update this section, the parity table and "Shipped so far" in
grade by behaviour against `plan/illustrator/`, not by whether a menu item exists.
## Shipped so far
- **Simplified Chinese and horizontal CJK composition:** `zh-hans` catalog and legacy language preference migration; punctuation compression, inter-character justification, per-family UI font fallback and responsive dock/dialog fixes. Desktop CJK fonts use the optional craft-fonts input rather than font binaries in this repository. Ruby, configurable mojikumi and vertical font metrics remain open.
- **Architecture:** 19+ crates with enforced layering (`cargo xtask layers`). Every action is a command (~400 engine + ~50 UI). Undo is unlimited via structural sharing. `command.batch` runs several commands as one transaction.
- **Automation:**
- Actions panel (record/playback, persisted), generic parameter dialogs for every "…" command.
- JSON-lines control channel with real egui pointer and keyboard injection.
- MCP server with 25 tools (drawing, text, effects, Pathfinder, transforms, graphs, text wrap, export, screenshots, any command), attached to the running app or headless. Tool descriptions and replies agree with the engine: format lists come from its format table, `save_file` says it keeps the document's own format, `inspect_document` reports the paint type's characters show, and selection exports report the encoder's warnings.
- MCP server with 25 tools (drawing, text, effects, Pathfinder, transforms, graphs, text wrap, export, screenshots, any command), attached to the running app or headless.
- MCP protocol: five prompts (`prompts/list` / `prompts/get`: poster, icon set, recolour, trace-and-style, export set), `completion/complete` for prompt arguments and template variables read from the live catalogues (formats, effect ids, command ids, trace presets, swatch and object ids), four resource templates (`vectorcraft://object/{id}`, `//command/{id}`, `//effect/{id}`, `//swatch/{name}`) so an agent reads one thing instead of the whole document, and `logging/setLevel` with `notifications/message`. `docs/mcp.md` has a Protocol section covering the capability table and what is deliberately absent (subscriptions, progress, cancellation, sampling, elicitation, Streamable HTTP — all of which need the transport to interleave reads).
- Headless CLI (`vectorcraft-cli run`, `convert`, `info`, `bench`, `perf`, `mcp`).
- Actions panel that records and plays back commands.
- **UI:** Illustrator 2026 layout restyled to measured values:
- Medium Dark theme, categorized and Advanced toolbars, 35 pt document tabs, 33 pt panel tabs.
- Hint bar, contextual task bar, 19 dock panels with ≡ menus.
- Localised UI: menus (in-window and native), panels, dialogs, toolbar and Preferences read from per-language catalogs (`crates/ui-egui/src/i18n`, see `docs/development.md`); Traditional Chinese (Taiwan) ships complete, and Czech and Japanese cover every menu label, with system-locale detection on macOS, Windows and Linux, a VectorCraft ▸ Language menu and a Language preference. Names are never translated (fonts and their styles, layers, artboards, saved presets, user libraries, custom workspaces, recent files, plug-ins).
- Localised UI: menus (in-window and native), panels, dialogs, toolbar and Preferences read from per-language catalogs (`crates/ui-egui/src/i18n`, see `docs/development.md`); Traditional Chinese (Taiwan) ships complete, Czech covers every menu label and Japanese the main menus, with system-locale detection on macOS, Windows and Linux, a VectorCraft ▸ Language menu and a Language preference. Names are never translated (fonts and their styles, layers, artboards, saved presets, user libraries, custom workspaces, recent files, plug-ins).
- Native macOS menu bar, vector tool cursors, a ⌘K command palette, middle-button panning with any tool.
- A canvas context menu: right-click selects the object under the pointer and lists what applies to the selection (Undo/Redo, clipboard, group, isolation, join, masks, compound paths, guides, Transform, Arrange, Select, Export Selection), or the view commands on empty canvas.
- Save / Don't Save / Cancel before closing or quitting with unsaved documents (tabs, Close, Close All, Quit, window close).
@ -107,21 +106,16 @@ grade by behaviour against `plan/illustrator/`, not by whether a menu item exist
- **Drawing:** Pen, Curvature, anchor tools, Pencil, Paintbrush, Blob Brush, Smooth, Path Eraser, Join.
- **Shapes:** all shape tools (including Flare) and the line, arc, spiral and grid tools.
- **Cutting:** Eraser, Scissors, Knife, Mirror & Cut, Line Cut and Rectangle Cut (real geometry, compound paths keep their holes).
- **Transform:** Rotate, Reflect, Scale, Shear (click or Alt-click snaps the reference point to anchors and centres), Reshape, Free Transform (free and perspective distort and shear, switched by the keys held during a handle drag).
- **Transform:** Rotate, Reflect, Scale, Shear (click or Alt-click snaps the reference point to anchors and centres), Reshape, Free Transform (distort/perspective).
- **Live Corners:** drag a live rectangle's corner widgets (Selection or Direct Selection) to round all corners, with a radius readout.
- **Graphs:** Column, Stacked Column, Bar, Stacked Bar, Line, Area, Scatter, Pie and Radar graph tools with Graph Data and Graph Type.
- **Other:** Eyedropper, Gradient annotator, Artboard, Measure, Type, Hand, Zoom, Rotate View.
- **Editing type:** double-clicking type with a selection tool switches to the Type tool with the caret where it was clicked.
- **Temporary tools:** Cmd with any other tool drags with the selection tool used last (Selection, Direct Selection or Group Selection). Held Space pans and Cmd+Space zooms (Cmd+Alt+Space out) whatever the tool.
- **Panel drag and drop:** art dragged off the canvas onto the Symbols panel becomes a symbol, and a symbol dragged onto the canvas places an instance where it is dropped.
- **Tool double-clicks:** double-clicking a tool's button opens its options: Hand fits the artboard in the window, Zoom shows 100 %, Rotate, Scale, Reflect and Shear open their Object › Transform dialogs, Gradient, Eyedropper, Blend and the Liquify tools their panels or options.
- **Drawing aids:** Smart Guides and snapping, guides dragged out of the rulers, and Draw Normal / Behind / Inside modes.
- **Views:** the status bar's artboard navigator (first, previous, next, last; `view.goToArtboard`) goes to an artboard and fits it, and Fit Artboard in Window and Actual Size show the navigator's artboard.
- **Drawing aids:** Smart Guides and snapping, and Draw Normal / Behind / Inside modes.
- **Geometry and effects:**
- Pathfinder (10 exact curve booleans), Offset, Outline Stroke, Simplify, Clean Up, Split Into Grid, Divide Objects Below.
- Live effects with previewing dialogs: Distort & Transform, Path, Convert to Shape, 15 Warp styles, Round Corners, Scribble, Effect → Pathfinder (all 10 operations, live on groups; several loose objects are grouped first, in one undo step), Color Adjustments (Brightness/Contrast, Curves, Levels, Hue/Saturation, Shift to Color, Temperature/Tint, on vectors, live type and embedded images), and raster drop shadow, glows and feather. SVG and PDF export keep live effects (geometry baked; SVG raster effects as filters).
- **Type:** Text Wrap, Type on a Path effects (Rainbow/Skew/3D Ribbon/Stair Step/Gravity), Character and Paragraph Styles (override-preserving redefine), Area Type Options (rows/columns/inset/first baseline), threaded text across any closed shapes, Fit Headline. 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.
- **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 Chinese covers the whole interface, Czech and Japanese every menu label (tested); untranslated text stays English. Japanese and Chinese glyphs come from the craft-fonts build input (release builds) or the installed fonts, Czech ones from the bundled UI fonts. 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; 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.
- **Type:** Text Wrap, Type on a Path effects (Rainbow/Skew/3D Ribbon/Stair Step/Gravity), Character and Paragraph Styles (override-preserving redefine), Area Type Options (rows/columns/inset/first baseline), threaded text across any closed shapes, Fit Headline.
- **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 Chinese covers the whole interface, Czech every menu label (tested) and Japanese the main menus; untranslated text stays English. Japanese and Chinese glyphs come from the craft-fonts build input (release builds) or the installed fonts, Czech ones from the bundled UI fonts. 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, upright glyphs centred on the column, point type's anchor on the first column's centre line); kinsoku (the strict set) applies to horizontal and vertical Japanese; 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 `<mask>` 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, Gradient Mesh, Shape Builder, Live Paint (every path an edge, open lines included), Image Trace (12 presets), pattern swatches with pattern editing mode, live Repeat (radial/grid/mirror).
- **Paint and appearance (M3):**
@ -138,7 +132,7 @@ grade by behaviour against `plan/illustrator/`, not by whether a menu item exist
- **Fonts:** a font is found by any of its names (family and style in every language of its name table, legacy family/style pairs, PostScript name), so documents from other apps open with the font they name; Find Font and `text.fonts` say for each font whether it was found exactly, by another name, substituted or missing, and how many glyphs are missing.
- **Files (M4):**
- `.vectorcraft` (lossless JSON, compressed, atomic saves, save down to v1), Save As with a format chooser, Save a Copy, Revert, templates, Data Recovery after a crash, background save and export.
- SVG/SVGZ in and out with SVG Options, Preserve Editing, symbols, filters, rich text and physical units; PDF and PDF-compatible `.ai` in and out (layers, masks, editable text with type set along a curve coming back as type on a path, each artboard's art on its own page only, spot colours, presets, security, marks and bleed, ICC output intents, raster effects, subset fonts, PDF/X, PDF layers, overprint, page thumbnails, fast web view, PDF 1.3).
- SVG/SVGZ in and out with SVG Options, Preserve Editing, symbols, filters, rich text and physical units; PDF and PDF-compatible `.ai` in and out (layers, masks, editable text, spot colours, presets, security, marks and bleed, ICC output intents, raster effects, subset fonts, PDF/X, PDF layers, overprint, page thumbnails, fast web view, PDF 1.3).
- EPS and DXF in and out, EMF/WMF in and out; PNG (with PNG-8), JPEG, WebP, GIF, TIFF, BMP, Targa and layered PSD export. EPS import runs Illustrator's AGM/CoolType prologs (resource categories, `resourceforall`, `clipsave`/`cliprestore`, subarrays and substrings that share storage) and falls back to its palette TIFF preview. DXF TEXT justified Fit or Aligned spans its two points (stretched, or scaled as a whole).
- Place and the Links panel, Package, File Info, Print with print presets, PostScript output and print tiling, slices and Save for Web, Export for Screens and Asset Export, CSS Properties, PNG/PDF/SVG/text clipboard flavours.
- **Performance:** 20k shapes + 1k texts render in 27 ms per full-retina frame (7.8 ms zoomed), 7× faster than the first version. The UI thread never blocks. The web build is 7.1 MB gzipped.
@ -155,14 +149,14 @@ grade by behaviour against `plan/illustrator/`, not by whether a menu item exist
| M4 | Files (native, SVG, PDF, raster, Export for Screens, clipboard interop) | ✅ done (M4.14–M4.98 on 2026-10-05): Save As/Save a Copy/Revert/templates, Data Recovery and background save, SVG import and export fidelity (units, text, symbols, filters, SVGZ, Preserve Editing, SVG Options), PDF import (colours, layers, masks, editable text, security) and export (presets, marks, bleed, ICC and output intent, raster effects, subset fonts, PDF/X-1a, X-3 and X-4, PDF layers, overprint, page thumbnails, fast web view, PDF 1.3), Place and Links, Package, EPS and DXF in and out, EMF/WMF, TIFF/BMP/Targa/PSD/GIF/PNG-8 export, Print and print presets, slices, Save for Web, Asset Export, clipboard flavours, File Info. Left: DWG (use DXF), PSD placement as layers, overprint read back from PDF, polish | 3–6 |
| M5 | Performance | 🟡 background render + caches + MT done; `vectorcraft-cli bench` and `vectorcraft-cli perf` (budget suite); file format v2 opens 3× faster (50k paths: 722 → 244 ms); raster effects (glows, shadows, blur, feather) no longer force the whole frame single-threaded (filtered offscreen per effect, verified equal to the single-threaded reference); effect-heavy demos need a clean-machine benchmark; dirty-region rendering, GPU backend spike pending | 15–25 |
| M6 | Path operations (Pathfinder, Shape Builder, offset…) | ✅ mostly done (Boolean precision on almost-horizontal edges fixed and the property tests made deterministic; Shape Builder edge erase, large-offset bug open) | 3–6 |
| M7 | Type (point/area/path, editing, styles, OpenType, threading, glyphs) | 🟡 Character/Paragraph Styles, Area Type Options (with Width/Height), type areas resized by their handles and reshaped with Direct Selection, threaded text, Fit Headline, Glyphs, OpenType panel, Find Font, installed system fonts in every font menu (searchable) and found by name on open/import, CJK names in the UI, input methods (marked text in place, candidate window at the caret; Japanese IME), Text Wrap (offset, invert, both sides of an object; follows edits), Type on a Path effects, tab stops + Tabs panel done; tab leaders, spell check, vertical type pending | 45–60 |
| M7 | Type (point/area/path, editing, styles, OpenType, threading, glyphs) | 🟡 Character/Paragraph Styles, Area Type Options, threaded text, Fit Headline, Glyphs, OpenType panel, Find Font, installed system fonts in every font menu (searchable) and found by name on open/import, CJK names in the UI, input methods (marked text in place, candidate window at the caret; Japanese IME), Text Wrap (offset, invert, both sides of an object; follows edits), Type on a Path effects, tab stops + Tabs panel done; tab leaders, spell check, vertical type pending | 45–60 |
| M8 | Transform & distort (Puppet Warp, Liquify tools, Envelopes, Blends, Perspective Grid) | ✅ done (M8.1–M8.20 on 2026-10-06, fidelity pass): Liquify Tool Options with one shared brush, pen pressure, hold-to-apply, a safe scope and incremental strokes; tool options that last; Puppet Warp rotation, multi-select, Control bar and a rest-shape session that follows Undo; Width tool on compound paths; Envelope dialogs with preview, Reset with Warp/Mesh, full Envelope Options, type/images/symbols/appearance/gradients/patterns distorted on canvas and in every export, warps that keep their frame, Edit Contents, mesh handles and Control bar; Blend Options, anchor-targeted Blend tool, editable spine, keys picked on the canvas, faithful interpolation and knockout; Perspective Grid with Define Grid, presets, lock/snap/rulers, widgets, the 1–4 plane switch, movable planes, Perspective Selection scale/copy/perpendicular/Transform Again, and type and symbols truly projected with Edit Text. Left: Anti-Alias and Preserve Shape output, warp-envelope point editing, brush interpolation in blends, Free Transform/Scale/Reflect along a rotated box | 2–4 |
| M9 | Live effects (+ 3D & Materials) | 🟡 2D effects done incl. Effect → Pathfinder and Color Adjustments; SVG Filters, Document Raster Effects Settings, 3D pending | 86–135 |
| M10 | Brushes, symbols, patterns, Repeat | 🟡 pattern swatches (5 tile types, Pattern Options, editing mode, SVG `<pattern>`/PDF export) and live Repeat (radial/grid/mirror) done; brushes/symbols in progress | 23–37 |
| M11 | Artboards & views (artboard panel/tool, Trim View, middle-button pan, print tiling and the status bar's artboard navigator done; multiple windows, presentation polish) | 🟡 | 15–25 |
| M11 | Artboards & views (artboard panel/tool, Trim View, middle-button pan and print tiling done; multiple windows, presentation polish) | 🟡 | 15–25 |
| M12 | Advanced color & art (CMYK/ICC, separations, Gradient Mesh, Live Paint, Image Trace, Graphs) | 🟡 Gradient Mesh, Live Paint, Image Trace (12 presets, 18 ms/1k² image), Recolor Artwork, colour management (ICC, soft proofing, separations preview), Graphs (all 9 tools, Graph Data/Type, regenerate in place) done; graph Design/Column/Marker designs pending | 6–10 |
| M13 | Automation (Actions ✅ record/playback, persisted; variables, scripting, batch) | 🟡 | 18–27 |
| M14 | 1.0 polish (preferences, shortcut editor, workspaces, accessibility, packaging for all OSes) | 🟡 Preferences, shortcut editor (chords with Shift and a punctuation key fire as typed), workspaces, a custom title bar on Windows/Linux with a Home button, content-sized dialogs and menus that scroll when longer than the window done; accessibility, Windows/Linux packaging pending | 18–28 |
| M14 | 1.0 polish (preferences, shortcut editor, workspaces, accessibility, packaging for all OSes) | 🟡 Preferences, shortcut editor, workspaces, a custom title bar on Windows/Linux with a Home button, content-sized dialogs and menus that scroll when longer than the window done; accessibility, Windows/Linux packaging pending | 18–28 |
| — | Interaction fidelity pass (every tool's modifiers, Properties panel per context, isolation, nuance) | ⬜ | 60–90 |
| — | Hardening at scale (big-file corpus, fuzzing, cross-platform + browser QA) | 🟡 | 50–80 |
| | **Total to full parity** (one agent; re-derived from the [Parity estimate](#parity-estimate) table) | | **~320–500** |
@ -190,13 +184,13 @@ about 1–1.5 agent-hours each, so the other rows (estimated on the older scale)
| Live vector effects | 5 | 85% | Outline Object, Pathfinder Hard/Soft Mix and Trap, SVG Filters | 6–10 |
| Raster effects (Effect Gallery, Document Raster Effects Settings) | 4 | 20% | ~55 Photoshop-style filters (Artistic, Brush Strokes, Distort, Pixelate, Sketch, Stylize, Texture, Video) and the Effect Gallery; Document Raster Effects Settings and raster effects in PDF are done | 28–42 |
| 3D and Materials | 4 | 0% | Extrude & Bevel, Revolve, Inflate, Rotate, lighting, materials (software renderer) | 50–80 |
| Type core | 9 | 78% | composer/hyphenation options, Optical Margin Alignment, hidden characters, Transform Again after a type-area resize (it scales the type), partial selection of type-area anchors by marquee | 15–20 |
| Type core | 9 | 78% | composer/hyphenation options, Optical Margin Alignment, hidden characters | 15–20 |
| Type advanced | 4 | 48% | CJK composition for vertical type (ruby, mojikumi, vertical metrics, manual tate-chu-yoko), tab leaders, spell check (open dictionary), Touch Type, Retype; vertical point/area/path type and Type Orientation have initial support | 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 (Vector Halftone is done) | 6–10 |
| Layers, artboards, document setup | 5 | 80% | Layers panel options depth, artboard presets/rearrange polish (Document Setup and New Document are done) | 5–8 |
| 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 | 75% | global/video rulers, smart-guide preference depth, ruler-drag modifiers (Shift snaps to ticks, Alt swaps orientation) and dragging existing guides | 4–8 |
| Guides, grids, smart guides, snapping, rulers | 3 | 75% | global/video rulers, smart-guide preference depth | 4–8 |
| File formats | 6 | 85% | DWG (no open spec: DXF instead), PSD placement as layers, Illustrator EPS checked against real files (only reduced repros so far), the remaining fidelity polish; EPS, DXF, EMF/WMF, TIFF, BMP, Targa, PSD export, SVGZ, PDF security, PDF/X, PDF layers and presets are done | 6–10 |
| Export for Screens, Asset Export, slices, Save for Web | 3 | 85% | polish only (all four are done) | 2–4 |
| Print, colour management, separations, flattener | 3 | 80% | print preview fidelity (flattener presets in PDF and print, overprint in PDF and composite print, Print dialog, presets, PostScript, marks, separations, Print Tiling, print overprint/flattener/bitmap options and printer profile are done) | 1–2 |

View File

@ -2,7 +2,7 @@
//!
//! ```text
//! vectorcraft-cli mcp [--connect 127.0.0.1:7979 | --headless]
//! vectorcraft-cli run [--in FILE] [--cmd id [--params '{json}']]... [--export out.svg]... [--scale 2]
//! vectorcraft-cli run [--in FILE] [--cmd id [--params '{json}']]... [--export out.svg|.png|.pdf|.jpg|.webp|.vectorcraft]... [--scale 2]
//! vectorcraft-cli commands
//! vectorcraft-cli convert IN OUT [--scale 2] [--artboard 0 | --range 1-3,5] [--outline-text]
//! vectorcraft-cli info FILE
@ -59,17 +59,16 @@ USAGE:
vectorcraft-cli run [--in FILE] [--cmd ID [--params JSON]]... [--export FILE]... [--scale N]
Headless batch: open FILE (any readable format) or start a new document, run commands in
order, export each FILE in the format its extension picks (see Writable formats). Prints one
JSON result per step.
order, export (.svg, .png, .pdf, .jpg, .webp, .vectorcraft by extension). Prints one JSON result per step.
vectorcraft-cli commands
Print the command catalogue as JSON.
vectorcraft-cli convert IN OUT [--scale N] [--artboard I | --range R] [--outline-text]
Open IN (any readable format) and export OUT in the format its extension picks (see Writable
formats). --artboard is 0-based, --range 1-based (\"1-3,5\"); a PDF gets every artboard
unless one of them is given, EPS the bounds of the art, the other formats the first artboard.
Live effects are kept; --outline-text writes SVG text as paths.
Open IN (any readable format) and export OUT by extension (.svg, .pdf, .png, .jpg, .webp,
.vectorcraft). --artboard is 0-based, --range 1-based (\"1-3,5\"); a PDF gets every artboard
unless one of them is given, the other formats the first. Live effects are kept;
--outline-text writes SVG text as paths.
vectorcraft-cli info FILE
Print a JSON summary: title, colour mode, units, artboards, object counts by kind, fonts.
@ -83,10 +82,9 @@ USAGE:
synthetic N-path document (default 50000). Exits non-zero if a budget is exceeded.
";
/// The usage text plus the formats `document.open` reads and `document.export` writes.
/// The usage text plus the formats `document.open` reads.
fn usage() -> String {
use vectorcraft_engine::cmd::fileio::{OPEN_EXTS, export_extensions};
format!("{USAGE}\nReadable formats: .{}\nWritable formats: .{}\n", OPEN_EXTS.join(", ."), export_extensions().join(", ."))
format!("{USAGE}\nReadable formats: .{}\n", vectorcraft_engine::cmd::fileio::OPEN_EXTS.join(", ."))
}
fn main() -> ExitCode {

View File

@ -1,28 +1,14 @@
//! Loopback JSON-lines control server: one request per line, one reply per line.
//! This is the transport the MCP server (`vectorcraft mcp --connect`) wraps.
//!
//! The server only ever reads requests: a line that is not a JSON object with a string `method`
//! (an HTTP request line from a browser's cross-origin `fetch`, a stray `nc`, binary junk) gets
//! one error reply and the connection is closed, so nothing after it is executed. Lines are
//! bounded ([`MAX_LINE`]) and so is the number of open connections ([`MAX_CONNECTIONS`]); junk
//! never reaches the UI thread. See `docs/control-protocol.md`.
use std::io::{BufRead, BufReader, Read, Write};
use std::io::{BufRead, BufReader, Write};
use std::net::{TcpListener, TcpStream};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{Receiver, Sender, channel};
use std::time::Duration;
use serde_json::{Value, json};
use vectorcraft_ui_egui::ControlRequest;
/// Longest accepted request line (bytes, without the newline). Requests are small JSON objects;
/// anything longer is refused and the connection closed.
pub const MAX_LINE: usize = 4 * 1024 * 1024;
/// Connections served at once; further ones get an error line and are closed.
pub const MAX_CONNECTIONS: usize = 16;
pub fn start(port: u16, ctx: egui::Context) -> Receiver<ControlRequest> {
let (tx, rx) = channel::<ControlRequest>();
let listener = match TcpListener::bind(("127.0.0.1", port)) {
@ -33,249 +19,44 @@ pub fn start(port: u16, ctx: egui::Context) -> Receiver<ControlRequest> {
}
};
eprintln!("vectorcraft: control server listening on 127.0.0.1:{port}");
std::thread::spawn(move || accept_loop(listener, tx, ctx));
std::thread::spawn(move || {
for stream in listener.incoming().flatten() {
let tx = tx.clone();
let ctx = ctx.clone();
std::thread::spawn(move || serve(stream, tx, ctx));
}
});
rx
}
fn accept_loop(listener: TcpListener, tx: Sender<ControlRequest>, ctx: egui::Context) {
let open = Arc::new(AtomicUsize::new(0));
for mut stream in listener.incoming().flatten() {
if open.fetch_add(1, Ordering::SeqCst) >= MAX_CONNECTIONS {
open.fetch_sub(1, Ordering::SeqCst);
// Best effort: the connection is dropped either way, and a peer that can't read the reason loses nothing.
let _ = writeln!(stream, "{}", json!({"ok": false, "error": "too many control connections"}));
fn serve(stream: TcpStream, tx: Sender<ControlRequest>, ctx: egui::Context) {
let Ok(read) = stream.try_clone() else { return };
let mut out = stream;
for line in BufReader::new(read).lines() {
let Ok(line) = line else { break };
if line.trim().is_empty() {
continue;
}
let tx = tx.clone();
let ctx = ctx.clone();
let open = Arc::clone(&open);
std::thread::spawn(move || {
serve(stream, &tx, &ctx);
open.fetch_sub(1, Ordering::SeqCst);
});
}
}
fn serve(stream: TcpStream, tx: &Sender<ControlRequest>, ctx: &egui::Context) {
let Ok(read) = stream.try_clone() else { return };
serve_lines(read, stream, |method, params| {
let (req, rrx) = ControlRequest::new(method, params);
tx.send(req).ok()?;
ctx.request_repaint();
Some(rrx.recv_timeout(Duration::from_secs(60)).unwrap_or_else(|_| json!({"ok": false, "error": "timeout"})))
});
}
/// One parsed line.
enum Line {
Request {
id: Value,
method: String,
params: Value,
},
Blank,
/// Not a request: reply with this error and close the connection.
Reject(String),
}
fn parse_line(bytes: &[u8]) -> Line {
let Ok(text) = std::str::from_utf8(bytes) else {
return Line::Reject("not a control request (invalid UTF-8); closing the connection".into());
};
let text = text.trim();
if text.is_empty() {
return Line::Blank;
}
let msg = match serde_json::from_str::<Value>(text) {
Ok(v) => v,
Err(e) => return Line::Reject(format!("bad JSON ({e}); expected one JSON request object per line; closing the connection")),
};
let Some(obj) = msg.as_object() else {
return Line::Reject("not a control request (expected a JSON object); closing the connection".into());
};
let Some(method) = obj.get("method").and_then(Value::as_str) else {
return Line::Reject("not a control request (missing string `method`); closing the connection".into());
};
Line::Request {
id: obj.get("id").cloned().unwrap_or(Value::Null),
method: method.to_string(),
params: obj.get("params").cloned().unwrap_or(json!({})),
}
}
/// Read one `\n`-terminated line of at most `max` bytes into `buf` (newline stripped).
/// `Ok(false)` at end of stream; `Err` when the line is too long or the read fails.
fn read_bounded_line(reader: &mut impl BufRead, buf: &mut Vec<u8>, max: usize) -> Result<bool, String> {
buf.clear();
// `take` bounds the bytes buffered for one line: a peer can't make us allocate more than `max`.
let limit = u64::try_from(max).unwrap_or(u64::MAX).saturating_add(1);
let n = reader.take(limit).read_until(b'\n', buf).map_err(|e| e.to_string())?;
if n == 0 {
return Ok(false);
}
if buf.last() == Some(&b'\n') {
buf.pop();
if buf.last() == Some(&b'\r') {
buf.pop();
}
return Ok(true);
}
if buf.len() > max {
return Err(format!("request line longer than {max} bytes; closing the connection"));
}
// Last line without a newline, then end of stream.
Ok(true)
}
/// Serve requests from `read`, answering on `out`, until the peer closes, sends something that is
/// not a request, or `handle` returns `None` (app gone). `handle` gets `(method, params)` and
/// returns the reply object (the request's `id` is added here).
fn serve_lines<R: Read, W: Write>(read: R, mut out: W, mut handle: impl FnMut(String, Value) -> Option<Value>) {
let mut reader = BufReader::new(read);
let mut buf = Vec::new();
loop {
let reject = match read_bounded_line(&mut reader, &mut buf, MAX_LINE) {
Ok(false) => return,
Err(e) => e,
Ok(true) => match parse_line(&buf) {
Line::Blank => continue,
Line::Reject(e) => e,
Line::Request { id, method, params } => {
let Some(mut r) = handle(method, params) else { return };
if let Some(o) = r.as_object_mut() {
o.insert("id".into(), id);
}
if writeln!(out, "{r}").and_then(|()| out.flush()).is_err() {
return;
}
continue;
let reply = match serde_json::from_str::<Value>(&line) {
Ok(msg) => {
let id = msg.get("id").cloned().unwrap_or(Value::Null);
let method = msg.get("method").and_then(Value::as_str).unwrap_or("").to_string();
let params = msg.get("params").cloned().unwrap_or(json!({}));
let (req, rrx) = ControlRequest::new(method, params);
if tx.send(req).is_err() {
break;
}
},
ctx.request_repaint();
let mut r = rrx.recv_timeout(Duration::from_secs(60)).unwrap_or_else(|_| json!({"ok": false, "error": "timeout"}));
if let Some(o) = r.as_object_mut() {
o.insert("id".into(), id);
}
r
}
Err(e) => json!({"ok": false, "error": format!("bad JSON: {e}")}),
};
// Best effort: the connection closes either way, and a peer that can't read the reason loses nothing.
let _ = writeln!(out, "{}", json!({"ok": false, "error": reject})).and_then(|()| out.flush());
return;
}
}
#[cfg(test)]
mod tests {
use super::*;
fn run(input: &[u8]) -> (Vec<Value>, Vec<String>) {
let mut out = Vec::new();
let mut calls = Vec::new();
serve_lines(input, &mut out, |m, _p| {
calls.push(m);
Some(json!({"ok": true, "result": null}))
});
let replies = String::from_utf8(out).unwrap().lines().map(|l| serde_json::from_str::<Value>(l).unwrap()).collect();
(replies, calls)
}
#[test]
fn requests_are_answered_in_order_with_ids() {
let (r, calls) = run(b"{\"id\":1,\"method\":\"a\"}\n\n{\"id\":2,\"method\":\"b\",\"params\":{}}\r\n{\"method\":\"c\"}");
assert_eq!(calls, ["a", "b", "c"]);
assert_eq!(r.len(), 3);
assert_eq!(r[0]["id"], 1);
assert_eq!(r[1]["id"], 2);
assert_eq!(r[2]["id"], Value::Null);
}
#[test]
fn http_request_closes_before_the_body_runs() {
// A browser's cross-origin `fetch` POST: the request line is rejected and the
// connection closed, so the JSON body is never executed.
let http = b"POST / HTTP/1.1\r\nHost: 127.0.0.1:7979\r\nOrigin: https://attacker.example\r\nContent-Type: text/plain\r\n\r\n\
{\"id\":7,\"method\":\"engine.execute\",\"params\":{\"command\":\"file.new\",\"params\":{}}}\n";
let (r, calls) = run(http);
assert!(calls.is_empty(), "nothing may run: {calls:?}");
assert_eq!(r.len(), 1);
assert_eq!(r[0]["ok"], false);
assert!(r[0]["error"].as_str().unwrap().contains("closing the connection"));
}
#[test]
fn non_request_json_closes_the_connection() {
for junk in [
&b"[1,2]\n{\"method\":\"a\"}\n"[..],
b"{\"id\":1}\n{\"method\":\"a\"}\n",
b"{\"method\":5}\n{\"method\":\"a\"}\n",
b"\xff\xfe\n{\"method\":\"a\"}\n",
] {
let (r, calls) = run(junk);
assert!(calls.is_empty(), "{calls:?}");
assert_eq!(r.len(), 1);
assert_eq!(r[0]["ok"], false);
if writeln!(out, "{reply}").is_err() {
break;
}
}
#[test]
fn a_request_before_junk_still_runs() {
let (r, calls) = run(b"{\"method\":\"a\"}\nGET / HTTP/1.1\n{\"method\":\"b\"}\n");
assert_eq!(calls, ["a"]);
assert_eq!(r.len(), 2);
assert_eq!(r[1]["ok"], false);
}
#[test]
fn overlong_line_is_refused() {
// One byte over the limit, then a valid request: neither runs.
let mut input = vec![b'x'; MAX_LINE + 1];
input.extend_from_slice(b"\n{\"method\":\"a\"}\n");
let (r, calls) = run(&input);
assert!(calls.is_empty(), "{calls:?}");
assert_eq!(r.len(), 1);
assert!(r[0]["error"].as_str().unwrap().contains("longer than"));
}
#[test]
fn line_at_the_limit_is_accepted() {
let mut buf = Vec::new();
let line = vec![b'a'; 10];
let mut input = line.clone();
input.push(b'\n');
assert_eq!(read_bounded_line(&mut &input[..], &mut buf, 10), Ok(true));
assert_eq!(buf, line);
assert!(read_bounded_line(&mut &[b'a'; 11][..], &mut buf, 10).is_err());
}
#[test]
fn tcp_connection_is_closed_after_junk() {
// End to end over a real loopback socket (the transport the app uses).
let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
let addr = listener.local_addr().unwrap();
let server = std::thread::spawn(move || {
let (s, _) = listener.accept().unwrap();
let read = s.try_clone().unwrap();
serve_lines(read, s, |_, _| Some(json!({"ok": true})));
});
let mut c = TcpStream::connect(addr).unwrap();
c.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
c.write_all(b"{\"id\":7,\"method\":\"x\"}\nhello\n{\"method\":\"y\"}\n").unwrap();
let mut text = String::new();
c.read_to_string(&mut text).unwrap(); // returns at EOF: the server closed the connection
server.join().unwrap();
let lines: Vec<&str> = text.lines().collect();
assert_eq!(lines.len(), 2, "{text}");
assert!(lines[0].contains("\"id\":7"));
assert!(lines[1].contains("closing the connection"));
}
#[test]
fn extra_connections_are_refused() {
let listener = TcpListener::bind(("127.0.0.1", 0)).unwrap();
let addr = listener.local_addr().unwrap();
let (tx, _rx) = channel::<ControlRequest>();
std::thread::spawn(move || accept_loop(listener, tx, egui::Context::default()));
// Idle connections are accepted in order and held open.
let held: Vec<TcpStream> = (0..16).map(|_| TcpStream::connect(addr).unwrap()).collect();
let mut extra = TcpStream::connect(addr).unwrap();
extra.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
let mut line = String::new();
BufReader::new(&mut extra).read_line(&mut line).unwrap();
assert!(line.contains("too many control connections"), "{line}");
drop(held);
}
}

View File

@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};
use vectorcraft_color::{Color, Paint};
use vectorcraft_geom::{Affine, PathData, Point, Rect, Vec2};
use vectorcraft_geom::{Affine, PathData, Point, Rect};
use crate::appearance::{Appearance, AppearanceItem, Dash, FillLayer, LineCap, LineJoin, StrokeLayer};
@ -476,49 +476,6 @@ impl TextObject {
pub fn transform(&mut self, a: Affine) {
self.xf = a * self.xf;
}
/// Area type's frame (the type area) in document space; None for other type.
pub fn area_frame(&self) -> Option<PathData> {
match &self.kind {
TextKind::Area { frame } => Some(frame.transformed(self.xf)),
_ => None,
}
}
/// Reshape area type's frame by `a`, a document-space transform, keeping the type at its size
/// (a bounding-box resize: the text reflows, it isn't scaled). False, changing nothing, for
/// other type, a degenerate `xf` or a frame that would not be finite.
pub fn transform_area(&mut self, a: Affine) -> bool {
let xf = self.xf;
self.reshape_area(|frame, to_text| {
frame.transform(to_text * a * xf);
true
})
}
/// Move anchors `refs` (subpath, anchor) of area type's frame by `d` in document space, with
/// their handles (a Direct Selection drag of a frame corner or edge). False, changing
/// nothing, when an anchor doesn't exist, or as [`Self::transform_area`].
pub fn move_area_anchors(&mut self, refs: &[(usize, usize)], d: Vec2) -> bool {
self.reshape_area(|frame, to_text| {
// A distance: only the linear part of the document → text map applies.
let local = to_text * d.to_point() - to_text * Point::ZERO;
refs.iter().all(|&(si, ai)| frame.anchor_mut(si, ai).map(|a| a.translate(local)).is_some())
})
}
/// Edit a copy of the area frame with `f` (given the document → text space map) and keep it
/// when `f` succeeds and the result is finite.
fn reshape_area(&mut self, f: impl FnOnce(&mut PathData, Affine) -> bool) -> bool {
let det = self.xf.determinant();
if !det.is_finite() || det.abs() < 1e-12 {
return false;
}
let to_text = self.xf.inverse();
let TextKind::Area { frame } = &mut self.kind else { return false };
let mut next = frame.clone();
if !f(&mut next, to_text) || !next.anchors().all(|(_, _, a)| a.p.is_finite() && a.h_in.is_finite() && a.h_out.is_finite()) {
return false;
}
*frame = next;
true
}
/// Scale the character strokes' weights and dashes by `s` (they are drawn in text space, so
/// `1 / scale` keeps their weight through a transform that scales the type).
pub fn scale_char_strokes(&mut self, s: f64) {
@ -548,49 +505,4 @@ mod tests {
assert!(b.x0 >= 10.0 - 1e-9 && b.y1 > 20.0);
assert_eq!(CharStyle::default().effective_leading(), 14.399999999999999);
}
/// 120 × 40 area type at (40, 40), its text drawn at twice its size.
fn area_type() -> TextObject {
let mut t = TextObject::point(Point::ZERO, "Some text", CharStyle::default());
t.kind = TextKind::Area { frame: vectorcraft_geom::shapes::rectangle(Rect::new(0.0, 0.0, 60.0, 20.0)) };
t.xf = Affine::translate((40.0, 40.0)) * Affine::scale(2.0);
t
}
#[test]
fn area_resizes_its_frame_and_keeps_its_type() {
let mut t = area_type();
assert_eq!(t.bounds(), Some(Rect::new(40.0, 40.0, 160.0, 80.0)));
// Bottom-right handle to (200, 140), about the top-left corner.
let o = Affine::translate((40.0, 40.0));
assert!(t.transform_area(o * Affine::scale_non_uniform(160.0 / 120.0, 100.0 / 40.0) * o.inverse()));
assert_eq!(t.xf, Affine::translate((40.0, 40.0)) * Affine::scale(2.0), "the type keeps its size");
let b = t.bounds().unwrap();
assert!((b.x1 - 200.0).abs() < 1e-9 && (b.y1 - 140.0).abs() < 1e-9 && b.x0 == 40.0, "{b:?}");
assert_eq!(t.area_frame().unwrap().bounds(), Some(b));
// Point type has no area; a degenerate transform or a non-finite frame changes nothing.
let mut p = TextObject::point(Point::ZERO, "x", CharStyle::default());
assert!(!p.transform_area(Affine::scale(2.0)) && p.area_frame().is_none());
let before = t.clone();
assert!(!t.transform_area(Affine::scale(f64::INFINITY)));
t.xf = Affine::scale(0.0);
assert!(!t.transform_area(Affine::scale(2.0)));
t.xf = before.xf;
assert_eq!(t, before);
}
#[test]
fn area_anchors_move_in_document_space() {
let mut t = area_type();
// The bottom-right corner (anchor 2) 20 pt right: 10 pt in text space at 2×.
assert!(t.move_area_anchors(&[(0, 2)], Vec2::new(20.0, 0.0)));
let TextKind::Area { frame } = &t.kind else { panic!() };
assert_eq!(frame.subpaths[0].anchors[2].p, Point::new(70.0, 20.0));
assert_eq!(frame.subpaths[0].anchors[1].p, Point::new(60.0, 0.0), "the others stay");
// A missing anchor changes nothing.
let before = t.clone();
assert!(!t.move_area_anchors(&[(0, 1), (0, 9)], Vec2::new(5.0, 5.0)));
assert!(!t.move_area_anchors(&[(3, 0)], Vec2::new(5.0, 5.0)));
assert_eq!(t, before);
}
}

View File

@ -11,7 +11,7 @@ use crate::DocState;
use super::super::*;
use super::encode::single_artboard;
use super::{ARTBOARD_PARAMS, Format, default_name, encode, encode_all, encode_with_warnings, merge, writable, write_encoded, write_or_return};
use super::{ARTBOARD_PARAMS, Format, default_name, encode, encode_all, merge, writable, write_encoded, write_or_return};
pub(super) fn serialize(s: &mut Session, p: &Value) -> Result<Value> {
let f = writable("document.serialize", Some(str_param(p, "format").unwrap_or("vectorcraft")), None)?;
@ -151,10 +151,8 @@ pub(super) fn export_selection(s: &mut Session, p: &Value) -> Result<Value> {
let expanded = expand_presets(s, C, p)?;
let p = &*expanded;
let (d, bounds) = selection(s, C)?;
// The encoder's warnings (options accepted but not applied, features approximated or left
// out), as document.export reports them.
let (bytes, warnings) = encode_with_warnings(&d, f.id, &without_artboards(p))?;
write_or_return(path, &bytes, json!({ "format": f.id, "warnings": warnings, "bounds": [bounds.x0, bounds.y0, bounds.width(), bounds.height()] }))
let bytes = encode(&d, f.id, &without_artboards(p))?;
write_or_return(path, &bytes, json!({ "bounds": [bounds.x0, bounds.y0, bounds.width(), bounds.height()] }))
}
/// File → Save for Office Documents: one artboard as a PNG at `ppi`, on white unless

View File

@ -105,7 +105,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Export Selection…",
["File"],
None,
"{path?, format?: png|jpg|webp|svg|svgz|pdf (default: from the extension, else png), scale?: 1, …the format's options} the selected objects cropped to their bounds (template layers left out) → {path, format, bytes, warnings, bounds} (no path → {dataBase64, format, bytes, warnings, bounds}); warnings say what the format approximated or left out, as for document.export",
"{path?, format?: png|jpg|webp|svg|svgz|pdf (default: from the extension, else png), scale?: 1, …the format's options} the selected objects cropped to their bounds (template layers left out) → {path, bytes, bounds} (no path → {dataBase64, bounds})",
has_selection,
export::export_selection
),
@ -581,18 +581,6 @@ pub const OPEN_EXTS: &[&str] = &[
"eps",
];
/// The extension that picks each writable format when exporting (the format's first; PNG-8 shares
/// `.png` with PNG, so `.png` comes once), in [`FORMATS`] order.
pub fn export_extensions() -> Vec<&'static str> {
let mut v: Vec<&'static str> = Vec::new();
for e in FORMATS.iter().filter(|f| f.write).filter_map(|f| f.extensions.first()) {
if !v.contains(e) {
v.push(e);
}
}
v
}
/// Text files: File → Place sets them as area type (Text Import Options).
pub const TEXT_EXTS: &[&str] = &["txt"];

View File

@ -150,39 +150,6 @@ fn open_exts_cover_every_readable_format() {
assert_eq!(filters.last(), Some(&("Plug-ins", crate::cmd::plugin::EXTS)), "File › Open installs plug-ins");
}
/// The extensions usage texts list for export: one per writable format, each picking that format
/// (`.png` picks PNG; PNG-8 is asked for by `format`).
#[test]
fn export_extensions_name_every_writable_format() {
let exts = export_extensions();
assert_eq!(
exts,
[
"vectorcraft",
"svg",
"svgz",
"pdf",
"png",
"jpg",
"gif",
"webp",
"tif",
"bmp",
"vctemplate",
"txt",
"dxf",
"eps",
"emf",
"wmf",
"tga",
"psd"
]
);
for e in exts {
assert!(format_for_name(&format!("x.{e}")).is_some_and(|f| f.write), "{e}");
}
}
#[test]
fn formats_query_lists_readers_writers_and_options() {
let mut s = Session::new();

View File

@ -20,7 +20,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Transform",
[],
None,
"{matrix: [a,b,c,d,e,f], copy?: bool, ids?, strokes?: bool, corners?: bool, typeAreas?: bool} apply an affine to the selection (or ids); strokes/corners: Scale Strokes & Effects / Scale Corners (default: the preferences); typeAreas: area type among them (not type inside a group) reshapes its frame by the matrix and its text reflows at its size, as a bounding-box handle drag does (default: the type transforms too)",
"{matrix: [a,b,c,d,e,f], copy?: bool, ids?, strokes?: bool, corners?: bool} apply an affine to the selection (or ids); strokes/corners: Scale Strokes & Effects / Scale Corners (default: the preferences)",
has_doc,
transform
),
@ -202,18 +202,15 @@ pub(crate) fn scaling(s: &mut Session, p: &Value) -> Scaling {
Scaling { strokes, effects: strokes.then_some(vectorcraft_render::effects::scale_effect), keep_type_strokes: !strokes, keep_corners: !corners }
}
/// Apply `xf` to `ids` (`copy` param: duplicate first; `strokes`/`corners`: see [`scaling`];
/// `typeAreas`: see [`resize_type_area`]). Records Transform Again.
/// Apply `xf` to `ids` (`copy` param: duplicate first; `strokes`/`corners`: see [`scaling`]).
/// Records Transform Again.
pub(crate) fn apply_transform(s: &mut Session, label: &str, ids: Vec<NodeId>, xf: Affine, p: &Value) -> Result<Value> {
let copy = bool_or(p, "copy", false);
let areas = bool_or(p, "typeAreas", false);
let sc = if Scaling::factor(xf).is_some() { scaling(s, p) } else { Scaling::default() };
let ids = s.edit(label, |d, sel| {
let targets = if copy { duplicate_in(d, sel, &ids, Affine::IDENTITY)? } else { ids.clone() };
for id in &targets {
if let Some(n) = d.node_mut(*id)
&& !(areas && resize_type_area(n, xf))
{
if let Some(n) = d.node_mut(*id) {
n.transform(xf, sc);
}
}
@ -227,17 +224,6 @@ pub(crate) fn apply_transform(s: &mut Session, label: &str, ids: Vec<NodeId>, xf
Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>() }))
}
/// Area type resized by its bounding box: `xf` reshapes its frame (the type area) and the text
/// reflows at its size. False for anything else (and type in perspective), which transforms as
/// usual.
fn resize_type_area(n: &mut Node, xf: Affine) -> bool {
if n.perspective.is_some() {
return false;
}
let NodeKind::Text(t) = &mut n.kind else { return false };
super::typecmd::reshape_area_with(t, |t| t.transform_area(xf))
}
fn transform(s: &mut Session, p: &Value) -> Result<Value> {
let m = matrix_param(p, "matrix").ok_or_else(|| bad("object.transform", "missing matrix [a,b,c,d,e,f]"))?;
let ids = match ids_param(p, "ids") {

View File

@ -188,8 +188,7 @@ fn key(s: &mut Session, p: &Value) -> Result<Value> {
ok()
}
/// `[[subpath, anchor]…]` anchor references (malformed entries are left out).
pub(crate) fn parse_refs(v: Option<&Value>) -> Vec<(usize, usize)> {
fn parse_refs(v: Option<&Value>) -> Vec<(usize, usize)> {
v.and_then(Value::as_array)
.map(|a| a.iter().filter_map(|x| Some((x.get(0)?.as_u64()? as usize, x.get(1)?.as_u64()? as usize))).collect())
.unwrap_or_default()

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use serde_json::{Value, json};
use vectorcraft_doc::{Document, Justify, Node, NodeId, NodeKind, TextObject};
use vectorcraft_geom::{Affine, PathData, Vec2};
use vectorcraft_geom::PathData;
use super::edit::selected_roots;
use super::pathops::{len_param, num_param, shape_node};
@ -48,19 +48,10 @@ pub fn specs() -> Vec<CommandSpec> {
"Area Type Options…",
["Type"],
None,
"{ids?, width?: pt, height?: pt, rows?, columns?, gutter?: pt, inset?: pt, firstBaseline?: ascent|capHeight|xHeight|leading|fixed, firstBaselineMin?: pt} set the selected area type's options; width and height size the type area from its top-left corner, along the type's own axes, and the text reflows at its size (none given: query) → the first object's options",
"{ids?, rows?, columns?, gutter?: pt, inset?: pt, firstBaseline?: ascent|capHeight|xHeight|leading|fixed, firstBaselineMin?: pt} set the selected area type's options (none given: query) → the first object's options",
has_selection,
area_options
),
cmd!(
"text.reshapeArea",
"Reshape Type Area",
[],
None,
"{id, anchors: [[subpath, anchor]…], dx, dy} move anchors of area type's frame (the type area) by dx, dy points, with their handles; the text reflows at its size, through its thread too (what Direct Selection does dragging a frame corner or edge)",
has_doc,
reshape_area
),
cmd!(
"text.fitHeadline",
"Fit Headline",
@ -274,82 +265,25 @@ fn set_style(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>() }))
}
/// Reshape area type's frame with `f` ([`TextObject::transform_area`],
/// [`TextObject::move_area_anchors`]) and lay its text out again. False, changing nothing, when
/// `f` fails or the frame would reach past [`crate::MAX_COORD`] (the text flows over its height).
pub(crate) fn reshape_area_with(t: &mut TextObject, f: impl FnOnce(&mut TextObject) -> bool) -> bool {
let before = t.kind.clone();
let within = |t: &TextObject| match &t.kind {
vectorcraft_doc::TextKind::Area { frame } => {
frame.bounds().is_some_and(|b| [b.x0, b.y0, b.x1, b.y1].iter().all(|v| v.abs() <= crate::MAX_COORD))
}
_ => false,
};
if !(f(t) && within(t)) {
t.kind = before;
return false;
}
refresh_bounds(t);
true
}
/// Area type's text, if `n` is area type.
fn area_text(n: Option<&Node>) -> Option<&TextObject> {
match n.map(|n| &n.kind) {
Some(NodeKind::Text(t)) if matches!(t.kind, vectorcraft_doc::TextKind::Area { .. }) => Some(t),
_ => None,
}
}
/// The width and height of area type's frame in points, along the type's own axes, and the frame's
/// bounds in text space.
fn area_size(t: &TextObject) -> Option<(f64, f64, vectorcraft_geom::Rect)> {
let vectorcraft_doc::TextKind::Area { frame } = &t.kind else { return None };
let b = frame.bounds()?;
let [a, bb, c, d, _, _] = t.xf.as_coeffs();
Some((b.width() * a.hypot(bb), b.height() * c.hypot(d), b))
}
/// Size area type's frame to `w` × `h` points (None: keep that side) from its top-left corner,
/// and lay its text out again. False when the frame doesn't change.
fn size_area(t: &mut TextObject, w: Option<f64>, h: Option<f64>) -> bool {
let Some((cw, ch, b)) = area_size(t) else { return false };
let factor = |to: Option<f64>, cur: f64| match to {
Some(to) if cur > 1e-9 && (to - cur).abs() > 1e-9 => to / cur,
_ => 1.0,
};
let (sx, sy) = (factor(w, cw), factor(h, ch));
if sx == 1.0 && sy == 1.0 {
return false;
}
let o = Affine::translate(b.origin().to_vec2());
let a = t.xf * o * Affine::scale_non_uniform(sx, sy) * o.inverse() * t.xf.inverse();
reshape_area_with(t, |t| t.transform_area(a))
}
fn area_options(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "text.areaOptions";
let ids: Vec<NodeId> = {
let d = &s.doc()?.doc;
text_targets(s, p, C)?.into_iter().filter(|i| area_text(d.node(*i)).is_some()).collect()
text_targets(s, p, C)?
.into_iter()
.filter(|i| matches!(d.node(*i).map(|n| &n.kind), Some(NodeKind::Text(t)) if matches!(t.kind, vectorcraft_doc::TextKind::Area { .. })))
.collect()
};
let first = *ids.first().ok_or_else(|| bad(C, "select area type (text in a frame)"))?;
let options = |s: &Session| -> Result<Value> {
let t = area_text(s.doc()?.doc.node(first)).ok_or_else(|| bad(C, "select area type (text in a frame)"))?;
let mut v = serde_json::to_value(&t.area).map_err(|e| EngineError::Other(e.to_string()))?;
if let (Some(o), Some((w, h, _))) = (v.as_object_mut(), area_size(t)) {
o.insert("width".into(), json!(w));
o.insert("height".into(), json!(h));
}
Ok(v)
let first = ids.first().ok_or_else(|| bad(C, "select area type (text in a frame)"))?;
let current = match &s.doc()?.doc.node(*first).map(|n| &n.kind) {
Some(NodeKind::Text(t)) => t.area.clone(),
_ => return Err(bad(C, "select area type (text in a frame)")),
};
let mut v = options(s)?;
let size = |k: &str| p.get(k).and_then(Value::as_f64).map(|x| x.clamp(1.0, 100_000.0));
let (w, h) = (size("width"), size("height"));
let mut changed = w.is_some() || h.is_some();
let mut v = serde_json::to_value(&current).map_err(|e| EngineError::Other(e.to_string()))?;
let mut changed = false;
if let (Some(o), Some(src)) = (v.as_object_mut(), p.as_object()) {
for (k, val) in src {
if o.contains_key(k) && !matches!(k.as_str(), "ids" | "width" | "height") {
if o.contains_key(k) && k != "ids" {
o.insert(k.clone(), val.clone());
changed = true;
}
@ -364,43 +298,17 @@ fn area_options(s: &mut Session, p: &Value) -> Result<Value> {
opts.gutter = opts.gutter.clamp(0.0, 10_000.0);
opts.inset = opts.inset.clamp(0.0, 10_000.0);
opts.first_baseline_min = opts.first_baseline_min.clamp(0.0, 10_000.0);
let out = serde_json::to_value(&opts).map_err(|e| EngineError::Other(e.to_string()))?;
s.edit("Area Type Options", |d, _| {
for id in &ids {
if let Some(NodeKind::Text(t)) = d.node_mut(*id).map(|n| &mut n.kind) {
t.area = opts.clone();
// A resized frame has laid its text out again; otherwise the new options do here.
if !size_area(t, w, h) {
refresh_bounds(t);
}
refresh_bounds(t);
}
}
Ok(())
})?;
options(s)
}
fn reshape_area(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "text.reshapeArea";
let id = id_param(p, "id").ok_or_else(|| bad(C, "missing id"))?;
let mut refs = super::select::parse_refs(p.get("anchors"));
refs.sort_unstable();
refs.dedup();
if refs.is_empty() {
return Err(bad(C, "missing anchors [[subpath, anchor]…]"));
}
let d = Vec2::new(f64_req(p, "dx", C)?, f64_req(p, "dy", C)?);
let node = s.doc()?.doc.node(id);
if area_text(node).is_none() || node.is_some_and(|n| n.perspective.is_some()) {
return Err(bad(C, "not area type (text in a frame) outside perspective"));
}
s.edit("Reshape Type Area", |doc, _| {
let Some(NodeKind::Text(t)) = doc.node_mut(id).map(|n| &mut n.kind) else { return Err(EngineError::NoNode(id)) };
if !reshape_area_with(t, |t| t.move_area_anchors(&refs, d)) {
return Err(bad(C, "no such frame anchor, or the frame would reach past the canvas"));
}
Ok(())
})?;
ok()
Ok(out)
}
#[cfg(test)]

View File

@ -29,21 +29,7 @@ pub fn node_summary(n: &Node) -> Value {
if n.bbox_angle != 0.0 {
v["rotation"] = json!(n.bbox_angle);
}
if let NodeKind::Text(t) = &n.kind {
// Type shows its characters' paint: the first run's, as paint.proxies and the Stroke
// options read it. Fills and strokes of the type object itself, above or below its
// characters, come separately so the two stay apart.
let default = vectorcraft_doc::CharStyle::default();
let style = t.runs.first().map_or(&default, |r| &r.style);
v["fill"] = json!(style.fill.label());
v["stroke"] = json!(style.stroke.label());
v["strokeWidth"] = json!(if style.stroke.is_none() { 0.0 } else { style.stroke_width });
if n.appearance.fill().is_some() || n.appearance.stroke().is_some() {
v["objectFill"] = json!(n.appearance.fill_paint().label());
v["objectStroke"] = json!(n.appearance.stroke_paint().label());
v["objectStrokeWidth"] = json!(n.appearance.stroke_width());
}
} else if !n.is_container() {
if !n.is_container() {
v["fill"] = json!(n.appearance.fill_paint().label());
v["stroke"] = json!(n.appearance.stroke_paint().label());
v["strokeWidth"] = json!(n.appearance.stroke_width());

View File

@ -1388,8 +1388,6 @@ mod tests_toolsettings;
#[cfg(test)]
mod tests_transparencygrid;
#[cfg(test)]
mod tests_typearea;
#[cfg(test)]
mod tests_units;
#[cfg(test)]
mod tests_webexport;

View File

@ -285,39 +285,6 @@ fn inspect_lists_everything() {
assert!(s.commands().len() > 100);
}
/// Type reports the paint its characters show, and its own object-level paint apart from it.
#[test]
fn inspect_reports_the_paint_of_types_characters() {
let mut s = session();
let id = s.execute("text.create", &json!({"x": 50, "y": 60, "text": "HI", "size": 24})).unwrap()["id"].as_u64().unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000", "ids": [id]})).unwrap();
let node = |s: &mut Session| {
let v = s.execute("document.inspect", &json!({})).unwrap();
v["layers"][0]["children"].as_array().unwrap().iter().find(|n| n["id"] == id).cloned().unwrap()
};
let t = node(&mut s);
assert_eq!((t["fill"].as_str(), t["stroke"].as_str(), t["strokeWidth"].as_f64()), (Some("#ff0000"), Some("None"), Some(0.0)), "{t}");
assert!(t.get("objectFill").is_none(), "no object-level paint: {t}");
s.execute("paint.setFill", &json!({"color": "#0000ff", "ids": [id]})).unwrap();
s.execute("paint.setStroke", &json!({"color": "#00ff00", "ids": [id]})).unwrap();
s.execute("stroke.set", &json!({"weight": 3, "ids": [id]})).unwrap();
let t = node(&mut s);
assert_eq!((t["fill"].as_str(), t["stroke"].as_str(), t["strokeWidth"].as_f64()), (Some("#0000ff"), Some("#00ff00"), Some(3.0)), "{t}");
// An object-level fill on the type stays distinguishable from its characters' paint.
s.execute("appearance.addFill", &json!({"ids": [id]})).unwrap();
s.execute("paint.setFill", &json!({"color": "#ffff00", "item": 0, "ids": [id]})).unwrap();
let t = node(&mut s);
assert_eq!(t["objectFill"], "#ffff00", "{t}");
assert_eq!(t["fill"], "#0000ff", "{t}");
// A path keeps reporting its own appearance.
let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();
s.execute("paint.setFill", &json!({"color": "#ff0000", "ids": [r]})).unwrap();
let v = s.execute("document.inspect", &json!({})).unwrap();
let rect = v["layers"][0]["children"].as_array().unwrap().iter().find(|n| n["id"] == r).cloned().unwrap();
assert_eq!(rect["fill"], "#ff0000");
assert!(rect.get("objectFill").is_none());
}
#[test]
fn every_command_has_unique_id_and_doc() {
let mut ids: Vec<&str> = command_specs().iter().map(|c| c.id).collect();

View File

@ -168,33 +168,6 @@ fn export_selection_crops_to_the_selection() {
assert_eq!(text.matches("<path").count(), 1, "{text}");
}
/// A selection export reports the encoder's warnings like a whole-document export, and an empty
/// list when nothing was approximated.
#[test]
fn export_selection_reports_the_encoders_warnings() {
let mut s = session();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
s.execute("transparency.set", &json!({"blend": "Multiply"})).unwrap();
let warnings = |v: &serde_json::Value| v["warnings"].as_array().cloned().unwrap_or_else(|| panic!("no warnings key: {v}"));
// Control: nothing approximated.
let plain = s.execute("document.exportSelection", &json!({"format": "svg"})).unwrap();
assert_eq!(plain["format"], "svg");
assert!(warnings(&plain).is_empty(), "{plain}");
for (format, options, says) in [
("webp", json!({"lossless": false}), "lossless"),
("svg", json!({"profile": "tiny12"}), "blend"),
("pdf", json!({"createLayers": true, "compatibility": "1.4"}), "layers"),
] {
let mut p = options.clone();
p["format"] = json!(format);
let sel = s.execute("document.exportSelection", &p).unwrap();
let doc = s.execute("document.export", &p).unwrap();
let w = warnings(&sel);
assert!(w.iter().any(|w| w.as_str().unwrap_or("").to_lowercase().contains(says)), "{format}: {sel}");
assert_eq!(w, warnings(&doc), "{format}: the same warnings as a whole-document export");
}
}
#[test]
fn template_opens_as_untitled() {
let mut s = session();
@ -233,30 +206,3 @@ fn raster_export_too_large_is_an_error_not_a_crash() {
assert!(std::fs::read(&path).unwrap().starts_with(b"\x89PNG"));
let _ = std::fs::remove_dir_all(dir);
}
/// Japanese file and folder names save, open, export and title documents as typed: the native
/// format, SVG, PNG and PDF, in a folder with a Japanese name too.
#[test]
fn japanese_file_names_save_open_and_export() {
let mut s = session();
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 80, "height": 40})).unwrap();
s.execute("text.create", &json!({"x": 10, "y": 80, "text": "日本語のテキスト"})).unwrap();
let dir = std::env::temp_dir().join(format!("vc-日本語フォルダ-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let path = dir.join("運動会カード(最終版)・2024.vectorcraft");
s.execute("document.save", &json!({"path": path.to_string_lossy()})).unwrap();
assert!(path.exists());
assert_eq!(s.doc().unwrap().title(), "運動会カード(最終版)・2024.vectorcraft", "the tab names the file as typed");
s.execute("document.open", &json!({"path": path.to_string_lossy()})).unwrap();
let d = s.doc().unwrap();
assert_eq!(d.path.as_deref(), Some(path.to_string_lossy().as_ref()));
let mut found = false;
d.doc.walk(|n| found |= matches!(&n.kind, vectorcraft_doc::NodeKind::Text(t) if t.plain_text() == "日本語のテキスト"));
assert!(found, "the Japanese text comes back");
for (format, name) in [("svg", "書き出し.svg"), ("png", "書き出し.png"), ("pdf", "書き出し.pdf")] {
let out = dir.join(name);
s.execute("document.export", &json!({"format": format, "path": out.to_string_lossy()})).unwrap();
assert!(std::fs::metadata(&out).is_ok_and(|m| m.len() > 0), "{name}");
}
let _ = std::fs::remove_dir_all(dir);
}

View File

@ -328,23 +328,6 @@ fn select_all_and_cut_like_ui() {
assert_eq!(obj(&s, id).plain_text(), "abc defabc def");
}
#[test]
fn a_frame_dragged_with_the_type_tools_is_the_dragged_rectangle() {
for tool in ["type", "verticalType"] {
let mut s = session();
let v = ViewInfo::default();
s.select_tool(tool, v).unwrap();
for (k, x, y) in [(PointerKind::Down, 100.0, 100.0), (PointerKind::Drag, 300.0, 180.0), (PointerKind::Up, 300.0, 180.0)] {
s.pointer(&PointerEvent::new(k, x, y), v).unwrap();
}
let t = obj(&s, s.doc().unwrap().selection.objects[0]);
let TextKind::Area { frame } = &t.kind else { panic!("{tool}: not area type") };
let b = frame.bounds().unwrap();
let (a, z) = (t.xf * Point::new(b.x0, b.y0), t.xf * Point::new(b.x1, b.y1));
assert!((a - Point::new(100.0, 100.0)).hypot() < 1e-9 && (z - Point::new(300.0, 180.0)).hypot() < 1e-9, "{tool}: {a:?} {z:?}");
}
}
#[test]
fn area_type_from_a_circle_keeps_glyphs_inside() {
let mut s = session();

View File

@ -1,269 +0,0 @@
//! Resizing area type (#252): a bounding-box handle drag and Area Type Options size the type area
//! and the text reflows at its size; Direct Selection reshapes the frame by a corner or an edge.
//! Point type still scales.
use serde_json::{Value, json};
use vectorcraft_doc::{NodeKind, TextKind, TextObject};
use vectorcraft_geom::{Affine, Point, Rect};
use vectorcraft_text::TextLayout;
use vectorcraft_tools::bbox::Handle;
use vectorcraft_tools::{Mods, PointerEvent, PointerKind};
use super::*;
const STORY: &str = "The quick brown fox jumps over the lazy dog. A second sentence follows the first one here. Then a third one ends it.";
fn session() -> Session {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
s
}
fn id_of(v: &Value) -> NodeId {
NodeId(v["id"].as_u64().unwrap())
}
/// 12 pt area type in a `w` × `h` frame at (`x`, `y`).
fn area(s: &mut Session, x: f64, y: f64, w: f64, h: f64, text: &str) -> NodeId {
id_of(&s.execute("text.create", &json!({"x": x, "y": y, "size": 12, "area": {"width": w, "height": h}, "text": text})).unwrap())
}
fn sel(s: &mut Session, ids: &[NodeId]) {
s.execute("select.set", &json!({"ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()})).unwrap();
}
fn text(s: &Session, id: NodeId) -> TextObject {
match &s.doc().unwrap().doc.node(id).unwrap().kind {
NodeKind::Text(t) => (**t).clone(),
k => panic!("not text: {k:?}"),
}
}
/// The frame's anchors in text space.
fn corners(s: &Session, id: NodeId) -> Vec<Point> {
match text(s, id).kind {
TextKind::Area { frame } => frame.anchors().map(|(_, _, a)| a.p).collect(),
k => panic!("not area type: {k:?}"),
}
}
fn frame(s: &Session, id: NodeId) -> Rect {
match text(s, id).kind {
TextKind::Area { frame } => frame.bounds().unwrap(),
k => panic!("not area type: {k:?}"),
}
}
fn layout(s: &Session, id: NodeId) -> TextLayout {
vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &text(s, id))
}
fn undo_len(s: &Session) -> usize {
s.doc().unwrap().history.undo.len()
}
fn last_step(s: &Session) -> String {
s.doc().unwrap().history.undo.last().unwrap().label.clone()
}
/// Press, drag and release `tool` from `from` to `to`.
fn drag(s: &mut Session, tool: &str, from: Point, to: Point) {
let v = ViewInfo::default();
s.select_tool(tool, v).unwrap();
for (kind, p) in [(PointerKind::Down, from), (PointerKind::Drag, to), (PointerKind::Up, to)] {
s.pointer(&PointerEvent::new(kind, p.x, p.y).with_mods(Mods::default()), v).unwrap();
}
assert!(!s.in_interaction());
}
fn near(a: Point, b: Point) -> bool {
a.distance(b) < 1e-6
}
#[test]
fn a_handle_drag_resizes_the_type_area_and_the_text_reflows() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
let before = layout(&s, id);
assert!(before.overflow, "the story overflows 120 × 40");
sel(&mut s, &[id]);
let n = undo_len(&s);
// The bounding box's bottom-right handle, from (160, 80) to (200, 140): 160 × 100.
drag(&mut s, "selection", Point::new(160.0, 80.0), Point::new(200.0, 140.0));
assert_eq!(undo_len(&s), n + 1, "one step");
assert_eq!(last_step(&s), "Resize Type Area");
let r = frame(&s, id);
assert!(near(r.origin(), Point::ZERO) && (r.width() - 160.0).abs() < 1e-6 && (r.height() - 100.0).abs() < 1e-6, "{r:?}");
let t = text(&s, id);
assert_eq!(t.xf, Affine::translate((40.0, 40.0)), "the type isn't scaled");
assert!(t.runs.iter().all(|r| r.style.size == 12.0));
let after = layout(&s, id);
assert!(after.lines.len() > before.lines.len(), "more lines fit: {} → {}", before.lines.len(), after.lines.len());
assert!(after.glyphs.len() > before.glyphs.len());
assert!(!after.overflow, "the whole story fits 160 × 100");
// The bounding box hugs the new frame.
assert_eq!(s.doc().unwrap().doc.node(id).unwrap().geometric_bounds(), Some(Rect::new(40.0, 40.0, 200.0, 140.0)));
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 120.0, 40.0));
assert!(layout(&s, id).overflow);
}
#[test]
fn point_type_still_scales_with_its_handles() {
let mut s = session();
let id = id_of(&s.execute("text.create", &json!({"x": 40, "y": 40, "size": 12, "text": "Hello"})).unwrap());
sel(&mut s, &[id]);
let b = s.transform_box(&s.doc().unwrap().selection.objects).unwrap();
let (tl, br) = (b.to_doc() * Handle::TopLeft.pos(b.rect), b.to_doc() * Handle::BottomRight.pos(b.rect));
drag(&mut s, "selection", br, tl + (br - tl) * 2.0);
assert_eq!(last_step(&s), "Scale");
let c = text(&s, id).xf.as_coeffs();
assert!((c[0] - 2.0).abs() < 1e-6 && (c[3] - 2.0).abs() < 1e-6, "the type doubles: {c:?}");
}
#[test]
fn with_other_objects_the_type_area_resizes_and_the_others_scale() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
let r = id_of(&s.execute("shape.rectangle", &json!({"x": 40, "y": 100, "width": 120, "height": 20})).unwrap());
sel(&mut s, &[id, r]);
// The box spans (40, 40)–(160, 120); its right handle doubles the width.
drag(&mut s, "selection", Point::new(160.0, 80.0), Point::new(280.0, 80.0));
assert_eq!(last_step(&s), "Scale");
assert_eq!(s.doc().unwrap().doc.node(r).unwrap().geometric_bounds(), Some(Rect::new(40.0, 100.0, 280.0, 120.0)));
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 240.0, 40.0));
assert_eq!(text(&s, id).xf, Affine::translate((40.0, 40.0)));
}
#[test]
fn a_rotated_type_area_resizes_along_its_own_axes() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
sel(&mut s, &[id]);
s.execute("object.rotate", &json!({"angle": 30, "absolute": true})).unwrap();
let xf = text(&s, id).xf;
let b = s.transform_box(&[id]).unwrap();
let right = b.to_doc() * Handle::Right.pos(b.rect);
let along = (b.to_doc() * Handle::Right.pos(b.rect)) - (b.to_doc() * Handle::Left.pos(b.rect));
drag(&mut s, "selection", right, right + along * 0.5);
assert_eq!(text(&s, id).xf, xf, "the type keeps its size and angle");
let r = frame(&s, id);
assert!((r.width() - 180.0).abs() < 1e-6 && (r.height() - 40.0).abs() < 1e-6, "still a rectangle, 180 × 40: {r:?}");
assert_eq!(corners(&s, id).len(), 4);
}
#[test]
fn direct_selection_drags_a_frame_corner_or_edge() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
let glyphs = layout(&s, id).glyphs.len();
let n = undo_len(&s);
// The bottom-right corner, not selected yet: the corner moves, the others stay.
drag(&mut s, "directSelection", Point::new(160.0, 80.0), Point::new(200.0, 140.0));
assert_eq!(s.doc().unwrap().selection.objects, vec![id]);
assert_eq!(undo_len(&s), n + 1, "one step");
assert_eq!(last_step(&s), "Reshape Type Area");
let c = corners(&s, id);
assert!(near(c[0], Point::ZERO) && near(c[1], Point::new(120.0, 0.0)) && near(c[3], Point::new(0.0, 40.0)), "{c:?}");
assert!(near(c[2], Point::new(160.0, 100.0)), "{c:?}");
assert!(layout(&s, id).glyphs.len() > glyphs, "more text fits the larger area");
assert_eq!(text(&s, id).xf, Affine::translate((40.0, 40.0)));
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 120.0, 40.0));
// The right edge: both its ends move, and the area stays a rectangle.
drag(&mut s, "directSelection", Point::new(160.0, 60.0), Point::new(180.0, 60.0));
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 140.0, 40.0));
assert_eq!(text(&s, id).runs[0].style.size, 12.0);
}
#[test]
fn a_resized_frame_reflows_its_thread() {
let mut s = session();
let a = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
let b = area(&mut s, 300.0, 40.0, 120.0, 200.0, "");
sel(&mut s, &[a, b]);
s.execute("text.thread.create", &json!({})).unwrap();
let rest = text(&s, b).plain_text().len();
assert!(rest > 0, "the overflow flows on");
// Bounding-box resize of the first frame to 160 × 100, as the Selection tool sends it.
let m = Affine::translate((40.0, 40.0)) * Affine::scale_non_uniform(160.0 / 120.0, 100.0 / 40.0) * Affine::translate((-40.0, -40.0));
let c = m.as_coeffs();
s.execute("object.transform", &json!({"ids": [a.0], "matrix": c, "typeAreas": true})).unwrap();
assert!(text(&s, b).plain_text().len() < rest, "the second frame holds less");
assert_eq!(text(&s, a).plain_text().len() + text(&s, b).plain_text().len(), STORY.len());
}
#[test]
fn area_type_options_size_the_type_area() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
sel(&mut s, &[id]);
let q = s.execute("text.areaOptions", &json!({})).unwrap();
assert_eq!((q["width"].as_f64(), q["height"].as_f64()), (Some(120.0), Some(40.0)));
let n = undo_len(&s);
let r = s.execute("text.areaOptions", &json!({"width": 160, "height": 100})).unwrap();
assert_eq!((r["width"].as_f64(), r["height"].as_f64()), (Some(160.0), Some(100.0)));
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 160.0, 100.0));
assert_eq!(text(&s, id).xf, Affine::translate((40.0, 40.0)));
assert!(!layout(&s, id).overflow);
// The dialog's OK sends the size back unchanged with the other options: only those change.
s.execute("text.areaOptions", &json!({"width": 160, "height": 100, "inset": 4})).unwrap();
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 160.0, 100.0));
assert_eq!(undo_len(&s), n + 2);
s.execute("edit.undo", &json!({})).unwrap();
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 120.0, 40.0));
// Type scaled 200%: sizes are in points on the page, along the type's axes.
s.execute("object.scale", &json!({"sx": 200, "origin": [40, 40]})).unwrap();
assert_eq!(s.execute("text.areaOptions", &json!({})).unwrap()["width"].as_f64(), Some(240.0));
s.execute("text.areaOptions", &json!({"width": 300})).unwrap();
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 150.0, 40.0));
}
#[test]
fn reshape_area_takes_untrusted_params() {
let mut s = session();
let id = area(&mut s, 40.0, 40.0, 120.0, 40.0, STORY);
let point = id_of(&s.execute("text.create", &json!({"x": 40, "y": 300, "text": "Point"})).unwrap());
let rect = id_of(&s.execute("shape.rectangle", &json!({"x": 300, "y": 300, "width": 50, "height": 50})).unwrap());
let n = undo_len(&s);
for bad in [
json!({}),
json!({"anchors": [[0, 2]], "dx": 1, "dy": 1}),
json!({"id": point.0, "anchors": [[0, 0]], "dx": 1, "dy": 1}),
json!({"id": rect.0, "anchors": [[0, 0]], "dx": 1, "dy": 1}),
json!({"id": 99_999, "anchors": [[0, 0]], "dx": 1, "dy": 1}),
json!({"id": id.0, "dx": 1, "dy": 1}),
json!({"id": id.0, "anchors": [], "dx": 1, "dy": 1}),
json!({"id": id.0, "anchors": [["a", 1], [0], "x"], "dx": 1, "dy": 1}),
json!({"id": id.0, "anchors": [[0, 9]], "dx": 1, "dy": 1}),
json!({"id": id.0, "anchors": [[0, 1], [7, 0]], "dx": 1, "dy": 1}),
json!({"id": id.0, "anchors": [[0, 2]], "dy": 1}),
json!({"id": id.0, "anchors": [[0, 2]], "dx": "far", "dy": 1}),
json!({"id": id.0, "anchors": [[0, 2]], "dx": 0, "dy": 1e300}),
json!({"id": id.0, "anchors": [[0, 2]], "dx": -1e7, "dy": 0}),
] {
assert!(s.execute("text.reshapeArea", &bad).is_err(), "{bad}");
}
assert_eq!(undo_len(&s), n, "nothing changed");
assert_eq!(frame(&s, id), Rect::new(0.0, 0.0, 120.0, 40.0));
// Listed twice, an anchor still moves once.
s.execute("text.reshapeArea", &json!({"id": id.0, "anchors": [[0, 2], [0, 2]], "dx": 10, "dy": 5})).unwrap();
assert_eq!(corners(&s, id)[2], Point::new(130.0, 45.0));
assert_eq!(last_step(&s), "Reshape Type Area");
// A frame collapsed to nothing lays out (everything overflows) without trouble.
for m in [[0.0, 0.0, 0.0, 1.0, 40.0, 0.0], [1.0, 0.0, 0.0, 0.0, 0.0, 40.0], [0.0; 6]] {
s.execute("object.transform", &json!({"ids": [id.0], "matrix": m, "typeAreas": true})).unwrap();
assert!(layout(&s, id).overflow);
s.execute("edit.undo", &json!({})).unwrap();
}
}
#[test]
fn reshape_area_is_a_registered_command() {
let spec = cmd::find_command("text.reshapeArea").unwrap();
assert_eq!(spec.label, "Reshape Type Area");
assert!(spec.params.contains("anchors") && spec.params.contains("dx"));
assert!(cmd::find_command("object.transform").unwrap().params.contains("typeAreas"));
assert!(session().commands().iter().any(|c| c.id == "text.reshapeArea" && c.enabled));
}

View File

@ -148,27 +148,6 @@ fn free_transform_distort_mode_via_pointer() {
assert_eq!(s.journal.last().map(|j| j.0.as_str()), Some("object.distort"));
}
#[test]
fn free_transform_cmd_held_once_a_corner_drag_started_distorts_in_one_step() {
let mut s = session();
let a = rect(&mut s, 100.0, 100.0, 100.0, 100.0);
let v = ViewInfo::default();
s.select_tool("freeTransform", v).unwrap();
let before = undo_len(&s);
let cmd = Mods { cmd: true, ..Default::default() };
s.pointer(&PointerEvent::new(PointerKind::Down, 200.0, 200.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 210.0, 210.0), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Drag, 250.0, 260.0).with_mods(cmd), v).unwrap();
s.pointer(&PointerEvent::new(PointerKind::Up, 250.0, 260.0).with_mods(cmd), v).unwrap();
let d = &s.doc().unwrap().doc;
let pts: Vec<Point> = d.node(a).unwrap().path_data().unwrap().anchors().map(|(_, _, an)| an.p).collect();
for p in [Point::new(250.0, 260.0), Point::new(100.0, 100.0), Point::new(200.0, 100.0), Point::new(100.0, 200.0)] {
assert!(pts.iter().any(|q| q.distance(p) < 1e-6), "{p:?} not in {pts:?}");
}
assert_eq!(undo_len(&s), before + 1);
assert_eq!(s.doc().unwrap().history.undo.last().map(|e| e.label.as_str()), Some("Distort"));
}
#[test]
fn free_transform_side_handle_scales() {
let mut s = session();

View File

@ -284,36 +284,6 @@ fn headless_path_gesture_undo() {
assert_eq!(&std::fs::read(tmp("x.png")).unwrap()[..4], b"\x89PNG");
}
/// inspect_document reads back the paint type's characters show, as add_text and set_paint give it.
#[test]
fn inspect_document_reports_the_paint_of_type() {
let mut s = server();
let r = call(&mut s, 2, "add_text", json!({"text": "HI", "x": 50, "y": 60, "size": 24, "color": "#ff0000"}));
assert_eq!(r["isError"], false, "{r}");
let id = serde_json::from_str::<Value>(&text_of(&r)).unwrap()["id"].clone();
let node = |s: &mut Server, n: u64| {
let v: Value = serde_json::from_str(&text_of(&call(s, n, "inspect_document", json!({})))).unwrap();
v["layers"][0]["children"].as_array().unwrap().iter().find(|c| c["id"] == id).cloned().unwrap()
};
let t = node(&mut s, 3);
assert_eq!((t["fill"].as_str(), t["stroke"].as_str()), (Some("#ff0000"), Some("None")), "{t}");
let r = call(&mut s, 4, "set_paint", json!({"fill": "#0000ff", "stroke": "#00ff00", "strokeWidth": 3, "ids": [id]}));
assert_eq!(r["isError"], false, "{r}");
let t = node(&mut s, 5);
assert_eq!((t["fill"].as_str(), t["stroke"].as_str(), t["strokeWidth"].as_f64()), (Some("#0000ff"), Some("#00ff00"), Some(3.0)), "{t}");
}
/// save_file says it saves in the document's own format or the one the path's extension picks.
#[test]
fn save_file_describes_the_formats_it_writes() {
let tools = tool_definitions();
let d = tools.iter().find(|t| t["name"] == "save_file").and_then(|t| t["description"].as_str()).unwrap();
for ext in [".vectorcraft", ".vctemplate", ".pdf", ".svg", ".svgz", ".ai"] {
assert!(d.contains(ext), "{ext}: {d}");
}
assert!(d.contains("its own format"), "{d}");
}
#[test]
fn errors_are_tool_results_not_crashes() {
let mut s = server();

View File

@ -2,7 +2,7 @@
//! [`Backend`].
use serde_json::{Map, Value, json};
use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, OPEN_EXTS, SAVE_FORMATS, format};
use vectorcraft_engine::cmd::fileio::{ARTBOARD_PARAMS, FORMATS, OPEN_EXTS};
use crate::backend::Backend;
@ -57,12 +57,6 @@ fn obj(props: Value, required: &[&str]) -> Value {
}
o
}
/// The extension of each format Save writes, in [`SAVE_FORMATS`] order.
fn save_extensions() -> Vec<&'static str> {
SAVE_FORMATS.iter().filter_map(|id| format(id)?.extensions.first().copied()).collect()
}
fn tool(name: &str, title: &str, desc: &str, schema: Value, read_only: bool) -> Value {
json!({
"name": name,
@ -265,17 +259,14 @@ pub fn tool_definitions() -> Vec<Value> {
tool(
"save_file",
"Save file",
&format!(
"Save the active document with the engine's document.save: by default to its own file in its own format (native .vectorcraft unless it was opened from or saved as SVG, PDF or a restorable .ai). With `path`, the extension picks the format: .{}. Other formats are exports (see export). The reply's `format` says what was written and `warnings` what that format loses.",
save_extensions().join(", .")
),
obj(json!({"path": string("Destination; its extension picks the format (default: the document's own file)")}), &[]),
"Save the active document in the native .vectorcraft format.",
obj(json!({"path": string("Destination (default: the document's current path)")}), &[]),
false,
),
tool(
"export",
"Export",
"Export the active document with the engine's document.export (the same bytes in the app and headless), in any format of the `format` enum: vectors (svg/svgz with the artboard as viewBox, eps, dxf, emf, wmf), pdf (one page per artboard: all, or `artboard` / `range`), rasters (one rendered artboard: png, jpg, webp, gif, png8 as an indexed .png, tiff, bmp, tga, psd with its layers), txt (the stories, back to front), vectorcraft or template (a native copy or template; the document keeps its path). run_command document.formats lists each format's options. `selection: true` exports only the selected objects, cropped to their bounds. Template layers are left out; live effects are kept (geometry baked, SVG filters for shadows/glows/blur). Without `path` the bytes come back as dataBase64.",
"Export the active document with the engine's document.export (the same bytes in the app and headless): svg (artboard viewBox), pdf (one page per artboard: all, or `artboard` / `range`), png/jpg/webp/gif/png8/tiff/bmp/tga/psd (one rendered artboard; png8 is an indexed .png; psd keeps the layers), txt (the stories, back to front) or vectorcraft (a native copy; the document keeps its path). `selection: true` exports only the selected objects, cropped to their bounds. Template layers are left out; live effects are kept (geometry baked, SVG filters for shadows/glows/blur). Without `path` the bytes come back as dataBase64.",
obj(
json!({
"format": {"type": "string", "enum": FORMATS.iter().filter(|f| f.write).map(|f| f.id).collect::<Vec<_>>(), "description": "Default: from the path's extension"},

View File

@ -111,16 +111,7 @@ pub fn import_with_report(bytes: &[u8], opts: &ImportOptions) -> Result<ImportRe
let scan = scan_page(page, &mut ocgs, all_on, &mut b.fonts);
b.begin_page(scan);
interpret_page(page, &mut ctx, &mut b);
let mut parts = b.end_page();
// A file with several artboards writes, on each page, the art of its neighbours that
// reaches into the page's box: art lying wholly outside this page is theirs (each page
// draws it shifted by its own artboard spacing), so keep it only where it belongs.
if picked.len() > 1 {
for (_, art) in &mut parts {
art.retain(|n| n.visual_bounds().is_none_or(|r| r.x0 <= ab.x1 && r.x1 >= ab.x0 && r.y0 <= ab.y1 && r.y1 >= ab.y0));
}
parts.retain(|(_, art)| !art.is_empty());
}
let parts = b.end_page();
let children: Vec<Arc<Node>> = parts.iter().flat_map(|(_, v)| v.iter().cloned()).collect();
placeholder &= crate::pages::has_private_data(page) && only_text(&children);
let mut right = ab.x1;

View File

@ -3,15 +3,12 @@
//! fifth of the size reads as a space). Fonts are named from the file's base font name (its
//! subset prefix dropped, the family matched against the fonts available); a font that isn't
//! available keeps its name, and the text shows in the fallback font until it is.
//!
//! Glyphs each turned a little further along a curve (type set on a path: apps write each glyph
//! with its own placement) make one type-on-a-path object, its path through the glyphs' baseline.
use std::collections::HashMap;
use kurbo::{Affine, BezPath, Point, Vec2};
use kurbo::{Affine, Point, Vec2};
use vectorcraft_color::Paint;
use vectorcraft_doc::{CharStyle, TextKind, TextObject, TextRun};
use vectorcraft_doc::{CharStyle, TextObject, TextRun};
/// One glyph's placement: its baseline origin, advance direction, size and horizontal scale.
#[derive(Clone, Copy, Debug)]
@ -96,19 +93,12 @@ pub(crate) struct TextLine {
next: Point,
/// The last glyph's origin.
last: Point,
/// The last glyph's baseline direction.
last_dir: Vec2,
/// Each glyph's baseline origin, then where the last one ends.
baseline: Vec<Point>,
runs: Vec<(Look, String)>,
}
/// The most a glyph on a curve turns from the one before it (about 20°).
const CURVE_TURN_COS: f64 = 0.94;
impl TextLine {
pub fn new(at: Placement, opacity: f32) -> Self {
Self { at, opacity, next: at.origin, last: at.origin, last_dir: at.dir, baseline: vec![], runs: vec![] }
Self { at, opacity, next: at.origin, last: at.origin, runs: vec![] }
}
/// Add glyph `text` drawn with `look` at `at` (advancing `advance` points) at `opacity` if
@ -116,20 +106,13 @@ impl TextLine {
pub fn push(&mut self, look: &Look, at: Placement, opacity: f32, advance: f64, text: &str) -> bool {
if let Some((last, run)) = self.runs.last_mut() {
let size = self.at.size.max(at.size);
let gap = (at.origin - self.next).dot(self.last_dir);
let gap = (at.origin - self.next).dot(self.at.dir);
let on_line = opacity == self.opacity
&& at.dir.dot(self.at.dir) > 0.9995
&& (at.origin - self.at.origin).dot(self.at.up()).abs() < size * 0.15
&& gap > -size * 0.3
&& gap < size * 3.0;
// Or on a curve: turned a little from the glyph before it, and starting about where
// that one ends.
let on_curve = !on_line
&& opacity == self.opacity
&& at.dir.dot(self.last_dir) > CURVE_TURN_COS
&& at.dir.dot(self.last_dir) < 0.99999
&& (at.origin - self.next).hypot() < size * 0.6;
if !on_line && !on_curve {
if !on_line {
return false;
}
// A gap wider than a fifth of an em reads as a space.
@ -144,42 +127,11 @@ impl TextLine {
} else {
self.runs.push((look.clone(), text.to_string()));
}
self.next = at.origin + at.dir * advance;
self.next = at.origin + self.at.dir * advance;
self.last = at.origin;
self.last_dir = at.dir;
self.baseline.push(at.origin);
true
}
/// Has the baseline turned (more than about 3° from the first glyph to the last)?
fn curved(&self) -> bool {
self.last_dir.dot(self.at.dir) < 0.9986
}
/// A smooth path through the glyphs' baseline origins and the end of the last glyph, an em
/// further (Catmull-Rom through the points, as cubic Béziers).
fn baseline_path(&self) -> Option<BezPath> {
let mut pts = self.baseline.clone();
// On past the end of the last glyph by an em, so rounding in the spacing doesn't push it
// off the end of the path (where type on a path stops).
pts.push(self.next);
pts.push(self.next + self.last_dir * self.at.size);
let first = *pts.first()?;
// Finite placements far out can still overflow once an em is added: no path then.
if pts.len() < 3 || !pts.iter().all(|p| p.is_finite()) {
return None;
}
let mut bp = BezPath::new();
bp.move_to(first);
for (i, seg) in pts.windows(2).enumerate() {
let &[p1, p2] = seg else { continue };
let p0 = *pts.get(i.wrapping_sub(1)).unwrap_or(&p1);
let p3 = *pts.get(i + 2).unwrap_or(&p2);
bp.curve_to(p1 + (p2 - p0) / 6.0, p2 - (p3 - p1) / 6.0, p2);
}
Some(bp)
}
/// A stroke (`stroke`: paint and width) over the glyph just drawn at `at` in `font` (fill
/// and stroke rendering): the run is stroked. `false`: it isn't that glyph.
pub fn stroke_last(&mut self, font: u128, at: Placement, stroke: (Paint, f64)) -> bool {
@ -192,8 +144,6 @@ impl TextLine {
/// The point type object and its opacity.
pub fn finish(mut self) -> Option<(TextObject, f32)> {
// Turned along a curve: type on a path through the glyphs.
let path = if self.curved() { self.baseline_path() } else { None };
if let Some((_, last)) = self.runs.last_mut() {
last.truncate(last.trim_end().len());
}
@ -206,10 +156,6 @@ impl TextLine {
let mut t = TextObject::point(Point::ORIGIN, &first.text, first.style);
t.runs.extend(runs);
t.xf = Affine::translate(self.at.origin.to_vec2()) * Affine::rotate(self.at.dir.atan2());
if let Some(path) = path {
t.kind = TextKind::OnPath { path: vectorcraft_geom::PathData::from_bezpath(&path), start: 0.0 };
t.xf = Affine::IDENTITY;
}
Some((t, self.opacity))
}
}

View File

@ -359,34 +359,3 @@ fn appearance_items_are_untouched_for_plain_art() {
assert!(nodes.iter().all(|n| n.mask.is_none() && !matches!(n.kind, NodeKind::Group { .. })));
assert!(matches!(nodes.iter().find(|n| n.appearance.stroke().is_some()).unwrap().appearance.items[0], AppearanceItem::Stroke(_)));
}
/// Type set on a path (each glyph placed and turned along a curve, as apps write it) comes back
/// as type on a path through the glyphs, not as a straight line; straight type stays point type.
#[test]
fn glyphs_turned_along_a_curve_become_type_on_a_path() {
// "ARCHING" along an arc of radius 100 around (150, 0), each glyph where the one before
// it ends (Helvetica's advances), clockwise from 135° (PDF y up: the arc bulges upwards).
let mut content = String::from("BT /F1 18 Tf ");
let mut a = 135f64.to_radians();
for (c, adv) in "ARCHING".chars().zip([667.0, 722.0, 722.0, 722.0, 278.0, 722.0, 778.0]) {
let (x, y) = (150.0 + 100.0 * a.cos(), 100.0 * a.sin());
// The baseline's direction is the tangent, clockwise along the arc.
let (dx, dy) = (a.sin(), -a.cos());
content.push_str(&format!("{dx:.5} {dy:.5} {:.5} {dx:.5} {x:.3} {y:.3} Tm ({c}) Tj ", -dy));
a -= adv / 1000.0 * 18.0 / 100.0;
}
content.push_str("ET");
let t = texts(&open(&one_page(&content, HELVETICA, &[])));
assert_eq!(t.len(), 1, "one text object: {t:?}");
let text: String = t[0].runs.iter().map(|r| r.text.as_str()).collect();
assert_eq!(text, "ARCHING");
let vectorcraft_doc::TextKind::OnPath { path, .. } = &t[0].kind else { panic!("type on a path: {:?}", t[0].kind) };
let b = path.bounds().unwrap();
assert!(b.height() > 15.0, "the path curves: {b:?}");
// Every glyph fits on the path, the last one too.
assert_eq!(vectorcraft_text::layout(vectorcraft_text::FontDb::global(), &t[0]).glyphs.len(), 7);
// Straight type with a slight rotation stays one point type object.
let straight = texts(&open(&one_page("BT /F1 18 Tf 0.98481 0.17365 -0.17365 0.98481 20 40 Tm (Straight) Tj ET", HELVETICA, &[])));
assert_eq!(straight.len(), 1);
assert!(matches!(straight[0].kind, vectorcraft_doc::TextKind::Point), "{:?}", straight[0].kind);
}

View File

@ -106,19 +106,6 @@ fn bounding_boxes_of_several_pages_do_not_overlap() {
assert!(b.x0 >= a.x1 + 36.0, "{a:?} {b:?}");
}
#[test]
fn art_of_neighbouring_artboards_off_a_page_is_left_to_its_own_page() {
// Page 2 also draws page 1's square, off to its left (outside its box), as files with several
// artboards are written: only page 1 keeps it, so it doesn't come back twice.
let pages = [PdfPage::new(100.0, 100.0, "0 g 10 10 20 20 re f"), PdfPage::new(100.0, 100.0, "0 g -90 10 20 20 re f 1 0 0 rg 50 10 20 20 re f")];
let d = open(&pdf(&pages, None), ImportOptions::default());
let count = |i: usize| d.layers[i].children().map_or(0, |c| c.len());
assert_eq!((count(0), count(1)), (1, 1));
// A single page keeps its art off the page (the pasteboard).
let d = open(&pdf(&pages[1..], None), ImportOptions::default());
assert_eq!(d.layers[0].children().map_or(0, |c| c.len()), 2);
}
#[test]
fn an_encrypted_pdf_opens_with_its_password_only() {
let bytes = pdf(&[PdfPage::new(200.0, 100.0, "1 0 0 rg 10 10 50 50 re f")], Some("secret"));

View File

@ -5,18 +5,7 @@
//! hyphenation points. The breaks minimise the sum of squared (badness + penalty) demerits over
//! the whole paragraph, so loose lines are traded for evenly spaced ones.
use crate::shape::{SGlyph, can_break_between, is_cjk};
/// Whether justification may widen the gap between `g[i]` and `g[i + 1]`: a word space, or a CJK
/// character boundary (Chinese has no spaces, so 两端对齐 stretches the character gaps). Forbidden
/// line starts and ends are left alone so punctuation keeps its 标点挤压 spacing.
pub(crate) fn stretchable_gap(g: &[SGlyph], i: usize) -> bool {
if g[i].is_space() {
return true;
}
let Some(next) = g.get(i + 1) else { return false };
!next.is_space() && !next.continues_tcy() && (is_cjk(g[i].ch) || is_cjk(next.ch)) && can_break_between(g[i].ch, Some(next.ch))
}
use crate::shape::SGlyph;
const STRETCH: f64 = 0.5;
const SHRINK: f64 = 0.2;
@ -71,12 +60,6 @@ pub(crate) fn compose(
};
let mut all: Vec<Breakpoint> = cands.iter().copied().filter(|c| c.end > 0 && c.end < n).collect();
all.push(Breakpoint { end: n, hyphen: 0.0 });
// Prefix sums of the gaps that justification may stretch. Between words that is the space;
// between CJK characters, which have no space to stretch, it is the gap itself (两端对齐).
let mut gap = vec![0.0; n + 1];
for i in 0..n {
gap[i + 1] = gap[i] + if !g[i].is_space() && stretchable_gap(g, i) { g[i].adv * 0.5 } else { 0.0 };
}
let mut nodes = vec![Node { pos: 0, line: 0, demerits: 0.0, hyphenated: false, prev: None }];
let mut active: Vec<usize> = vec![0];
for bp in &all {
@ -88,14 +71,12 @@ pub(crate) fn compose(
let t = trim(bp.end, a.pos);
let natural = w[t] - w[a.pos] + bp.hyphen;
let spaces = sp[t] - sp[a.pos];
// A CJK line with no spaces stretches its character gaps instead.
let stretch = if spaces > 0.0 { spaces } else { gap[t] - gap[a.pos] };
let lw = width(a.line);
let ratio = if natural < lw {
if last && !justify_last {
0.0
} else if stretch > 0.0 {
(lw - natural) / (stretch * STRETCH)
} else if spaces > 0.0 {
(lw - natural) / (spaces * STRETCH)
} else {
f64::INFINITY
}

View File

@ -932,21 +932,6 @@ impl FontDb {
self.fallback_for(c, 0)
}
/// UI fallback at the requested weight; keep the official family preference and loader.
pub fn face_covering_weighted(&self, c: char, weight: f32) -> Option<Arc<FontFace>> {
self.fallback_for_weighted(c, 0, weight)
}
pub(crate) fn fallback_for_weighted(&self, c: char, exclude: u32, weight: f32) -> Option<Arc<FontFace>> {
let fallback = self.fallback_for(c, exclude)?;
self.read_faces()
.iter()
.filter(|face| face.id() != exclude && face.family == fallback.family && face.covers(c))
.min_by_key(|face| (face.italic, (face.weight - weight).abs() as i32))
.cloned()
.or(Some(fallback))
}
fn loaded_fallback(&self, c: char, exclude: u32) -> Option<Arc<FontFace>> {
let faces = self.read_faces();
let mut order: Vec<&Arc<FontFace>> = faces.iter().filter(|f| f.id != exclude).collect();

View File

@ -5,7 +5,7 @@ use std::ops::Range;
use kurbo::{Affine, BezPath, ParamCurve, ParamCurveArclen, PathEl, PathSeg, Point, Rect, Shape, Vec2};
use vectorcraft_doc::{CharStyle, Justify, ParaStyle, PathEffect, TextKind, TextObject};
use crate::composer::{Breakpoint, compose, stretchable_gap};
use crate::composer::{Breakpoint, compose};
use crate::fontdb::FontDb;
use crate::hyphen::hyphen_points;
use crate::shape::{SGlyph, Tcy, cap_x_heights, hyphen_glyph, no_line_end, no_line_start, shape_range, style_metrics};
@ -40,10 +40,13 @@ impl Ctx<'_> {
tate_chu_yoko(&mut v, |g| self.style_at(g.byte).size);
// An upright glyph advances at least one em down the column (the vertical advance of
// CJK fonts), centred in it: a narrow mark like § must not overlap its neighbours.
for g in v.iter_mut().filter(|g| g.adv > 0.0 && stands_upright(g)) {
let extra = upright_cell(g) - g.face.advance(g.gid) * g.sx;
g.dx += extra * 0.5;
g.adv += extra;
for g in v.iter_mut().filter(|g| stands_upright(g)) {
let natural = g.face.advance(g.gid) * g.sx;
let em = g.face.units_per_em() * g.sx;
if natural < em && g.adv > 0.0 {
g.dx += (em - natural) * 0.5;
g.adv += em - natural;
}
}
}
v
@ -65,12 +68,9 @@ impl Ctx<'_> {
let squeeze = Affine::translate((centre.x, 0.0)) * Affine::scale_non_uniform(t.squeeze, 1.0) * Affine::translate((-centre.x, 0.0));
m = Affine::rotate_about(-std::f64::consts::FRAC_PI_2, centre) * squeeze * across * m;
} else if self.vertical && stands_upright(g) {
// Turned about the centre of its em box, which the column's centre line runs through:
// the middle of its own cell, not of its advance (tracking and justification add space
// after the cell, and must not push the glyph off the centre line).
// Turned about the centre of its em box, which the column's centre line runs through.
let em = self.style_at(g.byte).size;
let cell = if g.adv > 0.0 { upright_cell(g) } else { advance };
m = Affine::rotate_about(-std::f64::consts::FRAC_PI_2, Point::new(origin.x + cell * 0.5, origin.y - EM_CENTER * em)) * m;
m = Affine::rotate_about(-std::f64::consts::FRAC_PI_2, Point::new(origin.x + advance * 0.5, origin.y - EM_CENTER * em)) * m;
}
// Control characters (tabs) and soft hyphens draw nothing (fonts map them to .notdef).
let outline = if src.elements().is_empty() || g.is_soft_hyphen() || g.ch.is_control() {
@ -214,12 +214,6 @@ fn tate_chu_yoko(g: &mut [SGlyph], size: impl Fn(&SGlyph) -> f64) {
}
}
/// The length an upright glyph takes down the column before tracking and justification: its
/// advance, at least one em.
fn upright_cell(g: &SGlyph) -> f64 {
(g.face.advance(g.gid) * g.sx).max(g.face.units_per_em() * g.sx)
}
/// Height of the centre of the ideographic em box above the baseline, in ems (the em box runs
/// from 0.12 em below the baseline to 0.88 em above it).
const EM_CENTER: f64 = 0.38;
@ -638,20 +632,6 @@ fn break_line(text: &str, g: &[SGlyph], i: usize, width: f64, hyphenate: bool) -
while end > i + 1 && end < g.len() && g[end].byte == g[end - 1].byte {
end -= 1;
}
if !hy {
// Keep punctuation and shaped clusters together even on an emergency overset line.
let allowed = |end: usize| end == g.len() || (g[end].byte != g[end - 1].byte && kinsoku_allows(g, end - 1));
let fitted = end;
while end > i && !allowed(end) {
end -= 1;
}
if end == i {
end = fitted.max(i + 1);
while end < g.len() && !allowed(end) {
end += 1;
}
}
}
(end, hy)
}
@ -842,27 +822,15 @@ fn flow(cx: &mut Ctx<'_>, paras: &[Range<usize>], para: &ParaStyle, regions: Opt
Justify::JustifyAll => (0, true),
};
let justify = justify && regions.is_some();
let (mut per_space, mut per_gap_base) = (0.0, 0.0);
let (mut per_space, mut per_gap) = (0.0, 0.0);
let spaces = sg[i..trimmed].iter().filter(|g| g.is_space()).count();
let vertical = cx.vertical;
let can_stretch = |j: usize| {
sg.get(j + 1).is_some_and(|next| !next.continues_tcy())
&& (vertical || para.justify == Justify::JustifyAll || stretchable_gap(&sg, j))
};
let gaps = (i..trimmed.saturating_sub(1)).filter(|&j| can_stretch(j)).count();
let gap_em = sg.get(i).map_or(0.0, |g| g.adv);
if justify && (width - w).abs() > EPS {
if spaces > 0 {
// Composed lines may shrink word spaces (never below zero).
per_space =
((width - w) / spaces as f64).max(-sg[i..trimmed].iter().filter(|g| g.is_space()).map(|g| g.adv).fold(f64::MAX, f64::min));
} else if gaps > 0 && width > w && (!cx.vertical || para.justify == Justify::JustifyAll) {
// 两端对齐 for scripts without spaces: widen the CJK character gaps. Half an em
// per gap is the most Chinese composition allows before the line looks tracked
// out, so a line that cannot reach the edge is left ragged. Justify All is the
// exception: there every line must reach the edge, so the gaps take the slack.
let per = (width - w) / gaps as f64;
per_gap_base = if para.justify == Justify::JustifyAll { per } else { per.min(gap_em * 0.5) };
} else if para.justify == Justify::JustifyAll && trimmed - i > 1 && width > w {
per_gap = (width - w) / (trimmed - i - 1) as f64;
}
}
let start_x = if justify {
@ -893,8 +861,8 @@ fn flow(cx: &mut Ctx<'_>, paras: &[Range<usize>], para: &ParaStyle, regions: Opt
} else if j < trimmed {
if g.is_space() {
adv += per_space;
} else if j + 1 < trimmed && can_stretch(j) {
adv += per_gap_base;
} else if j + 1 < trimmed {
adv += per_gap;
}
}
cx.emit(g, Affine::translate((x, baseline)), Point::new(x, baseline), 0.0, adv, li);

View File

@ -375,8 +375,6 @@ pub fn selection_quads(layout: &TextLayout, a: usize, b: usize) -> Vec<[Point; 4
#[cfg(test)]
mod tests;
#[cfg(test)]
mod tests_cjk;
#[cfg(test)]
mod tests_embed;
#[cfg(test)]
mod tests_scripts;

View File

@ -74,10 +74,6 @@ impl SGlyph {
pub fn is_letter(&self) -> bool {
self.ch.is_alphabetic() || matches!(self.ch, '\'' | '’')
}
/// Vertical type: a tate-chu-yoko glyph after its block's first, sharing that glyph's cell.
pub fn continues_tcy(&self) -> bool {
self.tcy.is_some_and(|t| t.pen > 0.0)
}
}
pub(crate) const SOFT_HYPHEN: char = '\u{00AD}';
@ -107,8 +103,7 @@ pub(crate) fn no_line_start(c: char) -> bool {
| 'ー' | 'ゝ' | 'ゞ' | 'ヽ' | 'ヾ' | '々' | '〻'
| 'ぁ' | 'ぃ' | 'ぅ' | 'ぇ' | 'ぉ' | 'っ' | 'ゃ' | 'ゅ' | 'ょ' | 'ゎ' | 'ゕ' | 'ゖ'
| 'ァ' | 'ィ' | 'ゥ' | 'ェ' | 'ォ' | 'ッ' | 'ャ' | 'ュ' | 'ョ' | 'ヮ' | 'ヵ' | 'ヶ' | 'ㇰ'..='ㇿ'
| '!' | ')' | ',' | '.' | ':' | ';' | '?' | ']' | '}' | '~' | '。' | '」' | '、' | '・' | 'ー' | 'ァ'..='ッ'
| '…' | '‥' | '—' | '%' | '%')
| '!' | ')' | ',' | '.' | ':' | ';' | '?' | ']' | '}' | '~' | '。' | '」' | '、' | '・' | 'ー' | 'ァ'..='ッ')
}
/// Kinsoku: a character that can't end a line (opening brackets).
@ -138,60 +133,10 @@ pub(crate) fn no_line_end(c: char) -> bool {
)
}
pub(crate) fn is_cjk(c: char) -> bool {
fn is_cjk(c: char) -> bool {
matches!(c as u32, 0x2E80..=0x9FFF | 0xAC00..=0xD7AF | 0xF900..=0xFAFF | 0xFF00..=0xFFEF | 0x20000..=0x2FFFF)
}
pub(crate) fn can_break_between(left: char, right: Option<char>) -> bool {
if left == SOFT_HYPHEN {
return true;
}
let Some(right) = right else { return true };
!no_line_end(left) && !no_line_start(right)
}
/// Half-width, in em, trimmed from each side of full-width punctuation (标点挤压).
///
/// Chinese composition trims an opening bracket on the left and a closing bracket on the right
/// by up to half an em; comma/full-stop forms lose the blank on the right. Proportional Latin
/// curly quotes keep their font's spacing. Actual side bearings limit the trim below.
/// The trim is applied to the glyph's offset and advance, so line breaking and justification see
/// the composed width.
pub(crate) fn cjk_punctuation_trim(c: char) -> (f64, f64) {
let (l, r) = cjk_punctuation_trim_impl(c);
(l, r)
}
fn cjk_punctuation_trim_impl(c: char) -> (f64, f64) {
// Tight punctuation: a comma or full stop hugs the character before it and takes half an em.
if matches!(c, '\u{3001}' | '\u{3002}' | '\u{FF0C}' | '\u{FF0E}' | '\u{FF1A}' | '\u{FF1B}' | '\u{FF01}' | '\u{FF1F}' | '\u{FF61}' | '\u{FF64}')
|| matches!(c, '\u{FE10}'..='\u{FE13}')
{
return (0.0, 0.5);
}
// Closing forms carry the blank half on the right.
if matches!(c, '\u{3009}' | '\u{300B}' | '\u{300D}' | '\u{300F}' | '\u{3011}' | '\u{3015}' | '\u{3017}' | '\u{3019}' | '\u{301B}')
|| matches!(c, '\u{FE18}')
|| matches!(c, '\u{FF09}' | '\u{FF3D}' | '\u{FF5D}' | '\u{FF60}' | '\u{FF63}')
|| matches!(c, '\u{301E}' | '\u{301F}')
{
return (0.0, 0.5);
}
// Opening forms carry the blank half on the left.
if matches!(c, '\u{3008}' | '\u{300A}' | '\u{300C}' | '\u{300E}' | '\u{3010}' | '\u{3014}' | '\u{3016}' | '\u{3018}' | '\u{301A}')
|| matches!(
c,
'\u{FE17}' | '\u{FE35}' | '\u{FE37}' | '\u{FE39}' | '\u{FE3B}' | '\u{FE3D}' | '\u{FE3F}' | '\u{FE41}' | '\u{FE43}' | '\u{FE47}'
)
|| matches!(c, '\u{FF08}' | '\u{FF3B}' | '\u{FF5B}' | '\u{FF5F}' | '\u{FF62}')
|| matches!(c, '\u{301D}')
{
return (0.5, 0.0);
}
// The interpunct and the ellipsis keep their full width but centre in it.
(0.0, 0.0)
}
/// Vertical metrics (points) of a style's resolved face: (ascent, descent, leading).
pub(crate) fn style_metrics(db: &FontDb, st: &CharStyle) -> (f64, f64, f64) {
let vs = st.v_scale / 100.0;
@ -238,8 +183,7 @@ pub(crate) fn shape_range(
} else if let Some((_, f)) = cache.iter().find(|(k, _)| *k == c) {
f.clone()
} else {
// Ask for the run's own weight, so a bold Chinese run gets a bold CJK face.
let f = db.fallback_for_weighted(c, primary.id(), crate::fontdb::style_weight(&st.font_style)).unwrap_or_else(|| primary.clone());
let f = db.fallback_for(c, primary.id()).unwrap_or_else(|| primary.clone());
cache.push((c, f.clone()));
f
};
@ -348,26 +292,6 @@ fn shape_segment(text: &str, seg: &Segment, feats: &OtFeatures, out: &mut Vec<SG
} else if last_in_cluster {
adv += tracking + manual_kern;
}
// 标点挤压, once per cluster: trim the outer blank of brackets and the right blank of
// comma/full-stop forms. Never take more than half the original cell or touch the ink.
let (tl, tr) = if last_in_cluster && !feats.vertical { cjk_punctuation_trim(ch) } else { (0.0, 0.0) };
let (mut tl, mut tr) = (tl * size * hs, tr * size * hs);
// Trim only actual side bearings: a font may already use narrow or centred forms.
if (tl > 0.0 || tr > 0.0)
&& let Some(bounds) =
face.skrifa().and_then(|f| f.glyph_metrics(Size::unscaled(), LocationRef::default()).bounds(skrifa::GlyphId::new(gid)))
{
tl = tl.min(((bounds.x_min as f64 + xo as f64) * k * hs).max(0.0));
tr = tr.min(((xa as f64 - bounds.x_max as f64 - xo as f64) * k * hs).max(0.0));
}
let room = adv.max(0.0) * 0.5;
let spend = tl + tr;
if spend > room && spend > 0.0 {
let scale = room / spend;
tl *= scale;
tr *= scale;
}
adv -= tl + tr;
out.push(SGlyph {
face: face.clone(),
gid,
@ -375,7 +299,7 @@ fn shape_segment(text: &str, seg: &Segment, feats: &OtFeatures, out: &mut Vec<SG
len: end.saturating_sub(cl).max(1),
run,
adv,
dx: xo as f64 * k * hs - tl,
dx: xo as f64 * k * hs,
dy: -(yo as f64) * k * vs,
sx: k * hs,
sy: k * vs,

View File

@ -1,204 +0,0 @@
//! Chinese composition (中文排版): 避头尾 line breaking, 标点挤压 and 两端对齐.
//!
//! Regression coverage for shared CJK punctuation break restrictions, side-bearing-limited
//! punctuation compression, and horizontal inter-character justification. This is an initial
//! composition implementation, not a claim of full typesetting-standard conformance.
use super::*;
use crate::shape::can_break_between;
use kurbo::{Affine, Shape};
use vectorcraft_doc::{CharStyle, Justify, TextKind};
use vectorcraft_geom::PathData;
/// Deterministic on native and web, without installed system fonts.
fn db() -> &'static FontDb {
static DB: std::sync::OnceLock<FontDb> = std::sync::OnceLock::new();
DB.get_or_init(|| FontDb::with_font_dirs(Vec::new()))
}
fn has_chinese_font() -> bool {
let available = db().face("Noto Sans CJK SC", "Regular").is_some_and(|face| face.glyph_for('中') != 0);
if !available {
eprintln!("skipped: Chinese glyph metrics require the optional craft-fonts input");
}
available
}
fn style(size: f64) -> CharStyle {
CharStyle { size, font_family: "Noto Sans CJK SC".into(), ..CharStyle::default() }
}
fn cjk_area(text: &str, frame: Rect, justify: Justify) -> TextObject {
let mut t = TextObject::point(Point::ZERO, text, style(12.0));
t.kind = TextKind::Area { frame: PathData::from_bezpath(&frame.to_path(0.1)) };
t.xf = Affine::IDENTITY;
t.para.justify = justify;
t
}
/// The advance the face gives `c` before any 标点挤压.
fn raw_advance(family: &str, c: char, size: f64) -> f64 {
use skrifa::MetadataProvider;
use skrifa::instance::{LocationRef, Size};
let f = db().face(family, "Regular").expect("face");
let gid = f.glyph_for(c);
assert_ne!(gid, 0, "{family} {c}: missing glyph");
let sk = f.skrifa().expect("skrifa");
let m = sk.glyph_metrics(Size::unscaled(), LocationRef::default()).advance_width(skrifa::GlyphId::new(gid));
f64::from(m.unwrap_or(0.0)) / f.units_per_em() * size
}
/// The advance the layout gives a one-character text object of `c`.
fn laid_advance(family: &str, c: char, size: f64) -> f64 {
let st = CharStyle { font_family: family.into(), size, ..CharStyle::default() };
layout(db(), &TextObject::point(Point::ZERO, c.to_string().as_str(), st)).glyphs.first().expect("glyph").advance
}
#[test]
fn kinsoku_keeps_punctuation_with_its_text() {
// Closing punctuation and closing brackets may not begin a line.
for &c in &[',', '。', '、', ';', ':', '!', '?', ')', '】', '》', '」', '”', '’', '…'] {
assert!(!can_break_between('字', Some(c)), "{c} must not begin a line");
}
// CJK opening brackets may not end a line.
for &c in &['(', '【', '《', '「', '“', '‘', '〔', '〖'] {
assert!(!can_break_between(c, Some('字')), "{c} must not end a line");
}
// Opening brackets may start a line; closing brackets may end one.
for &c in &['(', '【', '《', '「'] {
assert!(can_break_between('字', Some(c)), "{c} may begin a line");
}
for c in [')', '】', '》', '」', '〕', '〗'] {
assert!(can_break_between(c, Some('字')), "{c} may end a line");
}
// Latin brackets keep Western behaviour: a break before them is fine.
for &c in &['(', '[', '{'] {
assert!(can_break_between('a', Some(c)), "a Latin word may break before {c}");
assert!(!can_break_between(c, Some('a')), "{c} must not end a line");
}
// Ordinary ideographs and mixed CJK/Latin boundaries may break.
assert!(can_break_between('中', Some('文')));
assert!(can_break_between('中', Some('a')));
assert!(can_break_between('a', Some('中')));
assert!(can_break_between('中', None), "the paragraph end is always a break");
}
#[test]
fn punctuation_is_squeezed_on_its_outer_side() {
if !has_chinese_font() {
return;
}
for c in ['(', '【', '《', '「'] {
let (r, l) = (raw_advance("Noto Sans CJK SC", c, 20.0), laid_advance("Noto Sans CJK SC", c, 20.0));
assert!(l < r - 1.0, "{c}: laid {l} is not tighter than raw {r}");
assert!(l >= r * 0.5 - 1e-9, "{c}: laid {l} below the half-em floor of {r}");
}
for c in [',', '。', '、'] {
let (r, l) = (raw_advance("Noto Sans CJK SC", c, 20.0), laid_advance("Noto Sans CJK SC", c, 20.0));
assert!(l < r - 1.0 && l >= r * 0.5 - 1e-9, "{c}: laid {l} against raw {r}");
}
}
#[test]
fn no_chinese_punctuation_is_squeezed_out_of_existence() {
if !has_chinese_font() {
return;
}
// The trim must never take more than half a mark's cell, so the advance stays positive and the
// glyph keeps its id even in faces that carry these marks narrower than a full em.
let marks = ",。、;:!?()【】《》「」“”‘’…·";
for family in ["Noto Sans CJK SC", "Source Sans 3"] {
for c in marks.chars() {
let st = CharStyle { font_family: family.into(), size: 20.0, ..CharStyle::default() };
let l = layout(db(), &TextObject::point(Point::ZERO, c.to_string().as_str(), st));
let Some(g) = l.glyphs.first() else { panic!("{family} {c}: no glyph") };
assert!(g.advance > 0.0, "{family} {c}: advance {} squeezed to nothing", g.advance);
assert!(g.gid != 0, "{family} {c}: missing glyph (gid 0)");
}
}
}
#[test]
fn compressed_brackets_do_not_overlap_the_enclosed_text() {
if !has_chinese_font() {
return;
}
let l = layout(db(), &TextObject::point(Point::ZERO, "甲(乙)丙《丁》戊", style(20.0)));
for pair in l.glyphs.windows(2) {
let a = pair[0].outline.bounding_box();
let b = pair[1].outline.bounding_box();
assert!(a.x1 <= b.x0 + 0.01, "overlapping ink: {a:?} and {b:?}");
}
}
#[test]
fn latin_curly_quotes_and_apostrophes_keep_the_fonts_spacing() {
for c in ['‘', '’', '“', '”'] {
let raw = raw_advance("Source Sans 3", c, 40.0);
let laid = laid_advance("Source Sans 3", c, 40.0);
assert!((raw - laid).abs() < 1e-6, "{c}: {raw} vs {laid}");
}
}
#[test]
fn narrow_frames_keep_brackets_with_the_enclosed_character() {
if !has_chinese_font() {
return;
}
let text = "甲甲《乙》丙丙丙";
for width in [12.0, 24.0, 30.0, 40.0, 50.0] {
let l = layout(db(), &cjk_area(text, Rect::new(0.0, 0.0, width, 1000.0), Justify::Left));
for line in &l.lines {
let s = &text[line.start..line.end];
assert!(!s.starts_with('》') && !s.ends_with('《'), "width {width}: {s:?}");
}
}
}
#[test]
fn justified_chinese_reaches_the_frame_edge() {
if !has_chinese_font() {
return;
}
let text: String = "中文排版测试两端对齐标点挤压".repeat(12);
let frame = Rect::new(0.0, 0.0, 200.0, 4000.0);
let l = layout(db(), &cjk_area(&text, frame, Justify::JustifyLeft));
assert!(l.lines.len() > 3, "the text wraps: {} lines", l.lines.len());
for line in &l.lines[..l.lines.len() - 1] {
let avail = line.avail.1 - line.avail.0;
assert!((line.x1 - line.x0 - avail).abs() < 1e-6, "justified line does not reach the edge: {line:?}");
}
// The last line is left ragged rather than stretched.
assert!(l.lines.last().is_some_and(|l| l.x1 - l.x0 < 200.0));
}
#[test]
fn chinese_justification_does_not_track_out_latin_words() {
let frame = Rect::new(0.0, 0.0, 70.0, 4000.0);
let mut text = cjk_area("abcdefghijklmnopqrstuvwx".repeat(4).as_str(), frame, Justify::Left);
text.runs[0].style.font_family = "Source Sans 3".into();
let left = layout(db(), &text);
text.para.justify = Justify::JustifyLeft;
let justified = layout(db(), &text);
assert!(left.lines.len() > 2);
for (a, b) in left.glyphs.iter().zip(&justified.glyphs) {
assert!((a.advance - b.advance).abs() < 1e-9);
}
}
#[test]
fn lines_never_begin_with_closing_punctuation_or_end_with_an_opening_one() {
if !has_chinese_font() {
return;
}
let text: String = "他说:「中文排版,非常讲究。」然后他走了。".repeat(20);
let l = layout(db(), &cjk_area(&text, Rect::new(0.0, 0.0, 120.0, 6000.0), Justify::Left));
assert!(l.lines.len() > 5);
for line in &l.lines {
let s = text.get(line.start..line.end).unwrap_or("");
let first = s.chars().next();
assert!(first.is_none_or(|c| !",。、;:!?)】》」”’…".contains(c)), "line begins with closing punctuation {first:?}: {s:?}");
let last = s.chars().next_back();
assert!(last.is_none_or(|c| !"(【《「“‘[{".contains(c)), "line ends with an opening bracket {last:?}: {s:?}");
}
}

View File

@ -1,16 +1,11 @@
//! Vertical type (bundled fonts: `§` and `×` stand upright like CJK, letters lie on their side;
//! Japanese text only with craft-fonts' faces, skipped without them).
//! Vertical type (bundled fonts only: `§` and `×` stand upright like CJK, letters lie on their side).
use super::*;
use kurbo::Shape;
use vectorcraft_doc::{CharStyle, Justify, TextKind};
use vectorcraft_doc::{CharStyle, TextKind};
use vectorcraft_geom::PathData;
fn vertical(text: &str) -> TextObject {
vertical_styled(text, CharStyle { size: 20.0, ..CharStyle::default() })
}
fn vertical_styled(text: &str, style: CharStyle) -> TextObject {
let mut t = TextObject::point(Point::ZERO, text, style);
let mut t = TextObject::point(Point::ZERO, text, CharStyle { size: 20.0, ..CharStyle::default() });
t.xf = Affine::IDENTITY;
t.vertical = true;
t
@ -133,131 +128,3 @@ fn kinsoku_keeps_closing_marks_off_line_starts_and_opening_brackets_off_line_end
}
}
}
/// Each glyph's cell down the (single) column: from its origin over its advance. A glyph that
/// doesn't advance (the rest of a tate-chu-yoko block) shares the cell of the glyph before it.
fn column_cells(l: &TextLayout) -> Vec<(f64, f64)> {
let mut cells: Vec<(f64, f64)> = Vec::with_capacity(l.glyphs.len());
for g in &l.glyphs {
let cell = match cells.last() {
Some(&prev) if g.advance == 0.0 => prev,
_ => (g.origin.y, g.origin.y + g.advance),
};
cells.push(cell);
}
cells
}
/// One column, cells one after the other, each glyph's ink inside its own cell (within `tol`)
/// and no two glyphs' ink overlapping.
fn assert_own_cells(l: &TextLayout, text: &str, tol: f64) {
let label = |i: usize| &text[l.glyphs[i].byte..l.glyphs[i].byte + l.glyphs[i].len];
let cells = column_cells(l);
for (i, g) in l.glyphs.iter().enumerate() {
assert!((g.origin.x - l.glyphs[0].origin.x).abs() < 1e-9, "{:?} leaves the column: {g:?}", label(i));
if let Some(next) = l.glyphs.get(i + 1) {
assert!((next.origin.y - (g.origin.y + g.advance)).abs() < 1e-9, "{:?} starts where {:?} ends", label(i + 1), label(i));
}
if g.outline.elements().is_empty() {
continue;
}
let (r, (top, bottom)) = (ink(l, i), cells[i]);
assert!(r.y0 >= top - tol && r.y1 <= bottom + tol, "{:?}: ink {r:?} outside its cell {top}..{bottom}", label(i));
for j in (0..i).filter(|&j| !l.glyphs[j].outline.elements().is_empty()) {
let o = ink(l, j);
let (ox, oy) = (r.x1.min(o.x1) - r.x0.max(o.x0), r.y1.min(o.y1) - r.y0.max(o.y0));
assert!(ox <= tol || oy <= tol, "{:?} {r:?} overlaps {:?} {o:?}", label(i), label(j));
}
}
}
/// Index of the glyph of `needle`'s first byte in `text`.
fn glyph_of(l: &TextLayout, text: &str, needle: &str) -> usize {
let b = text.find(needle).unwrap();
l.glyphs.iter().position(|g| g.byte == b).unwrap()
}
/// Issue #260 with bundled glyphs (`§` stands in for the upright CJK characters).
#[test]
fn numbers_keep_their_own_cells_down_the_column() {
let text = "§§ §§§ 10§22§§ 1§ 100§ 2026§";
let l = layout(FontDb::global(), &vertical(text));
assert_own_cells(&l, text, 0.25);
// Tate-chu-yoko: one em of the column, centred on the column's centre line (x = 0), the next
// character right after it.
for block in ["10§", "22§", "100§"] {
let first = glyph_of(&l, text, block);
let digits = block.len() - '§'.len_utf8();
let after = first + digits;
let g = &l.glyphs[first];
assert!((g.advance - 20.0).abs() < 1e-9, "{block}: {g:?}");
assert!(l.glyphs[first + 1..after].iter().all(|d| d.advance == 0.0), "{block}");
assert!((l.glyphs[after].origin.y - (g.origin.y + 20.0)).abs() < 1e-9, "{block}: the next character follows the block's em");
let inks = (first..after).map(|i| ink(&l, i)).reduce(|a, b| a.union(b)).unwrap();
assert!(inks.center().x.abs() < 1.0, "{block} centred on the column: {inks:?}");
assert!((inks.center().y - (g.origin.y + 10.0)).abs() < 1.5, "{block} centred in its em: {inks:?} {g:?}");
}
// A single digit and longer numbers lie on their side, advancing by their own length.
let one = glyph_of(&l, text, "1§");
let r = ink(&l, one);
assert!(r.width() > r.height() && l.glyphs[one].advance < 20.0, "1 on its side: {r:?}");
let year = glyph_of(&l, text, "2026");
let len: f64 = l.glyphs[year..year + 4].iter().map(|g| g.advance).sum();
assert!(len > 30.0 && (l.glyphs[year + 4].origin.y - l.glyphs[year].origin.y - len).abs() < 1e-9, "2026 takes its length: {len}");
// Half-width spaces take their own (narrow) width.
for (i, g) in l.glyphs.iter().enumerate().filter(|(_, g)| text[g.byte..].starts_with(' ')) {
assert!(g.advance > 2.0 && g.advance < 10.0, "space {i}: {g:?}");
}
}
#[test]
fn justified_columns_keep_tate_chu_yoko_blocks_whole_and_marks_centred() {
let text = "§10§§";
let mut t = vertical(text);
t.kind = TextKind::Area { frame: PathData::from_bezpath(&Rect::new(0.0, 0.0, 40.0, 200.0).to_path(0.1)) };
t.para.justify = Justify::JustifyAll;
let l = layout(FontDb::global(), &t);
assert_eq!(l.lines.len(), 1);
// 200 pt of column, four 20 pt cells: three gaps of 40 pt between them, none inside "10".
let (one, zero) = (ink(&l, 1), ink(&l, 2));
assert!((one.center().y - zero.center().y).abs() < 0.5 && zero.x0 > one.x1, "10 side by side: {one:?} {zero:?}");
let marks: Vec<Rect> = [0, 3, 4].iter().map(|&i| ink(&l, i)).collect();
assert!((marks[1].center().y - marks[0].center().y - 120.0).abs() < 1e-6, "{marks:?}");
assert!((marks[2].center().y - marks[1].center().y - 60.0).abs() < 1e-6, "{marks:?}");
assert!(marks.iter().all(|m| (m.center().x - marks[0].center().x).abs() < 1e-6), "upright marks stay on the centre line: {marks:?}");
assert!(marks[2].y1 <= 200.0 + 1e-6, "inside the frame: {marks:?}");
}
#[test]
fn tracking_spaces_upright_marks_without_moving_them_off_the_centre_line() {
let plain = layout(FontDb::global(), &vertical("§§"));
let tracked = layout(FontDb::global(), &vertical_styled("§§", CharStyle { size: 20.0, tracking: 200.0, ..CharStyle::default() }));
for i in 0..2 {
assert!((ink(&tracked, i).center().x - ink(&plain, i).center().x).abs() < 1e-6, "{:?} {:?}", ink(&tracked, i), ink(&plain, i));
}
let step = ink(&tracked, 1).center().y - ink(&tracked, 0).center().y;
assert!((step - 24.0).abs() < 1e-6, "one em plus 200/1000 em of tracking: {step}");
}
/// Issue #260 as reported, with a Japanese face of craft-fonts (whose own digits are proportional).
#[test]
fn japanese_numbers_keep_their_own_cells_down_the_column() {
let Some(face) = crate::craft_fonts::japanese_ui_fonts(false).into_iter().next() else {
eprintln!("skipped: built without craft-fonts (set CRAFT_FONTS_DIR to a craft-fonts checkout to run it)");
return;
};
let db = FontDb::with_font_dirs(vec![]);
let text = "はただ商店 秋のセール 10月22日まで";
let t = vertical_styled(text, CharStyle { size: 28.0, font_family: face.family.into(), font_style: face.style.into(), ..CharStyle::default() });
let l = layout(&db, &t);
assert!(l.glyphs.iter().filter(|g| !text[g.byte..].starts_with(' ')).all(|g| g.gid != 0), "real glyphs, no tofu");
assert_own_cells(&l, text, 0.5);
for block in ["10月", "22日"] {
let first = glyph_of(&l, text, block);
let g = &l.glyphs[first];
assert!((g.advance - 28.0).abs() < 1e-9 && l.glyphs[first + 1].advance == 0.0, "{block}: one em");
assert!((l.glyphs[first + 2].origin.y - (g.origin.y + 28.0)).abs() < 1e-9, "{block}: the next character follows the em");
let inks = ink(&l, first).union(ink(&l, first + 1));
assert!(inks.center().x.abs() < 2.8, "{block} centred on the column: {inks:?}");
}
}

View File

@ -7,20 +7,16 @@
//! Both pick the key objects of a blend. Direct Selection also edits a blend's spine: drag its
//! points (a key object on a point moves with it) and, once a point is clicked, its handles; and
//! the points of selected gradient meshes and mesh envelopes and their handles ([`MeshEdit`]).
//! Dragging a corner or an edge of area type's frame reshapes the type area (`text.reshapeArea`):
//! the text reflows at its size.
use std::borrow::Cow;
use serde_json::{Value, json};
use vectorcraft_doc::hit::hit_test;
use vectorcraft_doc::{AnchorRef, Node, NodeId, NodeKind};
use vectorcraft_doc::{AnchorRef, NodeId, NodeKind};
use vectorcraft_geom::{PathData, Point, Rect};
use crate::bbox::move_delta;
use crate::corners::{CornerDrag, over_widget};
use crate::meshedit::MeshEdit;
use crate::select::{is_area_type, matrix_json};
use crate::select::matrix_json;
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext};
#[derive(Clone, Debug)]
@ -62,13 +58,6 @@ enum State {
},
/// Dragging a mesh point or handle ([`MeshEdit`]).
Mesh,
/// Dragging anchors of area type's frame (a corner, or the two ends of an edge).
TypeArea {
id: NodeId,
anchors: Vec<AnchorRef>,
start: Point,
began: bool,
},
}
pub struct DirectSelectionTool {
@ -126,45 +115,33 @@ fn spine_anchor(cx: &ToolContext, (id, ai): (NodeId, usize)) -> Option<vectorcra
}
}
/// The anchors Direct Selection edits on `n`, in document space: a path's, or area type's frame.
fn editable_path(n: &Node) -> Option<Cow<'_, PathData>> {
match &n.kind {
NodeKind::Path { path, .. } => Some(Cow::Borrowed(path)),
NodeKind::Text(t) => t.area_frame().map(Cow::Owned),
_ => None,
}
}
/// The editable objects `f` accepts, topmost first.
fn anchor_owners(cx: &ToolContext, f: fn(&Node) -> bool) -> Vec<NodeId> {
let mut v = vec![];
cx.doc.walk(|n| {
if f(n) {
v.push(n.id)
/// Anchor (or handle) of any selected/visible path under `p`.
fn hit_anchor(cx: &ToolContext, p: Point, tol: f64, selected_only: bool) -> Option<(NodeId, usize, usize)> {
let ids: Vec<NodeId> = if selected_only {
cx.selection.objects.clone()
} else {
let mut v = vec![];
cx.doc.walk(|n| {
if matches!(n.kind, NodeKind::Path { .. }) {
v.push(n.id)
}
});
v.reverse();
v
};
for id in ids {
if !cx.doc.is_editable(id) {
continue;
}
});
v.reverse();
v.retain(|id| cx.doc.is_editable(*id));
v
}
/// Anchor of any visible path or area type frame under `p`, topmost first.
fn hit_anchor(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, usize, usize)> {
let owners = anchor_owners(cx, |n| matches!(n.kind, NodeKind::Path { .. }) || is_area_type(n));
owners.into_iter().find_map(|id| {
let pd = cx.doc.node(id).and_then(editable_path)?;
pd.anchors().find(|(_, _, a)| a.p.distance(p) <= tol).map(|(si, ai, _)| (id, si, ai))
})
}
/// An edge of an area type frame under `p`, topmost first: (text, the edge's two anchors).
fn hit_frame_edge(cx: &ToolContext, p: Point, tol: f64) -> Option<(NodeId, Vec<AnchorRef>)> {
anchor_owners(cx, is_area_type).into_iter().find_map(|id| {
let frame = cx.doc.node(id).and_then(editable_path)?;
let (si, seg, _, _, d) = frame.nearest(p)?;
let n = frame.subpaths.get(si)?.anchors.len();
(d <= tol && n > 0).then(|| (id, vec![(si, seg % n), (si, (seg + 1) % n)]))
})
if let Some(pd) = cx.doc.node(id).and_then(|n| n.path_data()) {
for (si, ai, a) in pd.anchors() {
if a.p.distance(p) <= tol {
return Some((id, si, ai));
}
}
}
}
None
}
/// Direction handle of a partially selected anchor under `p`: (id, si, ai, is_out).
@ -246,10 +223,7 @@ impl Tool for DirectSelectionTool {
self.state = State::SpinePoint { id, anchor, from, start: p, began: false };
return if cx.selection.contains(id) { vec![] } else { vec![Action::Exec("select.set".into(), json!({"ids": [id.0]}))] };
}
if let Some((id, si, ai)) = hit_anchor(cx, p, tol) {
if cx.doc.node(id).is_some_and(is_area_type) {
return self.press_type_area(cx, id, vec![(si, ai)], p, ev.mods.shift);
}
if let Some((id, si, ai)) = hit_anchor(cx, p, tol, false) {
let already = cx.selection.partial(id).is_some_and(|s| s.contains(&(si, ai)));
self.state = State::MoveAnchors { start: p, began: false };
if ev.mods.shift {
@ -260,9 +234,6 @@ impl Tool for DirectSelectionTool {
}
return vec![];
}
if let Some((id, anchors)) = hit_frame_edge(cx, p, tol) {
return self.press_type_area(cx, id, anchors, p, ev.mods.shift);
}
if let Some(h) = hit_test(cx.doc, p, cx.hit_options()) {
// Clicking a segment/fill selects the whole leaf path (all anchors).
self.state = State::MoveObject { start: p, began: false };
@ -306,19 +277,6 @@ impl Tool for DirectSelectionTool {
));
out
}
(PointerKind::Drag, State::TypeArea { id, anchors, start, began }) => {
let mut out = vec![];
if !began {
if p.distance(start) < cx.tol(3.0) {
return out;
}
out.push(Action::Begin("Reshape Type Area".into()));
}
let d = move_delta(start, p, ev.mods.shift);
out.push(Action::Preview("text.reshapeArea".into(), json!({"id": id.0, "anchors": anchors_json(&anchors), "dx": d.x, "dy": d.y})));
self.state = State::TypeArea { id, anchors, start, began: true };
out
}
(PointerKind::Drag, State::Handle { id, si, ai, out }) => {
vec![Action::Preview(
"path.setHandle".into(),
@ -360,10 +318,7 @@ impl Tool for DirectSelectionTool {
self.state = State::Idle;
c.finish()
}
(
PointerKind::Up,
State::MoveAnchors { began, .. } | State::MoveObject { began, .. } | State::SpinePoint { began, .. } | State::TypeArea { began, .. },
) => {
(PointerKind::Up, State::MoveAnchors { began, .. } | State::MoveObject { began, .. } | State::SpinePoint { began, .. }) => {
self.state = State::Idle;
if began { vec![Action::Commit] } else { vec![] }
}
@ -401,9 +356,6 @@ impl Tool for DirectSelectionTool {
_ => {
let mut out = self.spine_overlays(cx);
out.extend(self.mesh.overlays(cx));
if !self.group {
out.extend(frame_overlays(cx));
}
out
}
}
@ -416,31 +368,7 @@ impl Tool for DirectSelectionTool {
}
}
/// The frame anchors of the selected area type, which Direct Selection drags.
fn frame_overlays(cx: &ToolContext) -> Vec<Overlay> {
let mut out = vec![];
for id in &cx.selection.objects {
let Some(frame) = cx.doc.node(*id).filter(|n| is_area_type(n)).and_then(editable_path) else { continue };
let color = cx.doc.layer_color(*id);
out.extend(frame.anchors().map(|(_, _, a)| Overlay::Anchor { p: a.p, color, filled: false, size: 5.0 }));
}
out
}
impl DirectSelectionTool {
/// Press on area type's frame anchors (a corner, or an edge's two ends): select the text and
/// get ready to drag them.
fn press_type_area(&mut self, cx: &ToolContext, id: NodeId, anchors: Vec<AnchorRef>, p: Point, shift: bool) -> Vec<Action> {
self.state = State::TypeArea { id, anchors, start: p, began: false };
if cx.selection.contains(id) {
vec![]
} else if shift {
vec![Action::Exec("select.add".into(), json!({"ids": [id.0]}))]
} else {
vec![Action::Exec("select.set".into(), json!({"ids": [id.0]}))]
}
}
/// The clicked spine point, filled, with its handles.
fn spine_overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
let Some(sel) = self.spine.filter(|(id, _)| cx.selection.contains(*id)) else { return vec![] };
@ -507,37 +435,6 @@ mod tests {
assert_eq!(a, vec![Action::Exec("select.set".into(), json!({"ids": [g.0]}))]);
}
#[test]
fn dragging_a_frame_corner_or_edge_reshapes_area_type() {
let (d, text) = doc_with_area_type();
let p = paint();
let s = Selection::default();
let cx1 = cx(&d, &s, &p);
let mut t = DirectSelectionTool::new(false);
// The bottom-right corner of the 120 × 40 frame at (300, 300) selects the text...
assert_eq!(
t.pointer(&cx1, &PointerEvent::new(PointerKind::Down, 421.0, 339.0)),
vec![Action::Exec("select.set".into(), json!({"ids": [text.0]}))]
);
// ...and drags that corner.
let a = t.pointer(&cx1, &PointerEvent::new(PointerKind::Drag, 461.0, 399.0));
assert_eq!(a[0], Action::Begin("Reshape Type Area".into()));
assert_eq!(a[1], Action::Preview("text.reshapeArea".into(), json!({"id": text.0, "anchors": [[0, 2]], "dx": 40.0, "dy": 60.0})));
assert_eq!(t.pointer(&cx1, &PointerEvent::new(PointerKind::Up, 461.0, 399.0)), vec![Action::Commit]);
// The top edge drags both its ends; a click alone changes nothing.
let mut s = Selection::default();
s.add(text);
let cx2 = cx(&d, &s, &p);
assert!(t.pointer(&cx2, &PointerEvent::new(PointerKind::Down, 350.0, 301.0)).is_empty());
let a = t.pointer(&cx2, &PointerEvent::new(PointerKind::Drag, 350.0, 281.0));
assert_eq!(a[1], Action::Preview("text.reshapeArea".into(), json!({"id": text.0, "anchors": [[0, 0], [0, 1]], "dx": 0.0, "dy": -20.0})));
t.pointer(&cx2, &PointerEvent::new(PointerKind::Up, 350.0, 281.0));
assert!(t.pointer(&cx2, &PointerEvent::new(PointerKind::Down, 300.0, 340.0)).is_empty());
assert!(t.pointer(&cx2, &PointerEvent::new(PointerKind::Up, 300.0, 340.0)).is_empty());
// The selected frame's corners show.
assert_eq!(t.overlays(&cx2).iter().filter(|o| matches!(o, Overlay::Anchor { filled: false, .. })).count(), 4);
}
#[test]
fn click_anchor_selects_it() {
let (d, id) = doc_with_rect();

View File

@ -477,17 +477,6 @@ pub(crate) mod testutil {
(d, id)
}
/// [`doc_with_rect`] plus 120 × 40 area type at (300, 300).
pub fn doc_with_area_type() -> (Document, NodeId) {
let (mut d, _) = doc_with_rect();
let l = d.layers[0].id;
let id = d.alloc_id();
let mut t = vectorcraft_doc::TextObject::point(Point::new(300.0, 300.0), "Some words", Default::default());
t.kind = vectorcraft_doc::TextKind::Area { frame: shapes::rectangle(Rect::new(0.0, 0.0, 120.0, 40.0)) };
d.insert(Some(l), 1, Node::new(id, vectorcraft_doc::NodeKind::Text(Box::new(t)))).unwrap();
(d, id)
}
pub fn paint() -> PaintDefaults {
PaintDefaults::default()
}

View File

@ -2,8 +2,7 @@
//! bounding-box scale (Shift proportional, Alt from centre) and rotate (outside corners, Shift 45°),
//! drag a live rectangle's corner widget to round its corners, double-click to enter isolation mode.
//! The bounding box stands at the selection's own angle after a rotation, so its handles scale
//! along the objects' axes. A handle drag resizes area type's frame (the type area) instead of
//! scaling its type: the text reflows at its size.
//! along the objects' axes.
use serde_json::{Value, json};
use vectorcraft_doc::hit::{hit_test, marquee};
@ -29,8 +28,6 @@ enum State {
Scaling {
handle: Handle,
bx: OrientedBox,
/// Area type is selected: its frame resizes (`typeAreas`), its type keeps its size.
areas: bool,
},
Rotating {
center: Point,
@ -132,12 +129,8 @@ impl Tool for SelectionTool {
{
match box_hit(cx, &bx, p) {
Some(BoxHit::Handle(handle)) => {
let is_area = |id: &NodeId| cx.doc.node(*id).is_some_and(is_area_type);
let areas = cx.selection.objects.iter().any(is_area);
// Only area type: the step resizes type areas; anything else scales.
let label = if areas && cx.selection.objects.iter().all(is_area) { "Resize Type Area" } else { "Scale" };
self.state = State::Scaling { handle, bx, areas };
return vec![Action::Begin(label.into())];
self.state = State::Scaling { handle, bx };
return vec![Action::Begin("Scale".into())];
}
Some(BoxHit::Rotate) => {
self.state = State::Rotating { center: bx.center(), start: p };
@ -203,16 +196,12 @@ impl Tool for SelectionTool {
out.push(Action::Preview("object.transform".into(), json!({ "matrix": matrix_json(Affine::translate(d)), "copy": m.alt })));
out
}
(PointerKind::Drag, State::Scaling { handle, bx, areas }) => {
(PointerKind::Drag, State::Scaling { handle, bx }) => {
// Scale in the box's own frame: along the objects' axes when it is rotated.
let a = scale_for_drag(bx.rect, handle, bx.to_local(p), m.shift, m.alt);
let nr = a.transform_rect_bbox(bx.rect);
self.measure = Some((p, cx.size_label(nr.width(), nr.height())));
let mut params = json!({ "matrix": matrix_json(bx.conjugate(a)), "copy": false });
if areas {
params["typeAreas"] = json!(true);
}
vec![Action::Preview("object.transform".into(), params)]
vec![Action::Preview("object.transform".into(), json!({ "matrix": matrix_json(bx.conjugate(a)), "copy": false }))]
}
(PointerKind::Drag, State::Rotating { center, start, .. }) => {
let (a, deg) = rotate_for_drag(center, start, p, m.shift);
@ -282,7 +271,7 @@ impl Tool for SelectionTool {
fn cursor(&self, cx: &ToolContext, p: Point, m: Mods) -> Cursor {
match self.state {
State::Rotating { .. } => return Cursor::Rotate,
State::Scaling { handle, bx, .. } => return handle_cursor(handle, bx.angle),
State::Scaling { handle, bx } => return handle_cursor(handle, bx.angle),
State::Moving { began: true, .. } => return Cursor::Arrow,
State::Corner(_) => return Cursor::CornerRadius,
_ => {}
@ -309,12 +298,6 @@ impl Tool for SelectionTool {
}
}
/// Is `n` area type (text in a frame) whose frame the tools reshape? Type in perspective isn't:
/// it transforms whole.
pub(crate) fn is_area_type(n: &vectorcraft_doc::Node) -> bool {
n.perspective.is_none() && matches!(&n.kind, vectorcraft_doc::NodeKind::Text(t) if matches!(t.kind, vectorcraft_doc::TextKind::Area { .. }))
}
/// The resize cursor for handle `h` of a box turned by `angle` (counter-clockwise degrees): the
/// handle that sits where `h` appears on screen, in 45° steps.
fn handle_cursor(h: Handle, angle: f64) -> Cursor {
@ -437,36 +420,6 @@ mod tests {
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 300.0, 300.0)), vec![Action::Commit]);
}
#[test]
fn handle_drag_on_area_type_resizes_its_frame() {
let (d, text) = doc_with_area_type();
let p = paint();
let mut s = Selection::default();
s.add(text);
let cx1 = cx(&d, &s, &p);
let mut t = SelectionTool::default();
// Bottom-right handle of the 120 × 40 frame at (300, 300).
assert_eq!(t.pointer(&cx1, &ev(PointerKind::Down, 420.0, 340.0)), vec![Action::Begin("Resize Type Area".into())]);
let a = t.pointer(&cx1, &ev(PointerKind::Drag, 460.0, 400.0));
assert!(matches!(&a[0], Action::Preview(c, v) if c == "object.transform" && v["typeAreas"] == true), "{a:?}");
assert_eq!(t.pointer(&cx1, &ev(PointerKind::Up, 460.0, 400.0)), vec![Action::Commit]);
// With another object the step is a scale, still resizing the type area.
let rect = d.layers[0].children().unwrap()[0].id;
s.add(rect);
let cx2 = cx(&d, &s, &p);
assert_eq!(t.pointer(&cx2, &ev(PointerKind::Down, 420.0, 340.0)), vec![Action::Begin("Scale".into())]);
let a = t.pointer(&cx2, &ev(PointerKind::Drag, 460.0, 400.0));
assert!(matches!(&a[0], Action::Preview(_, v) if v["typeAreas"] == true), "{a:?}");
t.pointer(&cx2, &ev(PointerKind::Up, 460.0, 400.0));
// Without area type the drag scales as before.
let mut s = Selection::default();
s.add(rect);
let cx3 = cx(&d, &s, &p);
t.pointer(&cx3, &ev(PointerKind::Down, 200.0, 200.0));
let a = t.pointer(&cx3, &ev(PointerKind::Drag, 300.0, 300.0));
assert!(matches!(&a[0], Action::Preview(_, v) if v.get("typeAreas").is_none()), "{a:?}");
}
#[test]
fn turned_box_handles_turn_and_scale_along_the_object() {
let (mut d, id) = doc_with_rect();

View File

@ -235,26 +235,19 @@ impl TypeTool {
}
}
/// Start editing the type under `p` with the caret there → the actions (ending the previous
/// edit, selecting the type); None when no type is under `p`.
fn edit_at(&mut self, cx: &ToolContext, p: Point) -> Option<Vec<Action>> {
let h = hit_test(cx.doc, p, cx.hit_options())?;
let Some(NodeKind::Text(t)) = cx.doc.node(h.leaf).map(|n| &n.kind) else { return None };
let lay = self.layout(t);
let byte = vectorcraft_text::hit_byte(&lay, t.xf.inverse() * p);
let mut out = self.finish(cx);
self.start_editing(h.leaf, byte);
self.clicks = (Some(p), 1);
out.push(Action::Exec("select.set".into(), json!({"ids": [h.leaf.0]})));
Some(out)
}
fn on_up(&mut self, cx: &ToolContext, start: Point) -> Vec<Action> {
let mut out = self.finish(cx);
// Click into existing text: place the caret.
if let Some(out) = self.edit_at(cx, start) {
if let Some(h) = hit_test(cx.doc, start, cx.hit_options())
&& let Some(NodeKind::Text(t)) = cx.doc.node(h.leaf).map(|n| &n.kind)
{
let lay = self.layout(t);
let byte = vectorcraft_text::hit_byte(&lay, t.xf.inverse() * start);
self.start_editing(h.leaf, byte);
self.clicks = (Some(start), 1);
out.push(Action::Exec("select.set".into(), json!({"ids": [h.leaf.0]})));
return out;
}
let mut out = self.finish(cx);
let drag = self.drag.take();
// Area Type / Type on a Path: click a path.
if self.mode != Mode::Type && drag.is_none() {
@ -271,7 +264,7 @@ impl TypeTool {
}
let area = drag.map(|d| Rect::from_points(start, d)).filter(|r| r.width() > cx.tol(6.0) && r.height() > cx.tol(6.0));
let mut params = match area {
Some(r) => json!({"x": r.x0, "y": r.y0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
Some(r) => json!({"x": r.x0, "y": r.y0 + 12.0, "text": "", "area": {"width": r.width(), "height": r.height()}}),
None => json!({"x": start.x, "y": start.y, "text": ""}),
};
params["vertical"] = json!(self.vertical);
@ -364,12 +357,6 @@ impl Tool for TypeTool {
return out;
}
self.clicks = (None, 0);
// A press on other type edits it from there, so a drag selects its text at once,
// as it does in the type being edited.
if let Some(out) = self.edit_at(cx, ev.pos) {
self.selecting = true;
return out;
}
self.press = Some(ev.pos);
self.drag = None;
vec![]

View File

@ -176,33 +176,6 @@ fn drag_selects_and_overlay_highlights() {
assert_eq!((opts["start"].as_u64(), opts["end"].as_u64()), (Some(7), Some(9)));
}
#[test]
fn a_drag_across_type_not_being_edited_selects_its_text() {
let (d, id) = doc_with_text("Select me please");
let mut tool = TypeTool::new("type");
let (sel, p) = (Selection::default(), paint());
let c = cx(&d, &sel, &p);
let t = TypeTool::text(&c, id).unwrap().clone();
let lay = vectorcraft_text::layout(FontDb::global(), &t);
let pt = |b: usize| {
let (a, bb) = vectorcraft_text::caret_position(&lay, b);
t.xf * a.midpoint(bb)
};
let (a, b) = (pt(7), pt(9));
// The press starts editing the type and the drag selects, in one gesture.
let out = tool.pointer(&c, &PointerEvent::new(PointerKind::Down, a.x + 0.1, a.y));
assert!(out.contains(&Action::Exec("select.set".into(), json!({"ids": [id.0]}))));
tool.pointer(&c, &PointerEvent::new(PointerKind::Drag, b.x + 0.1, b.y));
tool.pointer(&c, &PointerEvent::new(PointerKind::Up, b.x + 0.1, b.y));
assert_eq!(tool.editing, Some(id));
assert_eq!(tool.sel(), (7, 9));
// A plain click still just places the caret.
let mut tool = TypeTool::new("type");
tool.pointer(&c, &PointerEvent::new(PointerKind::Down, a.x + 0.1, a.y));
tool.pointer(&c, &PointerEvent::new(PointerKind::Up, a.x + 0.1, a.y));
assert_eq!((tool.editing, tool.sel()), (Some(id), (7, 7)));
}
#[test]
fn select_all_and_styled_paste() {
let (d, _, mut tool) = editing("abc");

View File

@ -44,27 +44,6 @@ enum Op {
Corners(Handle, DistortMode),
}
impl Op {
/// The bounding-box handle being dragged, if any.
fn handle(self) -> Option<Handle> {
match self {
Op::Scale(h) | Op::Shear(h) | Op::Corners(h, _) => Some(h),
Op::Move | Op::Rotate => None,
}
}
/// The undo step's name.
fn label(self) -> &'static str {
match self {
Op::Move => "Move",
Op::Scale(_) => "Scale",
Op::Shear(_) => "Shear",
Op::Rotate => "Rotate",
Op::Corners(..) => "Distort",
}
}
}
#[derive(Clone, Copy, Debug)]
struct Drag {
op: Op,
@ -146,28 +125,22 @@ pub fn distort_quad(r: Rect, h: Handle, d: Vec2, mode: DistortMode) -> [Point; 4
}
impl FreeTransformTool {
/// What dragging handle `h` with modifiers `m` does: Cmd on a corner distorts it freely,
/// Cmd+Alt+Shift in perspective, Cmd on a side shears; otherwise the tool's mode.
fn handle_op(&self, h: Handle, m: Mods) -> Op {
let mode = if h.is_corner() && m.cmd && m.alt && m.shift {
DistortMode::Perspective
} else if h.is_corner() && m.cmd {
DistortMode::Distort
} else {
self.mode
};
match mode {
DistortMode::Free if !h.is_corner() && m.cmd => Op::Shear(h),
DistortMode::Free => Op::Scale(h),
DistortMode::Perspective if !h.is_corner() => Op::Scale(h),
mode => Op::Corners(h, mode),
}
}
fn classify(&self, cx: &ToolContext, r: Rect, p: Point, m: Mods) -> Option<Op> {
let tol = cx.tol(5.0);
if let Some(h) = hit_handle(r, p, tol) {
return Some(self.handle_op(h, m));
let mode = if h.is_corner() && m.cmd && m.alt && m.shift {
DistortMode::Perspective
} else if h.is_corner() && m.cmd {
DistortMode::Distort
} else {
self.mode
};
return Some(match mode {
DistortMode::Free if !h.is_corner() && m.cmd => Op::Shear(h),
DistortMode::Free => Op::Scale(h),
DistortMode::Perspective if !h.is_corner() => Op::Scale(h),
mode => Op::Corners(h, mode),
});
}
if self.mode == DistortMode::Free && in_rotate_zone(r, p, tol, cx.tol(18.0)).is_some() {
return Some(Op::Rotate);
@ -232,24 +205,19 @@ impl Tool for FreeTransformTool {
PointerKind::Drag => {
let Some(mut d) = self.drag else { return vec![] };
let mut out = vec![];
// A handle drag follows the modifiers held now: the gesture is to start dragging
// and then hold Cmd (a Cmd press on the canvas is the temporary Selection tool).
if let Some(h) = d.op.handle() {
let op = self.handle_op(h, ev.mods);
if d.began && op.label() != d.op.label() {
// Another operation: it gets an undo step of its own.
out.push(Action::Cancel);
out.push(Action::Begin(op.label().into()));
}
d.op = op;
}
if !d.began {
if p.distance(d.start) < cx.tol(2.0) {
self.drag = Some(d);
return out;
}
d.began = true;
out.push(Action::Begin(d.op.label().into()));
let label = match d.op {
Op::Move => "Move",
Op::Scale(_) => "Scale",
Op::Shear(_) => "Shear",
Op::Rotate => "Rotate",
Op::Corners(..) => "Distort",
};
out.push(Action::Begin(label.into()));
}
self.drag = Some(d);
out.push(self.preview(cx, d, p, ev.mods));
@ -385,37 +353,6 @@ mod tests {
assert!((m * Point::new(100.0, 100.0)).distance(Point::new(120.0, 100.0)) < 1e-9);
}
#[test]
fn modifiers_pressed_during_a_handle_drag_change_what_it_does() {
let (d, id) = doc_with_rect();
let mut s = Selection::default();
s.add(id);
let p = paint();
let cx = cx(&d, &s, &p);
let mut t = FreeTransformTool::default();
let cmd = Mods { cmd: true, ..Default::default() };
let perspective = Mods { cmd: true, alt: true, shift: true, ..Default::default() };
// Start dragging the bottom-right corner, then hold Cmd: Free Distort, a step of its own.
t.pointer(&cx, &ev(PointerKind::Down, 200.0, 200.0));
let a = t.pointer(&cx, &ev(PointerKind::Drag, 210.0, 210.0));
assert_eq!(a[0], Action::Begin("Scale".into()));
let a = t.pointer(&cx, &ev(PointerKind::Drag, 220.0, 230.0).with_mods(cmd));
let corners = json!({"corners": [[100.0, 100.0], [200.0, 100.0], [220.0, 230.0], [100.0, 200.0]], "from": [100.0, 100.0, 200.0, 200.0]});
assert_eq!(a, vec![Action::Cancel, Action::Begin("Distort".into()), Action::Preview("object.distort".into(), corners)]);
// Cmd+Alt+Shift: Perspective Distort, still the same step.
let a = t.pointer(&cx, &ev(PointerKind::Drag, 220.0, 230.0).with_mods(perspective));
assert!(matches!(&a[..], [Action::Preview(c, _)] if c == "object.distort"), "{a:?}");
// Letting go of the keys scales again.
let a = t.pointer(&cx, &ev(PointerKind::Drag, 220.0, 230.0));
assert_eq!(a[..2], [Action::Cancel, Action::Begin("Scale".into())]);
assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, 220.0, 230.0)), vec![Action::Commit]);
// Cmd held during a side handle's drag shears.
t.pointer(&cx, &ev(PointerKind::Down, 150.0, 100.0));
t.pointer(&cx, &ev(PointerKind::Drag, 155.0, 100.0));
let a = t.pointer(&cx, &ev(PointerKind::Drag, 170.0, 100.0).with_mods(cmd));
assert_eq!(a[..2], [Action::Cancel, Action::Begin("Shear".into())]);
}
#[test]
fn distort_modes_emit_corners() {
let (d, id) = doc_with_rect();

View File

@ -92,11 +92,6 @@ fn temp_tool_id() -> egui::Id {
egui::Id::new("canvas-temp-tool")
}
/// Selection, Direct Selection and Group Selection: the tools Cmd switches to for a drag.
pub(crate) fn is_selection_tool(id: &str) -> bool {
matches!(id, "selection" | "directSelection" | "groupSelection")
}
/// The pen pressure (0..1) of the press in progress: the force of this frame's pen or touch
/// input, else the last one seen since the press (`pressed`: a new press, whose mouse has none
/// until a pen reports it). A mouse presses fully (1).
@ -125,14 +120,12 @@ pub fn fit(app: &mut VectorcraftApp, how: &str) {
}
return;
};
let current = app.view().map_or(0, |v| v.artboard);
let Some(st) = app.session.active() else { return };
let target = match how {
"view.fitAll" => {
st.doc.art_bounds().map(|a| st.doc.artboards.iter().fold(a, |r, ab| r.union(ab.rect))).or(st.doc.artboards.first().map(|a| a.rect))
}
// The navigator's artboard (the first if it has gone).
_ => st.doc.artboards.get(current).or(st.doc.artboards.first()).map(|a| a.rect),
_ => st.doc.artboards.first().map(|a| a.rect),
};
let Some(target) = target else { return };
let Some(v) = app.view_mut() else { return };
@ -349,7 +342,6 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if app.ui.view.rulers && app.ui.screen_mode < 3 {
rulers(ui, full, &xf, app.hover_doc, app.session.general_unit(), &t);
ruler_guides(app, ui, full, rect, &xf, &t);
}
if app.ui.task_bar && !app.session.tool_busy() && app.ui.screen_mode < 3 {
task_bar(app, ui, &xf);
@ -359,13 +351,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let m = ui.input(|i| i.modifiers);
let space = ui.input(|i| i.key_down(egui::Key::Space));
let panning = matches!(ui.data(|d| d.get_temp::<Drag>(drag_id())), Some(Drag::Pan { .. }));
let zooming = if space { m.command } else { app.session.tool_id() == "zoom" };
let cur = if panning {
egui::CursorIcon::Grabbing
} else if zooming {
if m.alt { egui::CursorIcon::ZoomOut } else { egui::CursorIcon::ZoomIn }
} else if space || app.session.tool_id() == "hand" {
egui::CursorIcon::Grab
} else if app.session.tool_id() == "zoom" {
if m.alt { egui::CursorIcon::ZoomOut } else { egui::CursorIcon::ZoomIn }
} else if let Some(p) = app.hover_doc {
let c = app.session.cursor(p, mods(m, space), view_info);
let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Tooltip, egui::Id::new("tool-cursor")));
@ -451,10 +442,7 @@ fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect:
}
let tool = app.session.tool_id();
// Held, Space is the Hand tool for the moment, and Cmd+Space the Zoom tool (with Alt, zooming
// out), whatever the tool.
let zoom_mode = if space { m.command } else { tool == "zoom" };
let pan_mode = if space { !m.command } else { tool == "hand" };
let pan_mode = space || tool == "hand";
let middle_pan = matches!(drag, Some(Drag::Pan { middle: true, .. }));
// egui counts a press a few pixels outside the canvas as on it (its interaction radius): only a
// press on the canvas itself reaches the tools, else it would land at the canvas's centre.
@ -465,20 +453,19 @@ fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect:
{
ui.ctx().memory_mut(|mem| mem.stop_text_input());
app.ui.flyout = None;
let d = if zoom_mode {
Drag::ZoomBox { start: p }
} else if pan_mode {
let d = if pan_mode {
Drag::Pan { start: p, center: v.center, middle: false }
} else if tool == "zoom" {
Drag::ZoomBox { start: p }
} else if tool == "rotateView" {
let c = rect.center();
Drag::RotateView { start_angle: (p.y - c.y).atan2(p.x - c.x) as f64, start_rot: v.rotation }
} else {
let selection_family = matches!(tool, "selection" | "directSelection" | "groupSelection");
let mut kind = Drag::Tool;
// Cmd with another tool: drag with the selection tool used last.
if m.command && !is_selection_tool(tool) {
if m.command && !selection_family {
ui.data_mut(|d| d.insert_temp(temp_tool_id(), tool.to_string()));
let last = app.ui.last_selection_tool.clone();
app.select_tool(if is_selection_tool(&last) { &last } else { "selection" });
app.select_tool("selection");
kind = Drag::TempSelect;
}
let ev = PointerEvent { kind: PointerKind::Down, pos: xf.to_doc(p), mods: mods(m, space), pressure: pen_pressure(ui, true) };
@ -576,15 +563,7 @@ fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect:
&& let Some(p) = hover
{
let ev = PointerEvent { kind: PointerKind::DoubleClick, pos: xf.to_doc(p), mods: mods(m, space), pressure: 1.0 };
let before = app.session.tool_id().to_string();
dispatch(app, &ev, view);
// A double-click on type switched a selection tool to the Type tool: the caret goes where
// the type was clicked, so typing edits it at once.
if before != "type" && app.session.tool_id() == "type" {
for kind in [PointerKind::Down, PointerKind::Up] {
dispatch(app, &PointerEvent { kind, ..ev }, view);
}
}
}
if drag.is_some() || pointer.is_moving() {
ui.ctx().request_repaint();
@ -701,39 +680,11 @@ pub(crate) fn ruler_label(v: f64, step: f64) -> String {
}
/// The rulers, numbered in `unit` (the General unit).
/// The top ruler, the left ruler and the box where they meet.
fn ruler_rects(full: egui::Rect) -> [egui::Rect; 3] {
let top = egui::Rect::from_min_max(pos2(full.left() + RULER, full.top()), pos2(full.right(), full.top() + RULER));
let left = egui::Rect::from_min_max(pos2(full.left(), full.top() + RULER), pos2(full.left() + RULER, full.bottom()));
[top, left, egui::Rect::from_min_size(full.min, vec2(RULER, RULER))]
}
/// A drag from a ruler onto the canvas makes a guide where the button is released: a horizontal
/// one from the top ruler, a vertical one from the left ruler. Released anywhere else, it makes
/// none.
fn ruler_guides(app: &mut VectorcraftApp, ui: &Ui, full: egui::Rect, canvas: egui::Rect, xf: &Xf, t: &Tokens) {
let [top, left, _] = ruler_rects(full);
for (r, vertical, id) in [(top, false, "ruler-top"), (left, true, "ruler-left")] {
let resp = ui.interact(r, egui::Id::new(id), Sense::drag());
let Some(p) = resp.interact_pointer_pos().filter(|p| canvas.contains(*p)) else { continue };
if resp.drag_stopped() {
let d = xf.to_doc(p);
// The new guide shows even if guides were hidden.
app.ui.view.guides = true;
if let Err(e) = app.run("guide.add", json!({ "vertical": vertical, "pos": if vertical { d.x } else { d.y } })) {
app.status(e);
}
} else if resp.dragged() {
let line =
if vertical { [pos2(p.x, canvas.top()), pos2(p.x, canvas.bottom())] } else { [pos2(canvas.left(), p.y), pos2(canvas.right(), p.y)] };
ui.painter_at(canvas).line_segment(line, Stroke::new(1.0, t.guide));
}
}
}
fn rulers(ui: &Ui, full: egui::Rect, xf: &Xf, hover: Option<Point>, unit: Unit, t: &Tokens) {
let p = ui.painter();
let [top, left, corner] = ruler_rects(full);
let top = egui::Rect::from_min_max(pos2(full.left() + RULER, full.top()), pos2(full.right(), full.top() + RULER));
let left = egui::Rect::from_min_max(pos2(full.left(), full.top() + RULER), pos2(full.left() + RULER, full.bottom()));
let corner = egui::Rect::from_min_size(full.min, vec2(RULER, RULER));
for r in [top, left, corner] {
p.rect_filled(r, 0.0, t.ruler);
}
@ -847,18 +798,11 @@ fn c32(rgb: [u8; 3]) -> Color32 {
Color32::from_rgb(rgb[0], rgb[1], rgb[2])
}
/// Outline of a node for highlighting (paths, compound children, area type frames, other
/// text/image bounds).
/// Outline of a node for highlighting (paths, compound children, text/image bounds).
fn node_outline(n: &Node) -> BezPath {
let mut bp = BezPath::new();
walk_drawn(n, &mut |c| match &c.kind {
NodeKind::Path { path, .. } => bp.extend(path.to_bezpath()),
// Area type shows its frame: the type area Direct Selection reshapes.
NodeKind::Text(t) if c.perspective.is_none() && matches!(t.kind, vectorcraft_doc::TextKind::Area { .. }) => {
if let Some(frame) = t.area_frame() {
bp.extend(frame.to_bezpath());
}
}
NodeKind::Text(_) | NodeKind::Image(_) | NodeKind::SymbolInstance { .. } => {
if let Some(b) = c.geometric_bounds() {
bp.extend(vectorcraft_geom::shapes::rectangle(b).to_bezpath());
@ -926,14 +870,6 @@ fn panel_drop(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, xf: &Xf)
return;
}
let Some(d) = resp.dnd_release_payload::<widgets::PanelDrag>() else { return };
// A symbol from the Symbols panel: an instance centred where it is dropped, on art or not.
if let widgets::PanelDrag::Symbol(name) = &*d {
let at = xf.to_doc(pos);
if let Err(e) = app.run("symbol.place", json!({"name": name, "x": at.x, "y": at.y})) {
app.status(e);
}
return;
}
let Some(hit) = hit_at(app, xf.to_doc(pos), xf.zoom) else { return };
let Some(st) = app.session.active() else { return };
let (cmd, params) = match &*d {
@ -958,9 +894,8 @@ fn panel_drop(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, xf: &Xf)
let add = ui.input(|i| i.modifiers.alt);
("graphicStyle.apply", json!({"name": name, "ids": [hit.top_object(st.isolation).0], "add": add}))
}
// Art dragged back onto the canvas: its move was already dropped. (A symbol was placed
// above.)
widgets::PanelDrag::Art(_) | widgets::PanelDrag::Symbol(_) => return,
// Art dragged back onto the canvas: its move was already dropped.
widgets::PanelDrag::Art(_) => return,
};
if let Err(e) = app.run(cmd, params) {
app.status(e);
@ -1196,10 +1131,8 @@ fn selection_overlay(app: &mut VectorcraftApp, p: &egui::Painter, xf: &Xf) {
{
anchor_square(p, xf.to_screen(b.center()), color, true, 4.0);
}
// Text: baseline marker (area type shows its frame instead, which may not be a rectangle).
if let NodeKind::Text(tx) = &n.kind
&& !matches!(tx.kind, vectorcraft_doc::TextKind::Area { .. })
{
// Text: baseline marker.
if let NodeKind::Text(tx) = &n.kind {
let o = xf.to_screen(tx.xf * Point::ZERO);
let b = n.geometric_bounds().unwrap_or_default();
let e = xf.to_screen(Point::new(b.x1, (tx.xf * Point::ZERO).y));
@ -1542,181 +1475,6 @@ mod tests {
assert_eq!(selected(&app), vec![vectorcraft_doc::NodeId(id)]);
}
#[test]
fn a_drag_from_a_ruler_onto_the_canvas_makes_a_guide() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
app.ui.view.rulers = true;
app.ui.view.guides = false;
// A drawing tool: the drag must not draw.
app.select_tool("rectangle");
let ctx = egui::Context::default();
frame(&mut app, &ctx, vec![]);
let rect = app.canvas_rect.unwrap();
let xf = Xf::new(rect, app.view().unwrap());
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
let drag = |app: &mut VectorcraftApp, from: Pos2, to: Pos2| {
frame(app, &ctx, vec![egui::Event::PointerMoved(from)]);
frame(app, &ctx, vec![button(from, true)]);
frame(app, &ctx, vec![egui::Event::PointerMoved(to)]);
frame(app, &ctx, vec![button(to, false)]);
};
let guides = |app: &VectorcraftApp| app.session.active().unwrap().doc.guides.iter().map(|g| (g.vertical, g.pos)).collect::<Vec<_>>();
// From the top ruler: a horizontal guide where the button was released.
let to = pos2(rect.center().x, rect.top() + 120.0);
drag(&mut app, pos2(rect.center().x, rect.top() - RULER / 2.0), to);
assert_eq!(guides(&app), [(false, xf.to_doc(to).y)]);
assert!(app.ui.view.guides, "the new guide shows");
// From the left ruler: a vertical one.
let to2 = pos2(rect.left() + 200.0, rect.center().y);
drag(&mut app, pos2(rect.left() - RULER / 2.0, rect.center().y), to2);
assert_eq!(guides(&app), [(false, xf.to_doc(to).y), (true, xf.to_doc(to2).x)]);
// Released back on the ruler: no guide.
drag(&mut app, pos2(rect.center().x, rect.top() - RULER / 2.0), pos2(rect.center().x + 40.0, rect.top() - 4.0));
assert_eq!(guides(&app).len(), 2);
assert_eq!(app.session.active().unwrap().doc.art_bounds(), None, "the tool drew nothing");
}
#[test]
fn cmd_with_another_tool_drags_with_the_selection_tool_used_last() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].as_u64().unwrap();
let ctx = egui::Context::default();
frame(&mut app, &ctx, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let cmd_frame = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
let events = std::iter::once(egui::Event::ModifiersChanged(egui::Modifiers::COMMAND)).chain(events).collect();
let raw = egui::RawInput { screen_rect: Some(screen), events, ..Default::default() };
let mut out = ctx.run_ui(raw, |ui| show(app, ui));
out.textures_delta.clear();
};
let button =
|pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::COMMAND };
// A Cmd drag from `a` to `b` with the Pen tool; → the tool that did it.
let cmd_drag = |app: &mut VectorcraftApp, a: Pos2, b: Pos2| {
app.select_tool("pen");
cmd_frame(app, vec![egui::Event::PointerMoved(a), button(a, true)]);
let used = app.session.tool_id().to_string();
cmd_frame(app, vec![egui::Event::PointerMoved(b)]);
cmd_frame(app, vec![button(b, false)]);
assert_eq!(app.session.tool_id(), "pen", "back to the Pen tool");
used
};
let bounds = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().geometric_bounds().unwrap();
// Direct Selection used last: the drag moves the rectangle's bottom-right corner only.
app.select_tool("directSelection");
let corner = xf.to_screen(Point::new(200.0, 150.0));
assert_eq!(cmd_drag(&mut app, corner, corner + vec2(20.0, 20.0)), "directSelection");
let b = bounds(&app);
assert_eq!((b.x0, b.y0), (100.0, 100.0));
assert!((b.x1 - xf.to_doc(corner + vec2(20.0, 20.0)).x).abs() < 1e-6, "{b:?}");
// Group Selection, then Selection: each is the one used.
app.select_tool("groupSelection");
let inside = xf.to_screen(Point::new(130.0, 120.0));
assert_eq!(cmd_drag(&mut app, inside, inside), "groupSelection");
app.select_tool("selection");
assert_eq!(cmd_drag(&mut app, inside, inside), "selection");
}
#[test]
fn cmd_space_zooms_and_space_pans_whatever_the_tool() {
use egui::{Event, Modifiers};
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
app.select_tool("rectangle");
let ctx = egui::Context::default();
frame(&mut app, &ctx, vec![]);
let at = app.canvas_rect.unwrap().center();
let space = |pressed, modifiers| Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers };
let button = |pos, pressed, modifiers| Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers };
// A drag from `at` to `to` with Space and `held` down.
let drag = |app: &mut VectorcraftApp, held: Modifiers, to: Pos2| {
frame(app, &ctx, vec![Event::ModifiersChanged(held), space(true, held), Event::PointerMoved(at)]);
frame(app, &ctx, vec![button(at, true, held)]);
frame(app, &ctx, vec![Event::PointerMoved(to)]);
frame(app, &ctx, vec![button(to, false, held)]);
frame(app, &ctx, vec![space(false, held), Event::ModifiersChanged(Modifiers::NONE)]);
};
let z0 = app.view().unwrap().zoom;
drag(&mut app, Modifiers::COMMAND, at);
let z1 = app.view().unwrap().zoom;
assert_eq!(z1, crate::state::next_zoom(z0, true), "Cmd+Space click zooms in");
drag(&mut app, Modifiers::COMMAND | Modifiers::ALT, at);
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(z1, false), "Cmd+Alt+Space click zooms out");
assert_eq!(app.session.active().unwrap().doc.art_bounds(), None, "the Rectangle tool drew nothing");
// Space alone pans, with the Zoom tool too.
app.select_tool("zoom");
let before = *app.view().unwrap();
drag(&mut app, Modifiers::NONE, at + vec2(30.0, 0.0));
let after = *app.view().unwrap();
assert_eq!(after.zoom, before.zoom);
assert!((after.center.x - (before.center.x - 30.0 / before.zoom)).abs() < 1e-6, "{before:?} → {after:?}");
}
#[test]
fn double_clicking_type_with_the_selection_tool_puts_the_caret_there() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
let id = app.session.execute("text.create", &json!({"x": 100, "y": 150, "text": "Hello world", "size": 24})).unwrap()["id"].as_u64().unwrap();
app.session.execute("select.none", &json!({})).unwrap();
app.select_tool("selection");
let ctx = egui::Context::default();
let timed = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
let mut out =
ctx.run_ui(egui::RawInput { screen_rect: Some(screen), time: Some(time), events, ..Default::default() }, |ui| show(app, ui));
out.textures_delta.clear();
};
timed(&mut app, 0.0, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let text = |app: &VectorcraftApp| match &app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().kind {
NodeKind::Text(t) => t.plain_text(),
_ => panic!("not text"),
};
// Double-click the middle of the text.
let b = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().geometric_bounds().unwrap();
let at = xf.to_screen(b.center());
let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
timed(&mut app, 1.0, vec![egui::Event::PointerMoved(at), button(true), button(false), button(true), button(false)]);
timed(&mut app, 1.1, vec![]);
// The Type tool edits the text, with the caret inside it, where it was clicked: typing goes
// into the text, not to tool shortcuts (X would swap fill and stroke).
assert_eq!(app.session.tool_id(), "type");
assert!(app.session.tool_wants_text());
let o = app.session.tool_options();
assert_eq!(o["editing"], json!(id));
let caret = o["caret"].as_u64().unwrap();
assert!((1..11).contains(&caret), "caret {caret}");
app.session.tool_text("X", app.view_info()).unwrap();
let t = text(&app);
assert_eq!((t.len(), t.find('X')), (12, Some(caret as usize)), "{t}");
}
#[test]
fn a_symbol_dropped_on_the_canvas_is_placed_there() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 20})).unwrap();
let name = app.session.execute("symbol.new", &json!({})).unwrap()["name"].as_str().unwrap().to_string();
app.session.execute("select.none", &json!({})).unwrap();
let ctx = egui::Context::default();
frame(&mut app, &ctx, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
// Released over empty canvas: an instance centred there.
let at = xf.to_screen(Point::new(250.0, 180.0));
egui::DragAndDrop::set_payload(&ctx, widgets::PanelDrag::Symbol(name.clone()));
let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() };
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), up]);
let st = app.session.active().unwrap();
let placed = st.selection.objects.first().copied().unwrap();
let n = st.doc.node(placed).unwrap();
assert!(matches!(&n.kind, NodeKind::SymbolInstance { symbol, .. } if *symbol == name));
let c = n.geometric_bounds().unwrap().center();
assert!((c - xf.to_doc(at)).hypot() < 1e-6, "{c:?}");
}
#[test]
fn middle_drag_pans_the_view_with_any_tool() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());

View File

@ -372,25 +372,13 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
},
);
ui.separator();
// The artboard navigator: first, previous, the current artboard's number, next, last.
let nab = app.session.active().map(|d| d.doc.artboards.len()).unwrap_or(0);
let cur = app.view().map_or(0, |v| v.artboard).min(nab.saturating_sub(1));
let mut go = None;
for (icon, to) in [("chevrons-left", "first"), ("chevron-left", "previous")] {
if widgets::icon_button_enabled(ui, icon, "", false, cur > 0, 18.0).clicked() {
go = Some(to);
}
for icon in ["chevrons-left", "chevron-left"] {
widgets::icon_button(ui, icon, "", false, 18.0);
}
ui.label(egui::RichText::new(if nab > 0 { (cur + 1).to_string() } else { "–".into() }).size(11.5));
for (icon, to) in [("chevron-right", "next"), ("chevrons-right", "last")] {
if widgets::icon_button_enabled(ui, icon, "", false, cur + 1 < nab, 18.0).clicked() {
go = Some(to);
}
}
if let Some(to) = go
&& let Err(e) = app.run("view.goToArtboard", json!({ "index": to }))
{
app.status(e);
ui.label(egui::RichText::new(if nab > 0 { "1" } else { "–" }).size(11.5));
for icon in ["chevron-right", "chevrons-right"] {
widgets::icon_button(ui, icon, "", false, 18.0);
}
ui.separator();
let tool = vectorcraft_tools::tool_info(app.session.tool_id())
@ -679,62 +667,6 @@ mod tests {
}
}
/// One headless frame of the status bar; returns the artboard navigator's buttons, left to
/// right: first, previous, next, last.
fn navigator(app: &mut crate::VectorcraftApp, ctx: &egui::Context, events: Vec<egui::Event>) -> Vec<egui::Rect> {
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 300.0));
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| super::status_bar(app, ui));
out.textures_delta.clear();
let size = egui::vec2(18.0, 18.0);
let mut r: Vec<egui::Rect> =
ctx.viewport(|vp| vp.prev_pass.widgets.layers().flat_map(|(_, w)| w.iter()).filter(|w| w.rect.size() == size).map(|w| w.rect).collect());
r.sort_by(|a, b| a.left().total_cmp(&b.left()));
r
}
#[test]
fn the_artboard_navigator_goes_to_artboards_and_fitting_shows_the_current_one() {
use vectorcraft_geom::Point;
let mut app = crate::VectorcraftApp::new(Session::new(), Default::default());
// Three 200 × 100 artboards in a row, centred at x = 100, 320 and 540.
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
app.run("artboard.new", json!({})).unwrap();
app.run("artboard.new", json!({})).unwrap();
app.canvas_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(460.0, 260.0)));
let ctx = egui::Context::default();
let buttons = navigator(&mut app, &ctx, vec![]);
assert_eq!(buttons.len(), 4);
let click = |app: &mut crate::VectorcraftApp, r: egui::Rect| {
let b = |pressed| egui::Event::PointerButton {
pos: r.center(),
button: egui::PointerButton::Primary,
pressed,
modifiers: Default::default(),
};
navigator(app, &ctx, vec![egui::Event::PointerMoved(r.center())]);
navigator(app, &ctx, vec![b(true)]);
navigator(app, &ctx, vec![b(false)]);
};
let at = |app: &crate::VectorcraftApp| (app.view().unwrap().artboard, app.view().unwrap().center);
click(&mut app, buttons[2]);
assert_eq!(at(&app), (1, Point::new(320.0, 50.0)), "next");
click(&mut app, buttons[3]);
assert_eq!(at(&app), (2, Point::new(540.0, 50.0)), "last");
click(&mut app, buttons[1]);
assert_eq!(at(&app), (1, Point::new(320.0, 50.0)), "previous");
// Fit Artboard in Window and Actual Size show the navigator's artboard.
app.run("view.setZoom", json!({"zoom": 300, "center": [0, 0]})).unwrap();
app.run("view.fitArtboard", json!({})).unwrap();
assert_eq!(at(&app), (1, Point::new(320.0, 50.0)));
app.run("view.actualSize", json!({})).unwrap();
assert_eq!((at(&app).1, app.view().unwrap().zoom), (Point::new(320.0, 50.0), 1.0));
click(&mut app, buttons[0]);
assert_eq!(at(&app), (0, Point::new(100.0, 50.0)), "first");
// The command also takes an index, clamped to the last artboard.
assert_eq!(app.run("view.goToArtboard", json!({"index": 9})), Ok(json!({"index": 2})));
assert!(app.run("view.goToArtboard", json!({"index": "sideways"})).is_err());
}
#[test]
fn the_tab_title_names_the_opacity_mask_while_it_is_edited() {
let mut s = Session::new();

View File

@ -26,7 +26,7 @@ fn lengths(command: &str) -> &'static [&'static str] {
"artboard.rearrange" => &["spacing"],
"perspective.grid.set" => &["cell", "distance"],
"object.repeat.options" => &["radius", "hSpacing", "vSpacing"],
"text.areaOptions" => &["width", "height", "gutter", "inset", "firstBaselineMin"],
"text.areaOptions" => &["gutter", "inset", "firstBaselineMin"],
_ => &[],
}
}

View File

@ -163,7 +163,7 @@ fn window(ctx: &egui::Context, id: &str, margin: i8, add: impl FnOnce(&mut egui:
.collapsible(false)
.resizable(false)
.title_bar(false)
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
.anchor(egui::Align2::CENTER_CENTER, [0.0, -20.0])
.frame(egui::Frame::window(&ctx.global_style()).fill(t.panel).inner_margin(egui::Margin::same(margin)))
.show(ctx, add);
}
@ -193,27 +193,20 @@ fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
sync(app, &mut d);
let t = Tokens::get(ctx);
let mut b = Buttons::default();
let width = (ctx.content_rect().width() - 36.0).clamp(360.0, 1020.0);
let height = (ctx.content_rect().height() - 48.0).clamp(200.0, HEIGHT + 36.0);
window(ctx, KIND, 0, |ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.horizontal_top(|ui| {
egui::Frame::NONE.inner_margin(egui::Margin { left: 22, right: 14, top: 14, bottom: 18 }).show(ui, |ui| {
ui.vertical(|ui| {
ui.set_width((width - DETAILS - 72.0).max(160.0));
ui.set_height(height - 32.0);
ui.set_width(640.0);
ui.set_min_height(HEIGHT - 32.0);
presets(app, ui, &mut d);
});
});
egui::Frame::NONE.fill(t.panel_darker).inner_margin(egui::Margin::same(18)).show(ui, |ui| {
ui.vertical(|ui| {
ui.set_width(DETAILS);
ui.set_height(height - 36.0);
egui::ScrollArea::vertical().id_salt("newdoc-details").max_height(height - 80.0).auto_shrink([false, false]).show(ui, |ui| {
details(app, ui, &mut d);
});
ui.add_space(12.0);
footer(ui, &mut b, "Create");
ui.set_min_height(HEIGHT);
details(app, ui, &mut d, &mut b);
});
});
});
@ -226,8 +219,7 @@ fn presets(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
let t = Tokens::get(ui.ctx());
let names: Vec<&str> = newdoc::category_names().collect();
let cat = names.iter().position(|n| n.eq_ignore_ascii_case(&d.str("category"))).unwrap_or(0);
let tab = egui::ScrollArea::horizontal().id_salt("newdoc-tabs").show(ui, |ui| widgets::tab_bar(ui, &names, cat)).inner;
if let Some(i) = tab {
if let Some(i) = widgets::tab_bar(ui, &names, cat) {
d.fields.insert("category".into(), json!(names[i]));
}
let list = names.get(cat).and_then(|c| newdoc::category(&app.session, c)).unwrap_or_default();
@ -246,7 +238,7 @@ fn presets(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
ui.label(egui::RichText::new(hint).color(t.text_dim));
return;
}
egui::ScrollArea::vertical().id_salt(("newdoc-presets", cat)).max_height(ui.available_height()).auto_shrink([false, false]).show(ui, |ui| {
egui::ScrollArea::vertical().id_salt(("newdoc-presets", cat)).max_height(HEIGHT - 110.0).auto_shrink([false, false]).show(ui, |ui| {
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = egui::vec2(12.0, 12.0);
let (w, h, preset) = (d.f64("width", 0.0), d.f64("height", 0.0), d.str("preset"));
@ -304,9 +296,10 @@ pub fn preset_card(ui: &mut egui::Ui, s: &DocSettings, selected: bool) -> egui::
}
/// The Preset Details column.
fn details(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
fn details(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog, b: &mut Buttons) {
let t = Tokens::get(ui.ctx());
ui.spacing_mut().item_spacing = egui::vec2(6.0, 4.0);
let top = ui.cursor().top();
ui.label(egui::RichText::new(tl!("PRESET DETAILS")).font(theme::semibold(11.0)).color(t.text_dim));
ui.add_space(8.0);
ui.horizontal(|ui| {
@ -358,11 +351,10 @@ fn details(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
if widgets::flat_button(ui, tl!("More Settings"), DETAILS).clicked() {
d.kind = MORE.into();
}
}
fn footer(ui: &mut egui::Ui, b: &mut Buttons, create: &str) {
// Close and Create at the bottom right.
ui.add_space((HEIGHT - (ui.cursor().top() - top) - 28.0).max(12.0));
ui.allocate_ui_with_layout(egui::vec2(ui.available_width(), 28.0), egui::Layout::right_to_left(egui::Align::Center), |ui| {
b.create = widgets::primary_button(ui, tl!(create)).clicked();
b.create = widgets::primary_button(ui, tl!("Create")).clicked();
ui.add_space(8.0);
b.close = widgets::secondary_button(ui, tl!("Close")).clicked();
});
@ -499,89 +491,87 @@ fn show_more(app: &mut VectorcraftApp, ctx: &egui::Context) {
ui.set_width(560.0);
ui.label(egui::RichText::new(tl!("More Settings")).font(theme::semibold(16.0)).color(t.text));
ui.add_space(12.0);
egui::ScrollArea::vertical().id_salt("newdoc-more-body").max_height((ctx.content_rect().height() - 160.0).max(100.0)).show(ui, |ui| {
widgets::label_row(ui, tl!("Name:"), L, |ui| {
form::text(ui, &mut d, "name", 300.0);
});
// Profile: the preset categories (the tabs); Size: the profile's presets.
let profiles: Vec<&str> = newdoc::CATEGORIES.iter().map(|c| c.0).collect();
let profile = profiles.iter().find(|p| p.eq_ignore_ascii_case(&d.str("category"))).copied().unwrap_or("[Custom]");
widgets::label_row(ui, tl!("Profile:"), L, |ui| {
if let Some(p) = widgets::dropdown(ui, "newdoc-profile", profile, &profiles, 220.0).and_then(|i| profiles.get(i)) {
d.fields.insert("category".into(), json!(p));
if let Some(first) = newdoc::category(&app.session, p).and_then(|v| v.into_iter().next()) {
apply(&mut d, &first);
}
widgets::label_row(ui, tl!("Name:"), L, |ui| {
form::text(ui, &mut d, "name", 300.0);
});
// Profile: the preset categories (the tabs); Size: the profile's presets.
let profiles: Vec<&str> = newdoc::CATEGORIES.iter().map(|c| c.0).collect();
let profile = profiles.iter().find(|p| p.eq_ignore_ascii_case(&d.str("category"))).copied().unwrap_or("[Custom]");
widgets::label_row(ui, tl!("Profile:"), L, |ui| {
if let Some(p) = widgets::dropdown(ui, "newdoc-profile", profile, &profiles, 220.0).and_then(|i| profiles.get(i)) {
d.fields.insert("category".into(), json!(p));
if let Some(first) = newdoc::category(&app.session, p).and_then(|v| v.into_iter().next()) {
apply(&mut d, &first);
}
});
}
});
ui.add_space(6.0);
let (lay, cols, spacing, rtl) = layout(&d);
let n = d.f64("artboards", 1.0);
let several = n > 1.0;
widgets::label_row(ui, tl!("Number of Artboards:"), L, |ui| {
artboards(ui, &mut d, 76.0);
ui.add_space(10.0);
for (l, icon) in [
(ArtboardLayout::GridByRow, "dc-grid-view"),
(ArtboardLayout::GridByColumn, "grid-3x3"),
(ArtboardLayout::Row, "arrow-left-right"),
(ArtboardLayout::Column, "arrow-up-down"),
] {
if widgets::icon_button_enabled(ui, icon, l.label(), lay == l, several, 26.0).clicked() {
set_layout(&mut d, "layout", json!(l.id()));
}
}
ui.add_space(6.0);
let (lay, cols, spacing, rtl) = layout(&d);
let n = d.f64("artboards", 1.0);
let several = n > 1.0;
widgets::label_row(ui, tl!("Number of Artboards:"), L, |ui| {
artboards(ui, &mut d, 76.0);
ui.add_space(10.0);
for (l, icon) in [
(ArtboardLayout::GridByRow, "dc-grid-view"),
(ArtboardLayout::GridByColumn, "grid-3x3"),
(ArtboardLayout::Row, "arrow-left-right"),
(ArtboardLayout::Column, "arrow-up-down"),
] {
if widgets::icon_button_enabled(ui, icon, l.label(), lay == l, several, 26.0).clicked() {
set_layout(&mut d, "layout", json!(l.id()));
}
if widgets::icon_button_enabled(ui, "chevrons-left", tl!("Change to Right-to-Left Layout"), rtl, several, 26.0).clicked() {
set_layout(&mut d, "rightToLeft", json!(!rtl));
}
});
ui.add_enabled_ui(several, |ui| {
widgets::label_row(ui, tl!("Spacing:"), L, |ui| {
if let Some(v) = widgets::num_field(ui, "newdoc-spacing", Some(spacing), unit(&d), 100.0) {
set_layout(&mut d, "spacing", json!(v.max(0.0)));
}
ui.add_space(6.0);
if widgets::icon_button_enabled(ui, "chevrons-left", tl!("Change to Right-to-Left Layout"), rtl, several, 26.0).clicked() {
set_layout(&mut d, "rightToLeft", json!(!rtl));
}
});
ui.add_enabled_ui(several, |ui| {
widgets::label_row(ui, tl!("Spacing:"), L, |ui| {
if let Some(v) = widgets::num_field(ui, "newdoc-spacing", Some(spacing), unit(&d), 100.0) {
set_layout(&mut d, "spacing", json!(v.max(0.0)));
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Columns:")).color(t.text));
let grid = matches!(lay, ArtboardLayout::GridByRow | ArtboardLayout::GridByColumn);
ui.add_enabled_ui(grid, |ui| {
if let Some(v) = widgets::spin_plain(ui, "newdoc-columns", cols as f64, "", 0, 76.0, 1.0, 1.0, &[]) {
set_layout(&mut d, "columns", json!(v.round().clamp(1.0, n) as u64));
}
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Columns:")).color(t.text));
let grid = matches!(lay, ArtboardLayout::GridByRow | ArtboardLayout::GridByColumn);
ui.add_enabled_ui(grid, |ui| {
if let Some(v) = widgets::spin_plain(ui, "newdoc-columns", cols as f64, "", 0, 76.0, 1.0, 1.0, &[]) {
set_layout(&mut d, "columns", json!(v.round().clamp(1.0, n) as u64));
}
});
});
});
ui.add_space(6.0);
let sizes = newdoc::category(&app.session, profile).unwrap_or_default();
let size_names: Vec<&str> = sizes.iter().map(|s| s.name.as_str()).collect();
let preset = d.str("preset");
widgets::label_row(ui, tl!("Size:"), L, |ui| {
// The profile's sizes are built in; the preset may be one the user saved.
let shown = if preset.is_empty() { tl!("Custom") } else { preset_name(&preset) };
if let Some(s) = super::mixed_dropdown(ui, "newdoc-size", shown, &size_names, 220.0, |_| true).and_then(|i| sizes.get(i)) {
apply(&mut d, s);
}
});
let unit = unit(&d);
widgets::label_row(ui, tl!("Width:"), L, |ui| {
form::length(ui, &mut d, "width", unit, 120.0);
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Units:")).color(t.text));
units_dropdown(ui, &mut d, 120.0);
});
widgets::label_row(ui, tl!("Height:"), L, |ui| {
form::length(ui, &mut d, "height", unit, 120.0);
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Orientation:")).color(t.text));
orientation(ui, &mut d);
});
ui.add_space(4.0);
widgets::label_row(ui, tl!("Bleed:"), L, |ui| form::bleed(ui, &mut d, unit, 64.0));
ui.add_space(4.0);
widgets::label_row(ui, tl!("Background Contents:"), L, |ui| background(ui, &mut d, 220.0));
ui.add_space(8.0);
advanced(ui, &mut d, L, 220.0);
});
ui.add_space(6.0);
let sizes = newdoc::category(&app.session, profile).unwrap_or_default();
let size_names: Vec<&str> = sizes.iter().map(|s| s.name.as_str()).collect();
let preset = d.str("preset");
widgets::label_row(ui, tl!("Size:"), L, |ui| {
// The profile's sizes are built in; the preset may be one the user saved.
let shown = if preset.is_empty() { tl!("Custom") } else { preset_name(&preset) };
if let Some(s) = super::mixed_dropdown(ui, "newdoc-size", shown, &size_names, 220.0, |_| true).and_then(|i| sizes.get(i)) {
apply(&mut d, s);
}
});
let unit = unit(&d);
widgets::label_row(ui, tl!("Width:"), L, |ui| {
form::length(ui, &mut d, "width", unit, 120.0);
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Units:")).color(t.text));
units_dropdown(ui, &mut d, 120.0);
});
widgets::label_row(ui, tl!("Height:"), L, |ui| {
form::length(ui, &mut d, "height", unit, 120.0);
ui.add_space(20.0);
ui.label(egui::RichText::new(tl!("Orientation:")).color(t.text));
orientation(ui, &mut d);
});
ui.add_space(4.0);
widgets::label_row(ui, tl!("Bleed:"), L, |ui| form::bleed(ui, &mut d, unit, 64.0));
ui.add_space(4.0);
widgets::label_row(ui, tl!("Background Contents:"), L, |ui| background(ui, &mut d, 220.0));
ui.add_space(8.0);
advanced(ui, &mut d, L, 220.0);
ui.add_space(16.0);
ui.horizontal(|ui| {
templates = widgets::secondary_button(ui, tl!("Templates…")).on_hover_text(tl!("New from Template")).clicked();
@ -612,37 +602,6 @@ mod tests {
use crate::VectorcraftApp;
#[test]
fn create_controls_stay_visible_on_short_screens() {
for height in [500.0, 600.0] {
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
crate::theme::apply(&ctx, Default::default());
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.newDialog", json!({})).unwrap();
set(&mut app, "advanced", json!(true));
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, height));
for (kind, label) in [(super::KIND, "Create"), (super::MORE, "Create Document")] {
app.ui.dialog.as_mut().unwrap().kind = kind.into();
let mut found = false;
for _ in 0..4 {
let mut out =
ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| crate::dialogs::show(&mut app, ui.ctx()));
for shape in &out.shapes {
if let egui::Shape::Text(text) = &shape.shape
&& text.galley.text() == label
{
assert!(screen.contains_rect(text.galley.rect.translate(text.pos.to_vec2())), "{kind}: create button outside screen");
found = true;
}
}
out.textures_delta.clear();
}
assert!(found, "{kind}: visible create button");
}
}
}
/// Cards translate the built-in presets' names only: Recent and Saved show the user's names.
#[test]
fn only_built_in_preset_names_are_translated() {

View File

@ -86,57 +86,38 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
pub fn floating_panel(app: &mut VectorcraftApp, ctx: &egui::Context) {
let Some(id) = app.ui.open_panel.clone() else { return };
let Some((_, label, _)) = ICON_PANELS.iter().find(|p| p.0 == id) else { return };
let display = tl!(label);
let t = Tokens::get(ctx);
let screen = ctx.content_rect();
let rail = egui::containers::panel::PanelState::load(ctx, egui::Id::new("icon_column"))
.map_or(screen.right() - ICON_COL - 300.0, |p| p.outer_rect.left());
let right = (rail - 2.0).max(screen.left() + 1.0);
let top = (screen.top() + 110.0).min(screen.bottom() - 100.0).max(screen.top());
let bounds = egui::Rect::from_min_max(screen.left_top(), egui::pos2(right, screen.bottom()));
let width = (bounds.width() - 2.0).clamp(1.0, 400.0);
// Pinned by its right edge, 6 points left of the icon column: a panel wider than its 256
// points grows towards the canvas rather than over the panel icons.
let right = screen.right() - ICON_COL - 300.0 - 6.0;
let mut open = true;
egui::Area::new(egui::Id::new("icon-panel"))
.order(egui::Order::Foreground)
.anchor(egui::Align2::RIGHT_TOP, vec2(0.0, top - screen.top()))
.constrain_to(bounds)
.show(ctx, |ui| {
egui::Frame::popup(ui.style()).fill(t.panel).corner_radius(CornerRadius::same(4)).inner_margin(egui::Margin::ZERO).show(ui, |ui| {
ui.set_min_width(width.min(280.0));
ui.set_max_width(width);
ui.set_max_height((screen.bottom() - top - 2.0).max(28.0));
let (mut strip, _) = ui.allocate_exact_size(vec2(width.min(280.0), 26.0), Sense::hover());
egui::ScrollArea::both()
.id_salt(("icon-panel-body", &id))
.max_width(width)
.max_height((screen.bottom() - top - 34.0).max(1.0))
.auto_shrink([true, true])
.show(ui, |ui| {
egui::Frame::NONE.inner_margin(egui::Margin::same(10)).show(ui, |ui| {
ui.set_width(width.min(280.0) - 20.0);
panels::show_icon_panel(app, ui, &id);
});
});
// Content can require more room than the preferred width. Size the entire header
// after laying it out, keeping its controls at the actual panel edge.
strip.max.x = ui.min_rect().right();
ui.painter().rect_filled(strip, CornerRadius { nw: 4, ne: 4, sw: 0, se: 0 }, t.panel_darker);
let tab = egui::Rect::from_min_size(
strip.min,
vec2(ui.painter().layout_no_wrap(display.to_string(), theme::semibold(12.0), t.text).size().x + 24.0, 26.0),
);
ui.painter().rect_filled(tab, CornerRadius { nw: 4, ne: 0, sw: 0, se: 0 }, t.panel);
ui.painter().text(tab.left_center() + vec2(12.0, 0.0), egui::Align2::LEFT_CENTER, display, theme::semibold(12.0), t.text);
let close = egui::Rect::from_center_size(strip.right_center() - vec2(13.0, 0.0), vec2(14.0, 14.0));
let cr = ui.interact(close, ui.id().with("close-panel"), Sense::click());
icons::paint(ui, "chevrons-right", close, if cr.hovered() { t.text } else { t.text_dim });
if cr.clicked() {
open = false;
}
let menu_r = egui::Rect::from_center_size(strip.right_center() - vec2(34.0, 0.0), vec2(16.0, 16.0));
panels::panel_menu(app, ui, &id, menu_r);
let area = egui::Area::new(egui::Id::new("icon-panel")).order(egui::Order::Foreground).pivot(egui::Align2::RIGHT_TOP);
area.fixed_pos(egui::pos2(right, 110.0)).show(ctx, |ui| {
egui::Frame::popup(ui.style()).fill(t.panel).corner_radius(CornerRadius::same(4)).inner_margin(egui::Margin::ZERO).show(ui, |ui| {
ui.set_width(256.0);
let (strip, _) = ui.allocate_exact_size(vec2(256.0, 26.0), Sense::hover());
ui.painter().rect_filled(strip, CornerRadius { nw: 4, ne: 4, sw: 0, se: 0 }, t.panel_darker);
let tab = egui::Rect::from_min_size(
strip.min,
vec2(ui.painter().layout_no_wrap(tl!(label).to_string(), theme::semibold(12.0), t.text).size().x + 24.0, 26.0),
);
ui.painter().rect_filled(tab, CornerRadius { nw: 4, ne: 0, sw: 0, se: 0 }, t.panel);
ui.painter().text(tab.left_center() + vec2(12.0, 0.0), egui::Align2::LEFT_CENTER, tl!(label), theme::semibold(12.0), t.text);
let close = egui::Rect::from_center_size(strip.right_center() - vec2(13.0, 0.0), vec2(14.0, 14.0));
let cr = ui.interact(close, ui.id().with("close-panel"), Sense::click());
icons::paint(ui, "chevrons-right", close, if cr.hovered() { t.text } else { t.text_dim });
if cr.clicked() {
open = false;
}
let menu_r = egui::Rect::from_center_size(strip.right_center() - vec2(34.0, 0.0), vec2(16.0, 16.0));
panels::panel_menu(app, ui, &id, menu_r);
egui::Frame::NONE.inner_margin(egui::Margin::same(10)).show(ui, |ui| {
ui.set_width(236.0);
panels::show_icon_panel(app, ui, &id);
});
});
});
if !open {
app.ui.open_panel = None;
}
@ -150,54 +131,6 @@ mod tests {
use super::*;
use crate::toolbar::tests::{wheel, widget_rects};
#[test]
fn all_floating_panels_fit_beside_the_actual_dock_and_share_a_full_width_header() {
for (size, dock_width, document) in
[(vec2(1440.0, 900.0), 230.0, true), (vec2(800.0, 500.0), 520.0, true), (vec2(1440.0, 900.0), 300.0, false)]
{
let ctx = egui::Context::default();
theme::install_fonts(&ctx);
theme::apply(&ctx, Default::default());
let mut app = VectorcraftApp::new(Session::new(), Default::default());
if document {
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
}
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size);
for &(id, _, _) in ICON_PANELS {
app.ui.open_panel = Some(id.into());
app.ui.status.clear();
let mut out = egui::FullOutput::default();
for k in 0..4 {
out = ctx.run_ui(egui::RawInput { time: Some(f64::from(k) + 1.0), screen_rect: Some(screen), ..Default::default() }, |ui| {
egui::Panel::right("dock").exact_size(dock_width).show(ui, |_| {});
egui::Panel::right("icon_column").exact_size(ICON_COL).show(ui, |_| {});
floating_panel(&mut app, ui.ctx());
});
out.textures_delta.clear();
}
let area = egui::AreaState::load(&ctx, egui::Id::new("icon-panel")).unwrap().rect();
let rail = egui::containers::panel::PanelState::load(&ctx, egui::Id::new("icon_column")).unwrap().outer_rect.left();
assert!(screen.contains_rect(area), "{id}: {area:?} outside {screen:?}");
assert!(app.ui.status.is_empty(), "{id}: painting a panel reported an error: {}", app.ui.status);
assert!(area.right() <= rail, "{id}: panel overlaps the icon column");
if id == "stroke" && size.y >= 900.0 {
assert!(area.height() > 400.0, "a tall panel should use available height before scrolling: {area:?}");
}
let header = out
.shapes
.iter()
.find_map(|s| match &s.shape {
egui::Shape::Rect(r) if r.fill == Tokens::get(&ctx).panel_darker && (r.rect.height() - 26.0).abs() < 0.1 => Some(r.rect),
_ => None,
})
.expect("header");
assert!((header.width() - area.width()).abs() <= 2.0, "{id}: header {header:?}, panel {area:?}");
assert!(widget_rects(&ctx, vec2(14.0, 14.0)).iter().any(|r| header.contains_rect(*r)), "{id}: close control inside header");
}
}
}
#[test]
fn every_flyout_stays_left_of_the_icon_column() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());

View File

@ -5,8 +5,8 @@
# common Czech desktop-software conventions (commands in the infinitive, menus as nouns); no other
# application's Czech localisation was consulted or copied.
#
# Coverage: every menu label (tested: `menu_catalogs_translate_every_menu_label`); panels and dialogs fall
# back to English. Left in English on purpose (`MENU_KEEP_AS_IS` in the tests): the product name,
# Coverage: every menu label (tested: `czech_translates_every_menu_label`); panels and dialogs fall
# back to English. Left in English on purpose (`CZECH_KEEP_AS_IS` in the tests): the product name,
# language names, OpenType, the built-in workspace names and the bracketed perspective grid preset
# names.
About VectorCraft O aplikaci VectorCraft

Can't render this file because it contains an unexpected character in line 2 and column 73.

View File

@ -1,571 +1,42 @@
# Japanese (ja) catalog. Same format as zh-hant.tsv: context <TAB> source <TAB> translation
# (empty context = a plain UI string; `@id` = a command id; `@plural` = "one|other" forms).
#
# Clean-room: menu and feature names follow the names Japanese users of vector illustration
# software know, written from the meaning of VectorCraft's English labels; no other application's
# Japanese localisation was copied. Toggles read as their action (「…を表示」「…を隠す」).
#
# Coverage: every menu label (tested: `menu_catalogs_translate_every_menu_label`); panels and
# dialogs fall back to English. Left in English on purpose (`MENU_KEEP_AS_IS` in the tests): the
# product name, language names, OpenType, the built-in workspace names and the bracketed perspective
# grid preset names. Set `complete_menus` in i18n/mod.rs once every `tl!` literal has a row too.
About VectorCraft VectorCraft について
Join Our Discord Discord に参加
Settings… 環境設定…
Language 表示言語
UI Brightness UI の明るさ
Dark 暗い
Medium Dark やや暗い
Medium Light やや明るい
Light 明るい
Quit VectorCraft VectorCraft を終了
# Coverage: the main menus. Untranslated text falls back to English, so rows can be added one at a
# time; set `complete_menus` in i18n/mod.rs once every menu string and `tl!` literal has a row.
# Every row's source must be a string the UI shows (menu label or `tl!` literal): tested.
Copy コピー
Color カラー
Cut 切り取り
Deselect 選択を解除
Edit 編集
Effect 効果
Export 書き出し
Export As… 形式を指定して書き出し…
File ファイル
Help ヘルプ
History 履歴
Horizontal 横書き
Language 表示言語
Layers レイヤー
New… 新規…
New from Template… テンプレートから新規…
Object オブジェクト
Open… 開く…
Open Recent Files 最近使用したファイルを開く
Clear Recent Files 最近使用したファイルを消去
Show in Folder フォルダーに表示
Close 閉じる
Close All すべてを閉じる
Paste 貼り付け
Preferences… 環境設定…
Print… 印刷…
Properties プロパティ
Redo やり直し
Revert 保存済みの状態に戻す
Save 保存
Save As… 別名で保存…
Save a Copy… コピーを保存…
Save as Template… テンプレートとして保存…
Save as PDF… PDF として保存…
Save for Office Documents… Office 用に保存…
Revert 保存済みの状態に戻す
Place… 配置…
Export 書き出し
Export for Screens… スクリーン用に書き出し…
Export As… 形式を指定して書き出し…
Export As SVG… SVG として書き出し…
Export As PNG… PNG として書き出し…
Save for Web (Legacy)… Web 用に保存…
Export Selection… 選択範囲を書き出し…
Package… パッケージ…
Scripts スクリプト
Other Script… その他のスクリプト…
Document Setup… ドキュメント設定…
Document Color Mode ドキュメントのカラーモード
CMYK Color CMYK カラー
RGB Color RGB カラー
File Info… ファイル情報…
Print… 印刷…
Edit 編集
Undo 取り消し
Redo やり直し
Cut 切り取り
Copy コピー
Paste 貼り付け
Paste in Front 前面へペースト
Paste in Back 背面へペースト
Paste in Place 同じ位置にペースト
Paste on All Artboards すべてのアートボードにペースト
Paste without Formatting 書式なしでペースト
Clear 消去
Find and Replace… 検索と置換…
Find Next 次を検索
Spelling スペルチェック
Auto Spell Check 自動スペルチェック
Check Spelling… スペルチェック…
Edit Custom Dictionary… カスタム辞書を編集…
Edit Colors カラーを編集
Recolor Artwork… オブジェクトを再配色…
Recolor with Preset プリセットで再配色
1 Color Job… 1 色ジョブ…
2 Color Job… 2 色ジョブ…
3 Color Job… 3 色ジョブ…
Color Library… カラーライブラリ…
Adjust Color Balance… カラーバランス調整…
Blend Front to Back 前後にブレンド
Blend Horizontally 左右にブレンド
Blend Vertically 上下にブレンド
Convert to CMYK CMYK に変換
Convert to Grayscale グレースケールに変換
Convert to RGB RGB に変換
Invert Colors カラー反転
Overprint Black… オーバープリントブラック…
Saturate… 彩度調整…
Edit Original オリジナルを編集
Transparency Flattener Presets… 透明の分割・統合プリセット…
Print Presets… プリントプリセット…
PDF Presets… PDF プリセット…
Perspective Grid Presets… 遠近グリッドプリセット…
Color Settings… カラー設定…
Assign Profile… プロファイルの指定…
Keyboard Shortcuts… キーボードショートカット…
Preferences… 環境設定…
Object オブジェクト
Transform 変形
Transform Again 変形の繰り返し
Move… 移動…
Rotate… 回転…
Reflect… リフレクト…
Scale… 拡大・縮小…
Shear… シアー…
Transform Each… 個別に変形…
Reset Bounding Box バウンディングボックスのリセット
Arrange 重ね順
Bring to Front 最前面へ
Bring Forward 前面へ
Send Backward 背面へ
Send to Back 最背面へ
Send to Current Layer 現在のレイヤーへ送る
Align 整列
Horizontal Align Left 水平方向左に整列
Horizontal Align Center 水平方向中央に整列
Horizontal Align Right 水平方向右に整列
Vertical Align Top 垂直方向上に整列
Vertical Align Center 垂直方向中央に整列
Vertical Align Bottom 垂直方向下に整列
Group グループ
Ungroup グループ解除
Lock ロック
Selection 選択
All Artwork Above 前面のすべてのアートワーク
Other Layers その他のレイヤー
Unlock All すべてをロック解除
Hide 隠す
Show All すべてを表示
Expand… 分割・拡張…
Expand Appearance アピアランスを分割
Crop Image 画像の切り抜き
Rasterize… ラスタライズ…
Create Gradient Mesh… グラデーションメッシュを作成…
Create Object Mosaic… モザイクオブジェクトを作成…
Vector Halftone… ベクターハーフトーン…
Create Trim Marks トリムマークを作成
Flatten Transparency… 透明部分を分割・統合…
Make Pixel Perfect ピクセルグリッドに最適化
Slice スライス
Make 作成
Release 解除
Create from Guides ガイドから作成
Create from Selection 選択範囲から作成
Duplicate Slice スライスを複製
Combine Slices スライスを結合
Divide Slices… スライスを分割…
Delete All すべてを削除
Slice Options… スライスオプション…
Clip to Artboard アートボードサイズでクリップ
Path パス
Join 連結
Average… 平均…
Outline Stroke パスのアウトライン
Offset Path… パスのオフセット…
Reverse Path Direction パスの方向反転
Simplify… 単純化…
Add Anchor Points アンカーポイントの追加
Remove Anchor Points アンカーポイントの削除
Divide Objects Below 背面のオブジェクトで型抜き
Split Into Grid… グリッドに分割…
Clean Up… 余分なポイントを削除…
Shape シェイプ
Convert to Shape シェイプに変換
Expand Shape シェイプを拡張
Pattern パターン
Edit Pattern パターンを編集
Tile Edge Color… タイルの境界線のカラー…
Repeat リピート
Radial ラジアル
Grid グリッド
Mirror ミラー
Options… オプション…
Blend ブレンド
Blend Options… ブレンドオプション…
Expand 拡張
Replace Spine ブレンド軸を置き換え
Reverse Spine ブレンド軸を反転
Reverse Front to Back 前後を反転
Envelope Distort エンベロープ
Make with Warp… ワープで作成…
Reset with Warp… ワープでリセット…
Make with Mesh… メッシュで作成…
Reset with Mesh… メッシュでリセット…
Make with Top Object 最前面のオブジェクトで作成
Envelope Options… エンベロープオプション…
Edit Contents 内容を編集
Perspective 遠近
Attach to Active Plane 現在の面に配置
Release with Perspective 遠近を解除
Move Plane to Match Object オブジェクトに合わせて面を移動
Edit Text テキストを編集
Live Paint ライブペイント
Merge 結合
Gap Options… 間隔オプション…
Image Trace 画像トレース
Make… 作成…
Make and Expand… 作成して拡張…
Text Wrap テキストの回り込み
Text Wrap Options… テキストの回り込みオプション…
Clipping Mask クリッピングマスク
Edit Clipping Path クリッピングパスを編集
Compound Path 複合パス
Artboards アートボード
Convert to Artboards アートボードに変換
Rearrange All Artboards… すべてのアートボードを再配置…
Fit to Artwork Bounds アートワーク境界に合わせる
Fit to Selected Art 選択オブジェクトに合わせる
Graph グラフ
Type… 種類…
Data… データ…
Design… デザイン…
Column… 棒グラフ…
Marker… マーカー…
Collect for Export 書き出し用に追加
As Single Asset 単一アセットとして
As Multiple Assets 複数アセットとして
Plug-ins プラグイン
No filter plug-ins installed フィルタープラグインはインストールされていません
Install Plug-in… プラグインをインストール…
Reload Plug-ins プラグインを再読み込み
Type 書式
Font フォント
Recent Fonts 最近使用したフォント
Size サイズ
Glyphs 字形
Insert Special Character 特殊文字を挿入
Bullet 箇条書き記号
Copyright Symbol 著作権記号
Ellipsis 省略記号
Paragraph Symbol 段落記号
Registered Trademark Symbol 登録商標記号
Section Symbol セクション記号
Trademark Symbol 商標記号
Em Dash EM ダッシュ
En Dash EN ダッシュ
Discretionary Hyphen 任意ハイフン
Nonbreaking Hyphen 分散禁止ハイフン
Double Left Quotation Marks 左二重引用符
Double Right Quotation Marks 右二重引用符
Single Left Quotation Mark 左一重引用符
Single Right Quotation Mark 右一重引用符
Insert Whitespace Character 空白文字を挿入
Em Space EM スペース
En Space EN スペース
Hair Space 極細スペース
Sixth Space 1/6 スペース
Thin Space 細いスペース
Nonbreaking Space 改行なしスペース
Figure Space 数字スペース
Punctuation Space 句読点スペース
Third Space 1/3 スペース
Quarter Space 1/4 スペース
Insert Break Character 分割文字を挿入
Forced Line Break 強制改行
Tab タブ
Convert To Area Type エリア内文字に切り換え
Convert To Point Type ポイント文字に切り換え
Area Type Options… エリア内文字オプション…
Type on a Path パス上文字オプション
Rainbow 虹
Skew 歪み
3D Ribbon 3D リボン
Stair Step 階段
Gravity 引力
Type on a Path Options… パス上文字オプション…
Threaded Text スレッドテキストオプション
Create 作成
Release Selection 選択部分をリリース
Remove Threading スレッドを解除
Fit Headline ヘッドラインを合わせる
Find Font… フォントの検索と置換…
Change Case 大文字と小文字の変更
UPPERCASE すべて大文字
lowercase すべて小文字
Title Case 単語の先頭のみ大文字
Sentence case 文頭のみ大文字
Smart Punctuation… 欧文用字形の自動置換…
Create Outlines アウトラインを作成
Optical Margin Alignment 最適なマージン揃え
Fill with Placeholder Text サンプルテキストの割り付け
Show Hidden Characters 制御文字を表示
Type Orientation 組み方向
Horizontal 横書き
Vertical 縦書き
Select 選択
All すべてを選択
All on Active Artboard 作業アートボードのすべてを選択
Deselect 選択を解除
Reselect 再選択
Inverse 選択範囲を反転
Next Object Above 前面のオブジェクト
Next Object Below 背面のオブジェクト
Same 共通
Appearance アピアランス
Appearance Attribute アピアランス属性
Blending Mode 描画モード
Fill & Stroke 塗りと線
Fill Color カラー (塗り)
Opacity 不透明度
Stroke Color カラー (線)
Stroke Weight 線幅
Graphic Style グラフィックスタイル
Symbol Instance シンボルインスタンス
Font Family フォントファミリー
Font Family & Style フォントファミリー (スタイル)
Font Family, Style & Size フォントファミリー (スタイルとサイズ)
Font Size フォントサイズ
Text Fill Color テキストカラー (塗り)
Text Stroke Color テキストカラー (線)
All on Same Layers 同じレイヤー上のすべて
Direction Handles 方向線ハンドル
Brush Strokes ブラシストローク
Bristle Brush Strokes 絵筆ブラシストローク
Clipping Masks クリッピングマスク
Slices スライス
Stray Points 余分なポイント
Open Paths オープンパス
All Text Objects すべてのテキストオブジェクト
Point Text Objects ポイント文字オブジェクト
Area Text Objects エリア内文字オブジェクト
Start Global Edit グローバル編集を開始
Save Selection… 選択範囲を保存…
Edit Selection… 選択範囲を編集…
Effect 効果
Apply Last Effect 前回の効果を適用
Last Effect… 前回の効果…
Document Raster Effects Settings… ドキュメントのラスタライズ効果設定…
Vector Effects ベクター効果
3D and Materials 3D とマテリアル
Extrude & Bevel… 押し出しとベベル…
Revolve… 回転体…
Inflate… 膨張…
Materials… マテリアル…
Color Adjustments 色調補正
Brightness/Contrast… 明るさ・コントラスト…
Curves… トーンカーブ…
Hue/Saturation… 色相・彩度…
Levels… レベル補正…
Shift to Color… カラーに変更…
Temperature/Tint… 色温度・色かぶり…
Rectangle… 長方形…
Rounded Rectangle… 角丸長方形…
Ellipse… 楕円形…
Crop Marks トリムマーク
Distort & Transform パスの変形
Free Distort… パスの自由変形…
Pucker & Bloat… パンク・膨張…
Roughen… ラフ…
Transform… 変形…
Tweak… ランダム・ひねり…
Twist… 旋回…
Zig Zag… ジグザグ…
Pathfinder パスファインダー
Add 追加
Intersect 交差
Exclude 中マド
Subtract 前面オブジェクトで型抜き
Minus Back 背面オブジェクトで型抜き
Divide 分割
Trim 刈り込み
Crop 切り抜き
Outline アウトライン
Stylize スタイライズ
Round Corners… 角を丸くする…
Scribble… 落書き…
Drop Shadow… ドロップシャドウ…
Inner Glow… 光彩 (内側)…
Outer Glow… 光彩 (外側)…
Feather… ぼかし…
SVG Filters SVG フィルター
Apply SVG Filter… SVG フィルターを適用…
Warp ワープ
Arc… 円弧…
Arc Lower… 円弧 (下弦)…
Arc Upper… 円弧 (上弦)…
Arch… アーチ…
Bulge… でこぼこ…
Shell Lower… 貝殻 (下向き)…
Shell Upper… 貝殻 (上向き)…
Flag… 旗…
Wave… 波形…
Fish… 魚形…
Rise… 上昇…
Fisheye… 魚眼レンズ…
Squeeze… 絞り込み…
Raster Effects ラスター効果
Blur ぼかし
Gaussian Blur… ぼかし (ガウス)…
Settings… 環境設定…
Tools ツール
Type 書式
Type Orientation 組み方向
Undo 取り消し
Vertical 縦書き
View 表示
Overprint Preview オーバープリントプレビュー
Pixel Preview ピクセルプレビュー
Trim View トリミング表示
Presentation Mode プレゼンテーションモード
Screen Mode スクリーンモード
Normal Screen Mode 標準スクリーンモード
Full Screen Mode with Menu Bar メニュー付きフルスクリーンモード
Full Screen Mode フルスクリーンモード
Proof Setup 校正設定
Working CMYK 作業用 CMYK
Legacy Macintosh RGB (Gamma 1.8) 従来の Macintosh RGB(ガンマ 1.8)
Internet Standard RGB (sRGB) インターネット標準 RGB(sRGB)
Monitor RGB モニター RGB
Color blindness – Protanopia-type P 型(1 型)色覚
Color blindness – Deuteranopia-type D 型(2 型)色覚
Customize… カスタマイズ…
Proof Colors 色の校正
Window ウィンドウ
Zoom In ズームイン
Zoom Out ズームアウト
Fit Artboard in Window アートボードを全体表示
Fit All in Window すべてのアートボードを全体表示
Actual Size 100% 表示
Reset Rotate View ビューを回転の初期化
Hide Edges エッジを隠す
Hide Artboards アートボードを隠す
Show Print Tiling プリント分割を表示
Hide Slices スライスを隠す
Lock Slices スライスをロック
Rulers 定規
Show Rulers 定規を表示
Change to Global Rulers グローバル定規に変更
Show Video Rulers ビデオ定規を表示
Hide Bounding Box バウンディングボックスを隠す
Show Transparency Grid 透明グリッドを表示
Hide Text Threads テキストのスレッドを隠す
Hide Gradient Annotator グラデーションガイドを隠す
Hide Corner Widget コーナーウィジェットを隠す
Guides ガイド
Hide Guides ガイドを隠す
Lock Guides ガイドをロック
Make Guides ガイドを作成
Release Guides ガイドを解除
Clear Guides ガイドを消去
Smart Guides スマートガイド
Perspective Grid 遠近グリッド
Show Grid グリッドを表示
Snap to Grid グリッドにスナップ
Lock Grid グリッドをロック
Lock Station Point 視点をロック
Define Grid… グリッドを定義…
One Point Perspective 1 点遠近法
Two Point Perspective 2 点遠近法
Three Point Perspective 3 点遠近法
Save Grid as Preset… グリッドをプリセットとして保存…
Snap to Pixel ピクセルにスナップ
Snap to Point ポイントにスナップ
Snap to Glyph グリフにスナップ
New View… 新規表示…
Edit Views… 表示の編集…
Saved View 1 保存した表示 1
Saved View 2 保存した表示 2
Saved View 3 保存した表示 3
Saved View 4 保存した表示 4
Saved View 5 保存した表示 5
Saved View 6 保存した表示 6
Saved View 7 保存した表示 7
Saved View 8 保存した表示 8
Saved View 9 保存した表示 9
Saved View 10 保存した表示 10
Window ウィンドウ
New Window 新規ウィンドウ
Cascade 重ねて表示
Tile 並べて表示
Float in Window ウィンドウを分離
Consolidate All Windows すべてのウィンドウを統合
Workspace ワークスペース
Reset Essentials 初期設定をリセット
New Workspace… 新規ワークスペース…
Manage Workspaces… ワークスペースを管理…
Control コントロール
Contextual Task Bar コンテキストタスクバー
Tools ツール
Toolbars ツールバー
Advanced 詳細
Single / Double Column 1 列/2 列
Actions アクション
Asset Export アセットの書き出し
Attributes 属性
Brushes ブラシ
Color カラー
Color Guide カラーガイド
Color Themes カラーテーマ
CSS Properties CSS プロパティ
Document Info ドキュメント情報
Flattener Preview 分割・統合プレビュー
Gradient グラデーション
Graphic Styles グラフィックスタイル
History 履歴
Info 情報
Layers レイヤー
Libraries ライブラリ
Links リンク
Magic Wand 自動選択
Navigator ナビゲーター
Pattern Options パターンオプション
Properties プロパティ
Separations Preview 分版プレビュー
Stroke 線
SVG Interactivity SVG インタラクティビティ
Swatches スウォッチ
Symbols シンボル
Transparency 透明
Character 文字
Character Styles 文字スタイル
Paragraph 段落
Paragraph Styles 段落スタイル
Tabs タブ
Variables 変数
Brush Libraries ブラシライブラリ
Built-in Libraries 内蔵ライブラリ
User Defined ユーザー定義
Other Library… その他のライブラリ…
Graphic Style Libraries グラフィックスタイルライブラリ
Shadows and Glows シャドウと光彩
Outlines and Rules アウトラインと罫線
Hand-Drawn 手描き風
Gradient Finishes グラデーション仕上げ
Shape Effects シェイプ効果
Blends and Transparency ブレンドと透明
Save Graphic Style Library… グラフィックスタイルライブラリを保存…
Swatch Libraries スウォッチライブラリ
Default Swatches 初期設定スウォッチ
Web Safe 216 Web セーフ 216
Grays and Neutrals グレーとニュートラル
Earth Tones アーストーン
Skin Tone Ramps 肌色のグラデーション
Pastels パステル
Brights ビビッド
Metallic Gradients メタリックグラデーション
Perceptual Scales 知覚的カラースケール
Harmony Sets ハーモニーセット
Gradients グラデーション
Spectrum Gradients スペクトルグラデーション
Sky Gradients 空のグラデーション
Neutral Gradients ニュートラルグラデーション
Duotone Gradients ダブルトーングラデーション
Radial Glows 円形グロー
Save Swatch Library… スウォッチライブラリを保存…
Symbol Libraries シンボルライブラリ
Help ヘルプ
ArtCraft Website ArtCraft の Web サイト
VectorCraft on getartcraft.com getartcraft.com の VectorCraft
VectorCraft on GitHub GitHub の VectorCraft
Search Commands… コマンドを検索…
VectorCraft Help… VectorCraft ヘルプ…
Preview プレビュー
Show Edges エッジを表示
Show Corner Widget コーナーウィジェットを表示
Show Text Threads テキストのスレッドを表示
Hide Hidden Characters 制御文字を隠す
Show Gradient Annotator グラデーションガイドを表示
Show Artboards アートボードを表示
Hide Rulers 定規を隠す
Show Bounding Box バウンディングボックスを表示
Hide Transparency Grid 透明グリッドを隠す
Show Guides ガイドを表示
Hide Grid グリッドを隠す
Unlock Guides ガイドをロック解除
Show Slices スライスを表示
Hide Print Tiling プリント分割を隠す
Unlock Grid グリッドをロック解除
Edit Envelope エンベロープを編集
Automatic 自動
Isolate Selected Group 選択したグループを分離
Exit Isolation Mode 分離モードを終了
Make Clipping Mask クリッピングマスクを作成
Release Clipping Mask クリッピングマスクを解除
Make Compound Path 複合パスを作成
Release Compound Path 複合パスを解除
Select All すべてを選択

Can't render this file because it contains an unexpected character in line 2 and column 73.

View File

@ -60,12 +60,12 @@ fn plural_czech(n: u64) -> usize {
}
/// The registry. English first: it is the fallback and the source language.
pub static LANGUAGES: [LangInfo; 5] = [
pub static LANGUAGES: [LangInfo; 4] = [
LangInfo { code: "en", name: "English", source: "", plural: plural_one_other, complete_menus: false, catalog: OnceLock::new() },
// Japanese: every menu label (`menu_catalogs_translate_every_menu_label`); panels and dialogs
// not yet. `complete_menus` once the catalog covers every menu string and `tl!` literal.
// Japanese: the main menus so far (untranslated text stays English); `complete_menus` once the
// catalog covers every menu string and `tl!` literal.
LangInfo { code: "ja", name: "日本語", source: include_str!("ja.tsv"), plural: plural_none, complete_menus: false, catalog: OnceLock::new() },
// Czech: every menu label (`menu_catalogs_translate_every_menu_label`); panels and dialogs not yet.
// Czech: every menu label (`czech_translates_every_menu_label`); panels and dialogs not yet.
LangInfo { code: "cs", name: "Čeština", source: include_str!("cs.tsv"), plural: plural_czech, complete_menus: false, catalog: OnceLock::new() },
// Traditional Chinese in the vocabulary used in Taiwan; `zh-TW`, `zh-HK`, `zh-MO` and `zh-Hant-*`
// locales all resolve here (see `candidates`).
@ -77,14 +77,6 @@ pub static LANGUAGES: [LangInfo; 5] = [
complete_menus: true,
catalog: OnceLock::new(),
},
LangInfo {
code: "zh-hans",
name: "简体中文",
source: include_str!("zh-hans.tsv"),
plural: plural_none,
complete_menus: true,
catalog: OnceLock::new(),
},
];
impl LangInfo {

View File

@ -23,7 +23,7 @@ fn tags_map_to_languages() {
// Simplified Chinese locales never pick up the Traditional catalog (they resolve to a
// `zh-hans` catalog once one is registered, and to English until then).
for tag in ["zh-CN", "zh_CN.UTF-8", "zh_SG", "zh-Hans", "zh-Hans-CN", "zh"] {
assert_eq!(lang_from_tag(tag), Lang::from_code("zh-hans"), "{tag}");
assert_ne!(lang_from_tag(tag), Some(ZH()), "{tag}");
}
assert_eq!(lang_from_tag(""), None);
assert_eq!(lang_from_tag("_"), None);
@ -51,7 +51,6 @@ fn os_language_lists_are_parsed() {
#[test]
fn preferences_resolve_with_fallback() {
assert_eq!(Lang::from_pref("zh-Hans"), Lang::from_code("zh-hans").unwrap());
assert_eq!(Lang::from_pref("zh-hant"), ZH());
assert_eq!(Lang::from_pref("ZH-Hant"), ZH());
assert_eq!(Lang::from_pref("en"), Lang::EN);
@ -323,10 +322,10 @@ fn cs() -> Lang {
Lang::from_code("cs").expect("cs registered")
}
/// Menu labels the menu-complete catalogs (Czech, Japanese) show as they are: the product name, a format name, the built-in workspace
/// Menu labels Czech shows as they are: the product name, a format name, the built-in workspace
/// names and the perspective grid presets (names, shown untranslated wherever else they appear).
/// Each language's own name in the Language menu is left alone too.
const MENU_KEEP_AS_IS: &[&str] = &[
const CZECH_KEEP_AS_IS: &[&str] = &[
"VectorCraft",
"OpenType",
"Essentials",
@ -413,10 +412,9 @@ fn toggled_labels() -> Vec<String> {
labels
}
/// Czech and Japanese cover every menu label, the Show/Hide pairs and the canvas context menu
/// included (panels and dialogs not yet).
/// Czech covers every menu label, the Show/Hide pairs included (panels and dialogs not yet).
#[test]
fn menu_catalogs_translate_every_menu_label() {
fn czech_translates_every_menu_label() {
let labels = menu_labels();
// What the menus show (recent files and fonts, user presets and libraries show their names).
let shown = crate::menus::menu_strings();
@ -424,24 +422,20 @@ fn menu_catalogs_translate_every_menu_label() {
// Font names and sizes, and installed plug-ins' own names, are not interface text.
let interface = |(label, id, p): &(&str, &str, serde_json::Value)| {
let plugin = *id == "plugin.dialog" || p.get("effect").and_then(serde_json::Value::as_str).is_some_and(|e| e.starts_with("plugin."));
*id != "text.setStyle" && !plugin && shown.contains(*label) && !MENU_KEEP_AS_IS.contains(label) && !language_name(label)
*id != "text.setStyle" && !plugin && shown.contains(*label) && !CZECH_KEEP_AS_IS.contains(label) && !language_name(label)
};
let mut all: Vec<String> = labels.iter().filter(|l| interface(l)).map(|(l, ..)| l.to_string()).collect();
all.extend(toggled_labels());
all.extend(crate::menus::CONTEXT_LABELS.iter().map(|l| l.to_string()));
all.sort();
all.dedup();
for code in ["cs", "ja"] {
let lang = Lang::from_code(code).expect("registered");
let missing: Vec<&String> = all.iter().filter(|l| !has(lang, l)).collect();
assert!(missing.is_empty(), "{code}: untranslated menu labels: {missing:?}");
for keep in MENU_KEEP_AS_IS {
assert!(labels.iter().any(|(l, ..)| l == keep), "`{keep}` isn't a menu label");
assert!(!has(lang, keep), "{code}: `{keep}` is both kept and translated");
}
let mut missing: Vec<String> = labels.iter().filter(|l| interface(l)).map(|(l, ..)| l.to_string()).collect();
missing.extend(toggled_labels());
missing.extend(crate::menus::CONTEXT_LABELS.iter().map(|l| l.to_string()));
missing.retain(|l| !has(cs(), l));
missing.sort();
missing.dedup();
assert!(missing.is_empty(), "untranslated Czech menu labels: {missing:?}");
for keep in CZECH_KEEP_AS_IS {
assert!(labels.iter().any(|(l, ..)| l == keep), "`{keep}` isn't a menu label");
assert!(!has(cs(), keep), "`{keep}` is both kept and translated");
}
assert_eq!(tr(cs(), "File"), "Soubor");
assert_eq!(tr(Lang::from_code("ja").expect("ja"), "File"), "ファイル");
}
#[test]

File diff suppressed because it is too large Load Diff

View File

@ -988,7 +988,6 @@
Global Process Color, CMYK 整體印刷色,CMYK
glyph {id} 字符 {id}
Glyphs 字符
Go to Artboard 前往工作區域
Go To Link 前往連結
GPL palettes keep solid colours only, as RGB. GPL 調色盤僅保留純色,並以 RGB 儲存。
GPU Performance GPU 效能
@ -2023,7 +2022,6 @@
Reshape 改變外框
Reshape Segment 改變線段外框
Reshape Tool 改變外框工具
Reshape Type Area 改變區域文字外框
Resolution: 解析度:
Responsive 回應式
Restore 還原

Can't render this file because it contains an unexpected character in line 6 and column 47.

View File

@ -274,7 +274,6 @@ pub struct VectorcraftApp {
/// Synthetic input events (from the control channel) injected one step per frame.
pub synthetic: Vec<egui::Event>,
styled: bool,
font_language: Option<&'static str>,
fonts_ready: bool,
/// Installed fonts added to the UI's for characters its own fonts lack (CJK names…).
ui_fonts: ui_fonts::UiFonts,
@ -361,7 +360,6 @@ impl VectorcraftApp {
screenshot_token: 0,
synthetic: vec![],
styled: false,
font_language: None,
fonts_ready: false,
ui_fonts: Default::default(),
frame: 0,
@ -515,9 +513,6 @@ impl VectorcraftApp {
{
*slot = id.to_string();
}
if canvas::is_selection_tool(id) {
self.ui.last_selection_tool = id.to_string();
}
toolbar::remember(self, id);
self.ui.flyout = None;
}
@ -671,11 +666,8 @@ impl VectorcraftApp {
fn logic_frame(&mut self, ctx: &egui::Context) {
i18n::set_current(self.ui_language());
if !self.styled || self.font_language != Some(self.ui_language().code()) {
if !self.styled {
theme::install_fonts(ctx);
self.font_language = Some(self.ui_language().code());
self.fonts_ready = false;
self.ui_fonts = Default::default();
theme::apply(ctx, self.ui.brightness);
egui_extras::install_image_loaders(ctx);
self.styled = true;

View File

@ -147,12 +147,6 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
("view.fitAll", "Fit All in Window", "Cmd+Alt+0", "{}"),
("view.actualSize", "Actual Size", "Cmd+1", "{}"),
("view.setZoom", "Set Zoom", "", "{zoom: percent, center?: [x,y]}"),
(
"view.goToArtboard",
"Go to Artboard",
"",
"{index: 0-based number | \"first\" | \"previous\" | \"next\" | \"last\"} make that artboard the status bar navigator's (the one Fit Artboard in Window and Actual Size show) and fit it in the window → {index}",
),
("view.edges", "Hide Edges", "Cmd+H", "{}"),
("view.artboards", "Hide Artboards", "Cmd+Shift+H", "{}"),
("view.rulers", "Show Rulers", "Cmd+R", "{}"),
@ -245,7 +239,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"tool.options",
"Tool Options…",
"",
"{tool: id} what double-clicking a tool button opens: hand → fits the artboard in the window (view.fitArtboard), zoom → 100% (view.actualSize), rotate|scale|reflect|shear → that Object › Transform dialog (dialog `rotate`, `scale`, `reflect` or `shear`; error `nothing selected` without a selection), gradient → the Gradient panel (window.panel), eyedropper → Eyedropper Options (dialog `eyedropperOptions`, fields sampleSize, pickUp, apply; OK runs eyedropper.setOptions), printTiling → resets the print tiling (print.tiling.set {reset: true}), warp|twirl|pucker|bloat|scallop|crystallize|wrinkle → that tool's Tool Options (dialog `liquifyOptions`, fields tool, width, height, angle, intensity %, usePressure, detail, simplify, simplifyOn, rate, complexity, horizontal %, vertical %, affectAnchors, affectIn, affectOut, showBrush; OK runs tool.setOption {tool, values})",
"{tool: id} what double-clicking a tool button opens: gradient → the Gradient panel (window.panel), eyedropper → Eyedropper Options (dialog `eyedropperOptions`, fields sampleSize, pickUp, apply; OK runs eyedropper.setOptions), printTiling → resets the print tiling (print.tiling.set {reset: true}), warp|twirl|pucker|bloat|scallop|crystallize|wrinkle → that tool's Tool Options (dialog `liquifyOptions`, fields tool, width, height, angle, intensity %, usePressure, detail, simplify, simplifyOn, rate, complexity, horizontal %, vertical %, affectAnchors, affectIn, affectOut, showBrush; OK runs tool.setOption {tool, values})",
),
(
"ui.colorGuideOptions",
@ -865,7 +859,6 @@ pub fn run_ui_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
crate::canvas::fit(app, id);
Ok(Value::Null)
}
"view.goToArtboard" => go_to_artboard(app, p),
"view.presentation" => {
app.ui.screen_mode = if app.ui.screen_mode == 3 { 0 } else { 3 };
Ok(json!(app.ui.screen_mode))
@ -1125,31 +1118,6 @@ pub fn run_ui_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
Some(r)
}
/// `view.goToArtboard`: make artboard `index` (a number, or first / previous / next / last from
/// the current one) the navigator's, and fit it in the window.
fn go_to_artboard(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
let n = app.session.active().map(|d| d.doc.artboards.len()).ok_or("no document open")?;
let last = n.checked_sub(1).ok_or("the document has no artboards")?;
let current = app.view().map_or(0, |v| v.artboard).min(last);
let to = match p.get("index") {
Some(Value::String(s)) => match s.as_str() {
"first" => 0,
"previous" => current.saturating_sub(1),
"next" => current + 1,
"last" => last,
other => return Err(format!("index must be a number or first, previous, next or last, not `{other}`")),
},
Some(v) => v.as_u64().and_then(|i| usize::try_from(i).ok()).ok_or("index must be a number or first, previous, next or last")?,
None => return Err("missing index".into()),
}
.min(last);
if let Some(v) = app.view_mut() {
v.artboard = to;
}
crate::canvas::fit(app, "view.fitArtboard");
Ok(json!({ "index": to }))
}
/// Checked state for toggle items.
pub fn checked(app: &VectorcraftApp, id: &str, p: &Value) -> Option<bool> {
if id == "app.language" {

View File

@ -42,13 +42,11 @@ struct Entry {
haystack: String,
}
/// The palette's entries in `lang`. They are built when the language, the installed plug-ins or
/// the keyboard shortcuts (shown beside each entry) change, not on every frame while a query is
/// typed.
/// The palette's entries in `lang`. They are built when the language or the installed plug-ins
/// change, not on every frame while a query is typed.
fn entries(ctx: &egui::Context, lang: crate::i18n::Lang) -> Arc<Vec<Entry>> {
type Cached = ((&'static str, u64, u64), Arc<Vec<Entry>>);
let shortcuts = crate::shortcut_editor::GENERATION.load(std::sync::atomic::Ordering::Relaxed);
let key = (lang.code(), menus::plugin_revision(), shortcuts);
type Cached = ((&'static str, u64), Arc<Vec<Entry>>);
let key = (lang.code(), menus::plugin_revision());
let id = egui::Id::new("palette-entries");
if let Some((k, v)) = ctx.data(|d| d.get_temp::<Cached>(id))
&& k == key
@ -125,9 +123,6 @@ mod tests {
assert!(Arc::ptr_eq(&en, &entries(&ctx, Lang::EN)), "kept while the language stays");
let zh_entries = entries(&ctx, zh);
assert!(!Arc::ptr_eq(&en, &zh_entries), "rebuilt for another language");
// Editing a shortcut rebuilds them, so the palette shows the new one.
crate::shortcut_editor::GENERATION.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
assert!(!Arc::ptr_eq(&zh_entries, &entries(&ctx, zh)), "rebuilt after a shortcut edit");
let group = zh_entries.iter().find(|e| e.id == "object.group").unwrap();
assert!(group.shown.ends_with(crate::i18n::tr(zh, "Group")), "{}", group.shown);
// A query matches the English label, the shown label or the id.

View File

@ -17,9 +17,6 @@ const KINDS: [(&str, &str); 5] =
/// (name, type) of every brush in the active document's library.
pub fn brushes(app: &mut VectorcraftApp) -> (Vec<(String, String)>, Option<String>) {
if app.session.active().is_none() {
return (vec![], None);
}
let Ok(v) = app.run("brush.list", json!({})) else { return (vec![], None) };
let list = v["brushes"]
.as_array()

View File

@ -351,7 +351,7 @@ fn zone_input(ui: &Ui, zone: &Response, d: &Document, ev: &mut Events) {
PanelDrag::GraphicStyle(n) => (Some(n), None),
PanelDrag::Art(ids) => (None, ids.first().copied()),
PanelDrag::Appearance(id) => (None, Some(*id)),
PanelDrag::Paint { .. } | PanelDrag::Symbol(_) => (None, None),
PanelDrag::Paint { .. } => (None, None),
};
if style.is_none() && source.is_none() {
return;

View File

@ -571,10 +571,6 @@ pub(crate) fn drag_preview(app: &VectorcraftApp, ctx: &egui::Context) {
None => return,
},
PanelDrag::GraphicStyle(name) => return pointer_chip(ctx, |ui, r| super::graphic_styles::paint_style(app, ui, r, name)),
PanelDrag::Symbol(name) => match app.session.active() {
Some(st) => return pointer_chip(ctx, |ui, r| super::symbols::chip(ui, &st.doc, r, name)),
None => return,
},
};
pointer_chip(ctx, |ui, r| {
if registration {

View File

@ -11,7 +11,7 @@ use vectorcraft_doc::{Document, Node, NodeKind};
use super::{pstate, set_pstate};
use crate::VectorcraftApp;
use crate::theme::Tokens;
use crate::widgets::{self, PanelDrag, menu_item};
use crate::widgets::{self, menu_item};
/// A thumbnail of symbol `name` (an instance at its natural size), cached by the art's identity.
fn thumb(ui: &Ui, doc: &Document, name: &str, size: f32) -> Option<egui::TextureHandle> {
@ -50,24 +50,6 @@ fn thumb(ui: &Ui, doc: &Document, name: &str, size: f32) -> Option<egui::Texture
Some(tex)
}
/// Symbol `name`'s thumbnail on white in `r` (the panel's tiles and the chip a dragged symbol
/// shows at the pointer).
pub(crate) fn chip(ui: &Ui, doc: &Document, r: egui::Rect, name: &str) {
ui.painter().rect_filled(r, 0.0, egui::Color32::WHITE);
if let Some(tex) = thumb(ui, doc, name, r.width()) {
ui.painter().image(tex.id(), r, egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), egui::Color32::WHITE);
}
}
/// Art dragged off the canvas over the symbol list: outline it; dropped, the art becomes a new
/// symbol (`ids`).
fn art_drop(ui: &Ui, zone: &egui::Response) -> Option<Vec<u64>> {
let drag = zone.dnd_hover_payload::<PanelDrag>()?;
let PanelDrag::Art(ids) = &*drag else { return None };
ui.painter().rect_stroke(zone.rect, 0.0, Stroke::new(1.5, Tokens::get(ui.ctx()).accent), StrokeKind::Inside);
zone.dnd_release_payload::<PanelDrag>().map(|_| ids.iter().map(|id| id.0).collect())
}
fn current(app: &mut VectorcraftApp) -> Option<String> {
app.run("symbol.list", json!({})).ok().and_then(|v| v["current"].as_str().map(str::to_string))
}
@ -91,24 +73,28 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let list: bool = pstate(ui.ctx(), "sym-list");
let sel = current(app);
let mut clicked: Option<(String, bool)> = None;
let list_rect = widgets::list_box(ui, |ui| {
widgets::list_box(ui, |ui| {
ui.set_min_height(110.0);
ui.set_width(ui.available_width());
if names.is_empty() {
super::empty_state(ui, "spray-can", tl!("No symbols in this document"), tl!("Select art and click New Symbol to make one."));
return ui.min_rect();
return;
}
let paint_thumb = |ui: &Ui, r: egui::Rect, n: &str| {
ui.painter().rect_filled(r, 0.0, egui::Color32::WHITE);
if let Some(tex) = thumb(ui, &doc, n, r.width()) {
ui.painter().image(tex.id(), r, egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)), egui::Color32::WHITE);
}
};
if list {
for n in &names {
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 26.0), Sense::click_and_drag());
// Dragged onto the canvas, the symbol is placed there.
widgets::drag_source(ui, &resp, || PanelDrag::Symbol(n.clone()));
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), 26.0), Sense::click());
if sel.as_deref() == Some(n.as_str()) {
ui.painter().rect_filled(r, 0.0, t.row_selected);
} else if resp.hovered() {
ui.painter().rect_filled(r, 0.0, t.hover);
}
chip(ui, &doc, egui::Rect::from_center_size(r.left_center() + vec2(14.0, 0.0), vec2(22.0, 22.0)), n);
paint_thumb(ui, egui::Rect::from_center_size(r.left_center() + vec2(14.0, 0.0), vec2(22.0, 22.0)), n);
ui.painter().text(r.left_center() + vec2(32.0, 0.0), egui::Align2::LEFT_CENTER, n, egui::FontId::proportional(12.5), t.text);
if resp.double_clicked() {
clicked = Some((n.clone(), true));
@ -119,9 +105,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
} else {
ui.horizontal_wrapped(|ui| {
for n in &names {
let (r, resp) = ui.allocate_exact_size(vec2(44.0, 44.0), Sense::click_and_drag());
widgets::drag_source(ui, &resp, || PanelDrag::Symbol(n.clone()));
chip(ui, &doc, r.shrink(2.0), n);
let (r, resp) = ui.allocate_exact_size(vec2(44.0, 44.0), Sense::click());
paint_thumb(ui, r.shrink(2.0), n);
let on = sel.as_deref() == Some(n.as_str());
ui.painter().rect_stroke(
r,
@ -138,14 +123,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
}
});
}
ui.min_rect()
});
let zone = ui.interact(list_rect, ui.id().with("symbols-drop"), Sense::hover());
if let Some(ids) = art_drop(ui, &zone)
&& let Err(e) = app.run("symbol.new", json!({ "ids": ids }))
{
app.status(e);
}
if let Some((n, place)) = clicked {
app.run("symbol.setCurrent", json!({"name": n})).ok();
if place {
@ -204,54 +182,3 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
set_pstate(ui.ctx(), "sym-list", true);
}
}
#[cfg(test)]
mod tests {
use egui::{Pos2, Rect, pos2};
use vectorcraft_doc::NodeId;
use vectorcraft_engine::Session;
use super::*;
/// One headless frame of the panel, 236 pt wide as in the dock.
fn frame(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec<egui::Event>) {
let raw = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(236.0, 400.0))), events, ..Default::default() };
let mut out = ctx.run_ui(raw, |ui| show(app, ui));
out.textures_delta.clear();
}
fn button(at: Pos2, pressed: bool) -> egui::Event {
egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }
}
fn symbols(app: &mut VectorcraftApp) -> Vec<String> {
let list = app.run("symbol.list", json!({})).unwrap();
list["symbols"].as_array().unwrap().iter().map(|s| s["name"].as_str().unwrap_or_default().to_string()).collect()
}
#[test]
fn art_dropped_on_the_panel_becomes_a_symbol_and_a_symbol_drags_out() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 30, "height": 20})).unwrap()["id"].as_u64().unwrap();
// Selected, as art dragged off the canvas is.
let ctx = egui::Context::default();
frame(&ctx, &mut app, vec![]);
// Art dragged off the canvas and released over the list.
let over = pos2(100.0, 50.0);
egui::DragAndDrop::set_payload(&ctx, PanelDrag::Art(vec![NodeId(id)]));
frame(&ctx, &mut app, vec![egui::Event::PointerMoved(over), button(over, false)]);
let names = symbols(&mut app);
assert_eq!(names.len(), 1, "{names:?}");
let doc = &app.session.active().unwrap().doc;
let first = doc.layers[0].children().unwrap().first().unwrap();
assert!(matches!(first.kind, NodeKind::SymbolInstance { .. }), "the art became an instance");
// Dragging the symbol's tile out of the panel carries the symbol.
frame(&ctx, &mut app, vec![]);
let tile = pos2(26.0, 26.0);
frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile), button(tile, true)]);
frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(40.0, 40.0))]);
frame(&ctx, &mut app, vec![egui::Event::PointerMoved(tile + vec2(80.0, 80.0))]);
assert_eq!(egui::DragAndDrop::payload::<PanelDrag>(&ctx).as_deref(), Some(&PanelDrag::Symbol(names[0].clone())));
}
}

View File

@ -67,23 +67,11 @@ pub fn restore(app: &mut VectorcraftApp) {
&& code != "en"
&& crate::i18n::Lang::from_code(&code).is_some()
{
p.interface_language = crate::i18n::Lang::from_code(&code).map_or(code.clone(), |lang| lang.code().to_string());
p.interface_language = code;
}
app.session.apply_prefs(p);
}
#[cfg(test)]
#[test]
fn old_chinese_locale_migrates_without_overwriting_an_explicit_new_preference() {
for (prefs, expected) in [(Value::Null, "zh-hans"), (json!({"interfaceLanguage": "ja"}), "ja")] {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.ui = serde_json::from_value(json!({"locale": "zh-Hans", "engine_prefs": prefs})).unwrap();
restore(&mut app);
assert_eq!(app.session.prefs.interface_language, expected);
assert!(app.ui.legacy_language.is_none());
}
}
#[derive(Clone, Copy, PartialEq)]
struct Applied {
brightness: Brightness,

View File

@ -189,12 +189,6 @@ pub fn format(sc: &KeyboardShortcut) -> String {
}
let k = sc.logical_key;
let name = match k {
// A shifted punctuation key is recorded as the key, not the character it types.
Key::CloseCurlyBracket if m.shift => "]",
Key::OpenCurlyBracket if m.shift => "[",
Key::Questionmark if m.shift => "/",
Key::Colon if m.shift => ";",
Key::Pipe if m.shift => "\\",
Key::CloseBracket => "]",
Key::OpenBracket => "[",
Key::Semicolon => ";",

View File

@ -75,22 +75,7 @@ pub(crate) fn all_shortcuts() -> Vec<(KeyboardShortcut, &'static str, serde_json
/// is ignored). `native`: the system menu already handles the chord as written, so only that
/// alias is left to match here.
pub(crate) fn consume(i: &mut egui::InputState, sc: &KeyboardShortcut, native: bool) -> bool {
(!native && i.consume_shortcut(sc))
|| (sc.logical_key == Key::Equals && i.consume_key(sc.modifiers, Key::Plus))
|| (sc.modifiers.shift && shifted(sc.logical_key).is_some_and(|k| i.consume_key(sc.modifiers, k)))
}
/// The key a shifted punctuation key arrives as: egui reports the character typed, so Cmd+Shift+[
/// comes in as Cmd+Shift+`{` (US-style layouts).
fn shifted(k: Key) -> Option<Key> {
Some(match k {
Key::OpenBracket => Key::OpenCurlyBracket,
Key::CloseBracket => Key::CloseCurlyBracket,
Key::Slash => Key::Questionmark,
Key::Semicolon => Key::Colon,
Key::Backslash => Key::Pipe,
_ => return None,
})
(!native && i.consume_shortcut(sc)) || (sc.logical_key == Key::Equals && i.consume_key(sc.modifiers, Key::Plus))
}
/// Keys that paste with Cmd, or alone. (Shift+Insert is left out: Ctrl+Insert copies.)
@ -386,16 +371,12 @@ pub fn handle(app: &mut VectorcraftApp, ctx: &egui::Context) {
}
let upper = text.to_uppercase();
let key = if m.shift && text.chars().all(|c| c.is_alphabetic()) { format!("Shift+{upper}") } else { upper.clone() };
// A shifted punctuation character can also be written with its Shift (the Curvature tool's
// Shift+~ arrives as `~`).
let shifted = m.shift.then(|| format!("Shift+{text}"));
let lookup = |find: fn(&str) -> Option<&'static str>| find(&key).or_else(|| find(&text)).or_else(|| shifted.as_deref().and_then(find));
// Single-key command shortcuts (X, Shift+X, D, /, Shift+D, F, Shift+F by default).
if let Some(id) = lookup(crate::shortcut_editor::command_for_key) {
if let Some(id) = crate::shortcut_editor::command_for_key(&key).or_else(|| crate::shortcut_editor::command_for_key(&text)) {
let _ = app.run(id, json!({}));
continue;
}
if let Some(t) = lookup(crate::shortcut_editor::tool_for_key) {
if let Some(t) = crate::shortcut_editor::tool_for_key(&key).or_else(|| crate::shortcut_editor::tool_for_key(&text)) {
app.select_tool(t);
}
}
@ -461,36 +442,6 @@ mod tests {
assert_eq!(fill(&app).color().unwrap().to_hex(), "#336699", "`,` applies the last colour");
}
#[test]
fn shifted_punctuation_shortcuts_work_as_typed() {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
let a = app.session.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap()["id"].clone();
let b = app.session.execute("shape.ellipse", &json!({"x": 20, "y": 20, "width": 50, "height": 50})).unwrap()["id"].clone();
app.session.execute("select.set", &json!({"ids": [a]})).unwrap();
let order =
|app: &VectorcraftApp| -> Vec<u64> { app.session.doc().unwrap().doc.layers[0].children().unwrap().iter().map(|n| n.id.0).collect() };
let (a, b) = (a.as_u64().unwrap(), b.as_u64().unwrap());
assert_eq!(order(&app), [a, b]);
let press = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
let cmd_shift = Modifiers::COMMAND | Modifiers::SHIFT;
// Recorded in the Keyboard Shortcuts editor, they read as the keys (and so conflict).
assert_eq!(crate::shortcut_editor::chord_from_event(Key::CloseCurlyBracket, cmd_shift).as_deref(), Some("Cmd+Shift+]"));
assert_eq!(crate::shortcut_editor::chord_from_event(Key::Questionmark, cmd_shift).as_deref(), Some("Cmd+Shift+/"));
// Cmd+Shift+] arrives as Cmd+Shift+`}`, Cmd+Shift+[ as Cmd+Shift+`{`.
frame(&mut app, vec![press(Key::CloseCurlyBracket, cmd_shift)]);
assert_eq!(order(&app), [b, a], "Bring to Front");
frame(&mut app, vec![press(Key::OpenCurlyBracket, cmd_shift)]);
assert_eq!(order(&app), [a, b], "Send to Back");
// Cmd+Shift+/ arrives as Cmd+Shift+`?`: Search Commands.
frame(&mut app, vec![press(Key::Questionmark, cmd_shift)]);
assert!(app.ui.palette_open, "Search Commands");
app.ui.palette_open = false;
// The Curvature tool's Shift+~ arrives as the text `~` with Shift.
frame(&mut app, vec![egui::Event::ModifiersChanged(Modifiers::SHIFT), egui::Event::Text("~".into())]);
assert_eq!(app.session.tool_id(), "curvature");
}
#[test]
fn plus_typed_any_way_zooms_in() {
assert_eq!(parse("Cmd++"), parse("Cmd+="), "`+` and `=` are one chord key");

View File

@ -17,15 +17,11 @@ pub struct View {
pub fitted: bool,
/// View rotation in degrees (Rotate View tool).
pub rotation: f64,
/// The artboard the status bar's navigator is on (an index): Fit Artboard in Window and Actual
/// Size show it.
#[serde(default)]
pub artboard: usize,
}
impl Default for View {
fn default() -> Self {
Self { zoom: 1.0, center: Point::new(306.0, 396.0), fitted: false, rotation: 0.0, artboard: 0 }
Self { zoom: 1.0, center: Point::new(306.0, 396.0), fitted: false, rotation: 0.0 }
}
}
@ -38,7 +34,6 @@ impl View {
center: v.center,
fitted: true,
rotation: if v.rotation.is_finite() { v.rotation } else { 0.0 },
artboard: 0,
},
_ => Self::default(),
}
@ -215,7 +210,7 @@ pub struct UiState {
/// The interface language older versions saved here (`ja`, `cs`…). It now lives in the
/// `interfaceLanguage` preference, which [`crate::prefs_dialog::restore`] carries it over to;
/// it is never written back.
#[serde(rename = "language", alias = "locale", skip_serializing)]
#[serde(rename = "language", skip_serializing)]
pub legacy_language: Option<String>,
pub brightness: Brightness,
pub dock_tab: DockTab,
@ -240,9 +235,6 @@ pub struct UiState {
pub flyout: Option<usize>,
/// Last tool shown for each toolbar group (flyout selection sticks).
pub group_tool: Vec<String>,
/// The selection tool used last (Selection, Direct Selection or Group Selection): a Cmd press
/// with any other tool drags with it.
pub last_selection_tool: String,
pub status: String,
pub palette_open: bool,
pub palette_query: String,
@ -371,7 +363,6 @@ impl Default for UiState {
dialog: None,
flyout: None,
group_tool: vectorcraft_tools::TOOL_GROUPS.iter().map(|g| g[0].id.to_string()).collect(),
last_selection_tool: "selection".into(),
status: String::new(),
palette_open: false,
palette_query: String::new(),

View File

@ -267,20 +267,12 @@ pub(crate) fn craft_font_name(f: &vectorcraft_text::CraftFont) -> String {
/// every family, after the app's own fonts and before the installed fonts `ui_fonts` adds: BIZ
/// UDPGothic first (bold first in the semibold family), then the Mincho faces.
fn add_craft_fonts(fonts: &mut FontDefinitions) {
for f in vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.is_japanese() || f.scripts.contains(&"Hans")) {
let data = if f.scripts.contains(&"Hans") { crate::ui_fonts::craft_font_data(f) } else { FontData::from_static(f.bytes) };
fonts.font_data.insert(craft_font_name(f), Arc::new(data));
for f in vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.is_japanese()) {
fonts.font_data.insert(craft_font_name(f), Arc::new(FontData::from_static(f.bytes)));
}
for (family, stack) in fonts.families.iter_mut() {
let bold = *family == FontFamily::Name(FONT_UI_SEMIBOLD.into());
let chinese: Vec<String> = vectorcraft_text::CRAFT_FONTS.iter().filter(|f| f.scripts.contains(&"Hans")).map(craft_font_name).collect();
if crate::i18n::current().code() == "zh-hans" {
stack.extend(chinese.iter().cloned());
}
stack.extend(vectorcraft_text::craft_fonts::japanese_ui_fonts(bold).into_iter().map(craft_font_name));
if crate::i18n::current().code() != "zh-hans" {
stack.extend(chinese);
}
}
}

View File

@ -208,21 +208,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
/// Open a tool's options (`tool.options`, a double-click on its button): the Gradient tool's are
/// the Gradient panel, the Eyedropper's the Eyedropper Options dialog, a Liquify tool's its Tool
/// Options dialog, the Blend tool's Blend
/// Options; the Print Tiling tool's resets the print tiling. As in the reference app, the Hand
/// tool's fits the artboard in the window, the Zoom tool's shows it at 100%, and the Rotate, Scale,
/// Reflect and Shear tools' are their Object › Transform dialogs.
/// Options; the Print Tiling tool's resets the print tiling.
pub fn open_options(app: &mut VectorcraftApp, tool: &str) -> Result<serde_json::Value, String> {
match tool {
"hand" => app.run("view.fitArtboard", json!({})),
"zoom" => app.run("view.actualSize", json!({})),
"rotate" | "scale" | "reflect" | "shear" => {
let id = format!("object.{tool}");
if let Some(c) = vectorcraft_engine::find_command(&id) {
(c.enabled)(&app.session)?;
}
crate::menus::invoke(app, &id, json!({}));
Ok(json!({ "dialog": tool }))
}
"gradient" if app.ui.open_panel.as_deref() == Some("gradient") => Ok(json!({ "open": "gradient" })),
"gradient" => app.run("window.panel", json!({ "panel": "gradient" })),
"eyedropper" => {
@ -498,35 +486,7 @@ pub(crate) mod tests {
crate::dialogs::confirm(&mut app).unwrap();
let o = app.session.prefs.eyedropper;
assert!(o.pick_up.appearance.transparency && !o.apply.appearance.transparency && o.apply.appearance.fill.color);
assert!(app.run("tool.options", json!({"tool": "lasso"})).is_err());
}
#[test]
fn double_clicking_the_hand_zoom_and_transform_tools() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
app.canvas_rect = Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(660.0, 460.0)));
app.run("view.setZoom", json!({"zoom": 333, "center": [10, 10]})).unwrap();
// Hand: the artboard fits the window. Zoom: 100%.
app.run("tool.options", json!({"tool": "hand"})).unwrap();
let v = *app.view().unwrap();
assert_eq!((v.center.x, v.center.y, v.zoom), (150.0, 100.0, 2.0));
app.run("tool.options", json!({"tool": "zoom"})).unwrap();
assert_eq!(app.view().unwrap().zoom, 1.0);
// The transform tools open their dialogs, like Object › Transform: not with nothing selected.
assert_eq!(app.run("tool.options", json!({"tool": "rotate"})), Err("nothing selected".into()));
assert!(app.ui.dialog.is_none());
let id = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 20})).unwrap()["id"].as_u64().unwrap();
for tool in ["rotate", "scale", "reflect", "shear"] {
app.run("tool.options", json!({"tool": tool})).unwrap();
assert_eq!(app.ui.dialog.take().map(|d| d.kind), Some(tool.to_string()));
}
// OK in Rotate turns the selection about its centre.
app.run("tool.options", json!({"tool": "rotate"})).unwrap();
app.ui.dialog.as_mut().unwrap().fields.insert("angle".into(), json!(90));
crate::dialogs::confirm(&mut app).unwrap();
let b = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().geometric_bounds().unwrap();
assert!((b.x0 - 20.0).abs() < 1e-9 && (b.y0 - 0.0).abs() < 1e-9 && (b.width() - 20.0).abs() < 1e-9, "{b:?}");
assert!(app.run("tool.options", json!({"tool": "zoom"})).is_err());
}
#[test]

View File

@ -12,23 +12,20 @@ use std::collections::HashSet;
use std::sync::Arc;
use egui::epaint::Shape;
use egui::epaint::text::FontTweak;
use egui::epaint::text::{FontInsert, FontPriority, InsertFontFamily};
use egui::{FontData, FontFamily, FontId, LayerId};
use vectorcraft_text::{FontDb, FontFace};
type FallbackFace = (FontFamily, Arc<FontFace>);
#[derive(Default)]
pub(crate) struct UiFonts {
/// Characters looked at already: the UI fonts have them, a fallback was added (or is being
/// looked for), or no font has them.
seen: HashSet<(FontFamily, char)>,
seen: HashSet<char>,
/// The fonts added to egui, by name.
added: HashSet<(FontFamily, String)>,
added: HashSet<String>,
/// The faces covering the characters being looked for (native: looked for on a thread).
#[cfg(not(target_arch = "wasm32"))]
pending: Option<std::sync::mpsc::Receiver<Vec<FallbackFace>>>,
pending: Option<std::sync::mpsc::Receiver<Vec<Arc<FontFace>>>>,
}
impl UiFonts {
@ -45,14 +42,12 @@ impl UiFonts {
return;
}
let find = move || {
let mut faces: Vec<FallbackFace> = vec![];
for (family, c) in missing {
// The face is looked up at the weight the character was painted in, so a semibold
// heading gets a semibold CJK face rather than the family's regular one.
if let Some(f) = FontDb::global().face_covering_weighted(c, family_weight(&family))
&& !faces.iter().any(|(fam, x)| *fam == family && x.id() == f.id())
let mut faces: Vec<Arc<FontFace>> = vec![];
for c in missing {
if let Some(f) = FontDb::global().face_covering(c)
&& !faces.iter().any(|x| x.id() == f.id())
{
faces.push((family, f));
faces.push(f);
}
}
faces
@ -79,7 +74,7 @@ impl UiFonts {
/// Characters painted this frame that the UI fonts lack and haven't been looked for, now
/// marked seen. None while a search is running.
fn missing(&mut self, ctx: &egui::Context) -> Vec<(FontFamily, char)> {
fn missing(&mut self, ctx: &egui::Context) -> Vec<char> {
#[cfg(not(target_arch = "wasm32"))]
if self.pending.is_some() {
return vec![];
@ -88,17 +83,12 @@ impl UiFonts {
if !layers.contains(&LayerId::background()) {
layers.push(LayerId::background());
}
let mut chars = HashSet::new();
let mut chars: Vec<char> = vec![];
let seen = &self.seen;
let mut note = |text: &str, family: &FontFamily, _size: f32| {
let mut note = |text: &str| {
// Most UI text is ASCII, which the UI fonts cover.
if !text.is_ascii() {
chars.extend(
text.chars()
.filter(|c| !c.is_ascii() && !c.is_whitespace() && !c.is_control())
.map(|c| (family.clone(), c))
.filter(|key| !seen.contains(key)),
);
chars.extend(text.chars().filter(|c| !c.is_ascii() && !c.is_whitespace() && !c.is_control() && !seen.contains(c)));
}
};
ctx.graphics(|g| {
@ -108,25 +98,30 @@ impl UiFonts {
}
}
});
let missing = ctx.fonts_mut(|f| chars.iter().filter(|(family, c)| !f.has_glyph(&FontId::new(13.0, family.clone()), *c)).cloned().collect());
if chars.is_empty() {
return chars;
}
chars.sort_unstable();
chars.dedup();
let font = FontId::new(13.0, FontFamily::Proportional);
let missing: Vec<char> = ctx.fonts_mut(|f| chars.iter().copied().filter(|c| !f.has_glyph(&font, *c)).collect());
self.seen.extend(chars);
missing
}
/// Add each face only to the family that requested its weight.
fn install(&mut self, ctx: &egui::Context, faces: &[FallbackFace]) {
for (family, face) in faces {
/// Add `faces` to every egui family, after the fonts it has.
fn install(&mut self, ctx: &egui::Context, faces: &[Arc<FontFace>]) {
let families: Vec<FontFamily> = ctx.fonts(|f| f.definitions().families.keys().cloned().collect());
for face in faces {
let name = format!("{} {} #{}", face.family, face.style, face.face_index());
if !self.added.insert((family.clone(), name.clone())) {
if !self.added.insert(name.clone()) {
continue;
}
// The face's file data, shared with the process-wide font database (which keeps every
// face it loads for the session) instead of copied: one handle is leaked per font added.
let face: &'static FontFace = Box::leak(Box::new(face.clone()));
// Align fallback metrics with the Latin UI baseline without changing the point size.
let tweak = latin_face().map_or_else(FontTweak::default, |latin| baseline_tweak(face, &latin));
let data = FontData { index: face.face_index(), ..FontData::from_static(face.file_data()) }.tweak(tweak);
let families = vec![InsertFontFamily { family: family.clone(), priority: FontPriority::Lowest }];
let data = FontData { index: face.face_index(), ..FontData::from_static(face.file_data()) };
let families = families.iter().map(|family| InsertFontFamily { family: family.clone(), priority: FontPriority::Lowest }).collect();
ctx.add_font(FontInsert { name, data, families });
}
if !faces.is_empty() {
@ -144,86 +139,18 @@ impl UiFonts {
}
/// Call `f` with the text of `shape` and the shapes it holds.
fn painted_text(shape: &Shape, f: &mut impl FnMut(&str, &FontFamily, f32)) {
fn painted_text(shape: &Shape, f: &mut impl FnMut(&str)) {
match shape {
Shape::Text(t) => {
let text = t.galley.text();
for section in &t.galley.job.sections {
let Some(slice) = text.get(section.byte_range.start.0..section.byte_range.end.0) else { continue };
f(slice, &section.format.font_id.family, section.format.font_id.size);
}
}
Shape::Text(t) => f(t.galley.text()),
Shape::Vec(v) => v.iter().for_each(|s| painted_text(s, f)),
_ => {}
}
}
fn baseline_tweak(face: &FontFace, family: &FontFace) -> FontTweak {
FontTweak { scale: 1.0, y_offset_factor: baseline_tweak_factor(face, family), ..Default::default() }
}
fn baseline_tweak_factor(face: &FontFace, family: &FontFace) -> f32 {
let em = |f: &FontFace| {
let (ascent, descent) = f.vertical_metrics();
let upem = f.units_per_em().max(1.0);
(ascent / upem, (ascent + descent) / upem)
};
let (face_ascent, face_height) = em(face);
let (family_ascent, family_height) = em(family);
baseline_factor(face_ascent, face_height, family_ascent, family_height)
}
fn baseline_factor(face_ascent: f64, face_height: f64, family_ascent: f64, family_height: f64) -> f32 {
// Positive `y_offset_factor` moves a glyph down, and epaint counts the tweak in the pen
// position as well as the raster offset, so the correction is twice the fallback's own
// displacement, with the sign that brings it back to the family's ink.
(2.0 * (face_ascent - family_ascent + 0.5 * (family_height - face_height))) as f32
}
fn latin_face() -> Option<Arc<FontFace>> {
static METRICS: std::sync::OnceLock<Option<Arc<FontFace>>> = std::sync::OnceLock::new();
METRICS
.get_or_init(|| {
let db = vectorcraft_text::FontDb::with_font_dirs(Vec::new());
db.add_font(include_bytes!("../../../assets/fonts/SourceSans3-Regular.ttf").to_vec());
db.face("Source Sans 3", "Regular")
})
.clone()
}
fn family_weight(family: &FontFamily) -> f32 {
if *family == FontFamily::Name(crate::theme::FONT_UI_SEMIBOLD.into()) { 600.0 } else { 400.0 }
}
pub(crate) fn craft_font_data(font: &vectorcraft_text::CraftFont) -> FontData {
static DB: std::sync::OnceLock<FontDb> = std::sync::OnceLock::new();
let db = DB.get_or_init(|| FontDb::with_font_dirs(Vec::new()));
let tweak = db.face(font.family, font.style).zip(latin_face()).map_or_else(FontTweak::default, |(face, latin)| baseline_tweak(&face, &latin));
FontData::from_static(font.bytes).tweak(tweak)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn missing_characters_are_tracked_per_family_not_font_size() {
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let mut fonts = UiFonts::default();
ctx.run_ui(Default::default(), |ui| {
ui.label(egui::RichText::new("\u{10FFFD}").font(FontId::proportional(26.0)));
ui.label(egui::RichText::new("\u{10FFFD}").font(crate::theme::semibold(12.0)));
let missing = fonts.missing(ui.ctx());
assert_eq!(missing.len(), 2);
let mut weights: Vec<_> = missing.iter().map(|(family, _)| family_weight(family) as u32).collect();
weights.sort_unstable();
assert_eq!(weights, [400, 600]);
})
.textures_delta
.clear();
}
/// Run a frame painting `text`, then the fallback search after it.
fn frame(ctx: &egui::Context, fonts: &mut UiFonts, text: &str) {
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
@ -297,9 +224,7 @@ mod tests {
crate::theme::install_fonts(&ctx);
let mut fonts = UiFonts::default();
frame(&ctx, &mut fonts, text);
if vectorcraft_text::CRAFT_FONTS.iter().any(|f| f.scripts.contains(&"Hans")) {
assert!(has_glyph(&ctx, '标'), "Chinese is available without waiting for system fonts");
}
assert!(!has_glyph(&ctx, '标'), "the UI fonts have no CJK");
fonts.finish(&ctx);
// The fonts arrive with the next frame.
frame(&ctx, &mut fonts, text);

View File

@ -1140,12 +1140,8 @@ pub enum PanelDrag {
/// `ids`); the panel moves it to where it is dropped.
GraphicStyle(String),
/// The selected art, dragged off the canvas with the Selection tool: the Graphic Styles panel
/// makes a style of the first object (`graphicStyle.new`), the Symbols panel a symbol of it all
/// (`symbol.new`).
/// makes a style of the first object (`graphicStyle.new`).
Art(Vec<vectorcraft_doc::NodeId>),
/// A Symbols panel symbol: the canvas places an instance of it centred where it is dropped
/// (`symbol.place`).
Symbol(String),
}
/// The Swatches panel rows a drag from that panel moves: the swatch, None, Registration or colour

View File

@ -3,16 +3,6 @@
`vectorcraft --control <port>` listens on `127.0.0.1:<port>` (loopback only). One JSON request per line:
`{"id": 1, "method": "ui.inspect", "params": {}}` → `{"id": 1, "ok": true, "result": {...}}` or `{"id":1,"ok":false,"error":"..."}`.
**Only requests are read.** Every line must be a JSON object with a string `method` (`id` and `params`
are optional; blank lines are skipped). Anything else gets one error reply
(`{"ok": false, "error": "… closing the connection"}`) and the server **closes the connection**, so
nothing sent after it on that connection runs. That covers text that isn't JSON, a JSON array or number,
an object without `method`, invalid UTF-8, and a line longer than 4 MiB. An HTTP request (for example a
web page's cross-origin `fetch` to `127.0.0.1:<port>`) therefore can't smuggle a command in its body:
its request line is rejected first. At most 16 connections are served at once; further ones get an error
line and are closed. Clients that get an error reply should reconnect. The port has no authentication,
so only enable it while you use it. Transport: `apps/vectorcraft/src/control_server.rs`.
| Method | Params | |
|---|---|---|
| `engine.execute` | `{command, params}` | run any engine or UI command (see `engine.commands`) |
@ -87,9 +77,7 @@ point (`paint.freeform.selectPoint`); its fields are `color` (hex), `opacity` an
Tool options: double-clicking a tool button runs `tool.options {tool}`. For `gradient` it opens the Gradient panel;
for `eyedropper` it opens Eyedropper Options, an `eyedropperOptions` dialog (fields `sampleSize` 1/3/5, `pickUp` and
`apply`, the attribute trees of `eyedropper.setOptions`) whose `ui.dialog.confirm` runs `eyedropper.setOptions` (what
`appearance.copyFrom` copies). For `hand` it fits the artboard in the window (`view.fitArtboard`) and for `zoom` it
shows 100% (`view.actualSize`). For `rotate`, `scale`, `reflect` and `shear` it opens the same dialog as Object ›
Transform (dialog kind = the tool id), or fails with `nothing selected`. Gradient tool handles snap to
`appearance.copyFrom` copies). Gradient tool handles snap to
anchors, edges and smart guides; Shift constrains them to 45° steps from the `constrainAngle` preference.
Effect dialogs: `engine.execute {command: "effect.dialog", params: {effect, index?, item?}}` opens the `effect` dialog

View File

@ -66,8 +66,8 @@ text at render time from one catalog per language (`i18n/<code>.tsv`; the format
always use the English ids and labels, so agents and scripts never see translated text.
Languages shipped: English (`en`, the source), Traditional Chinese (`zh-hant`, complete, in the vocabulary used
in Taiwan; `zh-TW`, `zh-HK`, `zh-MO` and `zh-Hant-*` locales all resolve to it), Czech (`cs`) and Japanese (`ja`), every menu
label for both. Untranslated text falls back to English until its rows are
in Taiwan; `zh-TW`, `zh-HK`, `zh-MO` and `zh-Hant-*` locales all resolve to it), Czech (`cs`, every menu
label) and Japanese (`ja`, the main menus so far). Untranslated text falls back to English until its rows are
added. Simplified Chinese locales
(`zh-CN`, `zh-SG`, `zh-Hans`) fall back to English until a `zh-hans` catalog is registered: the resolver already
tells the two scripts apart, so the Traditional catalog is never shown to a Simplified locale.

View File

@ -147,7 +147,7 @@ objects' fills or strokes differ (`fillMixed` / `strokeMixed`, drawn as a "?" pr
|---|---|---|
| `list_commands` | `{filter?, enabledOnly?}` | The command catalogue: id, label, menu, shortcut, params doc, enablement. |
| `run_command` | `{command, params?}` | Runs any command. Use it for everything without a dedicated tool. |
| `inspect_document` | `{}` | Artboards, layer tree (ids, kinds, bounds, paint), selection, history, tool. A type node's `fill`, `stroke` and `strokeWidth` are the paint its characters show (its first run's); fills and strokes of the type object itself come as `objectFill`, `objectStroke` and `objectStrokeWidth`. Paint comes as a label (`"#ff0000"`, `"None"`, `"G1 40% (#ff9999)"` for a swatch at a tint); `paint.proxies` gives it as an object. |
| `inspect_document` | `{}` | Artboards, layer tree (ids, kinds, bounds, paint), selection, history, tool. |
| `inspect_ui` | `{}` | UI state. Remote mode only. |
| `select_tool` | `{tool}` | `selection`, `directSelection`, `pen`, `rectangle`, `ellipse`, `polygon`, `star`, `lineSegment`, … |
| `pointer_gesture` | `{events:[{kind,x,y,mods?}], tool?, mods?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`. Events go through the same path as the mouse. |
@ -159,9 +159,9 @@ objects' fills or strokes differ (`fillMixed` / `strokeMixed`, drawn as a "?" pr
| `invoke_menu` | `{command, params?}` | Invokes a menu item by command id. Includes UI commands such as `view.*` and `window.*` in remote mode. |
| `open_panel` | `{panel}` | Remote only. |
| `screenshot` | `{path?, scale?, artboard?, window?}` | Returns MCP image content (`image/png`, base64) plus a text block. Renders the artboard; `window:true` captures the app window (remote only). |
| `open_file` | `{path}` | Opens any readable file as a new active document: `.vectorcraft`/`.drawcraft`, `.vctemplate`, `.svg`/`.svgz`, `.pdf`/`.ai`, `.ait`, `.eps`, `.dxf`, `.emf`, `.wmf`, PNG, JPEG, GIF, WebP, TIFF, BMP (an image opens as a document of its pixel size). Templates (`.vctemplate`, `.ait`) open as a new untitled document. PDF, `.ai` and SVG files saved with Preserve Editing reopen as the document they carry. `run_command document.formats` lists the formats. |
| `open_file` | `{path}` | Opens any readable file as a new active document: `.vectorcraft`/`.drawcraft`, `.svg`/`.svgz`, `.pdf`/`.ai`, `.ait`, PNG, JPEG, GIF, WebP, TIFF, BMP (an image opens as a document of its pixel size). Templates open as a new untitled document. PDF, `.ai` and SVG files saved with Preserve Editing reopen as the document they carry. `run_command document.formats` lists the formats. |
| `save_file` | `{path?}` | Runs `document.save`: the document's own file in its own format (native `.vectorcraft` unless it was opened from or saved as SVG, PDF or a restorable `.ai`; then `warnings` say what that format loses). A path's extension picks the format (`.vectorcraft`, `.vctemplate`, `.pdf`, `.svg`, `.svgz`, `.ai`: a PDF carrying the native document, which reopens editable). |
| `export` | `{path?, format?, scale?, artboard?, range?, selection?, outlineText?, options?}` | `svg`, `svgz`, `pdf`, `eps`, `dxf`, `emf`, `wmf`, `png`, `jpg`, `webp`, `gif`, `png8` (an indexed `.png`), `tiff`, `bmp`, `tga`, `psd` (layered), `txt` (the document's text), `vectorcraft` or `template` (a native template). The tool's `format` enum and `document.formats` list them, generated from the engine's format table. When `format` is omitted, it comes from the path's extension. PDF writes one page per artboard: all of them, or `artboard` (0-based) / `range` (`"1-3, 5"`, 1-based); the other formats write one artboard. `options` carries more format options (e.g. `{"quality": 80}` for JPEG). `selection: true` exports the selected objects cropped to their bounds (the reply adds their `bounds`, and reports `format` and the encoder's `warnings` as a whole-document export does); `outlineText: true` writes SVG text as paths. Template layers are left out, live effects are kept, and exporting `vectorcraft` never changes the document's path. Without `path` the bytes come back as `dataBase64`. Both backends run the same `document.export` call. |
| `export` | `{path?, format?, scale?, artboard?, range?, selection?, outlineText?, options?}` | `svg`, `pdf`, `png`, `jpg`, `webp`, `gif`, `png8` (an indexed `.png`), `tiff`, `bmp`, `tga`, `psd` (layered), `txt` (the document's text) or `vectorcraft` (the list comes from `document.formats`). When `format` is omitted, it comes from the path's extension. PDF writes one page per artboard: all of them, or `artboard` (0-based) / `range` (`"1-3, 5"`, 1-based); the other formats write one artboard. `options` carries more format options (e.g. `{"quality": 80}` for JPEG). `selection: true` exports the selected objects cropped to their bounds; `outlineText: true` writes SVG text as paths. Template layers are left out, live effects are kept, and exporting `vectorcraft` never changes the document's path. Without `path` the bytes come back as `dataBase64`. Both backends run the same `document.export` call. |
| `add_text` | `{text, x?, y?, width?, height?, path?, mode?, pathEffect?, size?, font?, color?}` | Point type at (x, y); area type with `width`/`height`; or `path` + `mode` (`area`/`onPath`) to flow text in or along a path, with `pathEffect` (`rainbow`, `skew`, `3dRibbon`, `stairStep`, `gravity`). |
| `apply_effect` | `{effect?, params?, ids?}` | Appends a live effect. Without `effect`, returns the effect catalogue with parameters and defaults. |
| `pathfinder` | `{operation, ids?}` | `unite`, `minusFront`, `intersect`, `exclude`, `divide`, `trim`, `merge`, `crop`, `outline`, `minusBack`. For a live version, apply the `pathfinder.*` effect to a group (`effect.apply` groups several loose selected objects first). |
@ -755,9 +755,8 @@ fills and strokes become objects among its members, and its members are expanded
A colour linked to a global or spot swatch has a tint (the reference app's T slider): `paint.setFill {swatch,
tint?: 0..100}` (and `paint.setStroke`) applies the swatch at that percentage, linked, so `swatch.edit` recolours it
at its own tint. `paint.proxies` shows the paint as `{type: "solid", color, swatch, tint}` (`tint` 0..1, left out at
100 %); `document.inspect` reports it as a label, the swatch name, the tint below 100 % and the colour it gives
(`"G1 40% (#ff9999)"`, `"G1 (#ff0000)"`). `swatch.new {tint?}` with the current fill (or `swatch`) saves a tint swatch,
at its own tint. `paint.proxies` and `document.inspect` show the paint as `{type: "solid", color, swatch, tint}`
(`tint` 0..1, left out at 100 %). `swatch.new {tint?}` with the current fill (or `swatch`) saves a tint swatch,
"Name 40%": `swatch.list` reports it with `tintOf` and `tint`, applying it links to its base at that tint, and it
follows edits of its base. A spot tint prints that percentage of its plate (Separations Preview, PDF Separation
value). `edit.colors.adjustBalance {tint: -100..100}` (Global mode) shifts the tints of the selection's linked
@ -1790,20 +1789,6 @@ its undo history are as if the click never happened. Commands on the edited text
{"name":"run_command","arguments":{"command":"text.discardEmpty","params":{"id":42}}}
```
## Resizing area type
As in the reference app, dragging a bounding-box handle of area type resizes its type area instead of scaling the
type: the Selection tool sends `object.transform {matrix, typeAreas: true}`, which reshapes the frame of each area
type object it transforms (other objects, type inside groups and point type transform as usual) and reflows the
text at its size, through its thread too. `text.reshapeArea {id, anchors: [[subpath, anchor]…], dx, dy}` moves
frame anchors with their handles (Direct Selection dragging a corner, or an edge's two ends), and
`text.areaOptions {width?, height?}` sizes the area from its top-left corner (the query returns both). Each is one
undo step. Object › Transform › Scale, the Scale tool and the Transform panel still scale the type.
```json
{"name":"run_command","arguments":{"command":"text.reshapeArea","params":{"id":42,"anchors":[[0,2]],"dx":40,"dy":60}}}
```
## Constrain proportions
The link between W and H in the Transform panel, the Properties panel and the Control bar is the