From bf8ce774cc2625cf8840f90768902a5f221d1800 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 2 May 2021 19:50:06 +0200 Subject: [PATCH] Don't draw bidi control characters Closes https://github.com/emilk/egui/issues/336 --- epaint/src/text/font.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/epaint/src/text/font.rs b/epaint/src/text/font.rs index 1ee359aa..9cef1b03 100644 --- a/epaint/src/text/font.rs +++ b/epaint/src/text/font.rs @@ -108,7 +108,14 @@ impl FontImpl { // Add new character: let glyph = self.rusttype_font.glyph(c); if glyph.id().0 == 0 { - None + if invisible_char(c) { + // hack + let glyph_info = GlyphInfo::default(); + self.glyph_info_cache.write().insert(c, glyph_info); + Some(glyph_info) + } else { + None + } } else { let mut glyph_info = allocate_glyph( &mut self.atlas.lock(), @@ -588,6 +595,14 @@ fn is_chinese(c: char) -> bool { || ('\u{2B740}' <= c && c <= '\u{2B81F}') } +#[inline] +fn invisible_char(c: char) -> bool { + // See https://github.com/emilk/egui/issues/336 + + // From https://www.fileformat.info/info/unicode/category/Cf/list.htm + ('\u{200B}'..='\u{206F}').contains(&c) // TODO: heed bidi characters +} + fn allocate_glyph( atlas: &mut TextureAtlas, glyph: rusttype::Glyph<'static>,