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
impl FontWidth
Sourcepub const ULTRA_CONDENSED: Self
pub const ULTRA_CONDENSED: Self
Width that is 50% of normal.
Sourcepub const EXTRA_CONDENSED: Self
pub const EXTRA_CONDENSED: Self
Width that is 62.5% of normal.
Sourcepub const SEMI_CONDENSED: Self
pub const SEMI_CONDENSED: Self
Width that is 87.5% of normal.
Sourcepub const SEMI_EXPANDED: Self
pub const SEMI_EXPANDED: Self
Width that is 112.5% of normal.
Sourcepub const EXTRA_EXPANDED: Self
pub const EXTRA_EXPANDED: Self
Width that is 150% of normal.
Sourcepub const ULTRA_EXPANDED: Self
pub const ULTRA_EXPANDED: Self
Width that is 200% of normal.
Source§impl FontWidth
impl FontWidth
Sourcepub fn from_ratio(ratio: f32) -> Self
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);Sourcepub fn from_percentage(percentage: f32) -> Self
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);Sourcepub fn ratio(self) -> f32
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);Sourcepub fn percentage(self) -> f32
pub fn percentage(self) -> f32
Returns the width attribute as a percentage value.
This is generally the value associated with the wdth axis.
Sourcepub fn is_condensed(self) -> bool
pub fn is_condensed(self) -> bool
Returns true if the width is condensed (less than normal).
Sourcepub fn is_expanded(self) -> bool
pub fn is_expanded(self) -> bool
Returns true if the width is expanded (greater than normal).
Sourcepub fn parse(s: &str) -> Option<Self>
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<'de> Deserialize<'de> for FontWidth
impl<'de> Deserialize<'de> for FontWidth
Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<FontWidth, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<FontWidth, D::Error>
Source§impl Ord for FontWidth
impl Ord for FontWidth
Source§impl PartialOrd for FontWidth
impl PartialOrd for FontWidth
impl Copy for FontWidth
impl Eq for FontWidth
impl StructuralPartialEq for FontWidth
Auto Trait Implementations§
impl Freeze for FontWidth
impl RefUnwindSafe for FontWidth
impl Send for FontWidth
impl Sync for FontWidth
impl Unpin for FontWidth
impl UnwindSafe for FontWidth
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.