1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

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.
This commit is contained in:
Andreas Kling 2022-03-27 00:49:27 +01:00
parent d5bba91a16
commit ff951c89fe
3 changed files with 7 additions and 0 deletions

View file

@ -37,6 +37,9 @@ public:
u8 presentation_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; } 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; } u16 weight() const override { return m_weight; }
void set_weight(u16 weight) { m_weight = weight; } void set_weight(u16 weight) { m_weight = weight; }

View file

@ -106,6 +106,8 @@ public:
FontMetrics metrics(u32 code_point) const; FontMetrics metrics(u32 code_point) const;
virtual u8 presentation_size() const = 0; virtual u8 presentation_size() const = 0;
virtual int pixel_size() const = 0;
virtual float point_size() const = 0;
virtual u8 slope() const = 0; virtual u8 slope() const = 0;
virtual u16 weight() const = 0; virtual u16 weight() const = 0;

View file

@ -126,6 +126,8 @@ public:
// Gfx::Font implementation // Gfx::Font implementation
virtual NonnullRefPtr<Font> clone() const override { return *this; } // FIXME: clone() should not need to be implemented 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 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 u8 slope() const override { return m_font->slope(); }
virtual u16 weight() const override { return m_font->weight(); } virtual u16 weight() const override { return m_font->weight(); }
virtual Gfx::Glyph glyph(u32 code_point) const override; virtual Gfx::Glyph glyph(u32 code_point) const override;