From 9ae87b1af652ae45be2a14af5e0ab0d55e0053f9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 11:52:06 -0800 Subject: [PATCH] Retype: untracked words are not read as spaced letters in tight tracking The space-aware tracking seed is tried only when untracked type does not already draw the whole line. --- crates/engine/src/cmd/retype.rs | 4 +++- crates/engine/src/cmd/retype_tests.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/retype.rs b/crates/engine/src/cmd/retype.rs index 7f3d65bee7..8f4bcb4b35 100644 --- a/crates/engine/src/cmd/retype.rs +++ b/crates/engine/src/cmd/retype.rs @@ -502,7 +502,9 @@ impl Line { // (tracking is added after the glyph and after the space): the seed then places the spaces // from the extra less one space, shared by the two. It goes last, so a reading that fits // without it is kept (an untracked "a b c" has no such tracking). - let spaced_seed = lower.map(|e| (e - space) / 2.0); + // Where untracked type already draws the whole line, a space and a tracking of half its + // advance less draw it too: that reading is not tried. + let spaced_seed = lower.filter(|_| plain_miss.is_some()).map(|e| (e - space) / 2.0); let mut tries = vec![]; for seed in [lower, median(extra, true), spaced_seed].into_iter().flatten() { let Some(measured) = measure(seed) else { continue }; diff --git a/crates/engine/src/cmd/retype_tests.rs b/crates/engine/src/cmd/retype_tests.rs index 6512d8a334..3d9dc5e3fe 100644 --- a/crates/engine/src/cmd/retype_tests.rs +++ b/crates/engine/src/cmd/retype_tests.rs @@ -859,6 +859,16 @@ fn a_word_space_between_kerned_letters_is_read_as_a_space() { assert_same_places(&before, &text_of(&s, r["ids"][0].as_u64().unwrap())); } +#[test] +fn an_untracked_word_is_not_read_as_spaced_letters_in_tight_tracking() { + // Letters, each followed by a space, at tracking of minus half a space, sit where the word's + // letters do. + let mut s = session(); + let (_, r) = retyped(&mut s, json!({"x": 40, "y": 100, "text": "Third", "size": 24}), &[]); + assert_eq!(r["texts"], json!(["Third"]), "{r}"); + assert_eq!(r["fonts"][0]["tracking"], json!(0.0), "{r}"); +} + #[test] fn glyphs_barely_ahead_of_each_other_stay_one_line() { let mut s = session();