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
impl FontWidth
pub const ULTRA_CONDENSED: FontWidth
pub const ULTRA_CONDENSED: FontWidth
Width that is 50% of normal.
pub const EXTRA_CONDENSED: FontWidth
pub const EXTRA_CONDENSED: FontWidth
Width that is 62.5% of normal.
pub const SEMI_CONDENSED: FontWidth
pub const SEMI_CONDENSED: FontWidth
Width that is 87.5% of normal.
pub const SEMI_EXPANDED: FontWidth
pub const SEMI_EXPANDED: FontWidth
Width that is 112.5% of normal.
pub const EXTRA_EXPANDED: FontWidth
pub const EXTRA_EXPANDED: FontWidth
Width that is 150% of normal.
pub const ULTRA_EXPANDED: FontWidth
pub const ULTRA_EXPANDED: FontWidth
Width that is 200% of normal.
§impl FontWidth
impl FontWidth
pub fn from_ratio(ratio: f32) -> 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
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
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
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_condensed(self) -> bool
pub fn is_condensed(self) -> bool
Returns true if the width is condensed (less than normal).
pub fn is_expanded(self) -> bool
pub fn is_expanded(self) -> bool
Returns true if the width is expanded (greater than normal).
pub 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);§impl FontWidth
impl FontWidth
pub fn from_fontconfig(width: i32) -> 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 PartialOrd for FontWidth
impl PartialOrd for FontWidth
impl Copy 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 UnsafeUnpin 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.