summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-17 23:35:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-17 23:45:21 +0100
commit8aec1cd23244ab38db4c953b506e33a36ba6bede (patch)
treeaa57d0e733153c30c60219f729cb25714dd2a356
parent13867600c3ddc65bbcfe2d6ccf76147e0c4acf5e (diff)
downloadserenity-8aec1cd23244ab38db4c953b506e33a36ba6bede.zip
LibTTF: ScaledFont should have a NonnullRefPtr<TTF::Font>
A ScaledFont without an underlying TTF::Font would not be valid.
-rw-r--r--Userland/Libraries/LibGfx/Typeface.cpp6
-rw-r--r--Userland/Libraries/LibTTF/Font.h6
2 files changed, 5 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGfx/Typeface.cpp b/Userland/Libraries/LibGfx/Typeface.cpp
index 5e049c5a14..76e7fcfbed 100644
--- a/Userland/Libraries/LibGfx/Typeface.cpp
+++ b/Userland/Libraries/LibGfx/Typeface.cpp
@@ -65,10 +65,8 @@ RefPtr<Font> Typeface::get_font(unsigned size)
return font;
}
- if (m_ttf_font) {
- auto font = adopt(*new TTF::ScaledFont(m_ttf_font, size, size));
- return font;
- }
+ if (m_ttf_font)
+ return adopt(*new TTF::ScaledFont(*m_ttf_font, size, size));
return {};
}
diff --git a/Userland/Libraries/LibTTF/Font.h b/Userland/Libraries/LibTTF/Font.h
index 8569d9c855..a14bc21412 100644
--- a/Userland/Libraries/LibTTF/Font.h
+++ b/Userland/Libraries/LibTTF/Font.h
@@ -121,8 +121,8 @@ private:
class ScaledFont : public Gfx::Font {
public:
- ScaledFont(RefPtr<TTF::Font> font, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI)
- : m_font(font)
+ ScaledFont(NonnullRefPtr<TTF::Font> font, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI)
+ : m_font(move(font))
, m_point_width(point_width)
, m_point_height(point_height)
{
@@ -163,7 +163,7 @@ public:
virtual const Font& bold_variant() const override { return *this; } // FIXME: Perhaps remove this from the Gfx::Font interface
private:
- RefPtr<TTF::Font> m_font;
+ NonnullRefPtr<TTF::Font> m_font;
float m_x_scale { 0.0f };
float m_y_scale { 0.0f };
float m_point_width { 0.0f };