mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Be slightly better at @font-face rules with multiple sources
This patch improves @font-face loading when there are multiple src values in two ways: - Invalid/empty URLs are ignored - Fonts with unsupported file extensions are ignored This makes us load and display the emblem font on modern Reddit, which is pretty neat! :^)
This commit is contained in:
parent
c5a19a4d55
commit
6d92c1d231
Notes:
sideshowbarker
2024-07-17 07:10:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6d92c1d231
1 changed files with 22 additions and 1 deletions
|
@ -1358,8 +1358,29 @@ void StyleComputer::load_fonts_from_sheet(CSSStyleSheet const& sheet)
|
|||
if (m_loaded_fonts.contains(font_face.font_family()))
|
||||
continue;
|
||||
|
||||
// NOTE: This is rather ad-hoc, we just look for the first valid
|
||||
// source URL that's either a WOFF or TTF file and try loading that.
|
||||
// FIXME: Find out exactly which resources we need to load and how.
|
||||
Optional<AK::URL> candidate_url;
|
||||
for (auto& source : font_face.sources()) {
|
||||
if (!source.url.is_valid())
|
||||
continue;
|
||||
|
||||
auto path = source.url.path();
|
||||
if (!path.ends_with(".woff"sv, AK::CaseSensitivity::CaseInsensitive)
|
||||
|| path.ends_with(".ttf"sv, AK::CaseSensitivity::CaseInsensitive)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
candidate_url = source.url;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!candidate_url.has_value())
|
||||
continue;
|
||||
|
||||
LoadRequest request;
|
||||
auto url = m_document.parse_url(font_face.sources().first().url.to_string());
|
||||
auto url = m_document.parse_url(candidate_url.value().to_string());
|
||||
auto loader = make<FontLoader>(const_cast<StyleComputer&>(*this), font_face.font_family(), move(url));
|
||||
const_cast<StyleComputer&>(*this).m_loaded_fonts.set(font_face.font_family(), move(loader));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue