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

LibGfx: Return 0 width for non-printable ASCII characters

Non-printable characters should always have a width of 0. This is not
true for some characters like tab, but those can be exempted as the need
arises. Doing this here saves us from a bunch of checks in any place
that needs to figure out glyph widths for text which can contain
non-printable characters.
This commit is contained in:
sin-ack 2021-08-28 02:02:03 +00:00 committed by Andreas Kling
parent 27c5eb66f1
commit b08bb0bdc3

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/CharacterTypes.h>
#include <AK/MappedFile.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
@ -45,7 +46,13 @@ public:
Glyph glyph(u32 code_point) const override;
bool contains_glyph(u32 code_point) const override { return code_point < (u32)glyph_count() && m_glyph_widths[code_point] > 0; }
u8 glyph_width(size_t ch) const override { return m_fixed_width ? m_glyph_width : m_glyph_widths[ch]; }
u8 glyph_width(size_t ch) const override
{
if (is_ascii(ch) && !is_ascii_printable(ch))
return 0;
return m_fixed_width ? m_glyph_width : m_glyph_widths[ch];
}
ALWAYS_INLINE int glyph_or_emoji_width(u32 code_point) const override
{
if (m_fixed_width)