@ -129,6 +129,15 @@ impl FontLoader {
self . get ( font_name )
self . get ( font_name )
}
}
#[ cfg(not(feature = " embed-fonts " )) ]
fn load_from_asset ( & self , font_name : & str ) -> Option < ExtendedFontFamily > {
warn ! (
"Tried to load {} from assets but build didn't include embed-fonts feature" ,
font_name
) ;
None
}
fn load ( & mut self , font_name : & str ) -> Option < ExtendedFontFamily > {
fn load ( & mut self , font_name : & str ) -> Option < ExtendedFontFamily > {
let handle = match self . source . select_family_by_name ( font_name ) {
let handle = match self . source . select_family_by_name ( font_name ) {
Ok ( it ) = > it ,
Ok ( it ) = > it ,
@ -136,20 +145,21 @@ impl FontLoader {
} ;
} ;
let family = ExtendedFontFamily ::from_normal_font_family ( handle . fonts ( ) ) ;
let family = ExtendedFontFamily ::from_normal_font_family ( handle . fonts ( ) ) ;
if ! family . fonts . is_empty ( ) {
self . cache . put ( String ::from ( font_name ) , family ) ;
self . cache . put ( String ::from ( font_name ) , family ) ;
self . get ( font_name )
self . get ( font_name )
}
} else {
None
pub fn get_or_load ( & mut self , font_name : & str , asset : bool ) -> Option < ExtendedFontFamily > {
if let Some ( family ) = self . get ( font_name ) {
return Some ( family ) ;
}
}
}
if asset {
pub fn get_or_load ( & mut self , font_name : & str ) -> Option < ExtendedFontFamily > {
self . load_from_asset ( font_name )
if let Some ( cached ) = self . get ( font_name ) {
Some ( cached )
} else if let Some ( loaded ) = self . load ( font_name ) {
Some ( loaded )
} else {
} else {
self . load ( font_name )
self . load _from_asset ( font_name )
}
}
}
}
}
}
@ -183,7 +193,7 @@ pub fn build_collection_by_font_name(
. chain ( iter ::once ( SYSTEM_DEFAULT_FONT ) ) ;
. chain ( iter ::once ( SYSTEM_DEFAULT_FONT ) ) ;
for font_name in gui_fonts {
for font_name in gui_fonts {
if let Some ( family ) = loader . get_or_load ( font_name , false ) {
if let Some ( family ) = loader . get_or_load ( font_name ) {
if let Some ( font ) = family . get ( properties ) {
if let Some ( font ) = family . get ( properties ) {
collection . add_family ( FontFamily ::new_from_font ( font . clone ( ) ) ) ;
collection . add_family ( FontFamily ::new_from_font ( font . clone ( ) ) ) ;
break ;
break ;
@ -191,14 +201,13 @@ pub fn build_collection_by_font_name(
}
}
}
}
for font in & [ SYSTEM_SYMBOL_FONT , SYSTEM_EMOJI_FONT ] {
for font in & [
if let Some ( family ) = loader . get_or_load ( font , false ) {
SYSTEM_SYMBOL_FONT ,
collection . add_family ( family . to_normal_font_family ( ) ) ;
SYSTEM_EMOJI_FONT ,
}
EXTRA_SYMBOL_FONT ,
}
MISSING_GLYPH_FONT ,
] {
for font in & [ EXTRA_SYMBOL_FONT , MISSING_GLYPH_FONT ] {
if let Some ( family ) = loader . get_or_load ( font ) {
if let Some ( family ) = loader . get_or_load ( font , true ) {
collection . add_family ( family . to_normal_font_family ( ) ) ;
collection . add_family ( family . to_normal_font_family ( ) ) ;
}
}
}
}