Skip to main content

LayoutFontMetrics

Struct LayoutFontMetrics 

Source
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

Source

pub fn baseline_scaled(&self, font_size: f32) -> f32

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> LayoutFontMetrics

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LayoutFontMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.