From ff951c89fe297ae83b20f278c184bc77730b3b13 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Mar 2022 00:49:27 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/BitmapFont.h | 3 +++ Userland/Libraries/LibGfx/Font.h | 2 ++ Userland/Libraries/LibGfx/TrueTypeFont/Font.h | 2 ++ 3 files changed, 7 insertions(+) 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(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 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;