diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index 6fee183ee9..2bd673edc2 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -43,6 +43,7 @@ public: void set_presentation_size(u8 size) { m_presentation_size = size; } virtual float pixel_size() const override { return m_glyph_height; } + virtual int pixel_size_rounded_up() const override { return m_glyph_height; } u16 width() const override { return FontWidth::Normal; } diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 49e574c771..9b88759a04 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -155,9 +155,14 @@ public: virtual FontPixelMetrics pixel_metrics() const = 0; virtual u8 presentation_size() const = 0; - virtual float pixel_size() const = 0; virtual u8 slope() const = 0; + // Font pixel size (distance between ascender and descender). + virtual float pixel_size() const = 0; + + // Font pixel size, rounded up to the nearest integer. + virtual int pixel_size_rounded_up() const = 0; + virtual u16 width() const = 0; virtual u16 weight() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 78c27f04e9..c5510fe5bf 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -22,6 +22,9 @@ ScaledFont::ScaledFont(NonnullRefPtr font, float point_width, float auto metrics = m_font->metrics(m_x_scale, m_y_scale); + m_pixel_size = m_point_height * 1.33333333f; + m_pixel_size_rounded_up = static_cast(ceilf(m_pixel_size)); + m_pixel_metrics = Gfx::FontPixelMetrics { .size = (float)pixel_size(), .x_height = (float)x_height(), @@ -148,4 +151,14 @@ Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const return m_pixel_metrics; } +float ScaledFont::pixel_size() const +{ + return m_pixel_size; +} + +int ScaledFont::pixel_size_rounded_up() const +{ + return m_pixel_size_rounded_up; +} + } diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index 14a3e38b33..7a2413cba1 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -36,7 +36,8 @@ 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 pixel_size() const override { return m_point_height * 1.33333333f; } + virtual float pixel_size() const override; + virtual int pixel_size_rounded_up() const override; virtual Gfx::FontPixelMetrics pixel_metrics() const override; virtual u8 slope() const override { return m_font->slope(); } virtual u16 width() const override { return m_font->width(); } @@ -80,6 +81,9 @@ private: mutable HashMap> m_cached_glyph_bitmaps; Gfx::FontPixelMetrics m_pixel_metrics; + float m_pixel_size { 0.0f }; + int m_pixel_size_rounded_up { 0 }; + template float unicode_view_width(T const& view) const; };