Browse Source

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

A ScaledFont without an underlying TTF::Font would not be valid.
Andreas Kling 4 years ago
parent
commit
8aec1cd232
2 changed files with 5 additions and 7 deletions
  1. 2 4
      Userland/Libraries/LibGfx/Typeface.cpp
  2. 3 3
      Userland/Libraries/LibTTF/Font.h

+ 2 - 4
Userland/Libraries/LibGfx/Typeface.cpp

@@ -65,10 +65,8 @@ RefPtr<Font> Typeface::get_font(unsigned size)
             return font;
             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 {};
     return {};
 }
 }

+ 3 - 3
Userland/Libraries/LibTTF/Font.h

@@ -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)
-        : 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_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 };