@@ -16,13 +16,23 @@ impl FontFallbacks {
16
16
#[ cfg( target_os = "macos" ) ]
17
17
pub const MONO : & ' static str = "Menlo" ;
18
18
19
+ #[ cfg( not( target_os = "macos" ) ) ]
20
+ pub const FALLBACKS : & ' static [ & ' static str ] = & [
21
+ // some special characters.
22
+ "Segoe UI Emoji" , "Segoe UI Symbol" , "Segoe UI Historic" ,
23
+ ] ;
24
+
25
+ #[ cfg( target_os = "macos" ) ]
26
+ pub const FALLBACKS : & ' static [ & ' static str ] = & [
27
+ // some special characters.
28
+ "Apple Color Emoji" ,
29
+ ] ;
30
+
19
31
#[ cfg( not( target_os = "macos" ) ) ]
20
32
pub const NORMAL : & ' static [ & ' static str ] = & [
21
33
"Segoe UI" ,
22
34
// CJK
23
35
"Microsoft YaHei UI" , "Microsoft JhengHei UI" , "Yu Gothic UI" , "Malgun Gothic" ,
24
- // some special characters.
25
- "Segoe UI Emoji" , "Segoe UI Symbol" , "Segoe UI Historic" ,
26
36
] ;
27
37
28
38
#[ cfg( target_os = "macos" ) ]
@@ -62,6 +72,7 @@ impl FontFallbacks {
62
72
}
63
73
64
74
pub fn load_all ( & self , db : & fontdb:: Database ) -> Vec < FontData > {
75
+ // load normal
65
76
let mut fonts: Vec < FontData > = FontFallbacks :: NORMAL . iter ( ) . filter_map ( |name| {
66
77
match self . load_font ( db, name) {
67
78
None => {
@@ -71,11 +82,20 @@ impl FontFallbacks {
71
82
Some ( data) => Some ( data)
72
83
}
73
84
} ) . collect ( ) ;
85
+ // load customized
74
86
if cfg ! ( target_os = "macos" ) {
75
- if let Some ( emoji) = self . load_macos_emoji ( ) {
87
+ if let Some ( emoji) = load_macos_emoji ( ) {
76
88
fonts. push ( emoji) ;
77
89
}
78
90
}
91
+ // load fallback
92
+ for name in FontFallbacks :: FALLBACKS {
93
+ if let Some ( font) = self . load_font ( db, name) {
94
+ fonts. push ( font) ;
95
+ } else {
96
+ warn ! ( "Failed to find system font family as a fallback: {}" , name) ;
97
+ }
98
+ }
79
99
fonts
80
100
}
81
101
@@ -85,9 +105,8 @@ impl FontFallbacks {
85
105
let font_data = db. with_face_data ( * id, |font_data, _| font_data. to_vec ( ) ) ?;
86
106
Some ( ( name, font_data) )
87
107
}
88
-
89
- pub fn load_macos_emoji ( & self ) -> Option < FontData > {
90
- let bytes = include_bytes ! ( "../fonts/NotoEmoji-Regular.ttf" ) ;
91
- Some ( ( "NotoEmoji" , bytes. to_vec ( ) ) )
92
- }
108
+ }
109
+ fn load_macos_emoji ( ) -> Option < FontData > {
110
+ let bytes = include_bytes ! ( "../fonts/NotoEmoji-Regular.ttf" ) ;
111
+ Some ( ( "NotoEmoji" , bytes. to_vec ( ) ) )
93
112
}
0 commit comments