@@ -359,10 +359,8 @@ fn open_file(open: Option<&str>, path: &Path) -> StrResult<()> {
359
359
/// Execute a font listing command.
360
360
fn fonts ( command : FontsSettings ) -> StrResult < ( ) > {
361
361
let mut searcher = FontSearcher :: new ( ) ;
362
- searcher. search_system ( ) ;
363
- for path in & command. font_paths {
364
- searcher. search_dir ( path)
365
- }
362
+ searcher. search ( & command. font_paths ) ;
363
+
366
364
for ( name, infos) in searcher. book . families ( ) {
367
365
println ! ( "{name}" ) ;
368
366
if command. variants {
@@ -405,14 +403,7 @@ struct PathSlot {
405
403
impl SystemWorld {
406
404
fn new ( root : PathBuf , font_paths : & [ PathBuf ] ) -> Self {
407
405
let mut searcher = FontSearcher :: new ( ) ;
408
- searcher. search_system ( ) ;
409
-
410
- #[ cfg( feature = "embed-fonts" ) ]
411
- searcher. add_embedded ( ) ;
412
-
413
- for path in font_paths {
414
- searcher. search_dir ( path)
415
- }
406
+ searcher. search ( font_paths) ;
416
407
417
408
Self {
418
409
root,
@@ -624,10 +615,22 @@ impl FontSearcher {
624
615
Self { book : FontBook :: new ( ) , fonts : vec ! [ ] }
625
616
}
626
617
618
+ /// Search everything that is available.
619
+ fn search ( & mut self , font_paths : & [ PathBuf ] ) {
620
+ self . search_system ( ) ;
621
+
622
+ #[ cfg( feature = "embed-fonts" ) ]
623
+ self . search_embedded ( ) ;
624
+
625
+ for path in font_paths {
626
+ self . search_dir ( path)
627
+ }
628
+ }
629
+
627
630
/// Add fonts that are embedded in the binary.
628
631
#[ cfg( feature = "embed-fonts" ) ]
629
- fn add_embedded ( & mut self ) {
630
- let mut add = |bytes : & ' static [ u8 ] | {
632
+ fn search_embedded ( & mut self ) {
633
+ let mut search = |bytes : & ' static [ u8 ] | {
631
634
let buffer = Buffer :: from_static ( bytes) ;
632
635
for ( i, font) in Font :: iter ( buffer) . enumerate ( ) {
633
636
self . book . push ( font. info ( ) . clone ( ) ) ;
@@ -640,20 +643,20 @@ impl FontSearcher {
640
643
} ;
641
644
642
645
// Embed default fonts.
643
- add ( include_bytes ! ( "../../assets/fonts/LinLibertine_R.ttf" ) ) ;
644
- add ( include_bytes ! ( "../../assets/fonts/LinLibertine_RB.ttf" ) ) ;
645
- add ( include_bytes ! ( "../../assets/fonts/LinLibertine_RBI.ttf" ) ) ;
646
- add ( include_bytes ! ( "../../assets/fonts/LinLibertine_RI.ttf" ) ) ;
647
- add ( include_bytes ! ( "../../assets/fonts/NewCMMath-Book.otf" ) ) ;
648
- add ( include_bytes ! ( "../../assets/fonts/NewCMMath-Regular.otf" ) ) ;
649
- add ( include_bytes ! ( "../../assets/fonts/NewCM10-Regular.otf" ) ) ;
650
- add ( include_bytes ! ( "../../assets/fonts/NewCM10-Bold.otf" ) ) ;
651
- add ( include_bytes ! ( "../../assets/fonts/NewCM10-Italic.otf" ) ) ;
652
- add ( include_bytes ! ( "../../assets/fonts/NewCM10-BoldItalic.otf" ) ) ;
653
- add ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono.ttf" ) ) ;
654
- add ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-Bold.ttf" ) ) ;
655
- add ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-Oblique.ttf" ) ) ;
656
- add ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-BoldOblique.ttf" ) ) ;
646
+ search ( include_bytes ! ( "../../assets/fonts/LinLibertine_R.ttf" ) ) ;
647
+ search ( include_bytes ! ( "../../assets/fonts/LinLibertine_RB.ttf" ) ) ;
648
+ search ( include_bytes ! ( "../../assets/fonts/LinLibertine_RBI.ttf" ) ) ;
649
+ search ( include_bytes ! ( "../../assets/fonts/LinLibertine_RI.ttf" ) ) ;
650
+ search ( include_bytes ! ( "../../assets/fonts/NewCMMath-Book.otf" ) ) ;
651
+ search ( include_bytes ! ( "../../assets/fonts/NewCMMath-Regular.otf" ) ) ;
652
+ search ( include_bytes ! ( "../../assets/fonts/NewCM10-Regular.otf" ) ) ;
653
+ search ( include_bytes ! ( "../../assets/fonts/NewCM10-Bold.otf" ) ) ;
654
+ search ( include_bytes ! ( "../../assets/fonts/NewCM10-Italic.otf" ) ) ;
655
+ search ( include_bytes ! ( "../../assets/fonts/NewCM10-BoldItalic.otf" ) ) ;
656
+ search ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono.ttf" ) ) ;
657
+ search ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-Bold.ttf" ) ) ;
658
+ search ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-Oblique.ttf" ) ) ;
659
+ search ( include_bytes ! ( "../../assets/fonts/DejaVuSansMono-BoldOblique.ttf" ) ) ;
657
660
}
658
661
659
662
/// Search for fonts in the linux system font directories.
0 commit comments