@@ -25,16 +25,20 @@ self_cell!(
25
25
}
26
26
) ;
27
27
28
+ struct FontMonospaceFallback {
29
+ monospace_em_width : Option < f32 > ,
30
+ scripts : Vec < [ u8 ; 4 ] > ,
31
+ unicode_codepoints : Vec < u32 > ,
32
+ }
33
+
28
34
/// A font
29
35
pub struct Font {
30
36
#[ cfg( feature = "swash" ) ]
31
37
swash : ( u32 , swash:: CacheKey ) ,
32
38
rustybuzz : OwnedFace ,
33
39
data : Arc < dyn AsRef < [ u8 ] > + Send + Sync > ,
34
40
id : fontdb:: ID ,
35
- monospace_em_width : Option < f32 > ,
36
- scripts : Vec < [ u8 ; 4 ] > ,
37
- unicode_codepoints : Vec < u32 > ,
41
+ monospace_fallback : Option < FontMonospaceFallback > ,
38
42
}
39
43
40
44
impl fmt:: Debug for Font {
@@ -51,15 +55,19 @@ impl Font {
51
55
}
52
56
53
57
pub fn monospace_em_width ( & self ) -> Option < f32 > {
54
- self . monospace_em_width
58
+ self . monospace_fallback
59
+ . as_ref ( )
60
+ . and_then ( |x| x. monospace_em_width )
55
61
}
56
62
57
63
pub fn scripts ( & self ) -> & [ [ u8 ; 4 ] ] {
58
- & self . scripts
64
+ self . monospace_fallback . as_ref ( ) . map_or ( & [ ] , |x| & x . scripts )
59
65
}
60
66
61
67
pub fn unicode_codepoints ( & self ) -> & [ u32 ] {
62
- & self . unicode_codepoints
68
+ self . monospace_fallback
69
+ . as_ref ( )
70
+ . map_or ( & [ ] , |x| & x. unicode_codepoints )
63
71
}
64
72
65
73
pub fn data ( & self ) -> & [ u8 ] {
@@ -85,7 +93,7 @@ impl Font {
85
93
pub fn new ( db : & fontdb:: Database , id : fontdb:: ID ) -> Option < Self > {
86
94
let info = db. face ( id) ?;
87
95
88
- let ( monospace_em_width , scripts , unicode_codepoints ) = {
96
+ let monospace_fallback = if cfg ! ( feature = "monospace_fallback" ) {
89
97
db. with_face_data ( id, |font_data, face_index| {
90
98
let face = ttf_parser:: Face :: parse ( font_data, face_index) . ok ( ) ?;
91
99
let monospace_em_width = info
@@ -128,9 +136,15 @@ impl Font {
128
136
129
137
unicode_codepoints. shrink_to_fit ( ) ;
130
138
131
- Some ( ( monospace_em_width, scripts, unicode_codepoints) )
139
+ Some ( FontMonospaceFallback {
140
+ monospace_em_width,
141
+ scripts,
142
+ unicode_codepoints,
143
+ } )
132
144
} ) ?
133
- } ?;
145
+ } else {
146
+ None
147
+ } ;
134
148
135
149
let data = match & info. source {
136
150
fontdb:: Source :: Binary ( data) => Arc :: clone ( data) ,
@@ -145,9 +159,7 @@ impl Font {
145
159
146
160
Some ( Self {
147
161
id : info. id ,
148
- monospace_em_width,
149
- scripts,
150
- unicode_codepoints,
162
+ monospace_fallback,
151
163
#[ cfg( feature = "swash" ) ]
152
164
swash : {
153
165
let swash = swash:: FontRef :: from_index ( ( * data) . as_ref ( ) , info. index as usize ) ?;
0 commit comments