From ecc9a35499298a885dc7c49652f62624694d888a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 21:58:11 -0800 Subject: [PATCH] Retype: each mark of a compound path keeps its own other character The other character a shape read as a combining mark also is was kept by the shape's id. The parts of a compound path share that id, so with two such marks in one compound the second mark's character replaced the first's, and a split that left the first mark first on a line set it as the second mark's character (a dot below became a small tilde). The character is now kept by the part's own glyph match, and the new test moves a dot below and a tilde off their base into one compound path. --- crates/engine/src/cmd/retype.rs | 24 +++++++++++++++++------- crates/engine/src/cmd/retype_tests.rs | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/retype.rs b/crates/engine/src/cmd/retype.rs index bd984c575d..8a68798aed 100644 --- a/crates/engine/src/cmd/retype.rs +++ b/crates/engine/src/cmd/retype.rs @@ -777,14 +777,22 @@ fn set_apart(t: &TextObject, g: &vectorcraft_text::PositionedGlyph, m: &GlyphMat /// The most glyphs [`verified`] measures the tracking of after a split. const MEASURE_SPAN: usize = 32; +/// One part of shape `id`, by the glyph it matched (face, glyph, origin, turn and scale): the parts +/// of a compound path share its id. +type PartKey = (NodeId, u32, u32, [u64; 4]); + +fn part_key(id: NodeId, m: &GlyphMatch) -> PartKey { + (id, m.face.id(), m.gid, [m.origin.x.to_bits(), m.origin.y.to_bits(), m.angle.to_bits(), m.scale.to_bits()]) +} + /// `lines` checked against their own layout: a line splits where its type stops drawing the /// outlines, and a glyph its type cannot draw even on its own stays an outline (`unmatched`). -/// `spacing` holds, for a shape read as a combining mark, the other character its shape is. -/// The glyphs laid out are bounded by a multiple of the number of glyphs. +/// `spacing` holds, for a part of a shape read as a combining mark, the other character that part +/// is. The glyphs laid out are bounded by a multiple of the number of glyphs. fn verified( lines: Vec, system_layout: bool, - spacing: &std::collections::HashMap, + spacing: &std::collections::HashMap, unmatched: &mut Vec, ) -> Vec { // Glyphs laid out in all, at most: past it, the glyphs left unchecked stay outlines. @@ -808,7 +816,7 @@ fn verified( // line with one). if l.matches.first().is_some_and(|m| vectorcraft_text::retype::is_combining_mark(m.ch)) { let first = l.pieces.first().copied(); - let alone = first.and_then(|id| spacing.get(&id).map(|m| reposed(&l, id, m))); + let alone = first.zip(l.matches.first()).and_then(|(id, mark)| spacing.get(&part_key(id, mark)).map(|m| reposed(&l, id, m))); if alone.is_none() { unmatched.extend(first); } @@ -1802,7 +1810,7 @@ fn retype(s: &mut Session, p: &Value) -> Result { let mut unmatched = vec![]; // An unmatched shape between glyphs ends the line: the type after it is painted after it. let mut open = false; - let mut spacing: std::collections::HashMap = std::collections::HashMap::new(); + let mut spacing: std::collections::HashMap = std::collections::HashMap::new(); // How many glyphs each shape is: a shape of several becomes type only when all of them do. let mut glyphs_of: std::collections::HashMap = std::collections::HashMap::new(); for (pc, parts) in pieces.iter().zip(&found) { @@ -1825,7 +1833,8 @@ fn retype(s: &mut Session, p: &Value) -> Result { }; // A part that joined a line, perhaps as a mark, that is also another character, in // that face or else in the face most shapes fit of those it is a character in: the - // character, should a split leave the shape first on a line ([`verified`]). + // character, should a split leave the part first on a line ([`verified`]). Kept by + // the glyph the part joined as, since the parts of a compound path share its id. let is_mark = |m: &GlyphMatch| vectorcraft_text::retype::is_combining_mark(m.ch); if joined && cands.iter().any(is_mark) @@ -1833,8 +1842,9 @@ fn retype(s: &mut Session, p: &Value) -> Result { .iter() .find(|m| !is_mark(m)) .or_else(|| ms.iter().enumerate().filter(|(_, m)| !is_mark(m)).max_by(ranked).map(|(_, m)| m)) + && let Some(at) = lines.last().and_then(|l| l.matches.last()) { - spacing.insert(pc.id, m.clone()); + spacing.insert(part_key(pc.id, at), m.clone()); } if !joined { // A part that is only marks in that face may be another character in a face diff --git a/crates/engine/src/cmd/retype_tests.rs b/crates/engine/src/cmd/retype_tests.rs index a95a32a939..3c3f35de6b 100644 --- a/crates/engine/src/cmd/retype_tests.rs +++ b/crates/engine/src/cmd/retype_tests.rs @@ -200,6 +200,27 @@ fn a_combining_mark_starts_no_line() { assert_eq!(left, pair, "{r}"); } +#[test] +fn marks_of_one_compound_path_each_become_their_own_character() { + // Two marks that are also other characters (dot below, dot above; tilde, small tilde), moved + // off their base and made one compound path: each becomes the character its own shape is. + let mut s = session(); + let g = outlined(&mut s, json!({"x": 40, "y": 100, "text": "x\u{323}\u{303}yz", "size": 40, "font": "Source Sans 3", "style": "Regular"})); + let kids: Vec = s.doc().unwrap().doc.children(Some(NodeId(g))).unwrap().iter().map(|n| n.id.0).collect(); + assert_eq!(kids.len(), 5); + s.execute("select.set", &json!({"ids": [kids[1], kids[2]]})).unwrap(); + s.execute("object.move", &json!({"dx": 3, "dy": 0})).unwrap(); + s.execute("object.compoundPath.make", &json!({})).unwrap(); + s.execute("select.set", &json!({"ids": [g]})).unwrap(); + let r = s.execute("type.retype", &json!({})).unwrap(); + assert_eq!(r["unmatched"], json!([]), "{r}"); + let texts: Vec<&str> = r["texts"].as_array().unwrap().iter().map(|t| t.as_str().unwrap()).collect(); + let mut marks = texts.get(1..3).unwrap_or_default().to_vec(); + marks.sort_unstable(); + assert_eq!((texts.first(), texts.get(3), texts.len()), (Some(&"x"), Some(&"yz"), 4), "{r}"); + assert_eq!(marks, ["\u{2d9}", "\u{2dc}"], "{r}"); +} + #[test] fn marks_first_after_a_split_leave_other_lines_their_tracking() { // Twenty marks moved off their base, each one first on its line in turn, do not use up the