From 4ec6ef01ae41f72ffc433fd2dfdfa6c6b9bb81b0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 20:09:47 -0800 Subject: [PATCH] silhouette-studio: a path after a text's trailing space is not read as a letter A space has a glyph record but no outline. When a text object ended with a space and the next object was an ordinary path, the importer matched the space's record to that path and reported the path as one of the text's letters. A space's record no longer claims the outline after it. --- crates/silhouette-studio/src/lib.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/silhouette-studio/src/lib.rs b/crates/silhouette-studio/src/lib.rs index a616fae9b1..2076880e07 100644 --- a/crates/silhouette-studio/src/lib.rs +++ b/crates/silhouette-studio/src/lib.rs @@ -199,9 +199,13 @@ pub fn import(bytes: &[u8]) -> Result { let records = glyph_records(body, &root)?; let (texts, owners) = build_texts(body, &records); for (shape, &(from, at)) in shapes.iter_mut().zip(&text_starts) { - // The letter's record comes just before its outline. - shape.text = - records.partition_point(|r| r.at < at).checked_sub(1).filter(|&i| records[i].at >= from && records[i].code != 0).and_then(|i| owners[i]); + // The letter's record comes just before its outline. A space has a record but no + // outline, so its record never claims the outline after it. + shape.text = records + .partition_point(|r| r.at < at) + .checked_sub(1) + .filter(|&i| records[i].at >= from && records[i].code != 0 && records[i].code != u32::from(' ')) + .and_then(|i| owners[i]); } Ok(Imported { version, page_mm: page_size(body, &root), shapes, group_parents, texts, warnings }) } @@ -744,6 +748,20 @@ mod tests { assert_eq!(owners, [Some(0); 4]); } + #[test] + fn a_path_after_a_trailing_space_is_not_part_of_the_text() { + let mut letter = glyph(0, 25.4, 10.0, 20.0); + letter.extend(glyph('A' as u32, 25.4, 10.0, 20.0)); + letter.extend(path_record(&[(true, &[(10.0, 10.0), (20.0, 10.0), (15.0, 20.0)])])); + let mut rect = glyph(' ' as u32, 25.4, 30.0, 20.0); + rect.extend(path_record(&[(true, RECT)])); + let got = import(&v2_records((304.8, 304.8), &[letter, rect])).unwrap(); + assert_eq!(got.texts.len(), 1); + assert_eq!(got.texts[0].text, "A "); + let owners: Vec<_> = got.shapes.iter().map(|s| s.text).collect(); + assert_eq!(owners, [Some(0), None], "a space has no outline, so the rectangle after it is not a letter"); + } + /// The tail of a style record as `.studio3` files store it: the cap and join names, then /// the fill flag and, with a fill, R, G, B, A as f32. fn style_tail(fill: Option<[f32; 4]>) -> Vec {