From ada197f94e0fef901da204bb892c42d9dcbc5438 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 19 Oct 2018 17:25:15 -0700 Subject: [PATCH] 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). --- src/font/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/font/mod.rs b/src/font/mod.rs index af46829b3..e57ae19b9 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -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, "?")?); + } } }