Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 16e9600

Browse files
committedDec 9, 2024·
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.
1 parent 4fc2a6d commit 16e9600

File tree

8 files changed

+135
-128
lines changed

8 files changed

+135
-128
lines changed
 

‎fontique/src/attributes.rs

+39-39
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ use core_maths::CoreFloat;
99

1010
use core::fmt;
1111

12-
/// Primary attributes for font matching: [`Stretch`], [`Style`] and [`Weight`].
12+
/// Primary attributes for font matching: [`FontStretch`], [`FontStyle`] and [`FontWeight`].
1313
///
1414
/// These are used to [configure] a [`Query`].
1515
///
1616
/// [configure]: crate::Query::set_attributes
1717
/// [`Query`]: crate::Query
1818
#[derive(Copy, Clone, PartialEq, Default, Debug)]
1919
pub struct Attributes {
20-
pub stretch: Stretch,
21-
pub style: Style,
22-
pub weight: Weight,
20+
pub stretch: FontStretch,
21+
pub style: FontStyle,
22+
pub weight: FontWeight,
2323
}
2424

2525
impl Attributes {
2626
/// Creates new attributes from the given stretch, style and weight.
27-
pub fn new(stretch: Stretch, style: Style, weight: Weight) -> Self {
27+
pub fn new(stretch: FontStretch, style: FontStyle, weight: FontWeight) -> Self {
2828
Self {
2929
stretch,
3030
style,
@@ -46,7 +46,7 @@ impl fmt::Display for Attributes {
4646
/// Visual width of a font-- a relative change from the normal aspect
4747
/// ratio, typically in the range `0.5` to `2.0`.
4848
///
49-
/// The default value is [`Stretch::NORMAL`] or `1.0`.
49+
/// The default value is [`FontStretch::NORMAL`] or `1.0`.
5050
///
5151
/// In variable fonts, this can be controlled with the `wdth` [axis].
5252
///
@@ -57,9 +57,9 @@ impl fmt::Display for Attributes {
5757
/// [axis]: crate::AxisInfo
5858
/// [`font-width`]: https://www.w3.org/TR/css-fonts-4/#font-width-prop
5959
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
60-
pub struct Stretch(f32);
60+
pub struct FontStretch(f32);
6161

62-
impl Stretch {
62+
impl FontStretch {
6363
/// Width that is 50% of normal.
6464
pub const ULTRA_CONDENSED: Self = Self(0.5);
6565

@@ -88,16 +88,16 @@ impl Stretch {
8888
pub const ULTRA_EXPANDED: Self = Self(2.0);
8989
}
9090

91-
impl Stretch {
91+
impl FontStretch {
9292
/// Creates a new stretch attribute with the given ratio.
9393
///
9494
/// This can also be created [from a percentage](Self::from_percentage).
9595
///
9696
/// # Example
9797
///
9898
/// ```
99-
/// # use fontique::Stretch;
100-
/// assert_eq!(Stretch::from_ratio(1.5), Stretch::EXTRA_EXPANDED);
99+
/// # use fontique::FontStretch;
100+
/// assert_eq!(FontStretch::from_ratio(1.5), FontStretch::EXTRA_EXPANDED);
101101
/// ```
102102
pub fn from_ratio(ratio: f32) -> Self {
103103
Self(ratio)
@@ -110,8 +110,8 @@ impl Stretch {
110110
/// # Example
111111
///
112112
/// ```
113-
/// # use fontique::Stretch;
114-
/// assert_eq!(Stretch::from_percentage(87.5), Stretch::SEMI_CONDENSED);
113+
/// # use fontique::FontStretch;
114+
/// assert_eq!(FontStretch::from_percentage(87.5), FontStretch::SEMI_CONDENSED);
115115
/// ```
116116
pub fn from_percentage(percentage: f32) -> Self {
117117
Self(percentage / 100.0)
@@ -124,8 +124,8 @@ impl Stretch {
124124
/// # Example
125125
///
126126
/// ```
127-
/// # use fontique::Stretch;
128-
/// assert_eq!(Stretch::NORMAL.ratio(), 1.0);
127+
/// # use fontique::FontStretch;
128+
/// assert_eq!(FontStretch::NORMAL.ratio(), 1.0);
129129
/// ```
130130
pub fn ratio(self) -> f32 {
131131
self.0
@@ -140,21 +140,21 @@ impl Stretch {
140140

141141
/// Returns `true` if the stretch is [normal].
142142
///
143-
/// [normal]: Stretch::NORMAL
143+
/// [normal]: FontStretch::NORMAL
144144
pub fn is_normal(self) -> bool {
145145
self == Self::NORMAL
146146
}
147147

148148
/// Returns `true` if the stretch is condensed (less than [normal]).
149149
///
150-
/// [normal]: Stretch::NORMAL
150+
/// [normal]: FontStretch::NORMAL
151151
pub fn is_condensed(self) -> bool {
152152
self < Self::NORMAL
153153
}
154154

155155
/// Returns `true` if the stretch is expanded (greater than [normal]).
156156
///
157-
/// [normal]: Stretch::NORMAL
157+
/// [normal]: FontStretch::NORMAL
158158
pub fn is_expanded(self) -> bool {
159159
self > Self::NORMAL
160160
}
@@ -164,10 +164,10 @@ impl Stretch {
164164
/// # Examples
165165
///
166166
/// ```
167-
/// # use fontique::Stretch;
168-
/// assert_eq!(Stretch::parse("semi-condensed"), Some(Stretch::SEMI_CONDENSED));
169-
/// assert_eq!(Stretch::parse("80%"), Some(Stretch::from_percentage(80.0)));
170-
/// assert_eq!(Stretch::parse("wideload"), None);
167+
/// # use fontique::FontStretch;
168+
/// assert_eq!(FontStretch::parse("semi-condensed"), Some(FontStretch::SEMI_CONDENSED));
169+
/// assert_eq!(FontStretch::parse("80%"), Some(FontStretch::from_percentage(80.0)));
170+
/// assert_eq!(FontStretch::parse("wideload"), None);
171171
/// ```
172172
pub fn parse(s: &str) -> Option<Self> {
173173
let s = s.trim();
@@ -191,7 +191,7 @@ impl Stretch {
191191
}
192192
}
193193

194-
impl fmt::Display for Stretch {
194+
impl fmt::Display for FontStretch {
195195
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
196196
let value = self.0 * 1000.0;
197197
if value.fract() == 0.0 {
@@ -216,15 +216,15 @@ impl fmt::Display for Stretch {
216216
}
217217
}
218218

219-
impl Default for Stretch {
219+
impl Default for FontStretch {
220220
fn default() -> Self {
221221
Self::NORMAL
222222
}
223223
}
224224

225225
/// Visual weight class of a font, typically on a scale from 1.0 to 1000.0.
226226
///
227-
/// The default value is [`Weight::NORMAL`] or `400.0`.
227+
/// The default value is [`FontWeight::NORMAL`] or `400.0`.
228228
///
229229
/// In variable fonts, this can be controlled with the `wght` [axis].
230230
///
@@ -235,9 +235,9 @@ impl Default for Stretch {
235235
/// [axis]: crate::AxisInfo
236236
/// [`font-weight`]: https://www.w3.org/TR/css-fonts-4/#font-weight-prop
237237
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
238-
pub struct Weight(f32);
238+
pub struct FontWeight(f32);
239239

240-
impl Weight {
240+
impl FontWeight {
241241
/// Weight value of 100.
242242
pub const THIN: Self = Self(100.0);
243243

@@ -272,7 +272,7 @@ impl Weight {
272272
pub const EXTRA_BLACK: Self = Self(950.0);
273273
}
274274

275-
impl Weight {
275+
impl FontWeight {
276276
/// Creates a new weight attribute with the given value.
277277
pub fn new(weight: f32) -> Self {
278278
Self(weight)
@@ -288,11 +288,11 @@ impl Weight {
288288
/// # Examples
289289
///
290290
/// ```
291-
/// # use fontique::Weight;
292-
/// assert_eq!(Weight::parse("normal"), Some(Weight::NORMAL));
293-
/// assert_eq!(Weight::parse("bold"), Some(Weight::BOLD));
294-
/// assert_eq!(Weight::parse("850"), Some(Weight::new(850.0)));
295-
/// assert_eq!(Weight::parse("invalid"), None);
291+
/// # use fontique::FontWeight;
292+
/// assert_eq!(FontWeight::parse("normal"), Some(FontWeight::NORMAL));
293+
/// assert_eq!(FontWeight::parse("bold"), Some(FontWeight::BOLD));
294+
/// assert_eq!(FontWeight::parse("850"), Some(FontWeight::new(850.0)));
295+
/// assert_eq!(FontWeight::parse("invalid"), None);
296296
/// ```
297297
pub fn parse(s: &str) -> Option<Self> {
298298
let s = s.trim();
@@ -304,13 +304,13 @@ impl Weight {
304304
}
305305
}
306306

307-
impl Default for Weight {
307+
impl Default for FontWeight {
308308
fn default() -> Self {
309309
Self::NORMAL
310310
}
311311
}
312312

313-
impl fmt::Display for Weight {
313+
impl fmt::Display for FontWeight {
314314
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
315315
let value = self.0;
316316
if value.fract() == 0.0 {
@@ -335,7 +335,7 @@ impl fmt::Display for Weight {
335335

336336
/// Visual style or 'slope' of a font.
337337
///
338-
/// The default value is [`Style::Normal`].
338+
/// The default value is [`FontStyle::Normal`].
339339
///
340340
/// In variable fonts, this can be controlled with the `ital`
341341
/// and `slnt` [axes] for italic and oblique styles, respectively.
@@ -347,7 +347,7 @@ impl fmt::Display for Weight {
347347
/// [axes]: crate::AxisInfo
348348
/// [`font-style`]: https://www.w3.org/TR/css-fonts-4/#font-style-prop
349349
#[derive(Copy, Clone, PartialEq, Default, Debug)]
350-
pub enum Style {
350+
pub enum FontStyle {
351351
/// An upright or "roman" style.
352352
#[default]
353353
Normal,
@@ -359,7 +359,7 @@ pub enum Style {
359359
Oblique(Option<f32>),
360360
}
361361

362-
impl Style {
362+
impl FontStyle {
363363
/// Parses a font style from a CSS value.
364364
pub fn parse(mut s: &str) -> Option<Self> {
365365
s = s.trim();
@@ -399,7 +399,7 @@ impl Style {
399399
}
400400
}
401401

402-
impl fmt::Display for Style {
402+
impl fmt::Display for FontStyle {
403403
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
404404
let value = match self {
405405
Self::Normal => "normal",

‎fontique/src/backend/fontconfig/cache.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright 2024 the Parley Authors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
use super::{Stretch, Style, Weight};
4+
use super::{FontStretch, FontStyle, FontWeight};
55
use fontconfig_cache_parser::{Cache, CharSetLeaf, Object, Pattern, Value};
66
use std::io::Read;
77
use std::path::PathBuf;
88

9-
impl Stretch {
9+
impl FontStretch {
1010
/// Creates a new stretch attribute with the given value from Fontconfig.
1111
///
1212
/// The values are determined based on the [fonts.conf documentation].
@@ -28,7 +28,7 @@ impl Stretch {
2828
}
2929
}
3030

31-
impl Style {
31+
impl FontStyle {
3232
/// Creates a new style attribute with the given value from Fontconfig.
3333
///
3434
/// The values are determined based on the [fonts.conf documentation].
@@ -43,7 +43,7 @@ impl Style {
4343
}
4444
}
4545

46-
impl Weight {
46+
impl FontWeight {
4747
/// Creates a new weight attribute with the given value from Fontconfig.
4848
///
4949
/// The values are determined based on the [fonts.conf documentation].
@@ -79,7 +79,7 @@ impl Weight {
7979
return Self::new(ot_a + (ot_b - ot_a) * t);
8080
}
8181
}
82-
Weight::EXTRA_BLACK
82+
Self::EXTRA_BLACK
8383
}
8484
}
8585

@@ -88,9 +88,9 @@ pub struct CachedFont {
8888
pub family: Vec<String>,
8989
pub path: PathBuf,
9090
pub index: u32,
91-
pub stretch: Stretch,
92-
pub style: Style,
93-
pub weight: Weight,
91+
pub stretch: FontStretch,
92+
pub style: FontStyle,
93+
pub weight: FontWeight,
9494
pub coverage: Coverage,
9595
}
9696

@@ -100,9 +100,9 @@ impl CachedFont {
100100
self.path.clear();
101101
self.index = 0;
102102
self.coverage.clear();
103-
self.weight = Weight::default();
104-
self.style = Style::default();
105-
self.stretch = Stretch::default();
103+
self.weight = FontWeight::default();
104+
self.style = FontStyle::default();
105+
self.stretch = FontStretch::default();
106106
}
107107
}
108108

@@ -177,21 +177,21 @@ fn parse_font(
177177
Object::Slant => {
178178
for val in elt.values().ok()? {
179179
if let Value::Int(i) = val.ok()? {
180-
font.style = Style::from_fc(i as _);
180+
font.style = FontStyle::from_fc(i as _);
181181
}
182182
}
183183
}
184184
Object::Weight => {
185185
for val in elt.values().ok()? {
186186
if let Value::Int(i) = val.ok()? {
187-
font.weight = Weight::from_fc(i as _);
187+
font.weight = FontWeight::from_fc(i as _);
188188
}
189189
}
190190
}
191191
Object::Width => {
192192
for val in elt.values().ok()? {
193193
if let Value::Int(i) = val.ok()? {
194-
font.stretch = Stretch::from_fc(i as _);
194+
font.stretch = FontStretch::from_fc(i as _);
195195
}
196196
}
197197
}

‎fontique/src/backend/fontconfig/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
66
use std::sync::Arc;
77

88
use super::{
9-
super::{Stretch, Style, Weight},
9+
super::{FontStretch, FontStyle, FontWeight},
1010
FallbackKey, FamilyId, FamilyInfo, FamilyName, FamilyNameMap, FontInfo, GenericFamily,
1111
GenericFamilyMap, Script, SourceInfo, SourcePathMap,
1212
};
@@ -301,9 +301,9 @@ struct RawFamily {
301301
struct RawFont {
302302
source: SourceInfo,
303303
index: u32,
304-
stretch: Stretch,
305-
style: Style,
306-
weight: Weight,
304+
stretch: FontStretch,
305+
style: FontStyle,
306+
weight: FontWeight,
307307
coverage: cache::Coverage,
308308
}
309309

‎fontique/src/family.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Model for font families.
55
66
use super::{
7-
attributes::{Stretch, Style, Weight},
7+
attributes::{FontStretch, FontStyle, FontWeight},
88
family_name::FamilyName,
99
font::FontInfo,
1010
};
@@ -84,9 +84,9 @@ impl FamilyInfo {
8484
/// Returns the index of the best font from the family for the given attributes.
8585
pub fn match_index(
8686
&self,
87-
stretch: Stretch,
88-
style: Style,
89-
weight: Weight,
87+
stretch: FontStretch,
88+
style: FontStyle,
89+
weight: FontWeight,
9090
synthesize_style: bool,
9191
) -> Option<usize> {
9292
super::matching::match_font(self.fonts(), stretch, style, weight, synthesize_style)
@@ -95,9 +95,9 @@ impl FamilyInfo {
9595
/// Selects the best font from the family for the given attributes.
9696
pub fn match_font(
9797
&self,
98-
stretch: Stretch,
99-
style: Style,
100-
weight: Weight,
98+
stretch: FontStretch,
99+
style: FontStyle,
100+
weight: FontWeight,
101101
synthesize_style: bool,
102102
) -> Option<&FontInfo> {
103103
self.fonts()

‎fontique/src/font.rs

+42-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! Model for a font.
55
6-
use super::attributes::{Stretch, Style, Weight};
6+
use super::attributes::{FontStretch, FontStyle, FontWeight};
77
use super::source::{SourceInfo, SourceKind};
88
use super::{source_cache::SourceCache, Blob};
99
use read_fonts::{types::Tag, FontRef, TableProvider as _};
@@ -16,9 +16,9 @@ type AxisVec = SmallVec<[AxisInfo; 1]>;
1616
pub struct FontInfo {
1717
source: SourceInfo,
1818
index: u32,
19-
stretch: Stretch,
20-
style: Style,
21-
weight: Weight,
19+
stretch: FontStretch,
20+
style: FontStyle,
21+
weight: FontWeight,
2222
axes: AxisVec,
2323
attr_axes: u8,
2424
}
@@ -67,23 +67,28 @@ impl FontInfo {
6767

6868
/// Returns the visual width of the font-- a relative change from the normal
6969
/// aspect ratio, typically in the range `0.5` to `2.0`.
70-
pub fn stretch(&self) -> Stretch {
70+
pub fn stretch(&self) -> FontStretch {
7171
self.stretch
7272
}
7373

7474
/// Returns the visual style or 'slope' of the font.
75-
pub fn style(&self) -> Style {
75+
pub fn style(&self) -> FontStyle {
7676
self.style
7777
}
7878

7979
/// Returns the visual weight class of the font, typically on a scale
8080
/// from `1.0` to `1000.0`.
81-
pub fn weight(&self) -> Weight {
81+
pub fn weight(&self) -> FontWeight {
8282
self.weight
8383
}
8484

8585
/// Returns synthesis suggestions for this font with the given attributes.
86-
pub fn synthesis(&self, stretch: Stretch, style: Style, weight: Weight) -> Synthesis {
86+
pub fn synthesis(
87+
&self,
88+
stretch: FontStretch,
89+
style: FontStyle,
90+
weight: FontWeight,
91+
) -> Synthesis {
8792
let mut synth = Synthesis::default();
8893
let mut len = 0usize;
8994
if self.has_width_axis() && self.stretch != stretch {
@@ -100,9 +105,9 @@ impl FontInfo {
100105
}
101106
if self.style != style {
102107
match style {
103-
Style::Normal => {}
104-
Style::Italic => {
105-
if self.style == Style::Normal {
108+
FontStyle::Normal => {}
109+
FontStyle::Italic => {
110+
if self.style == FontStyle::Normal {
106111
if self.has_italic_axis() {
107112
synth.vars[len] = (Tag::new(b"ital"), 1.0);
108113
len += 1;
@@ -114,8 +119,8 @@ impl FontInfo {
114119
}
115120
}
116121
}
117-
Style::Oblique(angle) => {
118-
if self.style == Style::Normal {
122+
FontStyle::Oblique(angle) => {
123+
if self.style == FontStyle::Normal {
119124
let degrees = angle.unwrap_or(14.0);
120125
if self.has_slant_axis() {
121126
synth.vars[len] = (Tag::new(b"slnt"), degrees);
@@ -233,17 +238,17 @@ impl FontInfo {
233238
#[allow(unused)]
234239
pub(crate) fn maybe_override_attributes(
235240
&mut self,
236-
stretch: Stretch,
237-
style: Style,
238-
weight: Weight,
241+
stretch: FontStretch,
242+
style: FontStyle,
243+
weight: FontWeight,
239244
) {
240-
if self.stretch == Stretch::default() {
245+
if self.stretch == FontStretch::default() {
241246
self.stretch = stretch;
242247
}
243-
if self.style == Style::default() {
248+
if self.style == FontStyle::default() {
244249
self.style = style;
245250
}
246-
if self.weight == Weight::default() {
251+
if self.weight == FontWeight::default() {
247252
self.weight = weight;
248253
}
249254
}
@@ -268,7 +273,7 @@ const OPTICAL_SIZE_AXIS: u8 = 0x10;
268273
/// * [Italic](https://fonts.google.com/knowledge/glossary/italic_axis) or `ital`
269274
/// * [Optical Size](https://fonts.google.com/knowledge/glossary/optical_size_axis) or `opsz`
270275
/// * [Slant](https://fonts.google.com/knowledge/glossary/slant_axis) or `slnt`
271-
/// * [Weight](https://fonts.google.com/knowledge/glossary/weight_axis) or `wght`
276+
/// * [FontWeight](https://fonts.google.com/knowledge/glossary/weight_axis) or `wght`
272277
/// * [Width](https://fonts.google.com/knowledge/glossary/width_axis) or `wdth`
273278
///
274279
/// For a broader explanation of this, see
@@ -331,7 +336,7 @@ impl Synthesis {
331336
}
332337
}
333338

334-
fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) {
339+
fn read_attributes(font: &FontRef) -> (FontStretch, FontStyle, FontWeight) {
335340
use read_fonts::{
336341
tables::{
337342
head::{Head, MacStyle},
@@ -341,8 +346,8 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) {
341346
TableProvider,
342347
};
343348

344-
fn stretch_from_width_class(width_class: u16) -> Stretch {
345-
Stretch::from_ratio(match width_class {
349+
fn stretch_from_width_class(width_class: u16) -> FontStretch {
350+
FontStretch::from_ratio(match width_class {
346351
0..=1 => 0.5,
347352
2 => 0.625,
348353
3 => 0.75,
@@ -355,39 +360,39 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) {
355360
})
356361
}
357362

358-
fn from_os2_post(os2: Os2, post: Option<Post>) -> (Stretch, Style, Weight) {
363+
fn from_os2_post(os2: Os2, post: Option<Post>) -> (FontStretch, FontStyle, FontWeight) {
359364
let stretch = stretch_from_width_class(os2.us_width_class());
360365
// Bits 1 and 9 of the fsSelection field signify italic and
361366
// oblique, respectively.
362367
// See: <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fsselection>
363368
let fs_selection = os2.fs_selection();
364369
let style = if fs_selection.contains(SelectionFlags::ITALIC) {
365-
Style::Italic
370+
FontStyle::Italic
366371
} else if fs_selection.contains(SelectionFlags::OBLIQUE) {
367372
let angle = post.map(|post| post.italic_angle().to_f64() as f32);
368-
Style::Oblique(angle)
373+
FontStyle::Oblique(angle)
369374
} else {
370-
Style::Normal
375+
FontStyle::Normal
371376
};
372-
// The usWeightClass field is specified with a 1-1000 range, but
377+
// The usFontWeightClass field is specified with a 1-1000 range, but
373378
// we don't clamp here because variable fonts could potentially
374379
// have a value outside of that range.
375380
// See <https://learn.microsoft.com/en-us/typography/opentype/spec/os2#usweightclass>
376-
let weight = Weight::new(os2.us_weight_class() as f32);
381+
let weight = FontWeight::new(os2.us_weight_class() as f32);
377382
(stretch, style, weight)
378383
}
379384

380-
fn from_head(head: Head) -> (Stretch, Style, Weight) {
385+
fn from_head(head: Head) -> (FontStretch, FontStyle, FontWeight) {
381386
let mac_style = head.mac_style();
382387
let style = mac_style
383388
.contains(MacStyle::ITALIC)
384-
.then_some(Style::Italic)
389+
.then_some(FontStyle::Italic)
385390
.unwrap_or_default();
386391
let weight = mac_style
387392
.contains(MacStyle::BOLD)
388393
.then_some(700.0)
389394
.unwrap_or_default();
390-
(Stretch::default(), style, Weight::new(weight))
395+
(FontStretch::default(), style, FontWeight::new(weight))
391396
}
392397

393398
if let Ok(os2) = font.os2() {
@@ -398,6 +403,10 @@ fn read_attributes(font: &FontRef) -> (Stretch, Style, Weight) {
398403
// Otherwise, fall back to the macStyle field of the head table.
399404
from_head(head)
400405
} else {
401-
(Stretch::default(), Style::Normal, Weight::default())
406+
(
407+
FontStretch::default(),
408+
FontStyle::Normal,
409+
FontWeight::default(),
410+
)
402411
}
403412
}

‎fontique/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod source_cache;
4949
pub use icu_locid::LanguageIdentifier as Language;
5050
pub use peniko::Blob;
5151

52-
pub use attributes::{Attributes, Stretch, Style, Weight};
52+
pub use attributes::{Attributes, FontStretch, FontStyle, FontWeight};
5353
pub use collection::{Collection, CollectionOptions, Query, QueryFamily, QueryFont, QueryStatus};
5454
pub use fallback::FallbackKey;
5555
pub use family::{FamilyId, FamilyInfo};

‎fontique/src/matching.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
//! Implementation of the CSS font matching algorithm.
55
6-
use super::attributes::{Stretch, Style, Weight};
6+
use super::attributes::{FontStretch, FontStyle, FontWeight};
77
use super::font::FontInfo;
88
use smallvec::SmallVec;
99

1010
const DEFAULT_OBLIQUE_ANGLE: f32 = 14.0;
1111

1212
pub fn match_font(
1313
set: &[FontInfo],
14-
stretch: Stretch,
15-
style: Style,
16-
weight: Weight,
14+
stretch: FontStretch,
15+
style: FontStyle,
16+
weight: FontWeight,
1717
synthesize_style: bool,
1818
) -> Option<usize> {
1919
const OBLIQUE_THRESHOLD: f32 = DEFAULT_OBLIQUE_ANGLE;
@@ -26,7 +26,7 @@ pub fn match_font(
2626
struct Candidate {
2727
index: usize,
2828
stretch: i32,
29-
style: Style,
29+
style: FontStyle,
3030
weight: f32,
3131
has_slnt: bool,
3232
}
@@ -102,7 +102,7 @@ pub fn match_font(
102102
let mut _use_slnt = false;
103103
if !set.iter().any(|f| f.style == use_style) {
104104
// If the value of font-style is italic:
105-
if style == Style::Italic {
105+
if style == FontStyle::Italic {
106106
// oblique values greater than or equal to 14deg are checked in
107107
// ascending order
108108
if let Some(found) = oblique_fonts
@@ -162,16 +162,16 @@ pub fn match_font(
162162
if set.iter().any(|f| f.has_slnt) {
163163
_use_slnt = true;
164164
} else {
165-
use_style = if set.iter().any(|f| f.style == Style::Normal) {
166-
Style::Normal
165+
use_style = if set.iter().any(|f| f.style == FontStyle::Normal) {
166+
FontStyle::Normal
167167
} else {
168168
set[0].style
169169
};
170170
}
171171
} else {
172172
// Choose an italic style
173-
if set.iter().any(|f| f.style == Style::Italic) {
174-
use_style = Style::Italic;
173+
if set.iter().any(|f| f.style == FontStyle::Italic) {
174+
use_style = FontStyle::Italic;
175175
}
176176
// oblique values less than or equal to 0deg are checked in descending order
177177
else if let Some(found) = oblique_fonts
@@ -215,16 +215,16 @@ pub fn match_font(
215215
if set.iter().any(|f| f.has_slnt) {
216216
_use_slnt = true;
217217
} else {
218-
use_style = if set.iter().any(|f| f.style == Style::Normal) {
219-
Style::Normal
218+
use_style = if set.iter().any(|f| f.style == FontStyle::Normal) {
219+
FontStyle::Normal
220220
} else {
221221
set[0].style
222222
};
223223
}
224224
} else {
225225
// Choose an italic style
226-
if set.iter().any(|f| f.style == Style::Italic) {
227-
use_style = Style::Italic;
226+
if set.iter().any(|f| f.style == FontStyle::Italic) {
227+
use_style = FontStyle::Italic;
228228
}
229229
// oblique values less than or equal to 0deg are checked in descending order
230230
else if let Some(found) = oblique_fonts
@@ -267,16 +267,16 @@ pub fn match_font(
267267
if set.iter().any(|f| f.has_slnt) {
268268
_use_slnt = true;
269269
} else {
270-
use_style = if set.iter().any(|f| f.style == Style::Normal) {
271-
Style::Normal
270+
use_style = if set.iter().any(|f| f.style == FontStyle::Normal) {
271+
FontStyle::Normal
272272
} else {
273273
set[0].style
274274
};
275275
}
276276
} else {
277277
// Choose an italic style
278-
if set.iter().any(|f| f.style == Style::Italic) {
279-
use_style = Style::Italic;
278+
if set.iter().any(|f| f.style == FontStyle::Italic) {
279+
use_style = FontStyle::Italic;
280280
}
281281
// oblique values greater than or equal to 0deg are checked in ascending order
282282
else if let Some(found) = oblique_fonts
@@ -319,16 +319,16 @@ pub fn match_font(
319319
if set.iter().any(|f| f.has_slnt) {
320320
_use_slnt = true;
321321
} else {
322-
use_style = if set.iter().any(|f| f.style == Style::Normal) {
323-
Style::Normal
322+
use_style = if set.iter().any(|f| f.style == FontStyle::Normal) {
323+
FontStyle::Normal
324324
} else {
325325
set[0].style
326326
};
327327
}
328328
} else {
329329
// Choose an italic style
330-
if set.iter().any(|f| f.style == Style::Italic) {
331-
use_style = Style::Italic;
330+
if set.iter().any(|f| f.style == FontStyle::Italic) {
331+
use_style = FontStyle::Italic;
332332
}
333333
// oblique values greater than or equal to 0deg are checked in ascending order
334334
else if let Some(found) = oblique_fonts
@@ -356,7 +356,7 @@ pub fn match_font(
356356
use_style = found.0;
357357
}
358358
// followed by italic fonts
359-
else if let Some(found) = set.iter().find(|f| f.style == Style::Italic) {
359+
else if let Some(found) = set.iter().find(|f| f.style == FontStyle::Italic) {
360360
use_style = found.style;
361361
}
362362
// followed by oblique values less than 0deg in descending order
@@ -449,16 +449,16 @@ pub fn match_font(
449449
None
450450
}
451451

452-
fn oblique_angle(style: Style) -> Option<f32> {
452+
fn oblique_angle(style: FontStyle) -> Option<f32> {
453453
match style {
454-
Style::Oblique(angle) => Some(angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE)),
454+
FontStyle::Oblique(angle) => Some(angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE)),
455455
_ => None,
456456
}
457457
}
458458

459-
fn oblique_style(style: Style) -> Option<(Style, f32)> {
459+
fn oblique_style(style: FontStyle) -> Option<(FontStyle, f32)> {
460460
match style {
461-
Style::Oblique(angle) => Some((style, angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE))),
461+
FontStyle::Oblique(angle) => Some((style, angle.unwrap_or(DEFAULT_OBLIQUE_ANGLE))),
462462
_ => None,
463463
}
464464
}

‎parley/src/style/font.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use alloc::borrow::Cow;
55
use alloc::borrow::ToOwned;
66
use core::fmt;
77

8-
pub use fontique::{
9-
GenericFamily, Stretch as FontStretch, Style as FontStyle, Weight as FontWeight,
10-
};
8+
pub use fontique::{FontStretch, FontStyle, FontWeight, GenericFamily};
119

1210
/// Setting for a font variation.
1311
pub type FontVariation = swash::Setting<f32>;

0 commit comments

Comments
 (0)
Please sign in to comment.