@@ -372,28 +372,19 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
372372 }
373373 PortfolioMessage :: LoadFontCatalog => {
374374 if Editor :: environment ( ) . is_desktop ( ) && preferences. system_fonts {
375- let mut system_font_collection = Collection :: new ( CollectionOptions { shared : false , system_fonts : true } ) ;
375+ self . cached_data . system_font_collection . 0 = Collection :: new ( CollectionOptions { shared : false , system_fonts : true } ) ;
376376 // shove font metadata into cached data catalog
377- let system_font_family_names: Vec < String > = system_font_collection. family_names ( ) . map ( |n| n. to_owned ( ) ) . collect ( ) ;
377+ let system_font_family_names: Vec < String > = self . cached_data . system_font_collection . 0 . family_names ( ) . map ( |n| n. to_owned ( ) ) . collect ( ) ;
378378 let mut families_for_catalog = Vec :: new ( ) ;
379379 for name in system_font_family_names {
380- let family = system_font_collection. family_by_name ( & name) . unwrap ( ) ;
380+ let family = self . cached_data . system_font_collection . 0 . family_by_name ( & name) . unwrap ( ) ;
381381 let mut styles = Vec :: new ( ) ;
382382 for font in family. fonts ( ) {
383383 let style = FontCatalogStyle {
384384 weight : ( font. weight ( ) . value ( ) ) as u32 ,
385385 italic : font. style ( ) == FontStyle :: Italic ,
386386 url : "_SYSTEM" . to_owned ( ) ,
387387 } ;
388- // simultaneously call font loaded a bunch of times to shove data into font data cache
389- // need to add logic in font loaded to handle system font loading for it to be able to work without this
390- let mut font_data_vec = Vec :: new ( ) ;
391- font_data_vec. extend ( font. load ( None ) . unwrap ( ) . data ( ) ) ;
392- responses. add ( PortfolioMessage :: FontLoaded {
393- font_family : name. clone ( ) ,
394- font_style : style. to_named_style ( ) ,
395- data : font_data_vec,
396- } ) ;
397388 styles. push ( style) ;
398389 }
399390 families_for_catalog. push ( FontCatalogFamily { name : name. to_owned ( ) , styles } ) ;
@@ -422,7 +413,28 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
422413 let font = Font :: new ( font. font_family , style. to_named_style ( ) ) ;
423414
424415 if !self . cached_data . font_cache . loaded_font ( & font) {
425- responses. add ( FrontendMessage :: TriggerFontDataLoad { font, url : style. url } ) ;
416+ if style. url == "_SYSTEM" {
417+ let system_font_family_names: Vec < String > = self . cached_data . system_font_collection . 0 . family_names ( ) . map ( |n| n. to_owned ( ) ) . collect ( ) ;
418+ for name in system_font_family_names {
419+ if name == font. font_family {
420+ let family = self . cached_data . system_font_collection . 0 . family_by_name ( & name) . unwrap ( ) ;
421+ for system_font_style in family. fonts ( ) {
422+ if ( system_font_style. weight ( ) . value ( ) as u32 == style. weight ) && ( ( system_font_style. style ( ) == FontStyle :: Italic ) == style. italic ) {
423+ let mut font_data_vec = Vec :: new ( ) ;
424+ font_data_vec. extend ( system_font_style. load ( None ) . unwrap ( ) . data ( ) ) ;
425+ responses. add ( PortfolioMessage :: FontLoaded {
426+ font_family : name. clone ( ) ,
427+ font_style : style. to_named_style ( ) ,
428+ data : font_data_vec,
429+ } ) ;
430+ return ;
431+ }
432+ }
433+ }
434+ }
435+ } else {
436+ responses. add ( FrontendMessage :: TriggerFontDataLoad { font, url : style. url } ) ;
437+ }
426438 }
427439 }
428440 }
0 commit comments