From f27a0373a41d9e427e323d8c36b8a63de2da3ba7 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 9 Dec 2024 09:43:30 +0700 Subject: [PATCH] Rename `Stretch`, `Style`, `Weight` to have `Font` prefix This brings them into line with how they're used in `parley::style` as well as closer to how they're named in CSS where these properties are `font-stretch` (since renamed to `font-width`), `font-style`, and `font-weight`. This is a precursor to extracting this code into a separate crate for styling text. --- fontique/src/attributes.rs | 78 ++++++++++++------------ fontique/src/backend/fontconfig/cache.rs | 28 ++++----- fontique/src/backend/fontconfig/mod.rs | 8 +-- fontique/src/family.rs | 14 ++--- fontique/src/font.rs | 75 +++++++++++++---------- fontique/src/lib.rs | 2 +- fontique/src/matching.rs | 54 ++++++++-------- parley/src/style/font.rs | 4 +- 8 files changed, 135 insertions(+), 128 deletions(-) diff --git a/fontique/src/attributes.rs b/fontique/src/attributes.rs index 17c525cd..ae2a536d 100644 --- a/fontique/src/attributes.rs +++ b/fontique/src/attributes.rs @@ -9,7 +9,7 @@ use core_maths::CoreFloat; use core::fmt; -/// Primary attributes for font matching: [`Stretch`], [`Style`] and [`Weight`]. +/// Primary attributes for font matching: [`FontStretch`], [`FontStyle`] and [`FontWeight`]. /// /// These are used to [configure] a [`Query`]. /// @@ -17,14 +17,14 @@ use core::fmt; /// [`Query`]: crate::Query #[derive(Copy, Clone, PartialEq, Default, Debug)] pub struct Attributes { - pub stretch: Stretch, - pub style: Style, - pub weight: Weight, + pub stretch: FontStretch, + pub style: FontStyle, + pub weight: FontWeight, } impl Attributes { /// Creates new attributes from the given stretch, style and weight. - pub fn new(stretch: Stretch, style: Style, weight: Weight) -> Self { + pub fn new(stretch: FontStretch, style: FontStyle, weight: FontWeight) -> Self { Self { stretch, style, @@ -46,7 +46,7 @@ impl fmt::Display for Attributes { /// Visual width of a font-- a relative change from the normal aspect /// ratio, typically in the range `0.5` to `2.0`. /// -/// The default value is [`Stretch::NORMAL`] or `1.0`. +/// The default value is [`FontStretch::NORMAL`] or `1.0`. /// /// In variable fonts, this can be controlled with the `wdth` [axis]. /// @@ -57,9 +57,9 @@ impl fmt::Display for Attributes { /// [axis]: crate::AxisInfo /// [`font-width`]: https://www.w3.org/TR/css-fonts-4/#font-width-prop #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] -pub struct Stretch(f32); +pub struct FontStretch(f32); -impl Stretch { +impl FontStretch { /// Width that is 50% of normal. pub const ULTRA_CONDENSED: Self = Self(0.5); @@ -88,7 +88,7 @@ impl Stretch { pub const ULTRA_EXPANDED: Self = Self(2.0); } -impl Stretch { +impl FontStretch { /// Creates a new stretch attribute with the given ratio. /// /// This can also be created [from a percentage](Self::from_percentage). @@ -96,8 +96,8 @@ impl Stretch { /// # Example /// /// ``` - /// # use fontique::Stretch; - /// assert_eq!(Stretch::from_ratio(1.5), Stretch::EXTRA_EXPANDED); + /// # use fontique::FontStretch; + /// assert_eq!(FontStretch::from_ratio(1.5), Stretch::EXTRA_EXPANDED); /// ``` pub fn from_ratio(ratio: f32) -> Self { Self(ratio) @@ -110,8 +110,8 @@ impl Stretch { /// # Example /// /// ``` - /// # use fontique::Stretch; - /// assert_eq!(Stretch::from_percentage(87.5), Stretch::SEMI_CONDENSED); + /// # use fontique::FontStretch; + /// assert_eq!(FontStretch::from_percentage(87.5), FontStretch::SEMI_CONDENSED); /// ``` pub fn from_percentage(percentage: f32) -> Self { Self(percentage / 100.0) @@ -124,8 +124,8 @@ impl Stretch { /// # Example /// /// ``` - /// # use fontique::Stretch; - /// assert_eq!(Stretch::NORMAL.ratio(), 1.0); + /// # use fontique::FontStretch; + /// assert_eq!(FontStretch::NORMAL.ratio(), 1.0); /// ``` pub fn ratio(self) -> f32 { self.0 @@ -140,21 +140,21 @@ impl Stretch { /// Returns `true` if the stretch is [normal]. /// - /// [normal]: Stretch::NORMAL + /// [normal]: FontStretch::NORMAL pub fn is_normal(self) -> bool { self == Self::NORMAL } /// Returns `true` if the stretch is condensed (less than [normal]). /// - /// [normal]: Stretch::NORMAL + /// [normal]: FontStretch::NORMAL pub fn is_condensed(self) -> bool { self < Self::NORMAL } /// Returns `true` if the stretch is expanded (greater than [normal]). /// - /// [normal]: Stretch::NORMAL + /// [normal]: FontStretch::NORMAL pub fn is_expanded(self) -> bool { self > Self::NORMAL } @@ -164,10 +164,10 @@ impl Stretch { /// # Examples /// /// ``` - /// # use fontique::Stretch; - /// assert_eq!(Stretch::parse("semi-condensed"), Some(Stretch::SEMI_CONDENSED)); - /// assert_eq!(Stretch::parse("80%"), Some(Stretch::from_percentage(80.0))); - /// assert_eq!(Stretch::parse("wideload"), None); + /// # use fontique::FontStretch; + /// assert_eq!(FontStretch::parse("semi-condensed"), Some(FontStretch::SEMI_CONDENSED)); + /// assert_eq!(FontStretch::parse("80%"), Some(FontStretch::from_percentage(80.0))); + /// assert_eq!(FontStretch::parse("wideload"), None); /// ``` pub fn parse(s: &str) -> Option { let s = s.trim(); @@ -191,7 +191,7 @@ impl Stretch { } } -impl fmt::Display for Stretch { +impl fmt::Display for FontStretch { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let value = self.0 * 1000.0; if value.fract() == 0.0 { @@ -216,7 +216,7 @@ impl fmt::Display for Stretch { } } -impl Default for Stretch { +impl Default for FontStretch { fn default() -> Self { Self::NORMAL } @@ -224,7 +224,7 @@ impl Default for Stretch { /// Visual weight class of a font, typically on a scale from 1.0 to 1000.0. /// -/// The default value is [`Weight::NORMAL`] or `400.0`. +/// The default value is [`FontWeight::NORMAL`] or `400.0`. /// /// In variable fonts, this can be controlled with the `wght` [axis]. /// @@ -235,9 +235,9 @@ impl Default for Stretch { /// [axis]: crate::AxisInfo /// [`font-weight`]: https://www.w3.org/TR/css-fonts-4/#font-weight-prop #[derive(Copy, Clone, PartialEq, PartialOrd, Debug)] -pub struct Weight(f32); +pub struct FontWeight(f32); -impl Weight { +impl FontWeight { /// Weight value of 100. pub const THIN: Self = Self(100.0); @@ -272,7 +272,7 @@ impl Weight { pub const EXTRA_BLACK: Self = Self(950.0); } -impl Weight { +impl FontWeight { /// Creates a new weight attribute with the given value. pub fn new(weight: f32) -> Self { Self(weight) @@ -288,11 +288,11 @@ impl Weight { /// # Examples /// /// ``` - /// # use fontique::Weight; - /// assert_eq!(Weight::parse("normal"), Some(Weight::NORMAL)); - /// assert_eq!(Weight::parse("bold"), Some(Weight::BOLD)); - /// assert_eq!(Weight::parse("850"), Some(Weight::new(850.0))); - /// assert_eq!(Weight::parse("invalid"), None); + /// # use fontique::FontWeight; + /// assert_eq!(FontWeight::parse("normal"), Some(FontWeight::NORMAL)); + /// assert_eq!(FontWeight::parse("bold"), Some(FontWeight::BOLD)); + /// assert_eq!(FontWeight::parse("850"), Some(FontWeight::new(850.0))); + /// assert_eq!(FontWeight::parse("invalid"), None); /// ``` pub fn parse(s: &str) -> Option { let s = s.trim(); @@ -304,13 +304,13 @@ impl Weight { } } -impl Default for Weight { +impl Default for FontWeight { fn default() -> Self { Self::NORMAL } } -impl fmt::Display for Weight { +impl fmt::Display for FontWeight { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let value = self.0; if value.fract() == 0.0 { @@ -335,7 +335,7 @@ impl fmt::Display for Weight { /// Visual style or 'slope' of a font. /// -/// The default value is [`Style::Normal`]. +/// The default value is [`FontStyle::Normal`]. /// /// In variable fonts, this can be controlled with the `ital` /// and `slnt` [axes] for italic and oblique styles, respectively. @@ -347,7 +347,7 @@ impl fmt::Display for Weight { /// [axes]: crate::AxisInfo /// [`font-style`]: https://www.w3.org/TR/css-fonts-4/#font-style-prop #[derive(Copy, Clone, PartialEq, Default, Debug)] -pub enum Style { +pub enum FontStyle { /// An upright or "roman" style. #[default] Normal, @@ -359,7 +359,7 @@ pub enum Style { Oblique(Option), } -impl Style { +impl FontStyle { /// Parses a font style from a CSS value. pub fn parse(mut s: &str) -> Option { s = s.trim(); @@ -399,7 +399,7 @@ impl Style { } } -impl fmt::Display for Style { +impl fmt::Display for FontStyle { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let value = match self { Self::Normal => "normal", diff --git a/fontique/src/backend/fontconfig/cache.rs b/fontique/src/backend/fontconfig/cache.rs index a241252c..9eba2aea 100644 --- a/fontique/src/backend/fontconfig/cache.rs +++ b/fontique/src/backend/fontconfig/cache.rs @@ -1,12 +1,12 @@ // Copyright 2024 the Parley Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -use super::{Stretch, Style, Weight}; +use super::{FontStretch, FontStyle, FontWeight}; use fontconfig_cache_parser::{Cache, CharSetLeaf, Object, Pattern, Value}; use std::io::Read; use std::path::PathBuf; -impl Stretch { +impl FontStretch { /// Creates a new stretch attribute with the given value from Fontconfig. /// /// The values are determined based on the [fonts.conf documentation]. @@ -28,7 +28,7 @@ impl Stretch { } } -impl Style { +impl FontStyle { /// Creates a new style attribute with the given value from Fontconfig. /// /// The values are determined based on the [fonts.conf documentation]. @@ -43,7 +43,7 @@ impl Style { } } -impl Weight { +impl FontWeight { /// Creates a new weight attribute with the given value from Fontconfig. /// /// The values are determined based on the [fonts.conf documentation]. @@ -79,7 +79,7 @@ impl Weight { return Self::new(ot_a + (ot_b - ot_a) * t); } } - Weight::EXTRA_BLACK + Self::EXTRA_BLACK } } @@ -88,9 +88,9 @@ pub struct CachedFont { pub family: Vec, pub path: PathBuf, pub index: u32, - pub stretch: Stretch, - pub style: Style, - pub weight: Weight, + pub stretch: FontStretch, + pub style: FontStyle, + pub weight: FontWeight, pub coverage: Coverage, } @@ -100,9 +100,9 @@ impl CachedFont { self.path.clear(); self.index = 0; self.coverage.clear(); - self.weight = Weight::default(); - self.style = Style::default(); - self.stretch = Stretch::default(); + self.weight = FontWeight::default(); + self.style = FontStyle::default(); + self.stretch = FontStretch::default(); } } @@ -177,21 +177,21 @@ fn parse_font( Object::Slant => { for val in elt.values().ok()? { if let Value::Int(i) = val.ok()? { - font.style = Style::from_fc(i as _); + font.style = FontStyle::from_fc(i as _); } } } Object::Weight => { for val in elt.values().ok()? { if let Value::Int(i) = val.ok()? { - font.weight = Weight::from_fc(i as _); + font.weight = FontWeight::from_fc(i as _); } } } Object::Width => { for val in elt.values().ok()? { if let Value::Int(i) = val.ok()? { - font.stretch = Stretch::from_fc(i as _); + font.stretch = FontStretch::from_fc(i as _); } } } diff --git a/fontique/src/backend/fontconfig/mod.rs b/fontique/src/backend/fontconfig/mod.rs index 7134d890..1f80b181 100644 --- a/fontique/src/backend/fontconfig/mod.rs +++ b/fontique/src/backend/fontconfig/mod.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use super::{ - super::{Stretch, Style, Weight}, + super::{FontStretch, FontStyle, FontWeight}, FallbackKey, FamilyId, FamilyInfo, FamilyName, FamilyNameMap, FontInfo, GenericFamily, GenericFamilyMap, Script, SourceInfo, SourcePathMap, }; @@ -301,9 +301,9 @@ struct RawFamily { struct RawFont { source: SourceInfo, index: u32, - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, coverage: cache::Coverage, } diff --git a/fontique/src/family.rs b/fontique/src/family.rs index c017cba7..aed94714 100644 --- a/fontique/src/family.rs +++ b/fontique/src/family.rs @@ -4,7 +4,7 @@ //! Model for font families. use super::{ - attributes::{Stretch, Style, Weight}, + attributes::{FontStretch, FontStyle, FontWeight}, family_name::FamilyName, font::FontInfo, }; @@ -84,9 +84,9 @@ impl FamilyInfo { /// Returns the index of the best font from the family for the given attributes. pub fn match_index( &self, - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, synthesize_style: bool, ) -> Option { super::matching::match_font(self.fonts(), stretch, style, weight, synthesize_style) @@ -95,9 +95,9 @@ impl FamilyInfo { /// Selects the best font from the family for the given attributes. pub fn match_font( &self, - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, synthesize_style: bool, ) -> Option<&FontInfo> { self.fonts() diff --git a/fontique/src/font.rs b/fontique/src/font.rs index 19982c32..92a6b9ba 100644 --- a/fontique/src/font.rs +++ b/fontique/src/font.rs @@ -3,7 +3,7 @@ //! Model for a font. -use super::attributes::{Stretch, Style, Weight}; +use super::attributes::{FontStretch, FontStyle, FontWeight}; use super::source::{SourceInfo, SourceKind}; use super::{source_cache::SourceCache, Blob}; use read_fonts::{types::Tag, FontRef, TableProvider as _}; @@ -16,9 +16,9 @@ type AxisVec = SmallVec<[AxisInfo; 1]>; pub struct FontInfo { source: SourceInfo, index: u32, - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, axes: AxisVec, attr_axes: u8, } @@ -67,23 +67,28 @@ impl FontInfo { /// Returns the visual width of the font-- a relative change from the normal /// aspect ratio, typically in the range `0.5` to `2.0`. - pub fn stretch(&self) -> Stretch { + pub fn stretch(&self) -> FontStretch { self.stretch } /// Returns the visual style or 'slope' of the font. - pub fn style(&self) -> Style { + pub fn style(&self) -> FontStyle { self.style } /// Returns the visual weight class of the font, typically on a scale /// from `1.0` to `1000.0`. - pub fn weight(&self) -> Weight { + pub fn weight(&self) -> FontWeight { self.weight } /// Returns synthesis suggestions for this font with the given attributes. - pub fn synthesis(&self, stretch: Stretch, style: Style, weight: Weight) -> Synthesis { + pub fn synthesis( + &self, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, + ) -> Synthesis { let mut synth = Synthesis::default(); let mut len = 0usize; if self.has_width_axis() && self.stretch != stretch { @@ -100,9 +105,9 @@ impl FontInfo { } if self.style != style { match style { - Style::Normal => {} - Style::Italic => { - if self.style == Style::Normal { + FontStyle::Normal => {} + FontStyle::Italic => { + if self.style == FontStyle::Normal { if self.has_italic_axis() { synth.vars[len] = (Tag::new(b"ital"), 1.0); len += 1; @@ -114,8 +119,8 @@ impl FontInfo { } } } - Style::Oblique(angle) => { - if self.style == Style::Normal { + FontStyle::Oblique(angle) => { + if self.style == FontStyle::Normal { let degrees = angle.unwrap_or(14.0); if self.has_slant_axis() { synth.vars[len] = (Tag::new(b"slnt"), degrees); @@ -233,17 +238,17 @@ impl FontInfo { #[allow(unused)] pub(crate) fn maybe_override_attributes( &mut self, - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, ) { - if self.stretch == Stretch::default() { + if self.stretch == FontStretch::default() { self.stretch = stretch; } - if self.style == Style::default() { + if self.style == FontStyle::default() { self.style = style; } - if self.weight == Weight::default() { + if self.weight == FontWeight::default() { self.weight = weight; } } @@ -268,7 +273,7 @@ const OPTICAL_SIZE_AXIS: u8 = 0x10; /// * [Italic](https://fonts.google.com/knowledge/glossary/italic_axis) or `ital` /// * [Optical Size](https://fonts.google.com/knowledge/glossary/optical_size_axis) or `opsz` /// * [Slant](https://fonts.google.com/knowledge/glossary/slant_axis) or `slnt` -/// * [Weight](https://fonts.google.com/knowledge/glossary/weight_axis) or `wght` +/// * [FontWeight](https://fonts.google.com/knowledge/glossary/weight_axis) or `wght` /// * [Width](https://fonts.google.com/knowledge/glossary/width_axis) or `wdth` /// /// For a broader explanation of this, see @@ -331,7 +336,7 @@ impl Synthesis { } } -fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) { +fn read_attributes(font: &FontRef) -> (FontStretch, FontStyle, FontWeight) { use read_fonts::{ tables::{ head::{Head, MacStyle}, @@ -341,8 +346,8 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) { TableProvider, }; - fn stretch_from_width_class(width_class: u16) -> Stretch { - Stretch::from_ratio(match width_class { + fn stretch_from_width_class(width_class: u16) -> FontStretch { + FontStretch::from_ratio(match width_class { 0..=1 => 0.5, 2 => 0.625, 3 => 0.75, @@ -355,39 +360,39 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) { }) } - fn from_os2_post(os2: Os2, post: Option) -> (Stretch, Style, Weight) { + fn from_os2_post(os2: Os2, post: Option) -> (FontStretch, FontStyle, FontWeight) { let stretch = stretch_from_width_class(os2.us_width_class()); // Bits 1 and 9 of the fsSelection field signify italic and // oblique, respectively. // See: let fs_selection = os2.fs_selection(); let style = if fs_selection.contains(SelectionFlags::ITALIC) { - Style::Italic + FontStyle::Italic } else if fs_selection.contains(SelectionFlags::OBLIQUE) { let angle = post.map(|post| post.italic_angle().to_f64() as f32); - Style::Oblique(angle) + FontStyle::Oblique(angle) } else { - Style::Normal + FontStyle::Normal }; - // The usWeightClass field is specified with a 1-1000 range, but + // The usFontWeightClass field is specified with a 1-1000 range, but // we don't clamp here because variable fonts could potentially // have a value outside of that range. // See - let weight = Weight::new(os2.us_weight_class() as f32); + let weight = FontWeight::new(os2.us_weight_class() as f32); (stretch, style, weight) } - fn from_head(head: Head) -> (Stretch, Style, Weight) { + fn from_head(head: Head) -> (FontStretch, FontStyle, FontWeight) { let mac_style = head.mac_style(); let style = mac_style .contains(MacStyle::ITALIC) - .then_some(Style::Italic) + .then_some(FontStyle::Italic) .unwrap_or_default(); let weight = mac_style .contains(MacStyle::BOLD) .then_some(700.0) .unwrap_or_default(); - (Stretch::default(), style, Weight::new(weight)) + (FontStretch::default(), style, FontWeight::new(weight)) } if let Ok(os2) = font.os2() { @@ -398,6 +403,10 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) { // Otherwise, fall back to the macStyle field of the head table. from_head(head) } else { - (Stretch::default(), Style::Normal, Weight::default()) + ( + FontStretch::default(), + FontStyle::Normal, + FontWeight::default(), + ) } } diff --git a/fontique/src/lib.rs b/fontique/src/lib.rs index 89f70f9e..3dd64bff 100644 --- a/fontique/src/lib.rs +++ b/fontique/src/lib.rs @@ -49,7 +49,7 @@ mod source_cache; pub use icu_locid::LanguageIdentifier as Language; pub use peniko::Blob; -pub use attributes::{Attributes, Stretch, Style, Weight}; +pub use attributes::{Attributes, FontStretch, FontStyle, FontWeight}; pub use collection::{Collection, CollectionOptions, Query, QueryFamily, QueryFont, QueryStatus}; pub use fallback::FallbackKey; pub use family::{FamilyId, FamilyInfo}; diff --git a/fontique/src/matching.rs b/fontique/src/matching.rs index af708f3d..c0e1edd6 100644 --- a/fontique/src/matching.rs +++ b/fontique/src/matching.rs @@ -3,7 +3,7 @@ //! Implementation of the CSS font matching algorithm. -use super::attributes::{Stretch, Style, Weight}; +use super::attributes::{FontStretch, FontStyle, FontWeight}; use super::font::FontInfo; use smallvec::SmallVec; @@ -11,9 +11,9 @@ const DEFAULT_OBLIQUE_ANGLE: f32 = 14.0; pub fn match_font( set: &[FontInfo], - stretch: Stretch, - style: Style, - weight: Weight, + stretch: FontStretch, + style: FontStyle, + weight: FontWeight, synthesize_style: bool, ) -> Option { const OBLIQUE_THRESHOLD: f32 = DEFAULT_OBLIQUE_ANGLE; @@ -26,7 +26,7 @@ pub fn match_font( struct Candidate { index: usize, stretch: i32, - style: Style, + style: FontStyle, weight: f32, has_slnt: bool, } @@ -102,7 +102,7 @@ pub fn match_font( let mut _use_slnt = false; if !set.iter().any(|f| f.style == use_style) { // If the value of font-style is italic: - if style == Style::Italic { + if style == FontStyle::Italic { // oblique values greater than or equal to 14deg are checked in // ascending order if let Some(found) = oblique_fonts @@ -162,16 +162,16 @@ pub fn match_font( if set.iter().any(|f| f.has_slnt) { _use_slnt = true; } else { - use_style = if set.iter().any(|f| f.style == Style::Normal) { - Style::Normal + use_style = if set.iter().any(|f| f.style == FontStyle::Normal) { + FontStyle::Normal } else { set[0].style }; } } else { // Choose an italic style - if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic; + if set.iter().any(|f| f.style == FontStyle::Italic) { + use_style = FontStyle::Italic; } // oblique values less than or equal to 0deg are checked in descending order else if let Some(found) = oblique_fonts @@ -215,16 +215,16 @@ pub fn match_font( if set.iter().any(|f| f.has_slnt) { _use_slnt = true; } else { - use_style = if set.iter().any(|f| f.style == Style::Normal) { - Style::Normal + use_style = if set.iter().any(|f| f.style == FontStyle::Normal) { + FontStyle::Normal } else { set[0].style }; } } else { // Choose an italic style - if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic; + if set.iter().any(|f| f.style == FontStyle::Italic) { + use_style = FontStyle::Italic; } // oblique values less than or equal to 0deg are checked in descending order else if let Some(found) = oblique_fonts @@ -267,16 +267,16 @@ pub fn match_font( if set.iter().any(|f| f.has_slnt) { _use_slnt = true; } else { - use_style = if set.iter().any(|f| f.style == Style::Normal) { - Style::Normal + use_style = if set.iter().any(|f| f.style == FontStyle::Normal) { + FontStyle::Normal } else { set[0].style }; } } else { // Choose an italic style - if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic; + if set.iter().any(|f| f.style == FontStyle::Italic) { + use_style = FontStyle::Italic; } // oblique values greater than or equal to 0deg are checked in ascending order else if let Some(found) = oblique_fonts @@ -319,16 +319,16 @@ pub fn match_font( if set.iter().any(|f| f.has_slnt) { _use_slnt = true; } else { - use_style = if set.iter().any(|f| f.style == Style::Normal) { - Style::Normal + use_style = if set.iter().any(|f| f.style == FontStyle::Normal) { + FontStyle::Normal } else { set[0].style }; } } else { // Choose an italic style - if set.iter().any(|f| f.style == Style::Italic) { - use_style = Style::Italic; + if set.iter().any(|f| f.style == FontStyle::Italic) { + use_style = FontStyle::Italic; } // oblique values greater than or equal to 0deg are checked in ascending order else if let Some(found) = oblique_fonts @@ -356,7 +356,7 @@ pub fn match_font( use_style = found.0; } // followed by italic fonts - else if let Some(found) = set.iter().find(|f| f.style == Style::Italic) { + else if let Some(found) = set.iter().find(|f| f.style == FontStyle::Italic) { use_style = found.style; } // followed by oblique values less than 0deg in descending order @@ -449,16 +449,16 @@ pub fn match_font( None } -fn oblique_angle(style: Style) -> Option { +fn oblique_angle(style: FontStyle) -> Option { match style { - Style::Oblique(angle) => Some(angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE)), + FontStyle::Oblique(angle) => Some(angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE)), _ => None, } } -fn oblique_style(style: Style) -> Option<(Style, f32)> { +fn oblique_style(style: FontStyle) -> Option<(FontStyle, f32)> { match style { - Style::Oblique(angle) => Some((style, angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE))), + FontStyle::Oblique(angle) => Some((style, angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE))), _ => None, } } diff --git a/parley/src/style/font.rs b/parley/src/style/font.rs index 473dc967..3c44f646 100644 --- a/parley/src/style/font.rs +++ b/parley/src/style/font.rs @@ -5,9 +5,7 @@ use alloc::borrow::Cow; use alloc::borrow::ToOwned; use core::fmt; -pub use fontique::{ - GenericFamily, Stretch as FontStretch, Style as FontStyle, Weight as FontWeight, -}; +pub use fontique::{FontStretch, FontStyle, FontWeight, GenericFamily}; /// Setting for a font variation. pub type FontVariation = swash::Setting;