pub struct Font {
pub tables: BTreeMap<Tag, Table>,
/* private fields */
}Expand description
An OpenType font object
Fields§
§tables: BTreeMap<Tag, Table>Dictionary of tables in the font
Implementations§
Source§impl Font
impl Font
Sourcepub fn new(sfnt_version: SfntVersion) -> Self
pub fn new(sfnt_version: SfntVersion) -> Self
Create a new font, empty of a given version (TrueType/OpenType)
Sourcepub fn get_table<'a>(
&'a mut self,
tag: &Tag,
) -> Result<Option<&'a mut Table>, DeserializationError>
pub fn get_table<'a>( &'a mut self, tag: &Tag, ) -> Result<Option<&'a mut Table>, DeserializationError>
Retrieve a table from the font
If the table tag is known to this library and can be deserialized, this
is done and the appropriate Table enum entry is returned. If not, then
a Table::Unknown is returned with the binary table data as a Vec
Returns an Err if the table could not be correctly deserialized. Returns Ok(None) if the table was not present within the font. Returns Ok(Some(Table)) if the table was present.
Sourcepub fn fully_deserialize(&mut self)
pub fn fully_deserialize(&mut self)
Deserializes all tables in the font.
This is done in the correct order (as some tables can only be deserialized after certain others have been processed), so is a helpful way of getting the font into a useful state before working on it.
Sourcepub fn save<T>(&mut self, file: &mut T)where
T: Write,
pub fn save<T>(&mut self, file: &mut T)where
T: Write,
Writes the font to the given file handle
Sourcepub fn num_glyphs(&mut self) -> u16
pub fn num_glyphs(&mut self) -> u16
Total number of glyphs in the font, from the maxp table.
Deserializes the maxp table if this is not already done.
Sourcepub fn compile_glyf_loca_maxp(&mut self)
pub fn compile_glyf_loca_maxp(&mut self)
Compiles all dependent tables to binary.
Certain tables cannot be serialized independently, but need data from
other tables to be passed in to the deserializer. We handle this by
manually compiling those tables to binary here and replacing them with
Table::Unknown. This is automatically called on .save.
Trait Implementations§
Source§impl Deserialize for Font
impl Deserialize for Font
fn from_bytes(c: &mut ReaderContext) -> Result<Self, DeserializationError>
Auto Trait Implementations§
impl Freeze for Font
impl RefUnwindSafe for Font
impl Send for Font
impl Sync for Font
impl Unpin for Font
impl UnwindSafe for Font
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<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more