@@ -10,21 +10,31 @@ pub struct FontFallbacks {
10
10
pub type FontData = ( & ' static str , Vec < u8 > ) ;
11
11
12
12
impl FontFallbacks {
13
+ #[ cfg( not( target_os = "macos" ) ) ]
13
14
pub const MONO : & ' static str = "Consolas" ;
14
- pub const NORMAL_FAST : & ' static str = "Segoe UI" ;
15
15
16
- pub const NORMAL_ALL : & ' static [ & ' static str ] = & [
17
- FontFallbacks :: NORMAL_FAST ,
16
+ #[ cfg( target_os = "macos" ) ]
17
+ pub const MONO : & ' static str = "Menlo" ;
18
+
19
+ #[ cfg( not( target_os = "macos" ) ) ]
20
+ pub const NORMAL : & ' static [ & ' static str ] = & [
21
+ "Segoe UI" ,
18
22
// CJK
19
23
"Microsoft YaHei UI" , "Microsoft JhengHei UI" , "Yu Gothic UI" , "Malgun Gothic" ,
20
24
// some special characters.
21
25
"Segoe UI Emoji" , "Segoe UI Symbol" , "Segoe UI Historic" ,
22
26
] ;
23
27
28
+ #[ cfg( target_os = "macos" ) ]
29
+ pub const NORMAL : & ' static [ & ' static str ] = & [
30
+ "Arial" , ".SF NS" , "Menlo" , "Geneva" , "Arial Unicode MS" ,
31
+ // CJK
32
+ "PingFang SC" , "PingFang HK" , "PingFang TC" , "Apple SD Gothic Neo" , "Hiragino Sans" ,
33
+ ] ;
34
+
24
35
#[ inline]
25
36
fn needed_font ( family : & str ) -> bool {
26
- Self :: MONO == family ||
27
- Self :: NORMAL_ALL . iter ( ) . any ( |& name| name == family)
37
+ Self :: MONO == family || Self :: NORMAL . iter ( ) . any ( |& name| name == family)
28
38
}
29
39
30
40
#[ inline]
@@ -51,20 +61,22 @@ impl FontFallbacks {
51
61
self . load_font ( db, FontFallbacks :: MONO )
52
62
}
53
63
54
- pub fn load_fast ( & self , db : & fontdb:: Database ) -> Option < FontData > {
55
- self . load_font ( db, FontFallbacks :: NORMAL_FAST )
56
- }
57
-
58
64
pub fn load_all ( & self , db : & fontdb:: Database ) -> Vec < FontData > {
59
- FontFallbacks :: NORMAL_ALL . iter ( ) . filter_map ( |name| {
65
+ let mut fonts : Vec < FontData > = FontFallbacks :: NORMAL . iter ( ) . filter_map ( |name| {
60
66
match self . load_font ( db, name) {
61
67
None => {
62
68
warn ! ( "Failed to find system font family: {}" , name) ;
63
69
None
64
70
}
65
71
Some ( data) => Some ( data)
66
72
}
67
- } ) . collect ( )
73
+ } ) . collect ( ) ;
74
+ if cfg ! ( target_os = "macos" ) {
75
+ if let Some ( emoji) = self . load_macos_emoji ( ) {
76
+ fonts. push ( emoji) ;
77
+ }
78
+ }
79
+ fonts
68
80
}
69
81
70
82
#[ inline]
@@ -73,4 +85,9 @@ impl FontFallbacks {
73
85
let font_data = db. with_face_data ( * id, |font_data, _| font_data. to_vec ( ) ) ?;
74
86
Some ( ( name, font_data) )
75
87
}
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
+ }
76
93
}
0 commit comments