1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:07:43 +00:00

LibHTML: Move font loading from LayoutText to StyleProperties

Since LayoutText inherits all of its style information from its parent
Element anyway, it makes more sense to load the font at a higher level.

And since the font depends only on the style and nothing else, this
patch moves font loading (and caching) into StyleProperties. This could
be made a lot smarter to avoid loading the same font many times, etc.
This commit is contained in:
Andreas Kling 2019-10-06 11:23:58 +02:00
parent c8e5039418
commit b9557bf876
4 changed files with 72 additions and 66 deletions

View file

@ -2,6 +2,7 @@
#include <AK/HashMap.h>
#include <AK/NonnullRefPtr.h>
#include <LibDraw/Font.h>
#include <LibHTML/CSS/StyleValue.h>
class Color;
@ -24,6 +25,17 @@ public:
String string_or_fallback(const StringView& property_name, const StringView& fallback) const;
Color color_or_fallback(const StringView& property_name, const Document&, Color fallback) const;
const Font& font() const
{
if (!m_font)
load_font();
return *m_font;
}
private:
HashMap<String, NonnullRefPtr<StyleValue>> m_property_values;
void load_font() const;
mutable RefPtr<Font> m_font;
};