Skip to content

Commit

Permalink
Update fontdb, rustybuzz, and ttf-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdickinson committed Aug 18, 2024
1 parent e16b39f commit fec03d3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ rust-version = "1.65"
[dependencies]
bitflags = "2.4.1"
cosmic_undo_2 = { version = "0.2.0", optional = true }
fontdb = { version = "0.16", default-features = false }
fontdb = { version = "0.21", default-features = false }
hashbrown = { version = "0.14.1", optional = true, default-features = false }
libm = { version = "0.2.8", optional = true }
log = "0.4.20"
modit = { version = "0.1.4", optional = true }
rangemap = "1.4.0"
rustc-hash = { version = "1.1.0", default-features = false }
rustybuzz = { version = "0.14", default-features = false, features = ["libm"] }
rustybuzz = { version = "0.18", default-features = false }
self_cell = "1.0.1"
swash = { version = "0.1.17", optional = true }
syntect = { version = "5.1.0", optional = true }
sys-locale = { version = "0.3.1", optional = true }
ttf-parser = { version = "0.21", default-features = false }
ttf-parser = { version = "0.24", default-features = false }
unicode-linebreak = "0.1.5"
unicode-script = "0.5.5"
unicode-segmentation = "1.10.1"
Expand All @@ -39,7 +39,7 @@ features = ["hardcoded-data"]
default = ["std", "swash", "fontconfig"]
fontconfig = ["fontdb/fontconfig", "std"]
monospace_fallback = []
no_std = ["rustybuzz/libm", "hashbrown", "dep:libm"]
no_std = ["hashbrown", "dep:libm"]
shape-run-cache = []
std = [
"fontdb/memmap",
Expand All @@ -48,7 +48,7 @@ std = [
"sys-locale",
"ttf-parser/std",
"unicode-bidi/std",
"rayon"
"rayon",
]
vi = ["modit", "syntect", "cosmic_undo_2"]
wasm-web = ["sys-locale?/js"]
Expand Down
98 changes: 98 additions & 0 deletions src/attrs/properties.rs
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),
}

0 comments on commit fec03d3

Please sign in to comment.