[−][src]Struct ttf_parser::Font
A font data handle.
Methods
impl<'a> Font<'a>
[src]
pub fn glyph_index(&self, c: char) -> Result<GlyphId, Error>
[src]
Resolves Glyph ID for code point.
Returns Error::NoGlyph
instead of 0
when glyph is not found.
All subtable formats except Mixed Coverage (8) are supported.
pub fn glyph_variation_index(
&self,
c: char,
variation: char
) -> Result<GlyphId, Error>
[src]
&self,
c: char,
variation: char
) -> Result<GlyphId, Error>
Resolves a variation of a Glyph ID from two code points.
Implemented according to Unicode Variation Sequences.
Returns Error::NoGlyph
instead of 0
when glyph is not found.
impl<'a> Font<'a>
[src]
pub fn units_per_em(&self) -> Option<u16>
[src]
Returns font's units per EM.
Returns None
if value is not in a 16..16384 range.
impl<'a> Font<'a>
[src]
pub fn ascender(&self) -> i16
[src]
Returns font's ascender value.
pub fn descender(&self) -> i16
[src]
Returns font's descender value.
pub fn height(&self) -> i16
[src]
Returns font's height.
pub fn line_gap(&self) -> i16
[src]
Returns font's line gap.
impl<'a> Font<'a>
[src]
pub fn glyph_hor_metrics(
&self,
glyph_id: GlyphId
) -> Result<HorizontalMetrics, Error>
[src]
&self,
glyph_id: GlyphId
) -> Result<HorizontalMetrics, Error>
Returns glyph's horizontal metrics.
impl<'a> Font<'a>
[src]
pub fn glyphs_kerning(
&self,
glyph_id1: GlyphId,
glyph_id2: GlyphId
) -> Result<i16, Error>
[src]
&self,
glyph_id1: GlyphId,
glyph_id2: GlyphId
) -> Result<i16, Error>
Returns a glyphs pair kerning.
Only horizontal kerning is supported.
impl<'a> Font<'a>
[src]
ⓘImportant traits for Names<'a>pub fn names(&self) -> Names
[src]
Returns an iterator over Name Records.
pub fn family_name(&self) -> Option<String>
[src]
Returns font's family name.
Note that font can have multiple names. You can use names()
to list them all.
pub fn post_script_name(&self) -> Option<String>
[src]
Returns font's PostScript name.
Note that font can have multiple names. You can use names()
to list them all.
impl<'a> Font<'a>
[src]
pub fn weight(&self) -> Weight
[src]
Parses font's weight.
Returns Weight::Normal
when OS/2 table is not present.
pub fn width(&self) -> Width
[src]
Parses font's width.
Returns Width::Normal
when OS/2 table is not present or when value is invalid.
pub fn is_regular(&self) -> bool
[src]
Checks that font is marked as Regular.
Returns false
when OS/2 table is not present.
pub fn is_italic(&self) -> bool
[src]
Checks that font is marked as Italic.
Returns false
when OS/2 table is not present.
pub fn is_bold(&self) -> bool
[src]
Checks that font is marked as Bold.
Returns false
when OS/2 table is not present.
pub fn is_oblique(&self) -> bool
[src]
Checks that font is marked as Oblique.
Returns None
when OS/2 table is not present or when its version is < 4.
pub fn x_height(&self) -> Option<i16>
[src]
Parses font's X height.
Returns None
when OS/2 table is not present or when its version is < 2.
pub fn strikeout_metrics(&self) -> Option<LineMetrics>
[src]
Parses font's strikeout metrics.
Returns None
when OS/2 table is not present.
pub fn subscript_metrics(&self) -> Option<ScriptMetrics>
[src]
Parses font's subscript metrics.
Returns None
when OS/2 table is not present.
pub fn superscript_metrics(&self) -> Option<ScriptMetrics>
[src]
Parses font's superscript metrics.
Returns None
when OS/2 table is not present.
impl<'a> Font<'a>
[src]
pub fn underline_metrics(&self) -> Option<LineMetrics>
[src]
Parses font's underline metrics.
Returns None
when post
table is not present.
impl<'a> Font<'a>
[src]
pub fn glyph_ver_metrics(
&self,
glyph_id: GlyphId
) -> Result<VerticalMetrics, Error>
[src]
&self,
glyph_id: GlyphId
) -> Result<VerticalMetrics, Error>
Returns glyph's vertical metrics.
impl<'a> Font<'a>
[src]
pub fn from_data(data: &'a [u8], index: u32) -> Result<Self, Error>
[src]
Creates a Font
object from a raw data.
You can set index
in case of font collections.
For simple ttf
fonts set index
to 0.
This function only parses font tables, so it's relatively light.
Required tables: head
, hhea
and maxp
.
pub fn has_table(&self, name: TableName) -> bool
[src]
Checks that font has a specified table.
pub fn number_of_glyphs(&self) -> u16
[src]
Returns a total number of glyphs in the font.
The value was already parsed, so this function doesn't involve any parsing.
pub fn outline_glyph(
&self,
glyph_id: GlyphId,
builder: &mut impl OutlineBuilder
) -> Result<Rect, Error>
[src]
&self,
glyph_id: GlyphId,
builder: &mut impl OutlineBuilder
) -> Result<Rect, Error>
Outlines a glyph. Returns a tight glyph bounding box.
This method support both glyf
and CFF
tables.
Example
use std::fmt::Write; use ttf_parser; struct Builder(String); impl ttf_parser::OutlineBuilder for Builder { fn move_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "M {} {} ", x, y).unwrap(); } fn line_to(&mut self, x: f32, y: f32) { write!(&mut self.0, "L {} {} ", x, y).unwrap(); } fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) { write!(&mut self.0, "Q {} {} {} {} ", x1, y1, x, y).unwrap(); } fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) { write!(&mut self.0, "C {} {} {} {} {} {} ", x1, y1, x2, y2, x, y).unwrap(); } fn close(&mut self) { write!(&mut self.0, "Z ").unwrap(); } } let data = std::fs::read("tests/fonts/glyphs.ttf").unwrap(); let font = ttf_parser::Font::from_data(&data, 0).unwrap(); let mut builder = Builder(String::new()); let glyph = font.outline_glyph(ttf_parser::GlyphId(0), &mut builder).unwrap(); assert_eq!(builder.0, "M 50 0 L 50 750 L 450 750 L 450 0 L 50 0 Z ");
Trait Implementations
Auto Trait Implementations
impl<'a> Sync for Font<'a>
impl<'a> Unpin for Font<'a>
impl<'a> Send for Font<'a>
impl<'a> UnwindSafe for Font<'a>
impl<'a> RefUnwindSafe for Font<'a>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,