Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Merge main into #208 (after #207 and #209): keep both IME and vertical-arrow tests

Brandon Thomasf95b032c8237
diff --cc ROADMAP.md
index 804e018ee,c21b2a748..b8e776724
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -112,9 -113,9 +113,9 @@@ grade by behaviour against `plan/illust
- 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), 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.
-- **Japanese interface and vertical type:** VectorCraft ▸ Language switches the menus between English and Japanese (untranslated labels stay English) and persists; the bundled OFL Shippori Mincho gives Japanese glyphs without system fonts. Vertical Type, Vertical Area Type and Vertical Type on a Path create vertical text (columns right to left, upright CJK glyphs with `vert`/`vrt2` alternates); 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.
+- **Japanese interface and vertical type:** VectorCraft ▸ Language switches the menus between English and Japanese (untranslated labels stay English) and persists; the bundled OFL Shippori Mincho gives Japanese glyphs without system 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, Image Trace (12 presets), pattern swatches with pattern editing mode, live Repeat (radial/grid/mirror).
+ - **Advanced art:** live Blends (steps/distance/smooth colour, editable spine, anchor-targeted Blend tool, faithful interpolation, knockout), Envelope Distort (warp/mesh/top object, Reset, full Envelope Options, mesh handles, Edit Contents; type, images, symbols, gradients, patterns and appearance distorted everywhere), Liquify tools with options and pen pressure, Puppet Warp with rotating pins, Perspective Grid with presets, movable planes and projected type, 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):**
- **Swatches:** names follow the colour model and are unique; Swatch Options (process/spot, Global, Gray/RGB/HSB/CMYK/Web, live preview); editing a global or spot swatch recolours every linked fill, stroke and text run in one undo step; multi-select and delete with confirmation; New Swatch and New Color Group dialogs (a group from the selected artwork's colours); swatches in colour groups convert, separate and count like any other. The Swatches panel selects ranges and whole groups, has a find field, and drags swatches to reorder, regroup or paint art; Add Used Colors, Select All Unused, Merge, Ungroup and Sort by Kind; a CMYK document keeps applied colours in CMYK. Swatch libraries: nine generated colour libraries and five gradient libraries in a library panel, saved and loaded as `.vcswatches`, `.gpl` or CSS. Tints of global and spot colours ("Name 40%") stay linked and separate as a percentage of their plate. Spot colours can be defined in Lab (Spot Colors options). A built-in [Registration] swatch prints on every plate.
- **Colour:** a Color Picker (colour field, H/S/B/R/G/B channel slider, HSB/RGB/Lab/CMYK fields, hex, web-only snapping, out-of-gamut correction); the Color panel follows each colour's own model and Alt-click paints the other proxy; proxies look through groups and show "?" for mixed paint; Invert, Complement, Apply Last Color (`,`) and Apply Last Gradient (`.`) keep the colour model; every paint command feeds the recent colours. The Color Guide has 21 harmony rules, Steps and Variation options and Limit to Library. Adjust Color Balance (its Global mode shifts tints) and Saturate preview live; Edit Colors and Recolor also reach meshes, images and patterns. Recolor Artwork has colour reduction, five recolour methods, presets, Limit to Library, a colour-wheel Edit tab and Edit Color Group; a local Color Themes panel saves five-colour themes. Fill/Stroke chips open swatch and mixer popovers, panels have their shortcuts, and Eyedropper Options pick up and apply chosen attributes (Alt and Shift+Alt, image pixels). Fills and strokes can overprint (Attributes panel, Overprint Black options), and CMYK documents blend in inks on screen, in PDF and when flattening.
diff --cc crates/tools/src/text_tests.rs
index 332a3b8f8,519152b97..8188f40c3
--- a/crates/tools/src/text_tests.rs
+++ b/crates/tools/src/text_tests.rs
@@@ -228,21 -228,48 +228,67 @@@ fn vertical_tools_preserve_their_ids_an
}
}
+ #[test]
+ fn ime_ranges_convert_characters_to_bytes() {
+ assert_eq!(char_range_to_bytes("ががく", 1..3), Some(3..9));
+ assert_eq!(char_range_to_bytes("ががく", 3..3), Some(9..9));
+ assert_eq!(char_range_to_bytes("a雅b", 1..2), Some(1..4));
+ assert_eq!(char_range_to_bytes("ががく", 2..4), None, "past the end");
+ #[allow(clippy::reversed_empty_ranges)]
+ let backwards = 2..1;
+ assert_eq!(char_range_to_bytes("ががく", backwards), None, "backwards");
+ }
+
+ #[test]
+ fn marked_text_is_underlined_with_the_converting_clause_thick() {
+ let (mut d, id, mut tool) = editing("曲");
+ let snap = d.clone();
+ let (sel, p) = (Selection::default(), paint());
+ tool.caret = 3;
+ tool.anchor = 3;
+ let acts = tool.ime_preedit(&cx(&d, &sel, &p), "雅楽演奏", Some(2..4));
+ apply(&mut d, &snap, &acts);
+ let NodeKind::Text(t) = &d.node(id).unwrap().kind else { panic!() };
+ assert_eq!(t.plain_text(), "曲雅楽演奏");
+ assert_eq!(tool.preedit, Some(Preedit { range: 3..15, active: Some(6..12) }));
+ let widths: Vec<f32> = tool
+ .overlays(&cx(&d, &sel, &p))
+ .iter()
+ .filter_map(|o| match o {
+ Overlay::Path { width, .. } => Some(*width),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(widths, vec![1.0, 2.5], "a thin underline, then the thick one under 演奏");
+ // The candidate window follows the converting clause.
+ let (top, _) = tool.ime_caret(&cx(&d, &sel, &p)).unwrap();
+ let lay = vectorcraft_text::layout(FontDb::global(), t);
+ let (at, _) = vectorcraft_text::caret_position(&lay, 9);
+ assert!((top - t.xf * at).hypot() < 1e-6);
+ // Keys wait for the IME; a commit replaces the marked text.
+ assert!(key(&mut tool, &d, ToolKey::Backspace, Mods::default()).is_empty());
+ let acts = tool.text_input(&cx(&d, &sel, &p), "雅楽演奏会");
+ apply(&mut d, &snap, &acts);
+ let NodeKind::Text(t) = &d.node(id).unwrap().kind else { panic!() };
+ assert_eq!(t.plain_text(), "曲雅楽演奏会");
+ assert!(!tool.composing());
+ }
++
+#[test]
+fn arrows_follow_the_columns_of_vertical_type() {
+ let (mut d, id) = doc_with_text("§§§\n§§§");
+ if let Some(NodeKind::Text(t)) = d.node_mut(id).map(|n| &mut n.kind) {
+ t.vertical = true;
+ }
+ let mut tool = TypeTool::new("type");
+ tool.start_editing(id, 0);
+ let s = "§".len();
+ key(&mut tool, &d, ToolKey::Down, Mods::default());
+ assert_eq!(tool.caret, s, "↓ goes down the column to the next character");
+ key(&mut tool, &d, ToolKey::Left, Mods::default());
+ assert_eq!(tool.caret, "§§§\n§".len(), "← goes on to the next column, keeping the place in it");
+ key(&mut tool, &d, ToolKey::Right, Mods::default());
+ assert_eq!(tool.caret, s, "→ comes back");
+ key(&mut tool, &d, ToolKey::Up, Mods::default());
+ assert_eq!(tool.caret, 0);
+}