don't panic if we get confused by text char boundaries

This triggered for me when grepping a file containing various
foreign language translations (non UTF-8).
This commit is contained in:
Wez Furlong committed 2018-10-21 14:45:26 -07:00
1 parent 61fec42216
commit ada197f94e
1 file changed
+7 -3
+7 -3
View File
@@ -203,9 +203,13 @@ pub fn shape_with_harfbuzz(
first_fallback_pos = None;
}
if info.codepoint != 0 {
let text = &s[pos..pos + sizes[i]];
//debug!("glyph from `{}`", text);
cluster.push(GlyphInfo::new(text, font_idx, info, &positions[i]));
if s.is_char_boundary(pos) && s.is_char_boundary(pos + sizes[i]) {
let text = &s[pos..pos + sizes[i]];
//debug!("glyph from `{}`", text);
cluster.push(GlyphInfo::new(text, font_idx, info, &positions[i]));
} else {
cluster.append(&mut shape_with_harfbuzz(font, 0, "?")?);
}
}
}