diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-23 13:12:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-24 15:01:49 +0200 |
commit | d7586aff53871d1235711f1e513a9ba6cee805f0 (patch) | |
tree | 4dc49456d446ca38ae5fe329a377178f46c58efe /Userland/Libraries | |
parent | 3d36e4d944aead762648363c253c8d649c617422 (diff) | |
download | serenity-d7586aff53871d1235711f1e513a9ba6cee805f0.zip |
LibGfx: Add a simple Gfx::FontMetrics and Gfx::Font::metrics(code_point)
This is used to get a handy set of glyph metrics.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/BitmapFont.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font.h | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Forward.h | 1 |
3 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index 010d7c48d3..60ad4b16f0 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -373,4 +373,14 @@ Font const& Font::bold_variant() const return *m_bold_variant; } +FontMetrics Font::metrics(u32 code_point) const +{ + return FontMetrics { + .size = (float)presentation_size(), + .x_height = (float)x_height(), + .glyph_width = (float)glyph_width(code_point), + .glyph_spacing = (float)glyph_spacing(), + }; +} + } diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index 27c17aa5f2..fb680685a8 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -81,11 +81,20 @@ private: int m_ascent; }; +struct FontMetrics { + float size { 0 }; + float x_height { 0 }; + float glyph_width { 0 }; + float glyph_spacing { 0 }; +}; + class Font : public RefCounted<Font> { public: virtual NonnullRefPtr<Font> clone() const = 0; virtual ~Font() {}; + FontMetrics metrics(u32 code_point) const; + virtual u8 presentation_size() const = 0; virtual u16 weight() const = 0; diff --git a/Userland/Libraries/LibGfx/Forward.h b/Userland/Libraries/LibGfx/Forward.h index 92fbaff5f8..2c4baeb033 100644 --- a/Userland/Libraries/LibGfx/Forward.h +++ b/Userland/Libraries/LibGfx/Forward.h @@ -14,6 +14,7 @@ class Color; class DisjointRectSet; class Emoji; class Font; +class FontMetrics; class GlyphBitmap; class ImageDecoder; |