Skip to main content

FontWeight

Struct FontWeight 

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

Visual weight class of a font, typically on a scale from 1.0 to 1000.0.

The default value is FontWeight::NORMAL or 400.0.

In variable fonts, this can be controlled with the wght axis. This uses an f32 so that it can represent the full range of values possible with variable fonts.

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

In CSS, this corresponds to the font-weight property: https://www.w3.org/TR/css-fonts-4/#font-weight-prop.

Implementations§

Source§

impl FontWeight

Source

pub const THIN: FontWeight

Weight value of 100.

Source

pub const EXTRA_LIGHT: FontWeight

Weight value of 200.

Source

pub const LIGHT: FontWeight

Weight value of 300.

Source

pub const SEMI_LIGHT: FontWeight

Weight value of 350.

Source

pub const NORMAL: FontWeight

Weight value of 400. This is the default value.

Source

pub const MEDIUM: FontWeight

Weight value of 500.

Source

pub const SEMI_BOLD: FontWeight

Weight value of 600.

Source

pub const BOLD: FontWeight

Weight value of 700.

Source

pub const EXTRA_BOLD: FontWeight

Weight value of 800.

Source

pub const BLACK: FontWeight

Weight value of 900.

Source

pub const EXTRA_BLACK: FontWeight

Weight value of 950.

Source

pub const fn new(weight: f32) -> FontWeight

Creates a new weight value.

Source

pub const fn value(self) -> f32

Returns the underlying weight value.

Source

pub fn parse_css(s: &str) -> Option<FontWeight>

Parses a CSS font-weight value.

Supported syntax (after trimming ASCII whitespace):

  • normal → FontWeight::NORMAL
  • bold → FontWeight::BOLD
  • a number → FontWeight::new(value)

This parser is case-sensitive and does not clamp the numeric range.

use parlance::FontWeight;

assert_eq!(FontWeight::parse_css("normal"), Some(FontWeight::NORMAL));
assert_eq!(FontWeight::parse_css("bold"), Some(FontWeight::BOLD));
assert_eq!(FontWeight::parse_css("850"), Some(FontWeight::new(850.0)));
assert_eq!(FontWeight::parse_css("invalid"), None);

Trait Implementations§

Source§

impl Clone for FontWeight

Source§

fn clone(&self) -> FontWeight

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for FontWeight

Source§

impl Debug for FontWeight

Source§

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

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

impl Default for FontWeight

Source§

fn default() -> FontWeight

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

impl Display for FontWeight

Source§

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

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

impl FromFontconfig for FontWeight

Source§

fn from_fontconfig(weight: i32) -> FontWeight

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

The values are determined based on the fonts.conf documentation: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html.

Source§

impl PartialEq for FontWeight

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for FontWeight

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for FontWeight

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> Brush for T
where T: Clone + PartialEq + Default + Debug,

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<T> ErasedDestructor for T
where T: 'static,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.