pub trait FontLoader {
// Required methods
fn get_fallback_font(&mut self) -> String;
fn get_fallback_font_for_characters(
&mut self,
characters: &str,
weight: i32,
italic: bool,
) -> String;
fn load(
&mut self,
family: &str,
weight: i32,
italic: bool,
) -> Option<FontFile>;
}Expand description
User-defined font loader interface.
The library uses this to load all system fonts.
Every operating system has its own library of installed system fonts. The FontLoader interface is used to lookup these fonts and fetch the actual font data (raw TTF/OTF file data) for a given given font description.
§Usage
To provide your own custom FontLoader implementation, you should implement this trait, and then
pass an instance of your struct to [platform::set_fontloader]. before calling Renderer::create
or App::new.
§Note
There is a bug in Ultralight right now, and we can’t use custom Fontloader for now. So you can ignore this for now.
AppCore uses a default OS-specific FontLoader implementation when you call App::new.
If you are using Renderer::create, you can still use AppCore’s implementation by calling
platform::enable_platform_fontloader.
Required Methods§
Sourcefn get_fallback_font(&mut self) -> String
fn get_fallback_font(&mut self) -> String
Fallback font family name. Will be used if all other fonts fail to load.
This font should be guaranteed to exist (eg, ULFontLoader::load should not fail when when passed this font family name).
Return a font family name.
Sourcefn get_fallback_font_for_characters(
&mut self,
characters: &str,
weight: i32,
italic: bool,
) -> String
fn get_fallback_font_for_characters( &mut self, characters: &str, weight: i32, italic: bool, ) -> String
Fallback font family name that can render the specified characters. This is mainly used to support CJK (Chinese, Japanese, Korean) text display
§Arguments
characters- One or more UTF-16 characters. This is almost always a single characterweight- Font weightitalic- Whether or not the font should be italic
Should return a font family name that can render the text
Sourcefn load(&mut self, family: &str, weight: i32, italic: bool) -> Option<FontFile>
fn load(&mut self, family: &str, weight: i32, italic: bool) -> Option<FontFile>
Get the actual font file data (TTF/OTF) for a given font description.
§Arguments
family- Font family nameweight- Font weightitalic- Whether or not the font should be italic
Should return a FontFile that contains the font data. You can return None
here and the loader will fallback to another font.