@@ -9,22 +9,22 @@ use core_maths::CoreFloat;
9
9
10
10
use core:: fmt;
11
11
12
- /// Primary attributes for font matching: [`Stretch `], [`Style `] and [`Weight `].
12
+ /// Primary attributes for font matching: [`FontStretch `], [`FontStyle `] and [`FontWeight `].
13
13
///
14
14
/// These are used to [configure] a [`Query`].
15
15
///
16
16
/// [configure]: crate::Query::set_attributes
17
17
/// [`Query`]: crate::Query
18
18
#[ derive( Copy , Clone , PartialEq , Default , Debug ) ]
19
19
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 ,
23
23
}
24
24
25
25
impl Attributes {
26
26
/// 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 {
28
28
Self {
29
29
stretch,
30
30
style,
@@ -46,7 +46,7 @@ impl fmt::Display for Attributes {
46
46
/// Visual width of a font-- a relative change from the normal aspect
47
47
/// ratio, typically in the range `0.5` to `2.0`.
48
48
///
49
- /// The default value is [`Stretch ::NORMAL`] or `1.0`.
49
+ /// The default value is [`FontStretch ::NORMAL`] or `1.0`.
50
50
///
51
51
/// In variable fonts, this can be controlled with the `wdth` [axis].
52
52
///
@@ -57,9 +57,9 @@ impl fmt::Display for Attributes {
57
57
/// [axis]: crate::AxisInfo
58
58
/// [`font-width`]: https://www.w3.org/TR/css-fonts-4/#font-width-prop
59
59
#[ derive( Copy , Clone , PartialEq , PartialOrd , Debug ) ]
60
- pub struct Stretch ( f32 ) ;
60
+ pub struct FontStretch ( f32 ) ;
61
61
62
- impl Stretch {
62
+ impl FontStretch {
63
63
/// Width that is 50% of normal.
64
64
pub const ULTRA_CONDENSED : Self = Self ( 0.5 ) ;
65
65
@@ -88,16 +88,16 @@ impl Stretch {
88
88
pub const ULTRA_EXPANDED : Self = Self ( 2.0 ) ;
89
89
}
90
90
91
- impl Stretch {
91
+ impl FontStretch {
92
92
/// Creates a new stretch attribute with the given ratio.
93
93
///
94
94
/// This can also be created [from a percentage](Self::from_percentage).
95
95
///
96
96
/// # Example
97
97
///
98
98
/// ```
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);
101
101
/// ```
102
102
pub fn from_ratio ( ratio : f32 ) -> Self {
103
103
Self ( ratio)
@@ -110,8 +110,8 @@ impl Stretch {
110
110
/// # Example
111
111
///
112
112
/// ```
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);
115
115
/// ```
116
116
pub fn from_percentage ( percentage : f32 ) -> Self {
117
117
Self ( percentage / 100.0 )
@@ -124,8 +124,8 @@ impl Stretch {
124
124
/// # Example
125
125
///
126
126
/// ```
127
- /// # use fontique::Stretch ;
128
- /// assert_eq!(Stretch ::NORMAL.ratio(), 1.0);
127
+ /// # use fontique::FontStretch ;
128
+ /// assert_eq!(FontStretch ::NORMAL.ratio(), 1.0);
129
129
/// ```
130
130
pub fn ratio ( self ) -> f32 {
131
131
self . 0
@@ -140,21 +140,21 @@ impl Stretch {
140
140
141
141
/// Returns `true` if the stretch is [normal].
142
142
///
143
- /// [normal]: Stretch ::NORMAL
143
+ /// [normal]: FontStretch ::NORMAL
144
144
pub fn is_normal ( self ) -> bool {
145
145
self == Self :: NORMAL
146
146
}
147
147
148
148
/// Returns `true` if the stretch is condensed (less than [normal]).
149
149
///
150
- /// [normal]: Stretch ::NORMAL
150
+ /// [normal]: FontStretch ::NORMAL
151
151
pub fn is_condensed ( self ) -> bool {
152
152
self < Self :: NORMAL
153
153
}
154
154
155
155
/// Returns `true` if the stretch is expanded (greater than [normal]).
156
156
///
157
- /// [normal]: Stretch ::NORMAL
157
+ /// [normal]: FontStretch ::NORMAL
158
158
pub fn is_expanded ( self ) -> bool {
159
159
self > Self :: NORMAL
160
160
}
@@ -164,10 +164,10 @@ impl Stretch {
164
164
/// # Examples
165
165
///
166
166
/// ```
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);
171
171
/// ```
172
172
pub fn parse ( s : & str ) -> Option < Self > {
173
173
let s = s. trim ( ) ;
@@ -191,7 +191,7 @@ impl Stretch {
191
191
}
192
192
}
193
193
194
- impl fmt:: Display for Stretch {
194
+ impl fmt:: Display for FontStretch {
195
195
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
196
196
let value = self . 0 * 1000.0 ;
197
197
if value. fract ( ) == 0.0 {
@@ -216,15 +216,15 @@ impl fmt::Display for Stretch {
216
216
}
217
217
}
218
218
219
- impl Default for Stretch {
219
+ impl Default for FontStretch {
220
220
fn default ( ) -> Self {
221
221
Self :: NORMAL
222
222
}
223
223
}
224
224
225
225
/// Visual weight class of a font, typically on a scale from 1.0 to 1000.0.
226
226
///
227
- /// The default value is [`Weight ::NORMAL`] or `400.0`.
227
+ /// The default value is [`FontWeight ::NORMAL`] or `400.0`.
228
228
///
229
229
/// In variable fonts, this can be controlled with the `wght` [axis].
230
230
///
@@ -235,9 +235,9 @@ impl Default for Stretch {
235
235
/// [axis]: crate::AxisInfo
236
236
/// [`font-weight`]: https://www.w3.org/TR/css-fonts-4/#font-weight-prop
237
237
#[ derive( Copy , Clone , PartialEq , PartialOrd , Debug ) ]
238
- pub struct Weight ( f32 ) ;
238
+ pub struct FontWeight ( f32 ) ;
239
239
240
- impl Weight {
240
+ impl FontWeight {
241
241
/// Weight value of 100.
242
242
pub const THIN : Self = Self ( 100.0 ) ;
243
243
@@ -272,7 +272,7 @@ impl Weight {
272
272
pub const EXTRA_BLACK : Self = Self ( 950.0 ) ;
273
273
}
274
274
275
- impl Weight {
275
+ impl FontWeight {
276
276
/// Creates a new weight attribute with the given value.
277
277
pub fn new ( weight : f32 ) -> Self {
278
278
Self ( weight)
@@ -288,11 +288,11 @@ impl Weight {
288
288
/// # Examples
289
289
///
290
290
/// ```
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);
296
296
/// ```
297
297
pub fn parse ( s : & str ) -> Option < Self > {
298
298
let s = s. trim ( ) ;
@@ -304,13 +304,13 @@ impl Weight {
304
304
}
305
305
}
306
306
307
- impl Default for Weight {
307
+ impl Default for FontWeight {
308
308
fn default ( ) -> Self {
309
309
Self :: NORMAL
310
310
}
311
311
}
312
312
313
- impl fmt:: Display for Weight {
313
+ impl fmt:: Display for FontWeight {
314
314
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
315
315
let value = self . 0 ;
316
316
if value. fract ( ) == 0.0 {
@@ -335,7 +335,7 @@ impl fmt::Display for Weight {
335
335
336
336
/// Visual style or 'slope' of a font.
337
337
///
338
- /// The default value is [`Style ::Normal`].
338
+ /// The default value is [`FontStyle ::Normal`].
339
339
///
340
340
/// In variable fonts, this can be controlled with the `ital`
341
341
/// and `slnt` [axes] for italic and oblique styles, respectively.
@@ -347,7 +347,7 @@ impl fmt::Display for Weight {
347
347
/// [axes]: crate::AxisInfo
348
348
/// [`font-style`]: https://www.w3.org/TR/css-fonts-4/#font-style-prop
349
349
#[ derive( Copy , Clone , PartialEq , Default , Debug ) ]
350
- pub enum Style {
350
+ pub enum FontStyle {
351
351
/// An upright or "roman" style.
352
352
#[ default]
353
353
Normal ,
@@ -359,7 +359,7 @@ pub enum Style {
359
359
Oblique ( Option < f32 > ) ,
360
360
}
361
361
362
- impl Style {
362
+ impl FontStyle {
363
363
/// Parses a font style from a CSS value.
364
364
pub fn parse ( mut s : & str ) -> Option < Self > {
365
365
s = s. trim ( ) ;
@@ -399,7 +399,7 @@ impl Style {
399
399
}
400
400
}
401
401
402
- impl fmt:: Display for Style {
402
+ impl fmt:: Display for FontStyle {
403
403
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
404
404
let value = match self {
405
405
Self :: Normal => "normal" ,
0 commit comments