Skip to content

Commit

Permalink
LibWeb/CSS: Add valid default font if no font can be found
Browse files Browse the repository at this point in the history
- Before: If a font cannot computed based on style values, e.g. if the
          family is incorrect (try 'lolol'), then the list of found
          fonts contains only the default emoji font.
- After:  The default font of the Font plugin is added to the top of
          an empty list of computed fonts. This way, we're failing
          gracefully on author error, and we still display emojis :]m

Bonus: renamed `found_font` (misleading name; seems artifact) to
       `last_resort_font` (what it is)
  • Loading branch information
manuel-za committed Dec 17, 2024
1 parent 6fd7b9b commit 8f90b35
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Libraries/LibWeb/CSS/StyleComputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2090,12 +2090,18 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
font_list->extend(*other_font_list);
}

auto fallback_font = Platform::FontPlugin::the().default_font().with_size(font_size_in_pt);
if (font_list->is_empty()) {
// FIXME: Opinion: Platform::FontPlugin::the().default_font() (now: 'sans') should match the 'html' (top) style in Default.css ('serif')
font_list->add(*fallback_font);
}

if (auto emoji_font = Platform::FontPlugin::the().default_emoji_font(font_size_in_pt); emoji_font) {
font_list->add(*emoji_font);
}

auto found_font = StyleProperties::font_fallback(monospace, bold);
font_list->set_last_resort_font(found_font->with_size(font_size_in_pt));
auto last_resort_font = StyleProperties::font_fallback(monospace, bold);
font_list->set_last_resort_font(last_resort_font->with_size(font_size_in_pt));

return font_list;
}
Expand Down

0 comments on commit 8f90b35

Please sign in to comment.