1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

LibTTF: ScaledFont should have a NonnullRefPtr<TTF::Font>

A ScaledFont without an underlying TTF::Font would not be valid.
This commit is contained in:
Andreas Kling 2021-02-17 23:35:25 +01:00
parent 13867600c3
commit 8aec1cd232
2 changed files with 5 additions and 7 deletions

View file

@ -65,10 +65,8 @@ RefPtr<Font> Typeface::get_font(unsigned size)
return font; return font;
} }
if (m_ttf_font) { if (m_ttf_font)
auto font = adopt(*new TTF::ScaledFont(m_ttf_font, size, size)); return adopt(*new TTF::ScaledFont(*m_ttf_font, size, size));
return font;
}
return {}; return {};
} }

View file

@ -121,8 +121,8 @@ private:
class ScaledFont : public Gfx::Font { class ScaledFont : public Gfx::Font {
public: public:
ScaledFont(RefPtr<TTF::Font> font, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI) ScaledFont(NonnullRefPtr<TTF::Font> font, float point_width, float point_height, unsigned dpi_x = DEFAULT_DPI, unsigned dpi_y = DEFAULT_DPI)
: m_font(font) : m_font(move(font))
, m_point_width(point_width) , m_point_width(point_width)
, m_point_height(point_height) , 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 virtual const Font& bold_variant() const override { return *this; } // FIXME: Perhaps remove this from the Gfx::Font interface
private: private:
RefPtr<TTF::Font> m_font; NonnullRefPtr<TTF::Font> m_font;
float m_x_scale { 0.0f }; float m_x_scale { 0.0f };
float m_y_scale { 0.0f }; float m_y_scale { 0.0f };
float m_point_width { 0.0f }; float m_point_width { 0.0f };