1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibWeb: Load and use fonts described by @font-face rules :^)

When encountering a @font-face rule, StyleComputer will now fire off
a resource request and download the first source URL specified.

Once downloaded, we try to parse it as a TrueType font file, and if it
works, it's added to a cache in StyleComputer. This effectively makes
fonts per-document since every document has its own StyleComputer.

This is very unoptimized and could definitely use some caching, etc.
But it does work on Acid3. :^)
This commit is contained in:
Andreas Kling 2022-03-29 02:14:20 +02:00
parent dcb24e943d
commit 1f9aed2617
Notes: sideshowbarker 2024-07-17 16:35:41 +09:00
2 changed files with 84 additions and 1 deletions

View file

@ -11,6 +11,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/StyleComponentValueRule.h>
#include <LibWeb/CSS/Selector.h>
@ -48,7 +49,7 @@ private:
class StyleComputer {
public:
explicit StyleComputer(DOM::Document&);
~StyleComputer() = default;
~StyleComputer();
DOM::Document& document() { return m_document; }
DOM::Document const& document() const { return m_document; }
@ -71,6 +72,8 @@ public:
Gfx::Font const& initial_font() const;
void did_load_font(FlyString const& family_name);
private:
void compute_cascaded_values(StyleProperties&, DOM::Element&, Optional<CSS::Selector::PseudoElement>) const;
void compute_font(StyleProperties&, DOM::Element const*, Optional<CSS::Selector::PseudoElement>) const;
@ -109,6 +112,11 @@ private:
Vector<MatchingRule> other_rules;
};
OwnPtr<RuleCache> m_rule_cache;
void load_fonts_if_needed() const;
class FontLoader;
HashMap<String, NonnullOwnPtr<FontLoader>> m_loaded_fonts;
};
}