mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
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.
This commit is contained in:
1 parent
6a4729d5af
commit
4ec6ef01ae
1 file changed
+21
-3
@@ -199,9 +199,13 @@ pub fn import(bytes: &[u8]) -> Result<Imported, Error> {
|
||||
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<u8> {
|
||||
|
||||
Reference in new issue
Block a user