From 0185e0562ccb1be2e6eed9dc4abe6151c585da7a Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 27 Oct 2020 14:40:18 +0100 Subject: [PATCH] [escher/run_loop] Move kandinksy include To check whether an ExternalText could be written with Epsilon's fonts, UTF8Helper made a reference to Kandinsky, which is prohibited. This check is now done in Escher, before dispatching the event. Change-Id: I55e9db1ba43c3115775499db47b90a6bdd7cc7b3 --- escher/src/run_loop.cpp | 6 ++++++ ion/include/ion/events.h | 2 +- ion/include/ion/unicode/utf8_helper.h | 4 ---- ion/src/shared/unicode/utf8_helper.cpp | 14 -------------- ion/src/simulator/shared/events.h | 1 - ion/src/simulator/shared/events_keyboard.cpp | 3 --- kandinsky/include/kandinsky/font.h | 2 ++ kandinsky/src/font.cpp | 14 ++++++++++++++ 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 4653324ff..f5d8c3b97 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -1,4 +1,5 @@ #include +#include #include RunLoop::RunLoop() : @@ -64,6 +65,11 @@ bool RunLoop::step() { #endif if (event != Ion::Events::None) { +#if !PLATFORM_DEVICE + if (event == Ion::Events::ExternalText && !KDFont::CanBeWrittenWithGlyphs(event.text())) { + return true; + } +#endif dispatchEvent(event); } diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index fdffb1cef..c2326ff6d 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -234,7 +234,7 @@ constexpr Event USBPlug = Event::Special(4); constexpr Event BatteryCharging = Event::Special(5); /* This event is only used in the simulator, to handle text that cannot be * associated with a key. */ -// constexpr Event ExternalText = Event::Special(6); +constexpr Event ExternalText = Event::Special(6); } } diff --git a/ion/include/ion/unicode/utf8_helper.h b/ion/include/ion/unicode/utf8_helper.h index 3f3492b9c..edc379325 100644 --- a/ion/include/ion/unicode/utf8_helper.h +++ b/ion/include/ion/unicode/utf8_helper.h @@ -124,10 +124,6 @@ const char * EndOfWord(const char * word); // On a line, count number of glyphs before and after locations void countGlyphsInLine(const char * text, int * before, int * after, const char * beforeLocation, const char *afterLocation = nullptr); -/* Returns false if one of text's code points does not have a corresponding - * glyph in Epsilon's fonts.*/ -bool CanBeWrittenWithGlyphs(const char * text); - }; #endif diff --git a/ion/src/shared/unicode/utf8_helper.cpp b/ion/src/shared/unicode/utf8_helper.cpp index b1f57a3a2..40bf19bb2 100644 --- a/ion/src/shared/unicode/utf8_helper.cpp +++ b/ion/src/shared/unicode/utf8_helper.cpp @@ -489,18 +489,4 @@ void countGlyphsInLine(const char * text, int * before, int * after, const char UTF8Helper::PerformAtCodePoints(afterLocation, UCodePointLineFeed, nullptr, countGlyph, after, 0, 0, UCodePointLineFeed); } -bool CanBeWrittenWithGlyphs(const char * text) { - UTF8Decoder decoder(text); - CodePoint cp = decoder.nextCodePoint(); - while(cp != UCodePointNull) { - if (KDFont::LargeFont->indexForCodePoint(cp) == KDFont::IndexForReplacementCharacterCodePoint - || KDFont::SmallFont->indexForCodePoint(cp) == KDFont::IndexForReplacementCharacterCodePoint) - { - return false; - } - cp = decoder.nextCodePoint(); - } - return true; -} - } diff --git a/ion/src/simulator/shared/events.h b/ion/src/simulator/shared/events.h index 9896b88e7..1770c40ba 100644 --- a/ion/src/simulator/shared/events.h +++ b/ion/src/simulator/shared/events.h @@ -18,7 +18,6 @@ namespace Events { static constexpr size_t sharedExternalTextBufferSize = sizeof(SDL_TextInputEvent::text); char * sharedExternalTextBuffer(); -constexpr Event ExternalText = Event::Special(6); } } diff --git a/ion/src/simulator/shared/events_keyboard.cpp b/ion/src/simulator/shared/events_keyboard.cpp index f4867cdf8..1087528f1 100644 --- a/ion/src/simulator/shared/events_keyboard.cpp +++ b/ion/src/simulator/shared/events_keyboard.cpp @@ -166,9 +166,6 @@ static Event eventFromSDLTextInputEvent(SDL_TextInputEvent event) { } } } - if (!UTF8Helper::CanBeWrittenWithGlyphs(event.text)) { - return None; - } Ion::Events::removeShift(); strlcpy(sharedExternalTextBuffer(), event.text, sharedExternalTextBufferSize); return ExternalText; diff --git a/kandinsky/include/kandinsky/font.h b/kandinsky/include/kandinsky/font.h index a405370f3..0b871ea1c 100644 --- a/kandinsky/include/kandinsky/font.h +++ b/kandinsky/include/kandinsky/font.h @@ -33,6 +33,8 @@ public: static constexpr const KDFont * LargeFont = &privateLargeFont; static constexpr const KDFont * SmallFont = &privateSmallFont; + static bool CanBeWrittenWithGlyphs(const char * text); + KDSize stringSize(const char * text, int textLength = -1) const { return stringSizeUntil(text, textLength < 0 ? nullptr : text + textLength); } diff --git a/kandinsky/src/font.cpp b/kandinsky/src/font.cpp index cae40c789..25d82e93a 100644 --- a/kandinsky/src/font.cpp +++ b/kandinsky/src/font.cpp @@ -159,3 +159,17 @@ KDFont::GlyphIndex KDFont::indexForCodePoint(CodePoint c) const { return IndexForReplacementCharacterCodePoint; #endif } + +bool KDFont::CanBeWrittenWithGlyphs(const char * text) { + UTF8Decoder decoder(text); + CodePoint cp = decoder.nextCodePoint(); + while(cp != UCodePointNull) { + if (LargeFont->indexForCodePoint(cp) == KDFont::IndexForReplacementCharacterCodePoint + || SmallFont->indexForCodePoint(cp) == KDFont::IndexForReplacementCharacterCodePoint) + { + return false; + } + cp = decoder.nextCodePoint(); + } + return true; +}