pub struct SoftwareTextFontRegistry { /* private fields */ }Expand description
Font registration vocabulary named by AppLauncher’s font methods:
the platform font directory AppLauncher::with_system_font_family wants,
the weight set it registers, the registry and error
AppLauncher::with_fonts_from hands out, and the bytes
AppLauncher::with_font_face_bytes takes.
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
impl SoftwareTextFontRegistry
pub fn new() -> SoftwareTextFontRegistry
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_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<FontBytes>,
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_face_bytes_with_variations(
&mut self,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
bytes: impl Into<FontBytes>,
variations: &[([u8; 4], f32)],
) -> Result<(), FontLoadError>
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.
Sourcepub fn register_fallback_bytes(
&mut self,
bytes: impl Into<FontBytes>,
) -> Result<(), FontLoadError>
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.
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. 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.
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.
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.
Sourcepub fn register_system_face_with_variations(
&mut self,
directory: impl AsRef<Path>,
family: &FontFamily,
weight: FontWeight,
style: FontStyle,
variations: &[([u8; 4], f32)],
) -> Result<(), FontLoadError>
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.
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(self, fonts: &[&'static [u8]]) -> SoftwareTextFontSet
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
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 moreSource§impl Default for SoftwareTextFontRegistry
impl Default for SoftwareTextFontRegistry
Source§fn default() -> SoftwareTextFontRegistry
fn default() -> SoftwareTextFontRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for SoftwareTextFontRegistry
impl !UnwindSafe for SoftwareTextFontRegistry
impl Freeze for SoftwareTextFontRegistry
impl Send for SoftwareTextFontRegistry
impl Sync for SoftwareTextFontRegistry
impl Unpin for SoftwareTextFontRegistry
impl UnsafeUnpin for SoftwareTextFontRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.