From 2003eed2a54ade215b546b009aa701d5c330997d Mon Sep 17 00:00:00 2001 From: Dav999 Date: Wed, 3 Jan 2024 18:55:42 +0100 Subject: [PATCH] Hide unicode directional control characters They shouldn't be looked up in the font and displayed under any circumstances. --- desktop_version/src/Font.cpp | 6 ++++++ desktop_version/src/FontBidi.cpp | 29 +++++++++++++++++++++-------- desktop_version/src/FontBidi.h | 4 ++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Font.cpp b/desktop_version/src/Font.cpp index 78ec6e47..b0009d40 100644 --- a/desktop_version/src/Font.cpp +++ b/desktop_version/src/Font.cpp @@ -1074,6 +1074,12 @@ static int print_char( { /* Draws the glyph for a codepoint at x,y. * Returns the amount of pixels to advance the cursor. */ + if (is_directional_character(codepoint) || is_joiner(codepoint)) + { + // Some characters should be completely invisible + return 0; + } + const Font* f_glyph; GlyphInfo* glyph = find_glyphinfo(f, codepoint, &f_glyph); if (glyph == NULL) diff --git a/desktop_version/src/FontBidi.cpp b/desktop_version/src/FontBidi.cpp index b56a013d..199c1797 100644 --- a/desktop_version/src/FontBidi.cpp +++ b/desktop_version/src/FontBidi.cpp @@ -263,6 +263,25 @@ void bidi_destroy(void) } +bool is_directional_character(const uint32_t codepoint) +{ + // LEFT-TO-RIGHT MARK and RIGHT-TO-LEFT MARK + if (codepoint == 0x200E || codepoint == 0x200F) return true; + + // Some other directional formatting: LRE, RLE, PDF, RLO, LRO + if (codepoint >= 0x202A && codepoint <= 0x202E) return true; + + // The more recent isolates: LRI, RLI, FSI, PDI + if (codepoint >= 0x2066 && codepoint <= 0x2069) return true; + + return false; +} + +bool is_joiner(const uint32_t codepoint) +{ + return codepoint == 0x200C || codepoint == 0x200D; +} + bool bidi_should_transform(const char* text) { /* Just as an optimization, only run the whole bidi machinery if the @@ -278,14 +297,8 @@ bool bidi_should_transform(const char* text) // Extended Arabic B and A if (ch >= 0x870 && ch <= 0x8FF) return true; - // LEFT-TO-RIGHT MARK and RIGHT-TO-LEFT MARK - if (ch == 0x200E || ch == 0x200F) return true; - - // Some other directional formatting: LRE, RLE, PDF, RLO, LRO - if (ch >= 0x202A && ch <= 0x202E) return true; - - // The more recent isolates: LRI, RLI, FSI, PDI - if (ch >= 0x2066 && ch <= 0x2069) return true; + // Any directional control character + if (is_directional_character(ch)) return true; // Hebrew presentation forms if (ch >= 0xFB1D && ch <= 0xFB4F) return true; diff --git a/desktop_version/src/FontBidi.h b/desktop_version/src/FontBidi.h index bb0082dc..6824dd51 100644 --- a/desktop_version/src/FontBidi.h +++ b/desktop_version/src/FontBidi.h @@ -1,11 +1,15 @@ #ifndef FONTBIDI_H #define FONTBIDI_H +#include + namespace font { void bidi_init(void); void bidi_destroy(void); +bool is_directional_character(uint32_t codepoint); +bool is_joiner(uint32_t codepoint); bool bidi_should_transform(const char* text); const char* bidi_transform(const char* text);