Skip to main content

SkiaFonts

Struct SkiaFonts 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn load_font_file( &mut self, path: impl AsRef<Path>, ) -> Result<String, FontError>

load_font for a file on disk.

Source

pub fn load_font_file_as( &mut self, family: &str, path: impl AsRef<Path>, ) -> Result<(), FontError>

load_font_as for a file on disk.

Source

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.

Source

pub fn set_smooth(&mut self, smooth: bool)

Whether to anti-alias text and shapes. Off by default for a pixel look.

Source

pub fn smooth(&self) -> bool

Source

pub fn font(&self, spec: &FontSpec) -> Font

The Skia font for a style’s font spec, ready to draw with.

Trait Implementations§

Source§

impl Default for SkiaFonts

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Fonts for SkiaFonts

Source§

fn measure(&self, text: &str, spec: &FontSpec) -> TextMetrics

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.