Skip to content

Commit 10cdb86

Browse files
committed
allow previously added fonts to be replaced
- may address the patched-fonts use case in samizdatco#94
1 parent 9c929a7 commit 10cdb86

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/typography.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ impl FontLibrary{
450450
}
451451

452452
fn add_typeface(&mut self, font:Typeface, alias:Option<String>){
453+
// replace any previously added font with the same metadata/alias
454+
if let Some(idx) = self.fonts.iter().position(|(old_font, old_alias)|
455+
match alias.is_some(){
456+
true => old_alias == &alias,
457+
false => old_font.family_name() == font.family_name()
458+
} && old_font.font_style() == font.font_style()
459+
){
460+
self.fonts.remove(idx);
461+
}
453462
self.fonts.push((font, alias));
454463

455464
let mut assets = TypefaceFontProvider::new();

0 commit comments

Comments
 (0)