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
impl FontWeight
Sourcepub const THIN: FontWeight
pub const THIN: FontWeight
Weight value of 100.
Sourcepub const EXTRA_LIGHT: FontWeight
pub const EXTRA_LIGHT: FontWeight
Weight value of 200.
Sourcepub const LIGHT: FontWeight
pub const LIGHT: FontWeight
Weight value of 300.
Sourcepub const SEMI_LIGHT: FontWeight
pub const SEMI_LIGHT: FontWeight
Weight value of 350.
Sourcepub const NORMAL: FontWeight
pub const NORMAL: FontWeight
Weight value of 400. This is the default value.
Sourcepub const MEDIUM: FontWeight
pub const MEDIUM: FontWeight
Weight value of 500.
Sourcepub const SEMI_BOLD: FontWeight
pub const SEMI_BOLD: FontWeight
Weight value of 600.
Sourcepub const BOLD: FontWeight
pub const BOLD: FontWeight
Weight value of 700.
Sourcepub const EXTRA_BOLD: FontWeight
pub const EXTRA_BOLD: FontWeight
Weight value of 800.
Sourcepub const BLACK: FontWeight
pub const BLACK: FontWeight
Weight value of 900.
Sourcepub const EXTRA_BLACK: FontWeight
pub const EXTRA_BLACK: FontWeight
Weight value of 950.
Sourcepub const fn new(weight: f32) -> FontWeight
pub const fn new(weight: f32) -> FontWeight
Creates a new weight value.
Sourcepub fn parse_css(s: &str) -> Option<FontWeight>
pub fn parse_css(s: &str) -> Option<FontWeight>
Parses a CSS font-weight value.
Supported syntax (after trimming ASCII whitespace):
normal→FontWeight::NORMALbold→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
impl Clone for FontWeight
Source§fn clone(&self) -> FontWeight
fn clone(&self) -> FontWeight
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for FontWeight
Source§impl Debug for FontWeight
impl Debug for FontWeight
Source§impl Default for FontWeight
impl Default for FontWeight
Source§fn default() -> FontWeight
fn default() -> FontWeight
Source§impl Display for FontWeight
impl Display for FontWeight
Source§impl FromFontconfig for FontWeight
impl FromFontconfig for FontWeight
Source§fn from_fontconfig(weight: i32) -> FontWeight
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.