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
impl SoftwareTextFontRegistry
pub fn new() -> Self
Sourcepub fn register_family(
&mut self,
family: &FontFamily,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_face_path(
&mut self,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
path: impl AsRef<Path>,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_face_reader(
&mut self,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
reader: &mut impl Read,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_face_bytes(
&mut self,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
bytes: impl Into<Vec<u8>>,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_fallback_bytes(
&mut self,
bytes: impl Into<Vec<u8>>,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_system_family(
&mut self,
directory: impl AsRef<Path>,
family: &FontFamily,
weights: &[FontWeight],
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_system_face(
&mut self,
directory: impl AsRef<Path>,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
) -> Result<(), FontLoadError>
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.
Sourcepub fn faces(&self) -> &[SoftwareTextFont]
pub fn faces(&self) -> &[SoftwareTextFont]
The faces registered so far.
pub fn is_empty(&self) -> bool
Sourcepub fn into_font_set_or_default(self, fonts: &[&[u8]]) -> SoftwareTextFontSet
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
impl Clone for SoftwareTextFontRegistry
Source§fn clone(&self) -> SoftwareTextFontRegistry
fn clone(&self) -> SoftwareTextFontRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more