Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom default replacement glyphs for font #4642

Closed
Warpten opened this issue Jun 8, 2024 · 1 comment
Closed

Custom default replacement glyphs for font #4642

Warpten opened this issue Jun 8, 2024 · 1 comment

Comments

@Warpten
Copy link

Warpten commented Jun 8, 2024

Is your feature request related to a problem? Please describe.

There is currently no way to define a custom replacement glyph for user-provided fonts. For example, the font "MaterialSymbolsSharp" can't be used with egui because it does not have the replacement glyphs egui is hardcoded to look for. The font itself seems to load fine; however as soon as I try to use the font the code panics here:

Describe the solution you'd like
Add user-specified overrides to FontTweak that replace the glyphs that the library looks for.

Describe alternatives you've considered
Besides using another font, there isn't really any option. Even using font fallbacks (for example with RichText::append_to), egui still tries to load the font and panics before falling back.

Additional context
Seen on egui 0.27.2 on a custom vulkan backend (although that is unrelated to the issue at hand).

Usage:

// This happens on app start, looks through ./assets/fonts and loads everything:
def.font_data.insert(
    font_name.to_owned(), // MaterialSymbolsSharp
    FontData::from_owned(file_data.unwrap())
);

def.families.entry(value.clone())
    .and_modify(move |value| value.push(font_name.to_owned()))
    .or_insert(vec![font_name.to_owned()]);

def.families.insert(FontFamily::Name(font_name.into()), vec![font_name.to_owned()]);

// Later in the UI
let mut label_job = LayoutJob::default();
RichText::new("HOME")
    .family(FontFamily::Name("MaterialSymbolsSharp".into()))
    .append_to(&mut label_job, &Style::default(), FontSelection::Default, egui::Align::Min);
RichText::new("Home")
    .family(FontFamily::Name("Roboto-Light".into()))
    .append_to(&mut label_job, &Style::default(), FontSelection::Default, egui::Align::Min);

ui.selectable_value(&mut self.active_tab, Tab::Home, label_job);
@Warpten
Copy link
Author

Warpten commented Jun 8, 2024

Of course I find #3526 just after creating this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant