diff --git a/Cargo.toml b/Cargo.toml index 6b1acddd26..7202748a01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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", @@ -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"] diff --git a/src/attrs/properties.rs b/src/attrs/properties.rs new file mode 100644 index 0000000000..a1cc48d3cc --- /dev/null +++ b/src/attrs/properties.rs @@ -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), +}