mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Try to parse WOFF and WOFF2 even if MIME type says otherwise
As it turns out, websites can lie about this, and it doesn't really cost us much to try decoding as other formats before giving up.
This commit is contained in:
parent
9c608b46fd
commit
037b395b5d
Notes:
sideshowbarker
2024-07-16 23:23:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/037b395b5d
1 changed files with 15 additions and 6 deletions
|
@ -165,12 +165,21 @@ private:
|
|||
{
|
||||
// FIXME: This could maybe use the format() provided in @font-face as well, since often the mime type is just application/octet-stream and we have to try every format
|
||||
auto const& mime_type = resource()->mime_type();
|
||||
if (mime_type == "font/ttf"sv || mime_type == "application/x-font-ttf"sv)
|
||||
return OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||
if (mime_type == "font/woff"sv || mime_type == "application/font-woff"sv)
|
||||
return WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||
if (mime_type == "font/woff2"sv || mime_type == "application/font-woff2"sv)
|
||||
return WOFF2::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||
if (mime_type == "font/ttf"sv || mime_type == "application/x-font-ttf"sv) {
|
||||
if (auto result = OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (mime_type == "font/woff"sv || mime_type == "application/font-woff"sv) {
|
||||
if (auto result = WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (mime_type == "font/woff2"sv || mime_type == "application/font-woff2"sv) {
|
||||
if (auto result = WOFF2::Font::try_load_from_externally_owned_memory(resource()->encoded_data()); !result.is_error()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// We don't have the luxury of knowing the MIME type, so we have to try all formats.
|
||||
auto ttf = OpenType::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||
|
|
Loading…
Add table
Reference in a new issue