diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-17 17:45:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-17 22:35:25 +0200 |
commit | 35875b68f584736086a22c6b88c7455084457681 (patch) | |
tree | 2f93b81d7c31645b78d3b817c7bab27c561eb3cf | |
parent | 4ced12670453df331632c980e7479159ef5ddf83 (diff) | |
download | serenity-35875b68f584736086a22c6b88c7455084457681.zip |
LibGfx: Add Font::width(u32* codepoints, size_t)
This allows you to measure the width of a UTF-32 sequence.
-rw-r--r-- | Libraries/LibGfx/Font.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGfx/Font.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Libraries/LibGfx/Font.cpp b/Libraries/LibGfx/Font.cpp index ebb1933ab2..cb3861474f 100644 --- a/Libraries/LibGfx/Font.cpp +++ b/Libraries/LibGfx/Font.cpp @@ -255,4 +255,14 @@ int Font::width(const Utf8View& utf8) const return width; } +int Font::width(const u32* codepoints, size_t length) const +{ + if (length == 0) + return 0; + int width = (length - 1) * glyph_spacing(); + for (size_t i = 0; i < length; ++i) + width += glyph_or_emoji_width(codepoints[i]); + return width; +} + } diff --git a/Libraries/LibGfx/Font.h b/Libraries/LibGfx/Font.h index 1580f25e11..b71c2519ab 100644 --- a/Libraries/LibGfx/Font.h +++ b/Libraries/LibGfx/Font.h @@ -95,6 +95,7 @@ public: int width(const StringView&) const; int width(const Utf8View&) const; + int width(const u32* codepoints, size_t) const; String name() const { return m_name; } void set_name(const StringView& name) { m_name = name; } |