@@ -14,70 +14,70 @@ use usvg::fontdb::Database;
14
14
/// Loads fonts.
15
15
#[ cfg( not( target_arch = "wasm32" ) ) ]
16
16
pub fn load_fonts ( font_options : & JsFontOptions ) -> Database {
17
- // Create a new font database
18
- let mut fontdb = Database :: new ( ) ;
19
- let now = std:: time:: Instant :: now ( ) ;
17
+ // Create a new font database
18
+ let mut fontdb = Database :: new ( ) ;
19
+ let now = std:: time:: Instant :: now ( ) ;
20
20
21
- // 加载系统字体
22
- // https://github.com/RazrFalcon/fontdb/blob/052d74b9eb45f2c4f446846a53f33bd965e2662d/src/lib.rs#L261
23
- if font_options. load_system_fonts {
24
- fontdb. load_system_fonts ( ) ;
25
- }
21
+ // 加载系统字体
22
+ // https://github.com/RazrFalcon/fontdb/blob/052d74b9eb45f2c4f446846a53f33bd965e2662d/src/lib.rs#L261
23
+ if font_options. load_system_fonts {
24
+ fontdb. load_system_fonts ( ) ;
25
+ }
26
26
27
- // 加载指定路径的字体
28
- for path in & font_options. font_files {
29
- if let Err ( e) = fontdb. load_font_file ( path) {
30
- warn ! ( "Failed to load '{}' cause {}." , path, e) ;
27
+ // 加载指定路径的字体
28
+ for path in & font_options. font_files {
29
+ if let Err ( e) = fontdb. load_font_file ( path) {
30
+ warn ! ( "Failed to load '{}' cause {}." , path, e) ;
31
+ }
31
32
}
32
- }
33
33
34
- // Load font directories
35
- for path in & font_options. font_dirs {
36
- fontdb. load_fonts_dir ( path) ;
37
- }
34
+ // Load font directories
35
+ for path in & font_options. font_dirs {
36
+ fontdb. load_fonts_dir ( path) ;
37
+ }
38
38
39
- // Set generic font families
40
- // - `serif` - Times New Roman
41
- // - `sans-serif` - Arial
42
- // - `cursive` - Comic Sans MS
43
- // - `fantasy` - Impact (Papyrus on macOS)
44
- // - `monospace` - Courier New
45
- fontdb. set_serif_family ( & font_options. serif_family ) ;
46
- fontdb. set_sans_serif_family ( & font_options. sans_serif_family ) ;
47
- fontdb. set_cursive_family ( & font_options. cursive_family ) ;
48
- fontdb. set_fantasy_family ( & font_options. fantasy_family ) ;
49
- fontdb. set_monospace_family ( & font_options. monospace_family ) ;
50
- debug ! (
51
- "Loaded {} font faces in {}ms." ,
52
- fontdb. len( ) ,
53
- now. elapsed( ) . as_micros( ) as f64 / 1000.0
54
- ) ;
39
+ // Set generic font families
40
+ // - `serif` - Times New Roman
41
+ // - `sans-serif` - Arial
42
+ // - `cursive` - Comic Sans MS
43
+ // - `fantasy` - Impact (Papyrus on macOS)
44
+ // - `monospace` - Courier New
45
+ fontdb. set_serif_family ( & font_options. serif_family ) ;
46
+ fontdb. set_sans_serif_family ( & font_options. sans_serif_family ) ;
47
+ fontdb. set_cursive_family ( & font_options. cursive_family ) ;
48
+ fontdb. set_fantasy_family ( & font_options. fantasy_family ) ;
49
+ fontdb. set_monospace_family ( & font_options. monospace_family ) ;
50
+ debug ! (
51
+ "Loaded {} font faces in {}ms." ,
52
+ fontdb. len( ) ,
53
+ now. elapsed( ) . as_micros( ) as f64 / 1000.0
54
+ ) ;
55
55
56
- // 查找指定字体的路径
57
- let font_family: & str = & font_options. default_font_family ;
58
- let query = fontdb:: Query {
59
- families : & [ fontdb:: Family :: Name ( font_family) ] ,
60
- ..fontdb:: Query :: default ( )
61
- } ;
56
+ // 查找指定字体的路径
57
+ let font_family: & str = & font_options. default_font_family ;
58
+ let query = fontdb:: Query {
59
+ families : & [ fontdb:: Family :: Name ( font_family) ] ,
60
+ ..fontdb:: Query :: default ( )
61
+ } ;
62
62
63
- let now = std:: time:: Instant :: now ( ) ;
64
- // 当前使用的字体是否存在
65
- match fontdb. query ( & query) {
66
- Some ( id) => {
67
- let ( src, index) = fontdb. face_source ( id) . unwrap ( ) ;
68
- if let fontdb:: Source :: File ( ref path) = & src {
69
- debug ! (
70
- "Font '{}':{} found in {}ms." ,
71
- path. display( ) ,
72
- index,
73
- now. elapsed( ) . as_micros( ) as f64 / 1000.0
74
- ) ;
75
- }
76
- }
77
- None => {
78
- warn ! ( "Warning: The default font '{}' not found." , font_family) ;
63
+ let now = std:: time:: Instant :: now ( ) ;
64
+ // 当前使用的字体是否存在
65
+ match fontdb. query ( & query) {
66
+ Some ( id) => {
67
+ let ( src, index) = fontdb. face_source ( id) . unwrap ( ) ;
68
+ if let fontdb:: Source :: File ( ref path) = & src {
69
+ debug ! (
70
+ "Font '{}':{} found in {}ms." ,
71
+ path. display( ) ,
72
+ index,
73
+ now. elapsed( ) . as_micros( ) as f64 / 1000.0
74
+ ) ;
75
+ }
76
+ }
77
+ None => {
78
+ warn ! ( "Warning: The default font '{}' not found." , font_family) ;
79
+ }
79
80
}
80
- }
81
81
82
- fontdb
82
+ fontdb
83
83
}
0 commit comments