소스 검색

LibGfx: Add pure virtual fallible clone() for Fonts

thankyouverycool 2 년 전
부모
커밋
1be830e3c6
3개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      Userland/Libraries/LibGfx/Font/BitmapFont.h
  2. 1 0
      Userland/Libraries/LibGfx/Font/Font.h
  3. 2 1
      Userland/Libraries/LibGfx/Font/ScaledFont.h

+ 1 - 1
Userland/Libraries/LibGfx/Font/BitmapFont.h

@@ -21,7 +21,7 @@ namespace Gfx {
 class BitmapFont final : public Font {
 public:
     virtual NonnullRefPtr<Font> clone() const override;
-    ErrorOr<NonnullRefPtr<Font>> try_clone() const;
+    ErrorOr<NonnullRefPtr<Font>> try_clone() const override;
     static NonnullRefPtr<BitmapFont> create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
     static ErrorOr<NonnullRefPtr<BitmapFont>> try_create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count);
 

+ 1 - 0
Userland/Libraries/LibGfx/Font/Font.h

@@ -112,6 +112,7 @@ public:
     };
 
     virtual NonnullRefPtr<Font> clone() const = 0;
+    virtual ErrorOr<NonnullRefPtr<Font>> try_clone() const = 0;
     virtual ~Font() {};
 
     virtual FontPixelMetrics pixel_metrics() const = 0;

+ 2 - 1
Userland/Libraries/LibGfx/Font/ScaledFont.h

@@ -33,7 +33,8 @@ public:
     RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id) const;
 
     // ^Gfx::Font
-    virtual NonnullRefPtr<Font> clone() const override { return *this; } // FIXME: clone() should not need to be implemented
+    virtual NonnullRefPtr<Font> clone() const override { return MUST(try_clone()); } // FIXME: clone() should not need to be implemented
+    virtual ErrorOr<NonnullRefPtr<Font>> try_clone() const override { return *this; }
     virtual u8 presentation_size() const override { return m_point_height; }
     virtual int pixel_size() const override { return m_point_height * 1.33333333f; }
     virtual float point_size() const override { return m_point_height; }