Skip to main content

FontWidth

Struct FontWidth 

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

Visual width of a font– a relative change from the normal aspect ratio, typically in the range 0.5 to 2.0.

The default value is FontWidth::NORMAL or 1.0.

In variable fonts, this can be controlled with the wdth axis. This is an f32 so that it can represent the same range of values as 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.

This has also been known as “stretch” and has a legacy CSS name alias, font-stretch.

Implementations§

§

impl FontWidth

pub const ULTRA_CONDENSED: FontWidth

Width that is 50% of normal.

pub const EXTRA_CONDENSED: FontWidth

Width that is 62.5% of normal.

pub const CONDENSED: FontWidth

Width that is 75% of normal.

pub const SEMI_CONDENSED: FontWidth

Width that is 87.5% of normal.

pub const NORMAL: FontWidth

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

pub const SEMI_EXPANDED: FontWidth

Width that is 112.5% of normal.

pub const EXPANDED: FontWidth

Width that is 125% of normal.

pub const EXTRA_EXPANDED: FontWidth

Width that is 150% of normal.

pub const ULTRA_EXPANDED: FontWidth

Width that is 200% of normal.

§

impl FontWidth

pub fn from_ratio(ratio: f32) -> FontWidth

Creates a new width attribute with the given ratio.

This can also be created from a percentage.

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

pub fn from_percentage(percentage: f32) -> FontWidth

Creates a width attribute from a percentage.

This can also be created from a ratio.

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

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);

pub fn percentage(self) -> f32

Returns the width attribute as a percentage value.

This is generally the value associated with the wdth axis.

pub fn is_normal(self) -> bool

Returns true if the width is normal.

pub fn is_condensed(self) -> bool

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

pub fn is_expanded(self) -> bool

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

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

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);
§

impl FontWidth

pub fn from_fontconfig(width: i32) -> FontWidth

Creates a new width attribute with the given value from Fontconfig.

The values are determined based on the fonts.conf documentation.

Trait Implementations§

§

impl Clone for FontWidth

§

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
§

impl Debug for FontWidth

§

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

Formats the value using the given formatter. Read more
§

impl Default for FontWidth

§

fn default() -> FontWidth

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

impl Display for FontWidth

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for FontWidth

§

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.
§

impl PartialOrd for FontWidth

§

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
§

impl Copy for FontWidth

§

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

§

fn to_smolstr(&self) -> SmolStr

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,