Skip to content

Commit 35875b6

Browse files
committed
LibGfx: Add Font::width(u32* codepoints, size_t)
This allows you to measure the width of a UTF-32 sequence.
1 parent 4ced126 commit 35875b6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Libraries/LibGfx/Font.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,14 @@ int Font::width(const Utf8View& utf8) const
255255
return width;
256256
}
257257

258+
int Font::width(const u32* codepoints, size_t length) const
259+
{
260+
if (length == 0)
261+
return 0;
262+
int width = (length - 1) * glyph_spacing();
263+
for (size_t i = 0; i < length; ++i)
264+
width += glyph_or_emoji_width(codepoints[i]);
265+
return width;
266+
}
267+
258268
}

Libraries/LibGfx/Font.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Font : public RefCounted<Font> {
9595

9696
int width(const StringView&) const;
9797
int width(const Utf8View&) const;
98+
int width(const u32* codepoints, size_t) const;
9899

99100
String name() const { return m_name; }
100101
void set_name(const StringView& name) { m_name = name; }

0 commit comments

Comments
 (0)