[−][src]Struct ttf_parser::Face
A font face handle.
Implementations
impl<'a> Face<'a>
[src]
pub fn from_slice(data: &'a [u8], index: u32) -> Result<Self, FaceParsingError>
[src]
Creates a new Face
object from a raw data.
index
indicates the specific font face in a font collection.
Use fonts_in_collection
to get the total number of font faces.
Set to 0 if unsure.
This method will do some parsing and sanitization, so it's a bit expensive.
Required tables: head
, hhea
and maxp
.
If an optional table has an invalid data it will be skipped.
pub fn has_table(&self, name: TableName) -> bool
[src]
Checks that face has a specified table.
Will return true
only for tables that were successfully parsed.
pub fn table_data(&self, tag: Tag) -> Option<&'a [u8]>
[src]
Returns the raw data of a selected table.
Useful if you want to parse the data manually.
pub fn names(&self) -> Names<'_>ⓘ
[src]
Returns an iterator over Name Records.
An iterator can be empty.
pub fn is_regular(&self) -> bool
[src]
Checks that face is marked as Regular.
Returns false
when OS/2 table is not present.
pub fn is_italic(&self) -> bool
[src]
Checks that face is marked as Italic.
Returns false
when OS/2 table is not present.
pub fn is_bold(&self) -> bool
[src]
Checks that face is marked as Bold.
Returns false
when OS/2 table is not present.
pub fn is_oblique(&self) -> bool
[src]
Checks that face is marked as Oblique.
Returns false
when OS/2 table is not present or when its version is < 4.
pub fn is_monospaced(&self) -> bool
[src]
Checks that face is marked as Monospaced.
Returns false
when post
table is not present.
pub fn is_variable(&self) -> bool
[src]
Checks that face is variable.
Simply checks the presence of a fvar
table.
pub fn weight(&self) -> Weight
[src]
Returns face's weight.
Returns Weight::Normal
when OS/2 table is not present.
pub fn width(&self) -> Width
[src]
Returns face's width.
Returns Width::Normal
when OS/2 table is not present or when value is invalid.
pub fn italic_angle(&self) -> Option<f32>
[src]
Returns face's italic angle.
Returns None
when post
table is not present.
pub fn ascender(&self) -> i16
[src]
Returns a horizontal face ascender.
This method is affected by variation axes.
pub fn descender(&self) -> i16
[src]
Returns a horizontal face descender.
This method is affected by variation axes.
pub fn height(&self) -> i16
[src]
Returns face's height.
This method is affected by variation axes.
pub fn line_gap(&self) -> i16
[src]
Returns a horizontal face line gap.
This method is affected by variation axes.
pub fn typographic_ascender(&self) -> Option<i16>
[src]
Returns a horizontal typographic face ascender.
Prefer Face::ascender
unless you explicitly want this. This is a more
low-level alternative.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn typographic_descender(&self) -> Option<i16>
[src]
Returns a horizontal typographic face descender.
Prefer Face::descender
unless you explicitly want this. This is a more
low-level alternative.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn typographic_line_gap(&self) -> Option<i16>
[src]
Returns a horizontal typographic face line gap.
Prefer Face::line_gap
unless you explicitly want this. This is a more
low-level alternative.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn vertical_ascender(&self) -> Option<i16>
[src]
Returns a vertical face ascender.
This method is affected by variation axes.
pub fn vertical_descender(&self) -> Option<i16>
[src]
Returns a vertical face descender.
This method is affected by variation axes.
pub fn vertical_height(&self) -> Option<i16>
[src]
Returns a vertical face height.
This method is affected by variation axes.
pub fn vertical_line_gap(&self) -> Option<i16>
[src]
Returns a vertical face line gap.
This method is affected by variation axes.
pub fn units_per_em(&self) -> Option<u16>
[src]
Returns face's units per EM.
Returns None
when value is not in a 16..=16384 range.
pub fn x_height(&self) -> Option<i16>
[src]
Returns face's x height.
This method is affected by variation axes.
Returns None
when OS/2 table is not present or when its version is < 2.
pub fn capital_height(&self) -> Option<i16>
[src]
Returns face's capital height.
This method is affected by variation axes.
Returns None
when OS/2 table is not present or when its version is < 2.
pub fn underline_metrics(&self) -> Option<LineMetrics>
[src]
Returns face's underline metrics.
This method is affected by variation axes.
Returns None
when post
table is not present.
pub fn strikeout_metrics(&self) -> Option<LineMetrics>
[src]
Returns face's strikeout metrics.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn subscript_metrics(&self) -> Option<ScriptMetrics>
[src]
Returns face's subscript metrics.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn superscript_metrics(&self) -> Option<ScriptMetrics>
[src]
Returns face's superscript metrics.
This method is affected by variation axes.
Returns None
when OS/2 table is not present.
pub fn number_of_glyphs(&self) -> u16
[src]
Returns a total number of glyphs in the face.
Never zero.
The value was already parsed, so this function doesn't involve any parsing.
pub fn character_mapping_subtables(&self) -> Subtables<'_>ⓘ
[src]
Returns an iterator over character to glyph index mapping.
This is a more low-level alternative to Face::glyph_index
.
An iterator can be empty.
pub fn glyph_index(&self, c: char) -> Option<GlyphId>
[src]
Resolves a Glyph ID for a code point.
Returns None
instead of 0
when glyph is not found.
All subtable formats except Mixed Coverage (8) are supported.
If you need a more low-level control, prefer Face::character_mapping_subtables
.
pub fn glyph_variation_index(&self, c: char, variation: char) -> Option<GlyphId>
[src]
Resolves a variation of a Glyph ID from two code points.
Implemented according to Unicode Variation Sequences.
Returns None
instead of 0
when glyph is not found.
pub fn glyph_hor_advance(&self, glyph_id: GlyphId) -> Option<u16>
[src]
Returns glyph's horizontal advance.
This method is affected by variation axes.
pub fn glyph_ver_advance(&self, glyph_id: GlyphId) -> Option<u16>
[src]
Returns glyph's vertical advance.
This method is affected by variation axes.
pub fn glyph_hor_side_bearing(&self, glyph_id: GlyphId) -> Option<i16>
[src]
Returns glyph's horizontal side bearing.
This method is affected by variation axes.
pub fn glyph_ver_side_bearing(&self, glyph_id: GlyphId) -> Option<i16>
[src]
Returns glyph's vertical side bearing.
This method is affected by variation axes.
pub fn glyph_y_origin(&self, glyph_id: GlyphId) -> Option<i16>
[src]
Returns glyph's vertical origin according to Vertical Origin Table.
pub fn glyph_name(&self, glyph_id: GlyphId) -> Option<&str>
[src]
Returns glyph's name.
Uses the post
and CFF
tables as sources.
Returns None
when no name is associated with a glyph
.
pub fn has_glyph_classes(&self) -> bool
[src]
Checks that face has Glyph Class Definition Table.
pub fn glyph_class(&self, glyph_id: GlyphId) -> Option<GlyphClass>
[src]
Returns glyph's class according to Glyph Class Definition Table.
Returns None
when Glyph Class Definition Table is not set
or glyph class is not set or invalid.
pub fn glyph_mark_attachment_class(&self, glyph_id: GlyphId) -> Class
[src]
Returns glyph's mark attachment class according to Mark Attachment Class Definition Table.
All glyphs not assigned to a class fall into Class 0.
pub fn is_mark_glyph(&self, glyph_id: GlyphId, set_index: Option<u16>) -> bool
[src]
Checks that glyph is a mark according to Mark Glyph Sets Table.
set_index
allows checking a specific glyph coverage set.
Otherwise all sets will be checked.
pub fn glyph_variation_delta(
&self,
outer_index: u16,
inner_index: u16
) -> Option<f32>
[src]
&self,
outer_index: u16,
inner_index: u16
) -> Option<f32>
Returns glyph's variation delta at a specified index according to Item Variation Store Table.
pub fn kerning_subtables(&self) -> Subtables<'_>ⓘ
[src]
Returns a iterator over kerning subtables.
Supports both OpenType and Apple Advanced Typography variants.
pub fn outline_glyph(
&self,
glyph_id: GlyphId,
builder: &mut dyn OutlineBuilder
) -> Option<Rect>
[src]
&self,
glyph_id: GlyphId,
builder: &mut dyn OutlineBuilder
) -> Option<Rect>
Outlines a glyph and returns its tight bounding box.
Warning: since ttf-parser
is a pull parser,
OutlineBuilder
will emit segments even when outline is partially malformed.
You must check outline_glyph()
result before using
OutlineBuilder
's output.
gvar
, glyf
, CFF
and CFF2
tables are supported.
And they will be accesses in this specific order.
This method is affected by variation axes.
Returns None
when glyph has no outline or on error.
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("fonts/SourceSansPro-Regular-Tiny.ttf").unwrap(); let face = ttf_parser::Face::from_slice(&data, 0).unwrap(); let mut builder = Builder(String::new()); let bbox = face.outline_glyph(ttf_parser::GlyphId(13), &mut builder).unwrap(); assert_eq!(builder.0, "M 90 0 L 90 656 L 173 656 L 173 71 L 460 71 L 460 0 L 90 0 Z "); assert_eq!(bbox, ttf_parser::Rect { x_min: 90, y_min: 0, x_max: 460, y_max: 656 });
pub fn glyph_bounding_box(&self, glyph_id: GlyphId) -> Option<Rect>
[src]
Returns a tight glyph bounding box.
Unless the current face has a glyf
table, this is just a shorthand for outline_glyph()
since only the glyf
table stores a bounding box. In case of CFF and variable fonts
we have to actually outline a glyph to find it's bounding box.
When a glyph is defined by a raster or a vector image,
that can be obtained via glyph_image()
,
the bounding box must be calculated manually and this method will return None
.
This method is affected by variation axes.
pub fn global_bounding_box(&self) -> Rect
[src]
Returns a bounding box that large enough to enclose any glyph from the face.
pub fn glyph_raster_image(
&self,
glyph_id: GlyphId,
pixels_per_em: u16
) -> Option<RasterGlyphImage<'_>>
[src]
&self,
glyph_id: GlyphId,
pixels_per_em: u16
) -> Option<RasterGlyphImage<'_>>
Returns a reference to a glyph's raster image.
A font can define a glyph using a raster or a vector image instead of a simple outline. Which is primarily used for emojis. This method should be used to access raster images.
pixels_per_em
allows selecting a preferred image size. The chosen size will
be closer to an upper one. So when font has 64px and 96px images and pixels_per_em
is set to 72, 96px image will be returned.
To get the largest image simply use std::u16::MAX
.
Note that this method will return an encoded image. It should be decoded by the caller. We don't validate or preprocess it in any way.
Currently, only PNG images are supported.
Also, a font can contain both: images and outlines. So when this method returns None
you should also try outline_glyph()
afterwards.
There are multiple ways an image can be stored in a TrueType font
and this method supports only sbix
, CBLC
+CBDT
.
Font's tables be accesses in this specific order.
pub fn glyph_svg_image(&self, glyph_id: GlyphId) -> Option<&'a [u8]>
[src]
Returns a reference to a glyph's SVG image.
A font can define a glyph using a raster or a vector image instead of a simple outline. Which is primarily used for emojis. This method should be used to access SVG images.
Note that this method will return just an SVG data. It should be rendered or even decompressed (in case of SVGZ) by the caller. We don't validate or preprocess it in any way.
Also, a font can contain both: images and outlines. So when this method returns None
you should also try outline_glyph()
afterwards.
pub fn variation_axes(&self) -> VariationAxes<'_>ⓘNotable traits for VariationAxes<'a>
impl<'a> Iterator for VariationAxes<'a> type Item = VariationAxis;
[src]
Notable traits for VariationAxes<'a>
impl<'a> Iterator for VariationAxes<'a> type Item = VariationAxis;
Returns an iterator over variation axes.
pub fn set_variation(&mut self, axis: Tag, value: f32) -> Option<()>
[src]
Sets a variation axis coordinate.
This is the only mutable method in the library. We can simplify the API a lot by storing the variable coordinates in the face object itself.
Since coordinates are stored on the stack, we allow only 32 of them.
Returns None
when face is not variable or doesn't have such axis.
pub fn variation_coordinates(&self) -> &[NormalizedCoordinate]
[src]
Returns the current normalized variation coordinates.
pub fn has_non_default_variation_coordinates(&self) -> bool
[src]
Checks that face has non-default variation coordinates.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Face<'a>
impl<'a> Send for Face<'a>
impl<'a> Sync for Face<'a>
impl<'a> Unpin for Face<'a>
impl<'a> UnwindSafe for Face<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
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.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut 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.
pub 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>,