pub struct Metrics {Show 14 fields
pub units_per_em: u16,
pub raw_units_per_em: u16,
pub num_glyphs: u32,
pub bounds: BoundingBox<F48Dot16>,
pub hhea_line: Option<LineBox>,
pub max_h_advance: Option<F48Dot16>,
pub vhea_line: Option<LineBox>,
pub max_v_advance: Option<F48Dot16>,
pub typo_line: Option<LineBox>,
pub use_typo_metrics: bool,
pub win_line: Option<LineExtents<F48Dot16>>,
pub x_height: Option<F48Dot16>,
pub cap_height: Option<F48Dot16>,
pub average_char_width: Option<F48Dot16>,
}Expand description
Font-wide metrics.
Read from head, maxp, hhea, vhea and OS/2, which together are a
few hundred bytes.
A font has three sets of line metrics, and they often differ.
hhea_line is what macOS reads,
win_line is what Windows reads, and typo_line is what the
font asks for when use_typo_metrics is set.
Choosing between them is left to the caller.
A field missing from the font is None, which is distinct from a zero
value.
MVAR varies most of these, so a set belongs to the location it was read
at. The units per em, the counts, the bounding box, the widest and tallest
advance and the average width cannot vary.
§Units
Measurements are in font units. They are F48Dot16 because a
location can move them off a whole unit, and rounding here would decide
for every caller how that fraction is spent.
The two axes do not scale alike: vhea_line is
measured across the vertical baseline rather than along it, so it scales
on x where the horizontal sets scale on y.
Fields§
§units_per_em: u16Design units per em, which every measurement of the font uses.
Always between 16 and 16384. A font with a value outside that range,
or with no head, uses 1000.
raw_units_per_em: u16Design units per em as written in head, or zero if the font has no
head.
Differs from units_per_em only for a font with
an unusable value, which a caller may choose to reject.
num_glyphs: u32Number of glyphs in the font.
bounds: BoundingBox<F48Dot16>Box enclosing every glyph in the font.
hhea_line: Option<LineBox>Line metrics from hhea.
max_h_advance: Option<F48Dot16>Widest advance of any glyph.
vhea_line: Option<LineBox>Line metrics from vhea, measured across the vertical baseline.
max_v_advance: Option<F48Dot16>Tallest advance of any glyph.
typo_line: Option<LineBox>Typographic line metrics, from OS/2.
use_typo_metrics: bool§win_line: Option<LineExtents<F48Dot16>>The line outside which the font asks not to be clipped.
OS/2 gives the descent as a positive number below the baseline.
This negates it, so the pair describes a line like every other pair
here.
x_height: Option<F48Dot16>Height of a lowercase x.
cap_height: Option<F48Dot16>Height of a capital letter.
average_char_width: Option<F48Dot16>Average glyph width, as the font reports it.
Implementations§
Source§impl Metrics
impl Metrics
Sourcepub fn from_sfnt<'a>(
tables: &impl TableProvider<'a>,
normalized_coords: &[F2Dot14],
) -> Metrics
pub fn from_sfnt<'a>( tables: &impl TableProvider<'a>, normalized_coords: &[F2Dot14], ) -> Metrics
Reads the metrics from tables at normalized_coords.
A missing or unreadable table leaves the metrics that come from it unset rather than failing.
Pass an empty location for the font’s defaults. At any other location
MVAR is read and its deltas applied.
Sourcepub fn h_line(&self) -> Option<LineBox>
pub fn h_line(&self) -> Option<LineBox>
Returns the ascender, descender and gap for horizontal text.
The line is the first of these that applies:
- The typographic line, if
OS/2setsUSE_TYPO_METRICS. - The
hhealine, if either end is nonzero. - The typographic line, if either end is nonzero.
- The
OS/2clipping line, with no gap.
Returns None if the font has no line metrics.
Sourcepub fn from_type1(font: &Type1Font) -> Metrics
pub fn from_type1(font: &Type1Font) -> Metrics
Reads the metrics from a Type 1 font.
Such a font has only a bounding box, a glyph count and a matrix. The ascender and descender are the top and bottom of that box. Everything else is unset.
Sourcepub fn from_cff(font: &CffFontRef<'_>) -> Metrics
pub fn from_cff(font: &CffFontRef<'_>) -> Metrics
Reads the metrics from a standalone CFF font.
Source§impl Metrics
impl Metrics
Sourcepub fn scaled<S>(&self, scale: S) -> ScaledMetrics<'_, S>where
S: Scale,
pub fn scaled<S>(&self, scale: S) -> ScaledMetrics<'_, S>where
S: Scale,
Returns these metrics in the units scale describes.
Sourcepub fn scaled_f32(&self, ppem: f32) -> ScaledMetrics<'_, ScaleF32>
pub fn scaled_f32(&self, ppem: f32) -> ScaledMetrics<'_, ScaleF32>
Returns these metrics in pixels at ppem, as f32.
Sourcepub fn scaled_26dot6(&self, ppem: f32) -> ScaledMetrics<'_, Scale26Dot6>
pub fn scaled_26dot6(&self, ppem: f32) -> ScaledMetrics<'_, Scale26Dot6>
Returns these metrics in pixels at ppem, in 26.6 fixed point.