Struct fontdb::Database [−][src]
pub struct Database { /* fields omitted */ }
Expand description
A font database.
Implementations
impl Database
[src]
impl Database
[src]pub fn load_font_data(&mut self, data: Vec<u8>)
[src]
pub fn load_font_data(&mut self, data: Vec<u8>)
[src]Loads a font data into the Database
.
Will load all font faces in case of a font collection.
pub fn load_font_file<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>
[src]
pub fn load_font_file<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>
[src]Loads a font file into the Database
.
Will load all font faces in case of a font collection.
pub fn load_fonts_dir<P: AsRef<Path>>(&mut self, dir: P)
[src]
pub fn load_fonts_dir<P: AsRef<Path>>(&mut self, dir: P)
[src]Loads font files from the selected directory into the Database
.
This method will scan directories recursively.
Will load ttf
, otf
, ttc
and otc
fonts.
Unlike other load_*
methods, this one doesn’t return an error.
It will simply skip malformed fonts and will print a warning into the log for each of them.
pub fn load_system_fonts(&mut self)
[src]
pub fn load_system_fonts(&mut self)
[src]Attempts to load system fonts.
Supports Windows, Linux and macOS.
System fonts loading is a surprisingly complicated task,
mostly unsolvable without interacting with system libraries.
And since fontdb
tries to be small and portable, this method
will simply scan some predefined directories.
Which means that fonts that are not in those directories must
be added manually.
pub fn remove_face(&mut self, id: ID) -> bool
[src]
pub fn remove_face(&mut self, id: ID) -> bool
[src]Removes a font face by id
from the database.
Returns false
while attempting to remove a non-existing font face.
Useful when you want to ignore some specific font face(s) after loading a large directory with fonts. Or a specific face from a font.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]Returns the number of font faces in the Database
.
Note that Database
stores font faces, not fonts.
For example, if a caller will try to load a font collection (*.ttc
) that contains 5 faces,
then the Database
will load 5 font faces and this method will return 5, not 1.
pub fn set_serif_family<S: Into<String>>(&mut self, family: S)
[src]
pub fn set_serif_family<S: Into<String>>(&mut self, family: S)
[src]Sets the family that will be used by Family::Serif
.
pub fn set_sans_serif_family<S: Into<String>>(&mut self, family: S)
[src]
pub fn set_sans_serif_family<S: Into<String>>(&mut self, family: S)
[src]Sets the family that will be used by Family::SansSerif
.
pub fn set_cursive_family<S: Into<String>>(&mut self, family: S)
[src]
pub fn set_cursive_family<S: Into<String>>(&mut self, family: S)
[src]Sets the family that will be used by Family::Cursive
.
pub fn set_fantasy_family<S: Into<String>>(&mut self, family: S)
[src]
pub fn set_fantasy_family<S: Into<String>>(&mut self, family: S)
[src]Sets the family that will be used by Family::Fantasy
.
pub fn set_monospace_family<S: Into<String>>(&mut self, family: S)
[src]
pub fn set_monospace_family<S: Into<String>>(&mut self, family: S)
[src]Sets the family that will be used by Family::Monospace
.
pub fn query(&self, query: &Query<'_>) -> Option<ID>
[src]
pub fn query(&self, query: &Query<'_>) -> Option<ID>
[src]Performs a CSS-like query and returns the best matched font face.
pub fn faces(&self) -> &[FaceInfo]
[src]
pub fn faces(&self) -> &[FaceInfo]
[src]Returns a reference to an internal storage.
This can be used for manual font matching.
pub fn face(&self, id: ID) -> Option<&FaceInfo>
[src]
pub fn face(&self, id: ID) -> Option<&FaceInfo>
[src]Selects a FaceInfo
by id
.
Returns None
if a face with such ID was already removed,
or this ID belong to the other Database
.
pub fn face_source(&self, id: ID) -> Option<(Arc<Source>, u32)>
[src]
pub fn face_source(&self, id: ID) -> Option<(Arc<Source>, u32)>
[src]Returns font face storage and the face index by ID
.
pub fn with_face_data<P, T>(&self, id: ID, p: P) -> Option<T> where
P: FnOnce(&[u8], u32) -> T,
[src]
pub fn with_face_data<P, T>(&self, id: ID, p: P) -> Option<T> where
P: FnOnce(&[u8], u32) -> T,
[src]Executes a closure with a font’s data.
We can’t return a reference to a font binary data because of lifetimes. So instead, you can use this method to process font’s data.
The closure accepts raw font data and font face index.
In case of Source::File
, the font file will be memory mapped.
Returns None
when font file loading failed.
Example
let is_variable = db.with_face_data(id, |font_data, face_index| { let font = ttf_parser::Face::from_slice(font_data, face_index).unwrap(); font.is_variable() })?;
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more