diff --git a/crates/text/src/justify.rs b/crates/text/src/justify.rs index ef7f13be8..a3a141940 100644 --- a/crates/text/src/justify.rs +++ b/crates/text/src/justify.rs @@ -91,6 +91,7 @@ pub(crate) fn apply_desired(sg: &mut [SGlyph], j: &JustificationOptions, scale_g g.adv *= g_des; g.sx *= g_des; g.dx *= g_des; + g.kern_shift *= g_des; } f.width = g.adv; f.scale = g_des; diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 67c52220d..cc1080bdb 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -181,6 +181,7 @@ impl Ctx<'_> { tab.gid = 0; tab.dx = 0.0; tab.dy = 0.0; + tab.kern_shift = 0.0; tab.tcy = None; tab.vpal = None; let pen = para.left_indent + para.first_line_indent + marker.iter().map(|g| g.adv).sum::(); @@ -229,8 +230,9 @@ impl Ctx<'_> { Some(ib) => Affine::translate((-lead, -g.bshift)) * ib.xf, // Baseline shift moves the glyph across its line, and Character Rotation then turns it // about its shifted pen position, so the shift is across the line at any rotation. + // Right-to-left manual kerning moves that pen position along the line. None => { - Affine::translate((0.0, -g.bshift)) + Affine::translate((g.kern_shift, -g.bshift)) * Affine::rotate(-g.rotation.to_radians()) * Affine::translate((g.dx - lead, g.dy)) * Affine::scale_non_uniform(g.sx, g.sy) @@ -238,7 +240,7 @@ impl Ctx<'_> { }; // The turning point in font units, which later moves of the glyph's transform keep. let pivot = match local.determinant() { - det if det != 0.0 && det.is_finite() => local.inverse() * Point::new(0.0, -g.bshift), + det if det != 0.0 && det.is_finite() => local.inverse() * Point::new(g.kern_shift, -g.bshift), _ => Point::ZERO, }; let unturned = if g.inline.is_none() && g.rotation != 0.0 && g.sx != 0.0 && g.sy != 0.0 { @@ -332,6 +334,7 @@ impl Ctx<'_> { k.adv = t; k.dx = 0.0; k.dy = 0.0; + k.kern_shift = 0.0; k.len = 0; k.lead = 0.0; k.ch = kashida::TATWEEL; diff --git a/crates/text/src/layout/wrapping_tests.rs b/crates/text/src/layout/wrapping_tests.rs index 360c386ea..2e036c3cf 100644 --- a/crates/text/src/layout/wrapping_tests.rs +++ b/crates/text/src/layout/wrapping_tests.rs @@ -18,6 +18,7 @@ fn synthetic_glyphs(specs: &[(usize, usize, f64, char)]) -> Vec { adv, dx: 0.0, dy: 0.0, + kern_shift: 0.0, sx: 1.0, sy: 1.0, bshift: 0.0, diff --git a/crates/text/src/shape.rs b/crates/text/src/shape.rs index 6f22baa7f..273c2e95e 100644 --- a/crates/text/src/shape.rs +++ b/crates/text/src/shape.rs @@ -33,6 +33,9 @@ pub(crate) struct SGlyph { /// Offset from the pen position, y down. pub dx: f64, pub dy: f64, + /// Right to left: the run's manual kerning, which moves the glyph right along the baseline, + /// outside its Character Rotation. 0 otherwise. + pub kern_shift: f64, /// Outline scale (font units -> points). pub sx: f64, pub sy: f64, @@ -169,6 +172,7 @@ pub(crate) fn hyphen_glyph(g: &SGlyph) -> SGlyph { h.adv = g.face.advance(gid) * g.sx; h.dx = 0.0; h.dy = 0.0; + h.kern_shift = 0.0; h.byte = g.byte + g.len; h.len = 0; h.ch = '-'; @@ -616,13 +620,17 @@ fn optical_pairs(db: &FontDb, text: &str, glyphs: &mut [SGlyph], runs: &[(Range< { continue; } + // Neither glyph is rotated, so a right-to-left manual kerning shift adds to the offset. + let left_x = left.dx + left.kern_shift; + let right_x = right.dx + right.kern_shift; let left_y = left.dy - left.bshift; let right_y = right.dy - right.bshift; let Some(left_style) = runs.get(left.run).map(|(_, s)| *s) else { continue }; let em = left.sx * left.face.upem / (left_style.h_scale / 100.0); let tracking = left_style.tracking / 1000.0 * em; - let manual = left_style.kerning.unwrap_or(0.0) / 1000.0 * em; - let advance = glyphs[cluster_start..=cluster_end].iter().map(|g| g.adv).sum::() - tracking - manual; + // A manual kerning value on the left glyph is part of its advance and, right to left, of + // its offset too (it spaces the left glyph from its left neighbor): it is not taken off. + let advance = glyphs[cluster_start..=cluster_end].iter().map(|g| g.adv).sum::() - tracking; let key = [ u64::from(left.face.id()), u64::from(left.gid), @@ -630,11 +638,11 @@ fn optical_pairs(db: &FontDb, text: &str, glyphs: &mut [SGlyph], runs: &[(Range< u64::from(right.gid), left.sx.to_bits(), left.sy.to_bits(), - left.dx.to_bits(), + left_x.to_bits(), left_y.to_bits(), right.sx.to_bits(), right.sy.to_bits(), - right.dx.to_bits(), + right_x.to_bits(), right_y.to_bits(), advance.to_bits(), em.to_bits(), @@ -647,8 +655,8 @@ fn optical_pairs(db: &FontDb, text: &str, glyphs: &mut [SGlyph], runs: &[(Range< profile_correction( &a.0, &b.0, - (left.sx, left.sy, left.dx, left_y), - (right.sx, right.sy, right.dx, right_y), + (left.sx, left.sy, left_x, left_y), + (right.sx, right.sy, right_x, right_y), advance, em, left.face.upem, @@ -811,6 +819,7 @@ fn inline_glyph(face: &Arc, st: &CharStyle, art: &InlineArt, run: usiz adv: if adv.is_finite() { adv } else { 0.0 }, dx: 0.0, dy: 0.0, + kern_shift: 0.0, // Not used to draw (the art has its own transform), but they make the glyph's em box // its run's em: Character Alignment and Top-to-Top leading treat an inline graphic as a // character of its run's size, whatever its scale (see `layout::glyph_em`). @@ -1110,12 +1119,21 @@ fn shape_segment(text: &str, context: &Range, seg: &Segment, feats: &OtFe let last_in_cluster = gi + 1 == n || raw[gi + 1].1 as usize != cl; let ch = first_char(cl); let mut adv = xa as f64 * k * hs; + let mut kern_shift = 0.0; if ch == SOFT_HYPHEN || ch == '\u{2028}' { adv = 0.0; - } else if last_in_cluster { - let tracking = gst.tracking / 1000.0 * size; + } else { let manual_kern = gst.kerning.map(|v| v / 1000.0 * size).unwrap_or(0.0); - adv += tracking + manual_kern; + // Manual kerning spaces a character from the next one in reading order. Right to left, + // that one is drawn to its left: the cluster's glyphs move right along the baseline by + // the value, so that the space its last glyph's advance gains is at the cluster's left. + if level.is_rtl() && !feats.vertical { + kern_shift = manual_kern; + } + if last_in_cluster { + let tracking = gst.tracking / 1000.0 * size; + adv += tracking + manual_kern; + } } out.push(SGlyph { face: face.clone(), @@ -1126,6 +1144,7 @@ fn shape_segment(text: &str, context: &Range, seg: &Segment, feats: &OtFe adv, dx: xo as f64 * k * hs, dy: -(yo as f64) * k * vs, + kern_shift, sx: k * hs, sy: k * vs, bshift: gst.baseline_shift + pos_shift, diff --git a/crates/text/src/tests/typo.rs b/crates/text/src/tests/typo.rs index 4742806d1..2627b81ee 100644 --- a/crates/text/src/tests/typo.rs +++ b/crates/text/src/tests/typo.rs @@ -66,6 +66,64 @@ fn optical_pairs_cross_paint_runs_and_manual_and_tracking_are_independent() { assert!((pair_advance(&rtl_manual) - pair_advance(&rtl_pair_zero) - 20.0).abs() < 0.01, "manual spacing changes the adjacent right-to-left pair"); } +#[test] +fn rtl_manual_kerning_spaces_the_character_from_the_next_in_reading_order() { + for optical_kerning in [false, true] { + // Reading order: alef (bytes 0..2), bet (2..4), gimel (4..6); bet carries the kerning. + let base = CharStyle { size: 100.0, optical_kerning, ..CharStyle::default() }; + let kerned = |value: f64| { + let mut t = TextObject::point(Point::ZERO, "אבג", base.clone()); + edit::style_range(&mut t.runs, 2, 4, |s| s.kerning = Some(value)); + layout(db(), &t) + }; + let ink = |lay: &TextLayout, byte: usize| { + let g = lay.glyphs.iter().find(|g| g.byte == byte).unwrap(); + assert!(g.rtl && g.gid != 0, "byte {byte} is set right to left with a glyph of its own"); + (g.xf * Point::ZERO).x + }; + let (plain, spaced) = (kerned(0.0), kerned(200.0)); + let gap = |lay: &TextLayout, right: usize, left: usize| ink(lay, right) - ink(lay, left); + assert!( + (gap(&spaced, 2, 4) - gap(&plain, 2, 4) - 20.0).abs() < 0.01, + "kerning on bet spaces it from gimel, after it in reading order (Optical: {optical_kerning})" + ); + assert!( + (gap(&spaced, 0, 2) - gap(&plain, 0, 2)).abs() < 0.01, + "alef, before bet in reading order, keeps its place (Optical: {optical_kerning})" + ); + // The caret between bet and gimel stays at gimel: the new space is on bet's side of it. + let caret = |lay: &TextLayout| caret_position(lay, 4).0.x; + assert!((caret(&spaced) - ink(&spaced, 4) - (caret(&plain) - ink(&plain, 4))).abs() < 0.01); + assert!((ink(&spaced, 2) - caret(&spaced) - (ink(&plain, 2) - caret(&plain)) - 20.0).abs() < 0.01); + } +} + +#[test] +fn rtl_manual_kerning_on_a_rotated_character_moves_it_along_the_baseline() { + // Reading order: alef (bytes 0..2), bet (2..4), gimel (4..6); bet is turned 90 degrees and + // carries the kerning. + let kerned = |value: f64| { + let mut t = TextObject::point(Point::ZERO, "אבג", CharStyle { size: 100.0, ..CharStyle::default() }); + edit::style_range(&mut t.runs, 2, 4, |s| { + s.kerning = Some(value); + s.rotation = 90.0; + }); + layout(db(), &t) + }; + let origin = |lay: &TextLayout, byte: usize| { + let g = lay.glyphs.iter().find(|g| g.byte == byte).unwrap(); + assert!(g.rtl && g.gid != 0, "byte {byte} is set right to left with a glyph of its own"); + g.xf * Point::ZERO + }; + let (plain, spaced) = (kerned(0.0), kerned(200.0)); + let moved = origin(&spaced, 2) - origin(&plain, 2); + let gimel = origin(&spaced, 4) - origin(&plain, 4); + assert!((moved.x - gimel.x - 20.0).abs() < 0.01, "kerning on the turned bet spaces it from gimel along the line: {moved:?}, {gimel:?}"); + assert!(moved.y.abs() < 0.01, "the turned bet stays on its baseline: {moved:?}"); + let alef = origin(&spaced, 0) - origin(&plain, 0); + assert!((alef.x - moved.x).abs() < 0.01 && alef.y.abs() < 0.01, "alef keeps its place next to bet: {alef:?}"); +} + #[test] fn optical_pair_skips_an_invisible_soft_hyphen_with_an_outline() { use crate::test_fonts::{SOFT_HYPHEN_OUTLINE_FAMILY, soft_hyphen_outline_font}; diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index a7c8d45bf..a147941f2 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -864,6 +864,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Free Distort's dialog (Effect › Distort & Transform › Free Distort…) shows a box in the proportions of the first selected object's bounds with a handle on each corner. Dragging a handle moves that corner. A handle focused by a click or Tab moves 1% of the box with each arrow key, and 10% with Shift. Reset puts the four corners back on the box. The preview and OK run `effect.apply`, or `effect.setParams` when the dialog edits an applied effect, and the Appearance panel's inline editor opens the dialog with Edit…. Behavior reference: Illustrator CC Help (2014, [PDF](https://help.adobe.com/archive/en/illustrator/cc/2014/illustrator_reference.pdf)), page 285 (PDF page 291). - **Optical kerning:** Character and Properties offer Optical beside Auto for automatic pair spacing. The side-profile spacing method is VectorCraft's own. Optical keeps its mode across cosmetic style runs. Choosing Optical clears manual pair values, as Auto does, and leaves additive tracking intact; a manual value typed afterwards replaces that pair's correction ([Adjust kerning and tracking](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/adjust-kerning-and-tracking.html)). Native documents retain the mode and pair overrides; old documents use Auto. Behavior reference: [Line and character spacing](https://web.archive.org/web/20260916050333/https://helpx.adobe.com/illustrator/using/line-character-spacing.html) (public documentation). Tests: `crates/text/src/tests/typo.rs`, `crates/engine/src/tests/textedit.rs`. - **Kerning across style runs:** characters that differ only in fill, stroke, underline, strikethrough, overprint, character style name, leading, baseline shift, rotation, Character Alignment, kerning, or tracking that keeps or drops ligatures alike are shaped together, so restyling one character keeps the font's kerning pairs with its neighbors. A character with manual kerning that follows one with automatic kerning keeps the font's kerning with it (unless All Caps or Small Caps sets it as two letters, as ß becomes SS), and its value replaces the font's kerning after it. A ligature does not form across a change of style, and a change of font, size or OpenType features still shapes the characters apart. Behavior reference: [Line and character spacing](https://web.archive.org/web/20260916050333/https://helpx.adobe.com/illustrator/using/line-character-spacing.html) (public documentation). Tests: `crates/text/src/tests/typo.rs`, `crates/text/src/tests/bidi.rs`. +- **Manual kerning in right-to-left text:** a manual kerning value on a Hebrew or Arabic character changes the space between it and the next character in reading order, the one drawn to its left, under Auto and Optical kerning. The character before it keeps its place, and the caret between the pair stays beside the next character. The side the space goes on is VectorCraft's own rule. Behavior reference: [Line and character spacing](https://web.archive.org/web/20260916050333/https://helpx.adobe.com/illustrator/using/line-character-spacing.html) ("Kerning is the process of adding or subtracting space between specific pairs of characters."). Test: `rtl_manual_kerning_spaces_the_character_from_the_next_in_reading_order`. - **Recent font pickers (#3515):** The shared Character, Properties, Glyphs and Find Font family picker lists recently applied families first, once each, in most-recent order and limited by Preferences › Type › Number of Recent Fonts. Search and filters apply to both sections; unavailable families are omitted. Section headings cannot be selected or previewed. Confirmed character-range font edits update the same saved history; previews and failed edits do not. Requirement: [issue #3515](https://github.com/storytold/vectorcraft/issues/3515). - **Type:** Character size, leading, baseline shift and horizontal-scale controls account for object/group transforms (#1034): exact document-point sizes, mixed-value display and keyboard increments, range edits, resettable horizontal stretch, undo/redo and native save/reopen (`tests_typescale`, Character panel tests). Point size is the transformed em-height axis, independent of glyph ink bounds; affine rotation, reflection and shear are retained. Group scaling still scales text; preserving font sizes is a separate enhancement. Behaviour reference: [Transform text](https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/transform-text.html) (public documentation). Text Wrap, Type on a Path effects (Rainbow/Skew/3D Ribbon/Stair Step/Gravity) and Options (Flip, Align to Path, Spacing; OK keeps the type where it is), type on a path's start, centre and end brackets (Selection and Direct Selection drag them to set where the type runs, slide it along its path and, across the path, flip it: #429), Character and Paragraph Styles (override-preserving redefine), paragraph attributes per paragraph (alignment, indents, spacing, hyphenation, hanging punctuation, tab stops, paragraph style, direction, mojikumi and leading model; the Paragraph, Tabs and Paragraph Styles panels act on the paragraphs the Type tool's selection or caret touches, Return continues the paragraph's style, threads and SVG keep them), Area Type Options (rows/columns/inset/first baseline, Text Flow by rows or by columns (#4978), vertical Align Top/Center/Bottom/Justify per row/column, reflowing non-rectangular frames and text wrap), threaded text across any closed shapes, Fit Headline, the Every-line Composer for justified and ragged text (paragraph-wide breaks for an even rag, Single-line per object from the Paragraph panel menu or `text.setFormat {composer}`). Area type resizes like Illustrator's type areas: a bounding-box handle drag (Selection tool) or Area Type Options Width/Height size the frame and the text reflows at its size (threads too); Direct Selection drags a frame corner or edge (`text.reshapeArea`), and an anchor of the path of type on a path outside perspective, the type reflowing along it (`text.reshapePath`, #3980). Point type still scales. Auto Size: the frame height follows the text after every edit, in the same undo step (rectangular frames of horizontal type in one row; columns get the least height that holds them; a height set by hand or threading turns it off), and the "Auto Size New Area Type" preference gives it to new area type. Shrink Text to Fit (beyond Illustrator): overflowing area type scales its sizes, leading and baseline shifts down by the largest factor (in 0.1 pt steps of the first run, down to a minimum percentage) that fits, at layout time so every export sees it. `text.areaOptions` and `document.inspect` report overflow and the shrink factor. The Selection tool shows the type widget beside selected type's bounding box (hollow on point type, filled on area type); double-clicking it converts between them (Type › Convert To Area Type / Convert To Point Type), keeping the text and its styles in place. Variable fonts list every named instance as a style of their family (Figtree Light to Black and their italics, Bahnschrift, Segoe UI Variable), and the instance chosen is shaped, drawn, outlined and measured at its axis settings; PDF and SVG embed it as that instance. The Character panel's Variable Font sliders set each axis (see Fonts). Beyond Illustrator: inline graphics (`text.insertInline`, Type ▸ Insert Inline Symbol) set a document symbol in a run of type as one character that flows, wraps and justifies like a glyph (InDesign-style inline objects, e.g. mana symbols in card rules text): sized to a multiple of the font size, centred on the cap height, opening up tall lines, following Redefine Symbol; a character of its run's size for Character Alignment and Top-to-Top leading, placed by the bidi reordering in right-to-left text (a neutral U+FFFC); drawn on the canvas, kept as live text plus a `` in SVG and as vector art in PDF; Backspace removes it whole. Hebrew and Arabic are laid out right to left with the Unicode bidirectional algorithm (embedded Latin and numbers keep their direction, lines put in visual order after wrapping) in point, area and path type, with caret, selection and arrow keys in visual order; each paragraph's direction comes from its first strong character unless Paragraph Direction sets it (Paragraph panel with Show Indic Options, `text.setFormat {direction}`), and new type aligns to the start of its direction. SVG export outlines right-to-left text. Arabic typefaces: builds made with a craft-fonts checkout that holds its Arabic families (Noto Sans Arabic, the Arabic fallback, plus Cairo, Tajawal, Almarai, IBM Plex Sans Arabic, Noto Kufi Arabic, Amiri, Alexandria, Fustat, Reem Kufi, Aref Ruqaa and Gulzar once craft-fonts adds them, storytold/craft-fonts#11; releases get them when their craft-fonts pin moves) list them in the font menus on desktop; the web build fetches them from beside the wasm (Noto Sans Arabic before start, so Arabic never shows as boxes, the rest in the background). Font Size and Leading are combo boxes in the Character and Properties panels (Font Size in the Control bar too, beside the Character link, font family and style): type, step with ↑/↓ or the spinner, scrub the label, or pick a preset (6–72 pt, shown in the type unit; Leading also Auto), each pick one undo step; Kerning and Tracking list -100…200; a size, leading, kerning or tracking the selected text doesn't share shows blank (#458). Type › Bold and Italic (beyond Illustrator, as page layout apps have them; Cmd+Shift+B / Cmd+Shift+I while the Type tool edits text) switch the selected type to its family's own Bold or Italic face and back, keeping its width (a Narrow face stays Narrow); a family without that face says so (#724). The commands that make or restyle type (and the MCP `add_text` tool) say in their result when area type does not fit its frame, and `add_text` takes Auto Size and Shrink Text to Fit (#1500, fixes #1471). Cmd+Shift+C (Align center) works on Windows and Linux too (#1940). A double-click on area type's bottom middle handle turns on Auto Size (#1940). Print and Print Preview warn about the area type and type on a path that prints without the text that doesn't fit, and give their ids. A tab stop in the Tabs panel drags from where the press landed, a stop just added included (#1487, fixes #1458). Area type in a non-rectangular shape moves a word too wide for the top lines down to the first line that holds it instead of breaking it (#1617, fixes #1615). Stylistic sets (ss01–ss20), stylistic and titling alternates, proportional and lining figures, and superscript and subscript glyphs can be turned on as OpenType features of a character style (`text.setStyle {features}`), and the OpenType panel keeps them (#1611, fixes #1607). Escape while typing ends the edit, keeps the type selected and switches to the Selection tool (#1802, #1686, #1656). Select › Same matches type on its characters' fill and stroke (#1746, #1737). `text.create`, `text.createInPath` and the MCP `add_text` tool take `justify`, so point type can be centred on or end at its point (#1752, #1748). The Character panel menu's Show Font Height Options shows a Set Font Height Reference dropdown under Font Size (`text.setFormat` or `text.setRangeStyle` `{fontHeightReference}`). With Em Box, the default, the font size is the size of the em square; with Cap Height, x-Height or ICF Box, the characters are set at the em size at which the font's OS/2 cap height, its x height or the height of its ideographic character face equals the font size. With a font that has no such value, or one outside 0.1 to 2 em, the size measures the em box. SVG, PDF and legacy `.ai` export and the CSS Properties rules write the em size the characters are drawn at, and DXF export writes 0.7 times that em size as each TEXT entity's height (group 40, the height of its capitals). Behavior reference: [Vary font height](https://web.archive.org/web/20251118174722/https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/vary-font-height.html).