From dcb7429dcd014f71485f60c65ced33addba7abcb Mon Sep 17 00:00:00 2001 From: MrCheeze Date: Tue, 28 Nov 2023 02:06:19 -0500 Subject: [PATCH] core: Allow default fonts to use bold/italic fonts --- core/src/html/layout.rs | 2 ++ core/src/library.rs | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs index bb4c088cd146..c4ef734e5d78 100644 --- a/core/src/html/layout.rs +++ b/core/src/html/layout.rs @@ -510,6 +510,8 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> { .library .default_font( default_font, + span.bold, + span.italic, context.ui, context.renderer, context.gc_context, diff --git a/core/src/library.rs b/core/src/library.rs index c9eea7d18b72..14b77dc3892c 100644 --- a/core/src/library.rs +++ b/core/src/library.rs @@ -387,7 +387,7 @@ pub struct Library<'gc> { default_font_names: FnvHashMap>, /// The cached list of implementations per default font. - default_font_cache: FnvHashMap>>, + default_font_cache: FnvHashMap<(DefaultFont, bool, bool), Vec>>, /// A list of the symbols associated with specific AVM2 constructor /// prototypes. @@ -442,26 +442,29 @@ impl<'gc> Library<'gc> { pub fn default_font( &mut self, name: DefaultFont, + is_bold: bool, + is_italic: bool, ui: &dyn UiBackend, renderer: &mut dyn RenderBackend, gc_context: &Mutation<'gc>, ) -> Vec> { // Can't use entry api here as we want to use self for `load_device_font`. // Cache the value as this will be looked up a lot, and font lookup by name can be expensive if lots of fonts exist. - if let Some(cache) = self.default_font_cache.get(&name) { + if let Some(cache) = self.default_font_cache.get(&(name, is_bold, is_italic)) { return cache.clone(); } let mut result = vec![]; for name in self.default_font_names.entry(name).or_default().clone() { if let Some(font) = - self.get_or_load_device_font(&name, false, false, ui, renderer, gc_context) + self.get_or_load_device_font(&name, is_bold, is_italic, ui, renderer, gc_context) { result.push(font); } } - self.default_font_cache.insert(name, result.clone()); + self.default_font_cache + .insert((name, is_bold, is_italic), result.clone()); result }