Skip to main content

SoftwareTextFontRegistry

Struct SoftwareTextFontRegistry 

Source
pub struct SoftwareTextFontRegistry { /* private fields */ }
Expand description

Parsed app-supplied faces, on their way to a SoftwareTextFontSet.

Register everything an app needs once at startup, then call SoftwareTextFontRegistry::into_font_set_or_default. Registration is where files are read and faces parsed; nothing after it touches the disk.

Implementations§

Source§

impl SoftwareTextFontRegistry

Source

pub fn new() -> Self

Source

pub fn register_family( &mut self, family: &FontFamily, ) -> Result<(), FontLoadError>

Register every face of a file-backed family, reading each file from the filesystem.

Each FontFile’s declared weight and style are what resolution matches on, so one family can carry Regular/Medium/Bold/Italic faces and a FontWeight/FontStyle picks between them. A family whose files all fail to load registers nothing and reports the first failure; text asking for it then falls back to the default face rather than disappearing.

Source

pub fn register_face_path( &mut self, family: &FontFamily, weight: FontWeight, style: FontStyle, path: impl AsRef<Path>, ) -> Result<(), FontLoadError>

Register one face read from path.

Source

pub fn register_face_reader( &mut self, family: &FontFamily, weight: FontWeight, style: FontStyle, reader: &mut impl Read, ) -> Result<(), FontLoadError>

Register one face read from an arbitrary stream.

This is the seam for fonts that are not files on disk — an APK asset opened through AndroidApp::asset_manager(), an archive entry, a download cache. It mirrors SoftwareTextMeasurer::register_hyphenation_dictionary_reader.

Source

pub fn register_face_bytes( &mut self, family: &FontFamily, weight: FontWeight, style: FontStyle, bytes: impl Into<Vec<u8>>, ) -> Result<(), FontLoadError>

Register one face from bytes the app already holds.

Source

pub fn register_fallback_bytes( &mut self, bytes: impl Into<Vec<u8>>, ) -> Result<(), FontLoadError>

Register a face that belongs to no declared family.

These are the fallbacks: they are eligible for any request that names no family, and for a Named request their own name table decides.

Source

pub fn register_system_family( &mut self, directory: impl AsRef<Path>, family: &FontFamily, weights: &[FontWeight], ) -> Result<(), FontLoadError>

Register the platform’s own face for a generic family alias, at each of weights, so styles keep naming FontFamily::SansSerif and get the real system typeface.

Android backs sans-serif with a single variable Roboto-Regular.ttf and describes each weight as a wght axis position on it, so most devices resolve every weight to one file instanced several ways. Where a build does ship weight-specific static files (Roboto-Medium.ttf), they are preferred. Faces are registered in FontStyle::Normal; an app that wants a real italic rather than a synthesized slant should call SoftwareTextFontRegistry::register_system_face for it, because each extra face is another copy of the file’s bytes.

Source

pub fn register_system_face( &mut self, directory: impl AsRef<Path>, family: &FontFamily, weight: FontWeight, style: FontStyle, ) -> Result<(), FontLoadError>

Register one weight/style of a generic family alias from the platform’s font directory.

Source

pub fn faces(&self) -> &[SoftwareTextFont]

The faces registered so far.

Source

pub fn is_empty(&self) -> bool

Source

pub fn into_font_set_or_default(self, fonts: &[&[u8]]) -> SoftwareTextFontSet

Finish, folding in the static byte slices from AppLauncher::with_fonts as unregistered fallbacks and the embedded default face when nothing else loaded.

Registered faces come first, so when a request names no family and the scores tie, a face the app declared wins over one it merely handed over as bytes.

Trait Implementations§

Source§

impl Clone for SoftwareTextFontRegistry

Source§

fn clone(&self) -> SoftwareTextFontRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SoftwareTextFontRegistry

Source§

fn default() -> SoftwareTextFontRegistry

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.