LibGfx: Load default font lazily

This is required when trying to use a Painter from lagom, due to
/res/font not being present
This commit is contained in:
Hendiadyoin1 2021-11-28 16:09:38 +01:00 committed by Ali Mohammad Pur
parent e69276e704
commit 9e7c16d0a4
Notes: sideshowbarker 2024-07-18 00:29:58 +09:00
2 changed files with 8 additions and 2 deletions

View file

@ -64,7 +64,7 @@ Painter::Painter(Gfx::Bitmap& bitmap)
VERIFY(bitmap.physical_width() % scale == 0);
VERIFY(bitmap.physical_height() % scale == 0);
m_state_stack.append(State());
state().font = &FontDatabase::default_font();
state().font = nullptr;
state().clip_rect = { { 0, 0 }, bitmap.size() };
state().scale = scale;
m_clip_origin = state().clip_rect;

View file

@ -10,6 +10,7 @@
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
#include <LibGfx/Color.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
@ -108,7 +109,12 @@ public:
};
void fill_path(Path const&, Color, WindingRule rule = WindingRule::Nonzero);
Font const& font() const { return *state().font; }
Font const& font() const
{
if (!state().font)
return FontDatabase::default_font();
return *state().font;
}
void set_font(Font const& font) { state().font = &font; }
enum class DrawOp {