1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Context::add_font (#5228)

make it easier to add fonts. 

For example if I want to add a custom FontFamily or if the user wants to
add a Chinese fallback
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
frederik-uni
2024-10-23 14:29:44 +02:00
committed by GitHub
parent d9a35a7289
commit 04ab5e7574
5 changed files with 138 additions and 5 deletions

View File

@@ -254,6 +254,50 @@ pub struct FontDefinitions {
pub families: BTreeMap<FontFamily, Vec<String>>,
}
#[derive(Debug, Clone)]
pub struct FontInsert {
/// Font name
pub name: String,
/// A `.ttf` or `.otf` file and a font face index.
pub data: FontData,
/// Sets the font family and priority
pub families: Vec<InsertFontFamily>,
}
#[derive(Debug, Clone)]
pub struct InsertFontFamily {
/// Font family
pub family: FontFamily,
/// Fallback or Primary font
pub priority: FontPriority,
}
#[derive(Debug, Clone)]
pub enum FontPriority {
/// Prefer this font before all existing ones.
///
/// If a desired glyph exists in this font, it will be used.
Highest,
/// Use this font as a fallback, after all existing ones.
///
/// This font will only be used if the glyph is not found in any of the previously installed fonts.
Lowest,
}
impl FontInsert {
pub fn new(name: &str, data: FontData, families: Vec<InsertFontFamily>) -> Self {
Self {
name: name.to_owned(),
data,
families,
}
}
}
impl Default for FontDefinitions {
/// Specifies the default fonts if the feature `default_fonts` is enabled,
/// otherwise this is the same as [`Self::empty`].

View File

@@ -10,7 +10,10 @@ mod text_layout_types;
pub const TAB_SIZE: usize = 4;
pub use {
fonts::{FontData, FontDefinitions, FontFamily, FontId, FontTweak, Fonts, FontsImpl},
fonts::{
FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak, Fonts,
FontsImpl, InsertFontFamily,
},
text_layout::layout,
text_layout_types::*,
};