Skip to main content

FontWidth

Struct FontWidth 

Source
pub struct FontWidth(/* private fields */);
Expand description

Visual width of a font– a relative change from the normal aspect ratio, typically in the 50% - 200% range.

The default value is FontWidth::NORMAL.

In variable fonts, this can be controlled with the wdth axis.

In Open Type, the u16 usWidthClass field has 9 values, from 1-9, which doesn’t allow for the wide range of values possible with variable fonts.

See https://fonts.google.com/knowledge/glossary/width

In CSS, this corresponds to the font-width property, formerly known as font-stretch.

Implementations§

Source§

impl FontWidth

Source

pub const ULTRA_CONDENSED: Self

Width that is 50% of normal.

Source

pub const EXTRA_CONDENSED: Self

Width that is 62.5% of normal.

Source

pub const CONDENSED: Self

Width that is 75% of normal.

Source

pub const SEMI_CONDENSED: Self

Width that is 87.5% of normal.

Source

pub const NORMAL: Self

Width that is 100% of normal. This is the default value.

Source

pub const SEMI_EXPANDED: Self

Width that is 112.5% of normal.

Source

pub const EXPANDED: Self

Width that is 125% of normal.

Source

pub const EXTRA_EXPANDED: Self

Width that is 150% of normal.

Source

pub const ULTRA_EXPANDED: Self

Width that is 200% of normal.

Source§

impl FontWidth

Source

pub fn from_ratio(ratio: f32) -> Self

Creates a new width attribute with the given ratio.

Panics if the ratio is not between 0 and 255.996.

This can also be created from a percentage.

§Example
assert_eq!(FontWidth::from_ratio(1.5), FontWidth::EXTRA_EXPANDED);
Source

pub fn from_percentage(percentage: f32) -> Self

Creates a width attribute from a percentage.

Panics if the percentage is not between 0% and 25599.6%.

This can also be created from a ratio.

§Example
assert_eq!(FontWidth::from_percentage(87.5), FontWidth::SEMI_CONDENSED);
Source

pub fn ratio(self) -> f32

Returns the width attribute as a ratio.

This is a linear scaling factor with 1.0 being “normal” width.

§Example
assert_eq!(FontWidth::NORMAL.ratio(), 1.0);
Source

pub fn percentage(self) -> f32

Returns the width attribute as a percentage value.

This is generally the value associated with the wdth axis.

Source

pub fn is_normal(self) -> bool

Returns true if the width is normal.

Source

pub fn is_condensed(self) -> bool

Returns true if the width is condensed (less than normal).

Source

pub fn is_expanded(self) -> bool

Returns true if the width is expanded (greater than normal).

Source

pub fn parse(s: &str) -> Option<Self>

Parses the width from a CSS style keyword or a percentage value.

§Examples
assert_eq!(FontWidth::parse("semi-condensed"), Some(FontWidth::SEMI_CONDENSED));
assert_eq!(FontWidth::parse("80%"), Some(FontWidth::from_percentage(80.0)));
assert_eq!(FontWidth::parse("wideload"), None);

Trait Implementations§

Source§

impl Clone for FontWidth

Source§

fn clone(&self) -> FontWidth

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FontWidth

Source§

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

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

impl Default for FontWidth

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for FontWidth

Source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<FontWidth, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for FontWidth

Source§

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

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

impl From<FontWidth> for FontWidth

Source§

fn from(width: FontWidth) -> Self

Converts to this type from the input type.
Source§

impl Hash for FontWidth

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for FontWidth

Source§

fn cmp(&self, other: &FontWidth) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for FontWidth

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FontWidth

Source§

fn partial_cmp(&self, other: &FontWidth) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for FontWidth

Source§

fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for FontWidth

Source§

impl Eq for FontWidth

Source§

impl StructuralPartialEq for FontWidth

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<S, T> Cast<T> for S
where T: Conv<S>,

Source§

fn cast(self) -> T

Cast from Self to T Read more
Source§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
Source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

Source§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
Source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
Source§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

Source§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
Source§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
Source§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
Source§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
Source§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
Source§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
Source§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
Source§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer 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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,