Skip to content

Commit

Permalink
LibGfx: Return 0 width for non-printable ASCII characters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sin-ack authored and awesomekling committed Aug 28, 2021
1 parent 27c5eb6 commit b08bb0b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Userland/Libraries/LibGfx/BitmapFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include <AK/CharacterTypes.h>
#include <AK/MappedFile.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
Expand Down Expand Up @@ -45,7 +46,13 @@ class BitmapFont final : public Font {
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)
Expand Down

0 comments on commit b08bb0b

Please sign in to comment.