Skip to main content

FontWeight

Enum FontWeight 

Source
pub enum FontWeight {
    Regular,
    Medium,
    SemiBold,
    Bold,
}
Expand description

Font weight — a useful subset, mapped onto the CSS/OpenType weights.

Variants§

§

Regular

400 — regular.

§

Medium

§

SemiBold

§

Bold

700 — bold.

Implementations§

Source§

impl FontWeight

Source

pub fn to_u16(self) -> u16

The numeric OpenType weight (400/500/600/700).

Source

pub fn lerp(self, other: FontWeight, t: f32) -> FontWeight

The weight t of the way from self to other — the nearest of the four, not a number between them.

A weight is drawn with a face, and there are four faces. Interpolating the number would ask for a 437 that no font has, so what moves is the choice: the numeric weights are interpolated and the result snaps to whichever of the four is closest. Halfway from regular to bold is semi-bold, and a run of words thickens in steps rather than gliding.

The reference does exactly this over its nine weights, and this is its method rather than a lookalike: the position in the list is interpolated and rounded, not the OpenType number. The two agree here because the four are evenly spaced, and the list is what stays right if a fifth face is ever added between two of them.

A tie goes to the heavier face. Exactly halfway from regular to bold is 550, which has no nearest — rounding a half up the list answers semi-bold, going in either direction, so a run of words thickening and one thinning pass through the same face at the same moment instead of missing each other by one step.

Four steps make the stepping easier to see than nine would. That is a reason to say so here, not a reason to do something else: a variable-font axis is the thing that would make a weight glide, and this framework does not have one yet.

Trait Implementations§

Source§

impl Clone for FontWeight

Source§

fn clone(&self) -> Self

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 Copy for FontWeight

Source§

impl Debug for FontWeight

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FontWeight

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for FontWeight

Source§

impl PartialEq for FontWeight

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FontWeight

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.