[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
This commit is contained in:
Gabriel Ozouf
2020-10-27 14:40:18 +01:00
committed by Émilie Feral
parent d5e810f2b8
commit 0185e0562c
8 changed files with 23 additions and 23 deletions

View File

@@ -1,4 +1,5 @@
#include <escher/run_loop.h>
#include <kandinsky/font.h>
#include <assert.h>
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);
}

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -18,7 +18,6 @@ namespace Events {
static constexpr size_t sharedExternalTextBufferSize = sizeof(SDL_TextInputEvent::text);
char * sharedExternalTextBuffer();
constexpr Event ExternalText = Event::Special(6);
}
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;
}