emilk/egui

There should be a checked way to add fonts

Opened this issue · 1 comments

Context::add_font doesn't validate the font data, and lets egui load any invalid font data.
egui internally assumes that the font data is valid, and panics in several places if it isn't.

This makes it impossible to let the user add their own font data, and robustly handle errors (e.g. show a "Failed to add font" popup), and not panic.

A workaround is to explicitly depend on ab_glyph, and do

let data = egui::FontData::from_owned(data);
if let Err(e) = ab_glyph::FontRef::try_from_slice_and_index(&data.font, data.index) {
    // Show error message and cancel adding the font
}