@@ -6,83 +6,6 @@ use fontconfig_cache_parser::{Cache, CharSetLeaf, Object, Pattern, Value};
6
6
use std:: io:: Read ;
7
7
use std:: path:: PathBuf ;
8
8
9
- impl FontStretch {
10
- /// Creates a new stretch attribute with the given value from Fontconfig.
11
- ///
12
- /// The values are determined based on the [fonts.conf documentation].
13
- ///
14
- /// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
15
- pub fn from_fc ( width : i32 ) -> Self {
16
- match width {
17
- 50 => Self :: ULTRA_CONDENSED ,
18
- 63 => Self :: EXTRA_CONDENSED ,
19
- 75 => Self :: CONDENSED ,
20
- 87 => Self :: SEMI_CONDENSED ,
21
- 100 => Self :: NORMAL ,
22
- 113 => Self :: SEMI_EXPANDED ,
23
- 125 => Self :: EXPANDED ,
24
- 150 => Self :: EXTRA_EXPANDED ,
25
- 200 => Self :: ULTRA_EXPANDED ,
26
- _ => Self :: from_ratio ( width as f32 / 100.0 ) ,
27
- }
28
- }
29
- }
30
-
31
- impl FontStyle {
32
- /// Creates a new style attribute with the given value from Fontconfig.
33
- ///
34
- /// The values are determined based on the [fonts.conf documentation].
35
- ///
36
- /// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
37
- fn from_fc ( slant : i32 ) -> Self {
38
- match slant {
39
- 100 => Self :: Italic ,
40
- 110 => Self :: Oblique ( None ) ,
41
- _ => Self :: Normal ,
42
- }
43
- }
44
- }
45
-
46
- impl FontWeight {
47
- /// Creates a new weight attribute with the given value from Fontconfig.
48
- ///
49
- /// The values are determined based on the [fonts.conf documentation].
50
- ///
51
- /// [fonts.conf documentation]: https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
52
- fn from_fc ( weight : i32 ) -> Self {
53
- const MAP : & [ ( i32 , i32 ) ] = & [
54
- ( 0 , 0 ) ,
55
- ( 100 , 0 ) ,
56
- ( 200 , 40 ) ,
57
- ( 300 , 50 ) ,
58
- ( 350 , 55 ) ,
59
- ( 380 , 75 ) ,
60
- ( 400 , 80 ) ,
61
- ( 500 , 100 ) ,
62
- ( 600 , 180 ) ,
63
- ( 700 , 200 ) ,
64
- ( 800 , 205 ) ,
65
- ( 900 , 210 ) ,
66
- ( 950 , 215 ) ,
67
- ] ;
68
- for ( i, ( ot, fc) ) in MAP . iter ( ) . skip ( 1 ) . enumerate ( ) {
69
- if weight == * fc {
70
- return Self :: new ( * ot as f32 ) ;
71
- }
72
- if weight < * fc {
73
- let weight = weight as f32 ;
74
- let fc_a = MAP [ i - 1 ] . 1 as f32 ;
75
- let fc_b = * fc as f32 ;
76
- let ot_a = MAP [ i - 1 ] . 1 as f32 ;
77
- let ot_b = * ot as f32 ;
78
- let t = ( fc_a - fc_b) / ( weight - fc_a) ;
79
- return Self :: new ( ot_a + ( ot_b - ot_a) * t) ;
80
- }
81
- }
82
- Self :: EXTRA_BLACK
83
- }
84
- }
85
-
86
9
#[ derive( Default ) ]
87
10
pub struct CachedFont {
88
11
pub family : Vec < String > ,
@@ -177,21 +100,21 @@ fn parse_font(
177
100
Object :: Slant => {
178
101
for val in elt. values ( ) . ok ( ) ? {
179
102
if let Value :: Int ( i) = val. ok ( ) ? {
180
- font. style = FontStyle :: from_fc ( i as _ ) ;
103
+ font. style = FontStyle :: from_fontconfig ( i as _ ) ;
181
104
}
182
105
}
183
106
}
184
107
Object :: Weight => {
185
108
for val in elt. values ( ) . ok ( ) ? {
186
109
if let Value :: Int ( i) = val. ok ( ) ? {
187
- font. weight = FontWeight :: from_fc ( i as _ ) ;
110
+ font. weight = FontWeight :: from_fontconfig ( i as _ ) ;
188
111
}
189
112
}
190
113
}
191
114
Object :: Width => {
192
115
for val in elt. values ( ) . ok ( ) ? {
193
116
if let Value :: Int ( i) = val. ok ( ) ? {
194
- font. stretch = FontStretch :: from_fc ( i as _ ) ;
117
+ font. stretch = FontStretch :: from_fontconfig ( i as _ ) ;
195
118
}
196
119
}
197
120
}
0 commit comments