-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update fontdb, rustybuzz, and ttf-parser
- Loading branch information
1 parent
e16b39f
commit fec03d3
Showing
2 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/// A [font family](https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#propdef-font-family). | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
pub enum Family<'a> { | ||
/// The name of a font family of choice. | ||
/// | ||
/// This must be a *Typographic Family* (ID 16) or a *Family Name* (ID 1) in terms of TrueType. | ||
/// Meaning you have to pass a family without any additional suffixes like _Bold_, _Italic_, | ||
/// _Regular_, etc. | ||
/// | ||
/// Localized names are allowed. | ||
Name(&'a str), | ||
|
||
/// Serif fonts represent the formal text style for a script. | ||
Serif, | ||
|
||
/// Glyphs in sans-serif fonts, as the term is used in CSS, are generally low contrast | ||
/// and have stroke endings that are plain — without any flaring, cross stroke, | ||
/// or other ornamentation. | ||
SansSerif, | ||
|
||
/// Glyphs in cursive fonts generally use a more informal script style, | ||
/// and the result looks more like handwritten pen or brush writing than printed letterwork. | ||
Cursive, | ||
|
||
/// Fantasy fonts are primarily decorative or expressive fonts that | ||
/// contain decorative or expressive representations of characters. | ||
Fantasy, | ||
|
||
/// The sole criterion of a monospace font is that all glyphs have the same fixed width. | ||
Monospace, | ||
} | ||
|
||
/// The degree to which a font is stretched, represented as a per mille (1/1000). | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub struct Stretch(pub u16); | ||
|
||
impl Stretch { | ||
/// Ultra-condensed width (50%), the narrowest possible. | ||
pub const ULTRA_CONDENSED: Stretch = Stretch(500); | ||
/// Extra-condensed width (62.5%). | ||
pub const EXTRA_CONDENSED: Stretch = Stretch(625); | ||
/// Condensed width (75%). | ||
pub const CONDENSED: Stretch = Stretch(750); | ||
/// Semi-condensed width (87.5%). | ||
pub const SEMI_CONDENSED: Stretch = Stretch(875); | ||
/// Normal width (100%). | ||
pub const NORMAL: Stretch = Stretch(1000); | ||
/// Semi-expanded width (112.5%). | ||
pub const SEMI_EXPANDED: Stretch = Stretch(1125); | ||
/// Expanded width (125%). | ||
pub const EXPANDED: Stretch = Stretch(1250); | ||
/// Extra-expanded width (150%). | ||
pub const EXTRA_EXPANDED: Stretch = Stretch(1500); | ||
/// Ultra-expanded width (200%), the widest possible. | ||
pub const ULTRA_EXPANDED: Stretch = Stretch(2000); | ||
|
||
/// Gets the value as a ratio | ||
pub fn ratio(&self) -> f32 { | ||
self.0 as f32 / 1000. | ||
} | ||
} | ||
|
||
/// The degree of blackness or stroke thickness of a font. This value ranges from 100 to 900, | ||
/// with 400 as normal. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub struct Weight(pub u16); | ||
|
||
impl Weight { | ||
/// Thin weight (100), the thinnest value. | ||
pub const THIN: Weight = Weight(100); | ||
/// Extra light weight (200). | ||
pub const EXTRA_LIGHT: Weight = Weight(200); | ||
/// Light weight (300). | ||
pub const LIGHT: Weight = Weight(300); | ||
/// Normal (400). | ||
pub const NORMAL: Weight = Weight(400); | ||
/// Medium weight (500, higher than normal). | ||
pub const MEDIUM: Weight = Weight(500); | ||
/// Semibold weight (600). | ||
pub const SEMIBOLD: Weight = Weight(600); | ||
/// Bold weight (700). | ||
pub const BOLD: Weight = Weight(700); | ||
/// Extra-bold weight (800). | ||
pub const EXTRA_BOLD: Weight = Weight(800); | ||
/// Black weight (900), the thickest value. | ||
pub const BLACK: Weight = Weight(900); | ||
} | ||
|
||
/// The degree to which a font is italicized. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub enum Style { | ||
/// The font is normal, upright. | ||
Normal, | ||
/// The font is cursive. | ||
Italic, | ||
/// The font is slanted at a specific angle, measured in degrees between -90 and 90. | ||
Oblique(i8), | ||
} |