diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-27 00:49:27 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-27 01:14:56 +0100 |
commit | ff951c89fe297ae83b20f278c184bc77730b3b13 (patch) | |
tree | d7dad41d2795d1deb2abcf4efbe6841e6f1a1fe6 /Userland | |
parent | d5bba91a16eeb5cd2c927dbf0c08a4ab1bbe8631 (diff) | |
download | serenity-ff951c89fe297ae83b20f278c184bc77730b3b13.zip |
LibGfx: Add Font::pixel_size() and Font::point_size()
We've gotten ourselves into a bit of a mess by mixing pixel and point
sizes in multiple places. Step one towards getting out of this mess
is adding explicit accessors for the unit you're trying to fetch.
The core of the issue comes from bitmap fonts storing integer pixel
sizes and scaled (TTF) fonts storing float point sizes.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/BitmapFont.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 2 |
3 files changed, 7 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/BitmapFont.h b/Userland/Libraries/LibGfx/BitmapFont.h index b02222489d..4a4932e876 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.h +++ b/Userland/Libraries/LibGfx/BitmapFont.h @@ -37,6 +37,9 @@ public: u8 presentation_size() const override { return m_presentation_size; } void set_presentation_size(u8 size) { m_presentation_size = size; } + virtual int pixel_size() const override { return m_glyph_height; } + virtual float point_size() const override { return static_cast<float>(m_glyph_height) * 0.75f; } + u16 weight() const override { return m_weight; } void set_weight(u16 weight) { m_weight = weight; } diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index 8596764533..256623b907 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -106,6 +106,8 @@ public: FontMetrics metrics(u32 code_point) const; virtual u8 presentation_size() const = 0; + virtual int pixel_size() const = 0; + virtual float point_size() const = 0; virtual u8 slope() const = 0; virtual u16 weight() const = 0; diff --git a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h index 7e77053707..36be6d05c4 100644 --- a/Userland/Libraries/LibGfx/TrueTypeFont/Font.h +++ b/Userland/Libraries/LibGfx/TrueTypeFont/Font.h @@ -126,6 +126,8 @@ public: // Gfx::Font implementation virtual NonnullRefPtr<Font> clone() const override { return *this; } // FIXME: clone() should not need to be implemented 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 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; |