mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +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:
parent
27c5eb66f1
commit
b08bb0bdc3
Notes:
sideshowbarker
2024-07-18 05:06:40 +09:00
Author: https://github.com/sin-ack
Commit: b08bb0bdc3
Pull-request: https://github.com/SerenityOS/serenity/pull/9651
Issue: https://github.com/SerenityOS/serenity/issues/9415
Reviewed-by: https://github.com/TobyAsE
1 changed files with 8 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue