diff --git a/crates/engine/src/cmd/retype.rs b/crates/engine/src/cmd/retype.rs index 605ddd08ec..c846c34a51 100644 --- a/crates/engine/src/cmd/retype.rs +++ b/crates/engine/src/cmd/retype.rs @@ -48,7 +48,7 @@ pub fn specs() -> Vec { "Retype", ["Type"], None, - "{fonts?: [family…], tolerance?: 0..0.05 (default 0: exact matches only)} turn the selected outlined text (glyph paths and compound paths, inside groups too) back into live type: each shape is matched against the glyphs of the fonts the app has loaded, the document's fonts and the families in fonts, the same up to uniform scale, rotation and translation; with a tolerance above 0, a shape that is no glyph exactly may nearly be one (an outline simplified, a curve split in two, contours in another order, start or direction) when its leftover distance from the glyph, relative to the shape's outline spread (the root mean square distance of its sampled outline points from their center), is at most the tolerance (VectorCraft's own measure; shapes of at most 8 contours); a compound path holding several glyphs (a word outlined as one path, at most 256 contour groups and 512 contours, and 16,384 contours per command) is split into them, and becomes type only when every one of them matches; matched glyphs become point text in that font and size at the same baseline, one object per line unless lines stack into one (below), with the first glyph's fill, stroke, opacity and blend mode, in one undo step; a line of three or more exactly matched glyphs takes the spacing most of its gaps share as its tracking (pair kerning left out) when tracked type draws all of it in place, or more of it than untracked type (when untracked type also draws it, untracked type is kept if the tracking is under one unit or the tracked type would drop a gap one space wide (a b c keeps its spaces), and the tracked type otherwise), and negative tracking only when the line is opaque, Normal, with a solid fill or none and no stroke (its glyphs may overlap); lines that follow each other in paint order with the same group, paint, font, size, turn and tracking (an untracked line of one or two glyphs takes the others' tracking), each one the same leading (0.25 to 3 times the size) below the one before, and lined up at their starts, ends or centers become one area type object with that leading (Auto when Auto gives it) and left, right or center alignment, or one multi-line point type object when area type (after Text Wrap) would not draw the outlines' glyphs in their places or when checking the Text Wrap objects on the changed layers would copy more than 2,000,000 anchors, subpaths and shapes; where even that type would move a glyph, the lines before that glyph's line stay one object and the rest are joined again from that line; lines with an opacity below 100%, a blend mode other than Normal, a gradient or pattern fill or a stroke stay one object each; a line splits where its type would not draw the outlines' glyphs in their places (uneven spacing, manual kerning, font substitutions; with a tolerance, within it); a glyph must also paint the area the shape paints under its fill rule (a nonzero compound whose inner contour runs the same way as its outer one paints its center, so a ring glyph does not replace it; a contour narrower than three times the outline tolerance, or parts of a split compound that overlap where its fill rule leaves the overlap unpainted, also keep the shape an outline); shapes that match no font, glyphs type cannot draw as they are, and shapes with their own opacity mask stay as they are → {ids (the new type), texts (lines joined by \\n), fonts: [{family, style, size, tracking (1/1000 em), leading (pt, null for Auto or one line), area (bool), score (how closely the line's least close glyph fits, 1 for exact, 0 at a leftover distance of 0.05)}], unmatched: [id…] (shapes that stayed as they are when another shape became type), truncated (shapes past the limits of 2048 shapes or 16 nested groups were left out)}; an error, with no unmatched list, when no shape becomes type, or when tolerance is not a number from 0 to 0.05", + "{fonts?: [family…], tolerance?: 0..0.05 (default 0: exact matches only)} turn the selected outlined text (glyph paths and compound paths, inside groups too) back into live type: each shape is matched against the glyphs of the fonts the app has loaded, the document's fonts and the families in fonts, the same up to uniform scale, rotation and translation; with a tolerance above 0, a shape that is no glyph exactly may nearly be one (an outline simplified, a curve split in two, contours in another order, start or direction) when its leftover distance from the glyph, relative to the shape's outline spread (the root mean square distance of its sampled outline points from their center), is at most the tolerance (VectorCraft's own measure; shapes of at most 8 contours); a compound path holding several glyphs (a word outlined as one path, at most 256 contour groups and 512 contours, and 16,384 contours per command) is split into them, and becomes type only when every one of them matches; matched glyphs become point text in that font and size at the same baseline, one object per line unless lines stack into one (below), with the first glyph's fill, stroke, opacity and blend mode, in one undo step; a line of three or more exactly matched glyphs takes the spacing most of its gaps share as its tracking (pair kerning left out) when tracked type draws all of it in place, or more of it than untracked type (when untracked type also draws it, untracked type is kept if the tracking is under one unit or the tracked type would drop a gap one space wide (a b c keeps its spaces), and the tracked type otherwise), and negative tracking only when the line is opaque, Normal, with a solid fill or none and no stroke (its glyphs may overlap); lines that follow each other in paint order with the same group, paint, font, size, turn and tracking (an untracked line of one or two glyphs takes the others' tracking), each one the same leading (0.25 to 3 times the size) below the one before, and lined up at their starts, ends or centers become one area type object with that leading (Auto when Auto gives it) and left, right or center alignment, or one multi-line point type object when area type (after Text Wrap) would not draw the outlines' glyphs in their places or when checking the Text Wrap objects on the changed layers would copy more than 2,000,000 anchors, subpaths and shapes; where even that type would move a glyph, the lines before that glyph's line stay one object and the rest are joined again from that line; lines with an opacity below 100%, a blend mode other than Normal, a gradient or pattern fill or a stroke stay one object each; a line splits where its type would not draw the outlines' glyphs in their places (uneven spacing, manual kerning, font substitutions; with a tolerance, within it); a glyph must also paint the area the shape paints under its fill rule (a nonzero compound whose inner contour runs the same way as its outer one paints its center, so a ring glyph does not replace it; a counter narrower than three times the outline tolerance across in some direction, an outline too large to check, or parts of a split compound that overlap where its fill rule leaves the overlap unpainted, also keep the shape an outline); shapes that match no font, glyphs type cannot draw as they are, and shapes with their own opacity mask stay as they are → {ids (the new type), texts (lines joined by \\n), fonts: [{family, style, size, tracking (1/1000 em), leading (pt, null for Auto or one line), area (bool), score (how closely the line's least close glyph fits, 1 for exact, 0 at a leftover distance of 0.05)}], unmatched: [id…] (shapes that stayed as they are when another shape became type), truncated (shapes past the limits of 2048 shapes or 16 nested groups were left out)}; an error, with no unmatched list, when no shape becomes type, or when tolerance is not a number from 0 to 0.05", has_selected_path, retype )] @@ -1178,14 +1178,20 @@ fn split_groups(path: &BezPath, budget: &mut usize) -> Vec { /// a path's candidates: its `part` flag is set for a part of a split shape, whose contours Make /// Compound Path may have turned the other way round, and its `near` flag allows near matches. /// Exact matches come first: the whole shape, then its groups, then the whole shape nearly, then -/// its groups nearly. A split of several parts is kept only when `together` accepts the paths of -/// its runs (the parts, set one beside another, paint what the shape paints). -fn parts(path: &BezPath, groups: &[BezPath], find: &dyn Fn(&BezPath, bool, bool) -> Vec, together: &dyn Fn(&[BezPath]) -> bool) -> Vec> { +/// its groups nearly. A split of several parts is kept only when `together(runs, near)` accepts the +/// paths of its runs (the parts, set one beside another, paint what the shape paints); `near` is +/// set when the parts were found by near matching. +fn parts( + path: &BezPath, + groups: &[BezPath], + find: &dyn Fn(&BezPath, bool, bool) -> Vec, + together: &dyn Fn(&[BezPath], bool) -> bool, +) -> Vec> { let whole = find(path, false, false); if !whole.is_empty() { return vec![whole]; } - let exact = split_parts(groups, &|run| find(run, true, false), together); + let exact = split_parts(groups, &|run| find(run, true, false), &|runs| together(runs, false)); if !exact.is_empty() { return exact; } @@ -1193,7 +1199,7 @@ fn parts(path: &BezPath, groups: &[BezPath], find: &dyn Fn(&BezPath, bool, bo if !whole.is_empty() { return vec![whole]; } - split_parts(groups, &|run| find(run, true, true), together) + split_parts(groups, &|run| find(run, true, true), &|runs| together(runs, true)) } /// [`parts`] of a shape split into contour `groups`, each run's candidates from `find`; empty for @@ -1374,7 +1380,14 @@ fn retype(s: &mut Session, p: &Value) -> Result { return vec![]; } let fill = pc.filled.then_some(pc.nonzero); - let together = |runs: &[BezPath]| fill.is_none_or(|nz| vectorcraft_text::retype::parts_paint_alike(&pc.path, runs, nz, tolerance)); + // Parts that all match exactly are checked at tolerance 0, in the near phase as in + // the exact one; only a part that matches nearly brings the tolerance in. + let together = |runs: &[BezPath], near: bool| { + fill.is_none_or(|nz| { + let nearly = near && runs.iter().any(|r| find(r, true, false, fill).is_empty()); + vectorcraft_text::retype::parts_paint_alike(&pc.path, runs, nz, if nearly { tolerance } else { 0.0 }) + }) + }; parts(&pc.path, g, &|p, part, near| find(p, part, near, fill), &together) }) .collect(); diff --git a/crates/engine/src/cmd/retype_tests.rs b/crates/engine/src/cmd/retype_tests.rs index 05c8210542..f32b036fde 100644 --- a/crates/engine/src/cmd/retype_tests.rs +++ b/crates/engine/src/cmd/retype_tests.rs @@ -1202,6 +1202,50 @@ fn glyphs_that_overlap_in_an_even_odd_compound_stay_an_outline() { assert!(s.doc().unwrap().doc == before, "nothing changes"); } +#[test] +fn overlapping_exact_glyphs_stay_an_outline_when_near_matches_are_allowed() { + // Exact parts the even-odd rule rejects stay rejected when the near phase finds them again. + for dx in [-9.0, -11.0, -12.0, -13.0, -14.0] { + let mut s = session(); + let g = outlined(&mut s, json!({"x": 40, "y": 100, "text": "oo", "size": 40})); + let kids = children_of(&s, g); + s.execute("object.move", &json!({"ids": [kids[1]], "dx": dx, "dy": 0})).unwrap(); + s.execute("select.set", &json!({"ids": kids})).unwrap(); + let c = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap(); + s.execute("select.set", &json!({"ids": [c]})).unwrap(); + for tolerance in [0.0, 0.05] { + if let Ok(r) = s.execute("type.retype", &json!({"tolerance": tolerance})) { + panic!("the overlapping o's became type at dx {dx}, tolerance {tolerance}: {r}"); + } + } + } +} + +#[test] +fn exact_parts_of_a_compound_are_checked_at_tolerance_zero() { + let mut s = session(); + // A T and an o whose boxes overlap by 4 units, one painted area apart (the o sits under the + // bar's arm): a strip that the probes of tolerance 0.05 cannot see into but those of an exact + // match can. Both parts match exactly, so asking for near matches does not change the result. + let g = outlined(&mut s, json!({"x": 40, "y": 100, "text": "To", "size": 40})); + let kids = children_of(&s, g); + let (t, o) = (kids[0], kids[1]); + let bounds = |s: &Session, id: u64| s.doc().unwrap().doc.node(NodeId(id)).unwrap().geometric_bounds().unwrap(); + let dx = bounds(&s, t).x1 - 4.0 - bounds(&s, o).x0; + s.execute("object.move", &json!({"ids": [o], "dx": dx, "dy": 0})).unwrap(); + s.execute("select.set", &json!({"ids": kids})).unwrap(); + let c = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap(); + for params in [json!({}), json!({"tolerance": 0.05})] { + s.execute("select.set", &json!({"ids": [c]})).unwrap(); + let before = s.doc().unwrap().doc.clone(); + let r = s.execute("type.retype", ¶ms).unwrap(); + assert_eq!(r["unmatched"], json!([]), "{params}: {r}"); + assert!(s.doc().unwrap().doc.node(NodeId(c)).is_none(), "{params}: the compound becomes type"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.doc().unwrap().doc == before, "{params}: undo restores it"); + } +} + #[test] fn glyphs_side_by_side_in_an_even_odd_compound_still_become_type() { let mut s = session(); @@ -1257,15 +1301,15 @@ fn a_split_takes_a_shorter_run_when_the_longest_leaves_a_group_unmatched() { } }; let groups = all_groups(&p); - assert_eq!(super::parts(&p, &groups, &find, &|_| true), vec![vec!["A"], vec!["BC"]]); + assert_eq!(super::parts(&p, &groups, &find, &|_, _| true), vec![vec!["A"], vec!["BC"]]); // A split the parts' paint does not allow is dropped. - assert!(super::parts(&p, &groups, &find, &|_| false).is_empty()); + assert!(super::parts(&p, &groups, &find, &|_, _| false).is_empty()); // With no way to match every group, nothing. let none = |path: &kurbo::BezPath, part: bool, _near: bool| -> Vec<&'static str> { let b = path.bounding_box(); if part && b.x0.round() as i64 == 0 && b.x1.round() as i64 == 140 { vec!["AB"] } else { vec![] } }; - assert!(super::parts(&p, &groups, &none, &|_| true).is_empty()); + assert!(super::parts(&p, &groups, &none, &|_, _| true).is_empty()); } /// `path`'s contour groups, with no limit on the contours grouped. @@ -1292,7 +1336,7 @@ fn exact_matches_of_the_parts_come_before_a_near_match_of_the_whole() { } }; let groups = all_groups(&p); - assert_eq!(super::parts(&p, &groups, &find, &|_| true), vec![vec!["period"], vec!["period"]]); + assert_eq!(super::parts(&p, &groups, &find, &|_, _| true), vec![vec!["period"], vec!["period"]]); // When the parts match only nearly too, the whole near match comes first. let near_only = |path: &kurbo::BezPath, part: bool, near: bool| -> Vec<&'static str> { let b = path.bounding_box(); @@ -1302,7 +1346,26 @@ fn exact_matches_of_the_parts_come_before_a_near_match_of_the_whole() { _ => vec![], } }; - assert_eq!(super::parts(&p, &groups, &near_only, &|_| true), vec![vec!["dieresis"]]); + assert_eq!(super::parts(&p, &groups, &near_only, &|_, _| true), vec![vec!["dieresis"]]); + // The split's paint check is told whether the parts were found nearly: exact parts are + // checked at tolerance 0 whatever tolerance the command was given. + let seen = std::cell::RefCell::new(vec![]); + let record = |_: &[kurbo::BezPath], near: bool| { + seen.borrow_mut().push(near); + true + }; + assert_eq!(super::parts(&p, &groups, &find, &record), vec![vec!["period"], vec!["period"]]); + assert_eq!(*seen.borrow(), vec![false]); + seen.borrow_mut().clear(); + let split_near_only = |path: &kurbo::BezPath, part: bool, near: bool| -> Vec<&'static str> { + let b = path.bounding_box(); + match (part, near, b.x0.round() as i64, b.x1.round() as i64) { + (true, true, 0, 40) | (true, true, 100, 140) => vec!["period"], + _ => vec![], + } + }; + assert_eq!(super::parts(&p, &groups, &split_near_only, &record), vec![vec!["period"], vec!["period"]]); + assert_eq!(*seen.borrow(), vec![true]); } #[test] diff --git a/crates/text/src/retype.rs b/crates/text/src/retype.rs index 8a65126569..1c9f8795b1 100644 --- a/crates/text/src/retype.rs +++ b/crates/text/src/retype.rs @@ -1120,14 +1120,14 @@ const MAX_FILL_PROBES: usize = 512; /// `glyph` (filled by the nonzero rule), whose outlines lie within `tol` of each other, paint the /// same area? Each probe lies `1.5 tol` or `3 tol` to a side of the middle of a segment of the shape's /// outline; one within `tol` of either outline is skipped, so a region narrower than that is not -/// probed. `false` when a contour of the shape is narrower than `3 tol` on its shorter side, since -/// the probes cannot then tell whether the area inside it is painted; `true` when an outline is too -/// large to probe. +/// probed. `false` when a counter of the shape (a contour inside another) is narrower than `3 tol` +/// across in some direction, however it is turned, since the probes cannot then tell whether the +/// area inside it is painted, and `false` when an outline is too large to probe. fn paints_alike(shape: &BezPath, nonzero: bool, glyph: &BezPath, tol: f64) -> bool { if narrow_contour(shape, 3.0 * tol) { return false; } - let (Some(fs), Some(fg)) = (Flat::new(shape, tol), Flat::new(glyph, tol)) else { return true }; + let (Some(fs), Some(fg)) = (Flat::new(shape, tol), Flat::new(glyph, tol)) else { return false }; let step = fs.segs.len().div_ceil(MAX_FILL_PROBES).max(1); for (s, e) in fs.segs.iter().step_by(step) { let d = *e - *s; @@ -1154,9 +1154,74 @@ fn paints_alike(shape: &BezPath, nonzero: bool, glyph: &BezPath, tol: f64) -> bo true } -/// Does `path` have a contour no wider than `width` on its shorter side that lies inside another -/// contour (a counter)? +/// The least width of the convex hull of `path` over every direction it could be measured in, its +/// points flattened to within `tol`; 0 when the hull has fewer than three corners and when the +/// path flattens to more than [`MAX_OUTLINE_POINTS`] points. +fn hull_width(path: &BezPath, tol: f64) -> f64 { + let mut pts: Vec = vec![]; + let mut too_many = false; + kurbo::flatten(path.iter(), tol, |el| { + if let PathEl::MoveTo(q) | PathEl::LineTo(q) = el { + if pts.len() >= MAX_OUTLINE_POINTS { + too_many = true; + } else { + pts.push(q); + } + } + }); + if too_many { + return 0.0; + } + pts.sort_by(|a, b| a.x.total_cmp(&b.x).then(a.y.total_cmp(&b.y))); + // Points a thousandth of `tol` apart are one point: their chord has no direction to speak of. + let eps = tol * 1e-3; + pts.dedup_by(|b, a| a.distance(*b) <= eps); + let cross = |o: Point, a: Point, b: Point| (a - o).cross(b - o); + let mut hull: Vec = vec![]; + for pass in 0..2 { + let from = hull.len(); + let ordered: Vec = if pass == 0 { pts.clone() } else { pts.iter().rev().copied().collect() }; + for p in ordered { + while hull.len() >= from + 2 && hull.get(hull.len() - 2).zip(hull.last()).is_some_and(|(a, b)| cross(*a, *b, p) <= 0.0) { + hull.pop(); + } + hull.push(p); + } + hull.pop(); + } + if hull.len() < 3 { + return 0.0; + } + // Rotating calipers: the point farthest from each edge only moves forward from one edge to the + // next, so the whole walk visits each hull point a bounded number of times. + let n = hull.len(); + let mut least = f64::INFINITY; + let mut j = 1; + for (i, a) in hull.iter().enumerate() { + let Some(b) = hull.get((i + 1) % n) else { continue }; + let edge = *b - *a; + let len = edge.hypot(); + if len <= 0.0 || !len.is_finite() { + continue; + } + let away = |k: usize| hull.get(k % n).map_or(0.0, |p| (edge.cross(*p - *a) / len).abs()); + let mut steps = 0; + while steps < n && away(j + 1) >= away(j) { + j += 1; + steps += 1; + } + least = least.min(away(j)); + j %= n; + } + if least.is_finite() { least } else { 0.0 } +} + +/// Does `path` have a contour inside another contour (a counter) whose convex hull is no wider +/// than `width` in some direction? fn narrow_contour(path: &BezPath, width: f64) -> bool { + if !width.is_finite() || width <= 0.0 { + return false; + } let mut all: Vec = vec![]; for el in path.elements() { if matches!(el, PathEl::MoveTo(_)) { @@ -1168,8 +1233,7 @@ fn narrow_contour(path: &BezPath, width: f64) -> bool { } all.iter().enumerate().any(|(i, c)| { let Some(PathEl::MoveTo(at)) = c.elements().first().copied() else { return false }; - let bb = c.bounding_box(); - bb.width().min(bb.height()) <= width && all.iter().enumerate().any(|(j, o)| j != i && o.winding(at) != 0) + all.iter().enumerate().any(|(j, o)| j != i && o.winding(at) != 0) && hull_width(c, width / 30.0) <= width }) } @@ -1970,6 +2034,73 @@ mod tests { assert!(paints_alike(&wide_hole, true, &wide_hole, 1.0)); } + #[test] + fn a_counter_turned_too_narrow_to_probe_does_not_count_as_agreeing() { + let square = |x0: f64, y0: f64, x1: f64, y1: f64, back: bool| { + let p = kurbo::Rect::new(x0, y0, x1, y1).to_path(0.1); + if back { p.reverse_subpaths() } else { p } + }; + // A 60 by 10 counter turned 45 degrees: its box is about 49.5 square, wider than the + // threshold of about 31.8, but it is 10 across. + let strip = |back: bool| { + let turn = Affine::translate((50.0, 50.0)) * Affine::rotate(std::f64::consts::FRAC_PI_4); + let mut p = kurbo::Rect::new(-30.0, -5.0, 30.0, 5.0).to_path(0.1); + if back { + p = p.reverse_subpaths(); + } + turn * p + }; + let mut filled = square(0.0, 0.0, 100.0, 100.0, false); + filled.extend(strip(false).iter()); + let mut holed = square(0.0, 0.0, 100.0, 100.0, false); + holed.extend(strip(true).iter()); + let tol = 100.0_f64.hypot(100.0) * 0.5 * 3.0 * MAX_TOLERANCE; + assert!(narrow_contour(&filled, 3.0 * tol)); + assert!(!paints_alike(&filled, true, &holed, tol)); + // The same strip with its sides along the axes is told apart as before. + let mut level = square(0.0, 0.0, 100.0, 100.0, false); + level.extend(square(20.0, 45.0, 80.0, 55.0, false).iter()); + assert!(narrow_contour(&level, 3.0 * tol)); + // A counter wider than the threshold in every direction is not narrow. + let mut wide = square(0.0, 0.0, 100.0, 100.0, false); + wide.extend(square(10.0, 10.0, 90.0, 90.0, false).iter()); + assert!(!narrow_contour(&wide, 3.0 * tol)); + } + + #[test] + fn the_hull_width_is_the_least_width_in_any_direction() { + let strip = kurbo::Rect::new(-30.0, -5.0, 30.0, 5.0).to_path(0.1); + for deg in [0.0_f64, 17.0, 45.0, 90.0, 133.0] { + let w = hull_width(&(Affine::rotate(deg.to_radians()) * strip.clone()), 0.01); + assert!((w - 10.0).abs() < 0.05, "{deg} degrees: {w}"); + } + let circle = kurbo::Circle::new((5.0, 7.0), 50.0).to_path(0.1); + assert!((hull_width(&circle, 0.01) - 100.0).abs() < 0.5, "{}", hull_width(&circle, 0.01)); + // A triangle's least width is its shortest height. + let mut tri = BezPath::new(); + tri.move_to((0.0, 0.0)); + tri.line_to((40.0, 0.0)); + tri.line_to((0.0, 30.0)); + tri.close_path(); + assert!((hull_width(&tri, 0.01) - 24.0).abs() < 1e-9); + assert_eq!(hull_width(&BezPath::new(), 0.01), 0.0); + } + + #[test] + fn an_outline_too_large_to_probe_does_not_count_as_agreeing() { + let n = MAX_OUTLINE_POINTS + 64; + let mut many = BezPath::new(); + for i in 0..n { + let a = std::f64::consts::TAU * i as f64 / n as f64; + let p = Point::new(50.0 + 50.0 * a.cos(), 50.0 + 50.0 * a.sin()); + if i == 0 { many.move_to(p) } else { many.line_to(p) } + } + many.close_path(); + assert!(Flat::new(&many, 0.5).is_none(), "too many segments to flatten"); + assert!(!paints_alike(&many, true, &many, 0.5)); + assert!(paints_alike(&kurbo::Circle::new((50.0, 50.0), 50.0).to_path(0.1), true, &kurbo::Circle::new((50.0, 50.0), 50.0).to_path(0.1), 0.5)); + } + #[test] fn parts_that_overlap_under_the_even_odd_rule_do_not_paint_the_shape() { let square = |x0: f64, y0: f64, x1: f64, y1: f64| kurbo::Rect::new(x0, y0, x1, y1).to_path(0.1); diff --git a/docs/mcp.md b/docs/mcp.md index 30b2f3ea56..910853c024 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -11332,9 +11332,9 @@ first, then exact matches of its groups, then near matches of the whole shape, t compound becomes type only when every one of its glyphs does; otherwise it stays as it is and is reported once in `unmatched` when another shape of the selection becomes type, and the command returns an error when no shape does. A glyph also has to paint the area the shape paints under the shape's fill rule: a compound filled by the nonzero rule -whose inner contour runs the same way as its outer one paints its center, so a ring glyph does not replace it. A shape with a contour narrower than three times the -outline tolerance on its shorter side cannot be checked this way and stays an outline: at `tolerance` 0.05, a -counter 10 units wide in a 100 by 100 shape. The glyphs of a compound path that splits into several are set one beside +whose inner contour runs the same way as its outer one paints its center, so a ring glyph does not replace it. A shape with a counter narrower than three times the +outline tolerance across in some direction, turned or not, cannot be checked this way and stays an outline: at `tolerance` 0.05, a +counter 10 units wide in a 100 by 100 shape, or a 60 by 10 one turned 45 degrees. So does a shape whose outline is too large to check. The glyphs of a compound path that splits into several are set one beside another, so a split whose parts overlap where the shape's fill rule leaves the overlap unpainted (two o's on each other under the even-odd rule) stays an outline. Glyphs fused into one contour are not split, and a compound path of more than 256 groups or 512 contours is matched whole only. One command groups at most 16,384 contours, in selection order; the shapes after them are diff --git a/docs/type-parity.md b/docs/type-parity.md index d8e2c1e474..33867c2a92 100644 --- a/docs/type-parity.md +++ b/docs/type-parity.md @@ -56,7 +56,7 @@ against Illustrator's public documentation; **estimated** unless noted. | Alt + numeric-keypad codes while typing (Windows: `Alt+0176` → °) | partial | #5108: on Windows the character Windows posts when Alt comes up after keypad digits is typed at the caret like any other, in the typing's undo step, and the keypad digits typed with Alt run no shortcut. With NumLock off the keypad keys (Insert, End, arrows, Clear, Home, Page Up/Down without the extended-key flag) count as digits too and don't move the caret (`windows_alt_codes` unit tests; neither NumLock on nor off has been tried on a Windows machine yet). `type.insert {code}` (Windows Alt+0 code, Windows-1252 for 128–159) and `{unicode}` (hex code point) insert a character by its code (`menucmds::insert_a_character_by_its_code`). macOS and Linux have no such system convention and egui reports a keypad digit as the top-row digit, so there it does nothing; a floating panel window doesn't receive the character | | Caret: the arrows and Delete step over whole clusters (Thai consonant with its marks, combining accents, emoji); Backspace removes one character | done | in text with right-to-left characters the arrows move in visual order and stop on both sides of a character drawn with no width, such as a zero width non-joiner | | Touch Type tool | done | moves, scales and rotates one character through its kerning, baseline shift, scales and rotation (`text.touchType`); a character with a preceding logical character on the same line can move along the line in either reading direction; the first logical character moves only up and down. Positive `dx` follows reading order. These direction rules are VectorCraft's choices. | -| Retype (identify fonts in outlines/images) | partial | Phase 1 (#4934): Type › Retype (`type.retype`) turns outlined glyphs back into type when each shape is exactly a glyph of a loaded font, a font the document uses or a family named in `fonts` (the same up to uniform scale, rotation and translation): one object per line unless lines stack into one object as described below, in that font and size, at the same baseline and turn, with the first glyph's fill and stroke, in one undo step; shapes that match no font stay as they are and are reported. Near matches: with `tolerance` (0 to 0.05), shapes of up to 8 contours whose leftover distance from a glyph, relative to the shape's outline spread (the root mean square distance of its sampled outline points from their center), is at most the tolerance (simplified outlines, curves split in two, contours in another order or direction) match too, and each line reports a `score`; a compound path holding several glyphs is split into them and becomes type only when all of them match. Evenly spaced glyphs keep their spacing as tracking (gaps one space wide stay word spaces when type draws them), and lines stacked at one leading and lined up at their starts, ends or centers become one area type object with that leading and alignment (VectorCraft's own rules, checked against the layout). Window › Retype shows the Retype panel, which lists the fonts whose glyphs exactly match at least one selected outlined shape, comparing up to 96 loaded fonts with those of the document's live type first, ranked by how many shapes each matches, with samples, and sets a listed font on selected live type (`retype.find`, `type.retypeFonts`). Missing (phase 2): glyphs fused into one contour, near matches and compound paths of several glyphs in the panel's list, opening the panel from the Type menu, the context menu and the Properties panel's Quick Actions, filtering the list by font source and favorites, installed fonts not yet loaded, text in images. Public behaviour: [identify fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/identify-fonts-using-retype.html), [apply to live text](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/apply-retype-suggested-fonts-to-live-text.html) | +| Retype (identify fonts in outlines/images) | partial | Phase 1 (#4934): Type › Retype (`type.retype`) turns outlined glyphs back into type when each shape is exactly a glyph of a loaded font, a font the document uses or a family named in `fonts` (the same up to uniform scale, rotation and translation): one object per line unless lines stack into one object as described below, in that font and size, at the same baseline and turn, with the first glyph's fill and stroke, in one undo step; shapes that match no font stay as they are and are reported. Near matches: with `tolerance` (0 to 0.05), shapes of up to 8 contours whose leftover distance from a glyph, relative to the shape's outline spread (the root mean square distance of its sampled outline points from their center), is at most the tolerance (simplified outlines, curves split in two, contours in another order or direction) match too, and each line reports a `score`; a compound path holding several glyphs is split into them and becomes type only when all of them match. A line of three or more exactly matched glyphs keeps the spacing most of its gaps share as tracking (gaps one space wide stay word spaces when type draws them); other lines are set untracked, each glyph at its own position, and lines stacked at one leading and lined up at their starts, ends or centers become one area type object with that leading and alignment (VectorCraft's own rules, checked against the layout). Window › Retype shows the Retype panel, which lists the fonts whose glyphs exactly match at least one selected outlined shape, comparing up to 96 loaded fonts with those of the document's live type first, ranked by how many shapes each matches, with samples, and sets a listed font on selected live type (`retype.find`, `type.retypeFonts`). Missing (phase 2): glyphs fused into one contour, near matches and compound paths of several glyphs in the panel's list, opening the panel from the Type menu, the context menu and the Properties panel's Quick Actions, filtering the list by font source and favorites, installed fonts not yet loaded, text in images. Public behaviour: [identify fonts](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/identify-fonts-using-retype.html), [apply to live text](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/apply-retype-suggested-fonts-to-live-text.html) | | Snap to Glyph | done | View › Snap to Glyph (`view.snapToGlyph`): with Smart Guides on, new point type and drawing tools snap to live-text baselines and glyph bounds, the corners of each glyph's box included, turning with rotated type (#5112; `guides::tests::a_drawn_point_lands_on_a_corner_of_a_glyphs_bounds`, `Targets::for_drawing`, `tools::text_tests::snap_to_glyph_lines_up_new_point_type_with_a_baseline`). With Alignment Guides on as well, and Snap to Grid and Snap to Pixel off, both ends of a Measure or Measure & Inspect drag snap to those guides and show them during the drag (`Targets::for_measure`, `xform::measure::tests::its_ends_land_on_glyph_guides_with_snap_to_glyph`). That the Measure tools take the guides is VectorCraft's choice; they leave out Anchor Point, which [the help page](https://helpx.adobe.com/illustrator/desktop/design-with-text/special-characters-glyphs/snap-to-glyph.html) limits to the Pen tool and objects moved with the Selection tool. Character panel menu › Show Snap to Glyph Options: Baseline, x-height, Glyph Bounds, Proximity Guides, Angular Guides and Anchor Point each turn their guides on or off (`view.snapToGlyph.options`, all on by default; #4232), after a Snap to Glyph checkbox for View › Snap to Glyph; showing them scrolls the panel to them (#5273) | | Thai, Lao, Khmer, Myanmar: shaping (marks, reordering), lines broken between words, word-by-word caret and double-click | done | words found by ICU4X's line segmenter: dictionaries on the desktop, LSTM models on the web | | Middle Eastern: bidirectional layout, Paragraph Direction | done | PDF export keeps harakat and zero-advance Noto Arabic dot glyphs in one compatible batch per layout line, with per-glyph vertical offsets (#6309). `crates/pdf/src/tests/realtext.rs` (`mark_text_*`) checks decoded cluster mappings, mixed Arabic/Latin/digits, contour placement against outline export, vertical columns, differing path rotations and PDF/X-1a/3/4. Editable-text import still needs ActualText support (#6165); separately styled or differently rotated clusters and external viewer search/copy remain outside this export-only evidence. |