diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-28 12:11:09 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-30 00:57:15 +0200 |
commit | e398164f106a2660aae210d4c93012e8a01d2240 (patch) | |
tree | a5b57e53b7ed35c5c12db2bd5169b8ca25a1d227 /Userland | |
parent | 344374588bba63e8b6b90c9357bcce698fdbf0d3 (diff) | |
download | serenity-e398164f106a2660aae210d4c93012e8a01d2240.zip |
LibGfx: Make Font::pixel_metrics() virtual
This makes it easier for BitmapFont and ScaledFont to implement metrics
lookup themselves.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/BitmapFont.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/BitmapFont.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 1 |
5 files changed, 16 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index 9da41f8cb6..166e94caa8 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -372,10 +372,10 @@ Font const& Font::bold_variant() const return *m_bold_variant; } -FontPixelMetrics Font::pixel_metrics() const +FontPixelMetrics BitmapFont::pixel_metrics() const { return FontPixelMetrics { - .size = (float)presentation_size(), + .size = (float)pixel_size(), .x_height = (float)x_height(), .advance_of_ascii_zero = (float)glyph_width('0'), .glyph_spacing = (float)glyph_spacing(), diff --git a/Userland/Libraries/LibGfx/BitmapFont.h b/Userland/Libraries/LibGfx/BitmapFont.h index 4a4932e876..0146f2fa7b 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -23,6 +23,8 @@ public: NonnullRefPtr<Font> clone() const override; static NonnullRefPtr<BitmapFont> create(u8 glyph_height, u8 glyph_width, bool fixed, size_t glyph_count); + virtual FontPixelMetrics pixel_metrics() const override; + NonnullRefPtr<BitmapFont> masked_character_set() const; NonnullRefPtr<BitmapFont> unmasked_character_set() const; diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index e8e452a129..7e4a9a2f2e 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -103,7 +103,7 @@ public: virtual NonnullRefPtr<Font> clone() const = 0; virtual ~Font() {}; - FontPixelMetrics pixel_metrics() const; + virtual FontPixelMetrics pixel_metrics() const = 0; virtual u8 presentation_size() const = 0; virtual int pixel_size() const = 0; diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp index 8f961551e6..e4caca2d47 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.cpp @@ -724,6 +724,16 @@ u8 ScaledFont::glyph_fixed_width() const return glyph_metrics(glyph_id_for_code_point(' ')).advance_width; } +Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const +{ + return Gfx::FontPixelMetrics { + .size = (float)pixel_size(), + .x_height = (float)x_height(), + .advance_of_ascii_zero = (float)glyph_width('0'), + .glyph_spacing = (float)glyph_spacing(), + }; +} + u16 OS2::weight_class() const { return be_u16(m_slice.offset_pointer((u32)Offsets::WeightClass)); diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h index 36be6d05c4..2e9212d93a 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h @@ -128,6 +128,7 @@ public: 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; } + virtual Gfx::FontPixelMetrics pixel_metrics() const override; virtual u8 slope() const override { return m_font->slope(); } virtual u16 weight() const override { return m_font->weight(); } virtual Gfx::Glyph glyph(u32 code_point) const override; |