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.
This commit is contained in:
dotCooCoo
2026-11-21 21:58:11 -08:00
parent 675c53eed6
commit ecc9a35499
2 changed files with 38 additions and 7 deletions
+17 -7
View File
@@ -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<Line>,
system_layout: bool,
spacing: &std::collections::HashMap<NodeId, GlyphMatch>,
spacing: &std::collections::HashMap<PartKey, GlyphMatch>,
unmatched: &mut Vec<NodeId>,
) -> Vec<Line> {
// 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<Value> {
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<NodeId, GlyphMatch> = std::collections::HashMap::new();
let mut spacing: std::collections::HashMap<PartKey, GlyphMatch> = 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<NodeId, usize> = std::collections::HashMap::new();
for (pc, parts) in pieces.iter().zip(&found) {
@@ -1825,7 +1833,8 @@ fn retype(s: &mut Session, p: &Value) -> Result<Value> {
};
// 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<Value> {
.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
+21
View File
@@ -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<u64> = 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