pub struct LayoutFontMetrics {
pub ascent: f32,
pub descent: f32,
pub line_gap: f32,
pub units_per_em: u16,
pub x_height: Option<f32>,
pub cap_height: Option<f32>,
}Expand description
Layout-specific font metrics extracted from FontMetrics Contains only the metrics needed for text layout and rendering
Fields§
§ascent: f32§descent: f32§line_gap: f32§units_per_em: u16§x_height: Option<f32>OS/2 sxHeight: distance from baseline to top of lowercase ‘x’ (in font units).
Used for vertical-align: middle per CSS Inline 3 §4.1.
cap_height: Option<f32>OS/2 sCapHeight: height of capital letters from baseline (in font units). Used for drop cap / initial-letter alignment per CSS Inline 3 §7.1.1.
Implementations§
Source§impl LayoutFontMetrics
impl LayoutFontMetrics
pub fn baseline_scaled(&self, font_size: f32) -> f32
Sourcepub fn x_height_scaled(&self, font_size: f32) -> f32
pub fn x_height_scaled(&self, font_size: f32) -> f32
Returns the x-height scaled to the given font size in px. Falls back to 0.5em when the font doesn’t provide sxHeight.
Sourcepub fn cap_height_scaled(&self, font_size: f32) -> f32
pub fn cap_height_scaled(&self, font_size: f32) -> f32
Returns the cap height scaled to the given font size in px. Falls back to ascent when the font doesn’t provide sCapHeight.
Sourcepub fn from_font_metrics(metrics: &FontMetrics) -> Self
pub fn from_font_metrics(metrics: &FontMetrics) -> Self
Convert from full FontMetrics to layout-specific metrics.
Per CSS 2.2 §10.8.1: prefer OS/2 sTypoAscender/sTypoDescender, fall back to HHEA Ascent/Descent if OS/2 metrics are absent.
Sourcepub fn em_over(&self) -> f32
pub fn em_over(&self) -> f32
Synthesize em-over baseline offset (in font units). Per CSS Inline 3 Appendix A.1: em-over = central baseline + 0.5em. Central baseline is synthesized as midpoint of ascent and descent.
Sourcepub fn em_under(&self) -> f32
pub fn em_under(&self) -> f32
Synthesize em-under baseline offset (in font units). Per CSS Inline 3 Appendix A.1: em-under = central baseline - 0.5em.
Sourcepub fn central_baseline(&self) -> f32
pub fn central_baseline(&self) -> f32
Synthesize central baseline (in font units). Midpoint between ascent and descent when not provided by the font.
Trait Implementations§
Source§impl Clone for LayoutFontMetrics
impl Clone for LayoutFontMetrics
Source§fn clone(&self) -> LayoutFontMetrics
fn clone(&self) -> LayoutFontMetrics
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LayoutFontMetrics
impl RefUnwindSafe for LayoutFontMetrics
impl Send for LayoutFontMetrics
impl Sync for LayoutFontMetrics
impl Unpin for LayoutFontMetrics
impl UnsafeUnpin for LayoutFontMetrics
impl UnwindSafe for LayoutFontMetrics
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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