@@ -10,21 +10,31 @@ pub struct FontFallbacks {
1010pub type FontData = ( & ' static str , Vec < u8 > ) ;
1111
1212impl FontFallbacks {
13+ #[ cfg( not( target_os = "macos" ) ) ]
1314 pub const MONO : & ' static str = "Consolas" ;
14- pub const NORMAL_FAST : & ' static str = "Segoe UI" ;
1515
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" ,
1822 // CJK
1923 "Microsoft YaHei UI" , "Microsoft JhengHei UI" , "Yu Gothic UI" , "Malgun Gothic" ,
2024 // some special characters.
2125 "Segoe UI Emoji" , "Segoe UI Symbol" , "Segoe UI Historic" ,
2226 ] ;
2327
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+
2435 #[ inline]
2536 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)
2838 }
2939
3040 #[ inline]
@@ -51,20 +61,22 @@ impl FontFallbacks {
5161 self . load_font ( db, FontFallbacks :: MONO )
5262 }
5363
54- pub fn load_fast ( & self , db : & fontdb:: Database ) -> Option < FontData > {
55- self . load_font ( db, FontFallbacks :: NORMAL_FAST )
56- }
57-
5864 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| {
6066 match self . load_font ( db, name) {
6167 None => {
6268 warn ! ( "Failed to find system font family: {}" , name) ;
6369 None
6470 }
6571 Some ( data) => Some ( data)
6672 }
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
6880 }
6981
7082 #[ inline]
@@ -73,4 +85,9 @@ impl FontFallbacks {
7385 let font_data = db. with_face_data ( * id, |font_data, _| font_data. to_vec ( ) ) ?;
7486 Some ( ( name, font_data) )
7587 }
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+ }
7693}
0 commit comments