@@ -152,7 +152,8 @@ impl TextPipeline {
152
152
font_system,
153
153
& mut self . map_handle_to_font_id ,
154
154
fonts,
155
- ) ;
155
+ )
156
+ . ok_or ( TextError :: NoSuchFont ) ?;
156
157
157
158
// Save spans that aren't zero-sized.
158
159
if scale_factor <= 0.0 || text_font. font_size <= 0.0 {
@@ -508,11 +509,12 @@ pub fn load_font_to_fontdb(
508
509
font_system : & mut cosmic_text:: FontSystem ,
509
510
map_handle_to_font_id : & mut HashMap < AssetId < Font > , ( cosmic_text:: fontdb:: ID , Arc < str > ) > ,
510
511
fonts : & Assets < Font > ,
511
- ) -> FontFaceInfo {
512
+ ) -> Option < FontFaceInfo > {
512
513
let font_handle = text_font. font . clone ( ) ;
513
- let ( face_id, family_name) = map_handle_to_font_id
514
- . entry ( font_handle. id ( ) )
515
- . or_insert_with ( || {
514
+
515
+ let ( face_id, family_name) = match map_handle_to_font_id. get_mut ( & font_handle. id ( ) ) {
516
+ Some ( ( face_id, family_name) ) => ( face_id, family_name) ,
517
+ None => {
516
518
let font = fonts. get ( font_handle. id ( ) ) . expect (
517
519
"Tried getting a font that was not available, probably due to not being loaded yet" ,
518
520
) ;
@@ -545,26 +547,27 @@ pub fn load_font_to_fontdb(
545
547
style : * style,
546
548
} ;
547
549
548
- //todo: unwrapping here is fallible
549
- font_system. db ( ) . query ( & query) . unwrap ( )
550
+ font_system. db ( ) . query ( & query) ?
550
551
}
551
552
} ;
552
553
553
554
let face = font_system. db ( ) . face ( face_id) . unwrap ( ) ;
554
555
let family_name = Arc :: from ( face. families [ 0 ] . 0 . as_str ( ) ) ;
555
556
557
+ map_handle_to_font_id. insert ( font_handle. id ( ) , ( face_id, family_name) ) ;
558
+ let ( face_id, family_name) = map_handle_to_font_id. get_mut ( & font_handle. id ( ) ) . unwrap ( ) ;
556
559
( face_id, family_name)
560
+ }
561
+ } ;
557
562
558
- //let other_id = font_system.db().query(query)
559
- } ) ;
560
563
let face = font_system. db ( ) . face ( * face_id) . unwrap ( ) ;
561
564
562
- FontFaceInfo {
565
+ Some ( FontFaceInfo {
563
566
stretch : face. stretch ,
564
567
style : face. style ,
565
568
weight : face. weight ,
566
569
family_name : family_name. clone ( ) ,
567
- }
570
+ } )
568
571
}
569
572
570
573
/// Translates [`TextFont`] to [`Attrs`].
0 commit comments