From a4927f523ba57856db1e401d7175b9b2b146ee95 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 15 Mar 2023 10:46:06 +0100 Subject: [PATCH] LibGfx: Add Font::point_size() This returns the font size in pt instead of px. --- Userland/Libraries/LibGfx/Font/BitmapFont.h | 2 ++ Userland/Libraries/LibGfx/Font/Font.h | 3 +++ Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 5 +++++ Userland/Libraries/LibGfx/Font/ScaledFont.h | 1 + 4 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index 0d9fc97e91..dc174136e8 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -39,6 +39,8 @@ public: u8* rows() { return m_rows; } u8* widths() { return m_glyph_widths; } + virtual float point_size() const override { return m_presentation_size; } + u8 presentation_size() const override { return m_presentation_size; } void set_presentation_size(u8 size) { m_presentation_size = size; } diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index a73913e5c1..5df49042bf 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -161,6 +161,9 @@ public: virtual u8 presentation_size() const = 0; virtual u8 slope() const = 0; + // Font point size (distance between ascender and descender). + virtual float point_size() const = 0; + // Font pixel size (distance between ascender and descender). virtual float pixel_size() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index ccdc85529e..6a9891fb01 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -163,4 +163,9 @@ int ScaledFont::pixel_size_rounded_up() const return m_pixel_size_rounded_up; } +float ScaledFont::point_size() const +{ + return m_point_height; +} + } diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index 7615665d14..d968afcc95 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -36,6 +36,7 @@ public: virtual NonnullRefPtr clone() const override { return MUST(try_clone()); } // FIXME: clone() should not need to be implemented virtual ErrorOr> try_clone() const override { return const_cast(*this); } virtual u8 presentation_size() const override { return m_point_height; } + virtual float point_size() const override; virtual float pixel_size() const override; virtual int pixel_size_rounded_up() const override; virtual Gfx::FontPixelMetrics pixel_metrics() const override;