mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:47:42 +00:00
LibWeb: Support WOFF in font-face
This commit is contained in:
parent
bf6d64c199
commit
539adf5b9c
2 changed files with 20 additions and 2 deletions
|
@ -4488,7 +4488,7 @@ Vector<FontFace::Source> Parser::parse_font_face_src(TokenStream<ComponentValue>
|
||||||
// Format-name table: https://www.w3.org/TR/css-fonts-4/#font-format-definitions
|
// Format-name table: https://www.w3.org/TR/css-fonts-4/#font-format-definitions
|
||||||
auto font_format_is_supported = [](StringView name) {
|
auto font_format_is_supported = [](StringView name) {
|
||||||
// The spec requires us to treat opentype and truetype as synonymous.
|
// The spec requires us to treat opentype and truetype as synonymous.
|
||||||
if (name.is_one_of_ignoring_case("opentype"sv, "truetype"sv))
|
if (name.is_one_of_ignoring_case("opentype"sv, "truetype"sv, "woff"sv))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <LibGfx/Font/ScaledFont.h>
|
#include <LibGfx/Font/ScaledFont.h>
|
||||||
#include <LibGfx/Font/TrueType/Font.h>
|
#include <LibGfx/Font/TrueType/Font.h>
|
||||||
#include <LibGfx/Font/VectorFont.h>
|
#include <LibGfx/Font/VectorFont.h>
|
||||||
|
#include <LibGfx/Font/WOFF/Font.h>
|
||||||
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
||||||
#include <LibWeb/CSS/CSSStyleRule.h>
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
|
@ -52,7 +53,7 @@ public:
|
||||||
|
|
||||||
virtual void resource_did_load() override
|
virtual void resource_did_load() override
|
||||||
{
|
{
|
||||||
auto result = TTF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
auto result = try_load_font();
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return;
|
return;
|
||||||
m_vector_font = result.release_value();
|
m_vector_font = result.release_value();
|
||||||
|
@ -71,6 +72,23 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ErrorOr<NonnullRefPtr<Gfx::VectorFont>> try_load_font()
|
||||||
|
{
|
||||||
|
// 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 mime_type = resource()->mime_type();
|
||||||
|
if (mime_type == "font/ttf"sv || mime_type == "application/x-font-ttf"sv)
|
||||||
|
return TRY(TTF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()));
|
||||||
|
if (mime_type == "font/woff"sv)
|
||||||
|
return TRY(WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data()));
|
||||||
|
auto ttf = TTF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||||
|
if (!ttf.is_error())
|
||||||
|
return ttf.release_value();
|
||||||
|
auto woff = WOFF::Font::try_load_from_externally_owned_memory(resource()->encoded_data());
|
||||||
|
if (!woff.is_error())
|
||||||
|
return woff.release_value();
|
||||||
|
return ttf.release_error();
|
||||||
|
}
|
||||||
|
|
||||||
StyleComputer& m_style_computer;
|
StyleComputer& m_style_computer;
|
||||||
FlyString m_family_name;
|
FlyString m_family_name;
|
||||||
RefPtr<Gfx::VectorFont> m_vector_font;
|
RefPtr<Gfx::VectorFont> m_vector_font;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue