pub struct SkiaFonts { /* private fields */ }Expand description
Finds fonts and measures text with Skia.
Typefaces are looked up by the CSS family names in a style, first match
wins: fonts loaded with load_font and its
relatives are checked first, then the system font manager. The generic
families monospace, sans-serif, serif, system-ui and
ui-monospace map to common system fonts; anything unknown falls back
to the default typeface.
use eternal_ui_skia::SkiaFonts;
let mut fonts = SkiaFonts::new();
// Registered under the family name inside the file...
let family = fonts.load_font_file("assets/PixelOperator.ttf")?;
// ...or under a name of your choosing, so the stylesheet can say
// `font-family: pixel` without caring which file provides it.
fonts.load_font_file_as("pixel", "assets/PixelOperator.ttf")?;Implementations§
Source§impl SkiaFonts
impl SkiaFonts
pub fn new() -> Self
Sourcepub fn load_font(&mut self, bytes: &[u8]) -> Result<String, FontError>
pub fn load_font(&mut self, bytes: &[u8]) -> Result<String, FontError>
Loads a font from the bytes of a TrueType, OpenType or WOFF file and registers it under the family name the file declares, which is returned. Several weights and styles of one family can be loaded one file at a time; the closest match to a style’s weight and slant is used.
Sourcepub fn load_font_as(
&mut self,
family: &str,
bytes: &[u8],
) -> Result<(), FontError>
pub fn load_font_as( &mut self, family: &str, bytes: &[u8], ) -> Result<(), FontError>
Like load_font, but registers the font under
family instead of the name in the file, so a stylesheet can refer
to it as font-family: pixel whatever the file says.
Sourcepub fn load_font_file(
&mut self,
path: impl AsRef<Path>,
) -> Result<String, FontError>
pub fn load_font_file( &mut self, path: impl AsRef<Path>, ) -> Result<String, FontError>
load_font for a file on disk.
Sourcepub fn load_font_file_as(
&mut self,
family: &str,
path: impl AsRef<Path>,
) -> Result<(), FontError>
pub fn load_font_file_as( &mut self, family: &str, path: impl AsRef<Path>, ) -> Result<(), FontError>
load_font_as for a file on disk.
Sourcepub fn loaded_families(&self) -> impl Iterator<Item = &str>
pub fn loaded_families(&self) -> impl Iterator<Item = &str>
The family names of the fonts loaded so far, in load order, as they were registered.
Sourcepub fn set_smooth(&mut self, smooth: bool)
pub fn set_smooth(&mut self, smooth: bool)
Whether to anti-alias text and shapes. Off by default for a pixel look.