From 932fdae9e69801c0169b540f1f529285530cc86e Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Sun, 7 Jan 2024 05:33:08 +0800 Subject: [PATCH] Fix: allow using the full Private Use Area for custom fonts (#3509) The ignored characters are used in some custom fonts. for example: the \u{F0FF} is used as `cleaning_services` in MaterialIcons-Regular.ttf Closes . --------- Co-authored-by: Emil Ernerfeldt --- crates/epaint/src/text/font.rs | 6 ++++++ crates/epaint/src/text/fonts.rs | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index 045f42aa702..50500de8482 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -139,6 +139,12 @@ impl FontImpl { /// /// See also [`invisible_char`]. fn ignore_character(&self, chr: char) -> bool { + use crate::text::FontDefinitions; + + if !FontDefinitions::builtin_font_names().contains(&self.name.as_str()) { + return false; + } + if self.name == "emoji-icon-font" { // HACK: https://github.com/emilk/egui/issues/1284 https://github.com/jslegers/emoji-icon-font/issues/18 // Don't show the wrong fullwidth capital letters: diff --git a/crates/epaint/src/text/fonts.rs b/crates/epaint/src/text/fonts.rs index 177c7327819..1f54a5f6489 100644 --- a/crates/epaint/src/text/fonts.rs +++ b/crates/epaint/src/text/fonts.rs @@ -335,6 +335,23 @@ impl FontDefinitions { families, } } + + /// List of all the builtin font names used by `epaint`. + #[cfg(feature = "default_fonts")] + pub fn builtin_font_names() -> &'static [&'static str] { + &[ + "Ubuntu-Light", + "NotoEmoji-Regular", + "emoji-icon-font", + "Hack", + ] + } + + /// List of all the builtin font names used by `epaint`. + #[cfg(not(feature = "default_fonts"))] + pub fn builtin_font_names() -> &'static [&'static str] { + &[] + } } // ----------------------------------------------------------------------------