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. 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_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<FontBytes>, ) -> Result<(), FontLoadError>

Register one face from bytes the app already holds.

Source

pub fn register_face_bytes_with_variations( &mut self, family: &FontFamily, weight: FontWeight, style: FontStyle, bytes: impl Into<FontBytes>, variations: &[([u8; 4], f32)], ) -> Result<(), FontLoadError>

Register bytes with explicit OpenType axes, overriding the declared weight/style coordinates. Invalid axes fail without registering a face.

Source

pub fn register_fallback_bytes( &mut self, bytes: impl Into<FontBytes>, ) -> 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. Each weight is first resolved through system_declared_weight, so a request the platform’s font config does not declare registers the face Android would have returned for it rather than a wght position Android cannot reach. 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.

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.

weight is resolved through system_declared_weight before anything is read, so the registered face is one the platform’s font config declares. Use Self::register_system_face_with_variations when matching explicit coordinates supplied by the platform’s text API.

Source

pub fn register_system_face_with_variations( &mut self, directory: impl AsRef<Path>, family: &FontFamily, weight: FontWeight, style: FontStyle, variations: &[([u8; 4], f32)], ) -> Result<(), FontLoadError>

Register a system face at explicit OpenType coordinates, such as the optical size and weight returned by a platform text API. The first registration of a family/weight/style wins, as with Self::register_system_face.

Source

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

The faces registered so far.

Source

pub fn is_empty(&self) -> bool

Source

pub fn into_font_set(self, fonts: &[&'static [u8]]) -> SoftwareTextFontSet

Finish, folding in the static byte slices from AppLauncher::with_fonts as unregistered fallbacks.

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. The set holds only what the app supplied; whether the embedded face serves an app that supplied nothing is the launcher’s decision, made where the binary can leave the face out.

Trait Implementations§

Source§

impl Clone for SoftwareTextFontRegistry

Source§

fn clone(&self) -> Self

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() -> Self

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.