From 8d61d2bd34cb653dbf86d75d20c5be7c565d9cde Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 13:58:12 -0800 Subject: [PATCH] Retype: a tracking that translucent glyphs cannot take no longer drops the tracked prefix already found A negative tracking candidate for glyphs that do not paint as one object returned the untracked line and discarded the best tracked reading found from an earlier seed. It now skips that candidate and tries the next. --- crates/engine/src/cmd/retype.rs | 2 +- crates/engine/src/cmd/retype_tests.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/retype.rs b/crates/engine/src/cmd/retype.rs index 0e31d5632a..174d77c4a9 100644 --- a/crates/engine/src/cmd/retype.rs +++ b/crates/engine/src/cmd/retype.rs @@ -531,7 +531,7 @@ impl Line { continue; } if t < 0.0 && !paints_as_one(&self) { - return self; + continue; } let mut tracked = self.clone(); tracked.tracking = t; diff --git a/crates/engine/src/cmd/retype_tests.rs b/crates/engine/src/cmd/retype_tests.rs index 80361f1e0a..de2122fc09 100644 --- a/crates/engine/src/cmd/retype_tests.rs +++ b/crates/engine/src/cmd/retype_tests.rs @@ -1106,6 +1106,31 @@ fn tracking_near_a_whole_number_is_kept_as_measured_when_rounding_moves_glyphs() assert_same_places(&before, &text_of(&s, r["ids"][0].as_u64().unwrap())); } +#[test] +fn a_tracking_translucent_glyphs_cannot_take_keeps_the_tracking_that_fits() { + // The first three glyphs are tracked 50 and the last 150 further on. A tracking tighter than + // zero is not tried for glyphs that cannot be one object, and the tracked prefix is kept. + let mut s = session(); + let id = s.execute("text.create", &json!({"x": 40, "y": 100, "text": "MMMM", "size": 30})).unwrap()["id"].as_u64().unwrap(); + s.execute("text.setRangeStyle", &json!({"id": id, "start": 0, "end": 2, "tracking": 50})).unwrap(); + s.execute("text.setRangeStyle", &json!({"id": id, "start": 2, "end": 3, "tracking": 150})).unwrap(); + s.execute("select.set", &json!({"ids": [id]})).unwrap(); + let g = s.execute("type.createOutlines", &json!({})).unwrap()["ids"][0].as_u64().unwrap(); + let kids = children_of(&s, g); + s.edit("test", |d, _| { + for k in &kids { + d.node_mut(NodeId(*k)).unwrap().opacity = 0.5; + } + Ok(()) + }) + .unwrap(); + s.execute("select.set", &json!({"ids": [g]})).unwrap(); + let r = s.execute("type.retype", &json!({})).unwrap(); + let texts: Vec<&str> = r["texts"].as_array().unwrap().iter().map(|t| t.as_str().unwrap()).collect(); + assert_eq!(texts.concat(), "MMMM", "{r}"); + assert!(texts.iter().any(|t| t.len() > 1), "the tracked glyphs stay one object: {r}"); +} + #[test] fn overlapping_translucent_glyphs_are_not_tracked_into_one_object() { let mut s = session();