Struct kas_core::text::fonts::FontLibrary
source · pub struct FontLibrary { /* private fields */ }Expand description
Library of loaded fonts
This is the type of the global singleton accessible via the fonts
function. Thread-safety is handled via internal locks.
Implementations§
source§impl FontLibrary
impl FontLibrary
Font management
sourcepub fn read_db(&self) -> RwLockReadGuard<'_, Database>
pub fn read_db(&self) -> RwLockReadGuard<'_, Database>
Get a reference to the font database
sourcepub fn update_db<F, T>(&self, f: F) -> T
pub fn update_db<F, T>(&self, f: F) -> T
Get mutable access to the font database
This can be used to adjust font selection. Note that any changes only
affect new font selections, thus it is recommended only to adjust the
database before any fonts have been selected. No existing FaceId
or FontId will be affected by this; additionally any
FontSelector which has already been selected will continue to
resolve the existing FontId via the cache.
sourcepub fn first_face_for(&self, font_id: FontId) -> Result<FaceId, InvalidFontId>
pub fn first_face_for(&self, font_id: FontId) -> Result<FaceId, InvalidFontId>
Get the first face for a font
Assumes that font_id is valid; if not the method will panic.
Each font identifier has at least one font face. This resolves the first (default) one.
sourcepub fn get_first_face(&self, font_id: FontId) -> Result<FaceRef, InvalidFontId>
pub fn get_first_face(&self, font_id: FontId) -> Result<FaceRef, InvalidFontId>
Get the first face for a font
This is a wrapper around FontLibrary::first_face_for and FontLibrary::get_face.
sourcepub fn face_for_char(
&self,
font_id: FontId,
last_face_id: Option<FaceId>,
c: char
) -> Result<Option<FaceId>, InvalidFontId>
pub fn face_for_char( &self, font_id: FontId, last_face_id: Option<FaceId>, c: char ) -> Result<Option<FaceId>, InvalidFontId>
Resolve the font face for a character
If last_face_id is a face used by font_id and this face covers c,
then return last_face_id. (This is to avoid changing the font face
unnecessarily, such as when encountering a space amid Arabic text.)
Otherwise, return the first face of font_id which covers c.
Otherwise (if no face covers c) return None.
sourcepub fn face_for_char_or_first(
&self,
font_id: FontId,
last_face_id: Option<FaceId>,
c: char
) -> Result<FaceId, InvalidFontId>
pub fn face_for_char_or_first( &self, font_id: FontId, last_face_id: Option<FaceId>, c: char ) -> Result<FaceId, InvalidFontId>
Resolve the font face for a character
If last_face_id is a face used by font_id and this face covers c,
then return last_face_id. (This is to avoid changing the font face
unnecessarily, such as when encountering a space amid Arabic text.)
Otherwise, return the first face of font_id which covers c.
Otherwise (if no face covers c) return the first face for font_id.
sourcepub fn select_default(&self) -> Result<(), Box<dyn Error>>
pub fn select_default(&self) -> Result<(), Box<dyn Error>>
Select the default font
If the font database has not yet been initialized, it is initialized.
If FontId(0) has not been defined yet, this sets the default font.
This must be called (at least once) before any other font selection method, and before querying any font-derived properties (such as text dimensions).
sourcepub fn select_font(
&self,
selector: &FontSelector<'_>
) -> Result<FontId, Box<dyn Error>>
pub fn select_font( &self, selector: &FontSelector<'_> ) -> Result<FontId, Box<dyn Error>>
Select a font
This method uses internal caching to enable fast look-ups of existing (loaded) fonts. Resolving new fonts may be slower.
source§impl FontLibrary
impl FontLibrary
Face management
sourcepub fn get_face(&self, id: FaceId) -> FaceRef
pub fn get_face(&self, id: FaceId) -> FaceRef
Get a font face from its identifier
Panics if id is not valid (required: id.get() < self.num_faces()).
sourcepub fn num_faces(&self) -> usize
pub fn num_faces(&self) -> usize
Get the number of loaded font faces
FaceId values are indices assigned consecutively and are permanent.
For any x < self.num_faces(), FaceId(x) is a valid font face identifier.
This value may increase as fonts may be loaded on demand. It will not decrease since fonts are never unloaded during program execution.
sourcepub fn load_path(
&self,
path: &Path,
index: u32
) -> Result<FaceId, Box<dyn Error>>
pub fn load_path( &self, path: &Path, index: u32 ) -> Result<FaceId, Box<dyn Error>>
Load a font by path
In case the (path, index) combination has already been loaded, the
existing font object’s FontId will be returned.
The index is used to select fonts from a font-collection. If the font
is not a collection, use 0.
Auto Trait Implementations§
impl RefUnwindSafe for FontLibrary
impl Send for FontLibrary
impl Sync for FontLibrary
impl Unpin for FontLibrary
impl UnwindSafe for FontLibrary
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
source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.