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.
This has also been known as “stretch” and has a legacy CSS name alias,
font-stretch
.
Implementations§
Source§impl FontWidth
impl FontWidth
Sourcepub const ULTRA_CONDENSED: FontWidth
pub const ULTRA_CONDENSED: FontWidth
Width that is 50% of normal.
Sourcepub const EXTRA_CONDENSED: FontWidth
pub const EXTRA_CONDENSED: FontWidth
Width that is 62.5% of normal.
Sourcepub const SEMI_CONDENSED: FontWidth
pub const SEMI_CONDENSED: FontWidth
Width that is 87.5% of normal.
Sourcepub const SEMI_EXPANDED: FontWidth
pub const SEMI_EXPANDED: FontWidth
Width that is 112.5% of normal.
Sourcepub const EXTRA_EXPANDED: FontWidth
pub const EXTRA_EXPANDED: FontWidth
Width that is 150% of normal.
Sourcepub const ULTRA_EXPANDED: FontWidth
pub const ULTRA_EXPANDED: FontWidth
Width that is 200% of normal.
Source§impl FontWidth
impl FontWidth
Sourcepub fn from_ratio(ratio: f32) -> FontWidth
pub fn from_ratio(ratio: f32) -> FontWidth
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) -> FontWidth
pub fn from_percentage(percentage: f32) -> FontWidth
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<FontWidth>
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);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FontWidth
impl<'de> Deserialize<'de> for FontWidth
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<FontWidth, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<FontWidth, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Ord for FontWidth
impl Ord for FontWidth
Source§impl PartialOrd for FontWidth
impl PartialOrd for FontWidth
Source§impl Serialize for FontWidth
impl Serialize for FontWidth
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.