diff --git a/wled00/FX.h b/wled00/FX.h index 42897cb4..ee39887f 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -827,7 +827,8 @@ typedef struct Segment { void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2 = 0, bool drawShadow = false); inline void drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, CRGB c, CRGB c2) { drawCharacter(chr, x, y, w, h, uint32_t(c) & 0x00FFFFFF, uint32_t(c2) & 0x00FFFFFF); } // automatic inline // unicode-aware wrapper for drawCharacter(), to be called from mode_2Dscrollingtext() - void drawText(const unsigned char* Text, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2 = 0, bool drawShadow = false); + void drawText(const unsigned char* text, size_t maxLen, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2 = 0, bool drawShadow = false); + // #if !WLED_ENABLE_FULL_FONTS => drawText() will fall back to just forwarding each char to drawCharacter() void wu_pixel(uint32_t x, uint32_t y, CRGB c); //void blur1d(fract8 blur_amount); // blur all rows in 1 dimension diff --git a/wled00/src/font/unicodetool.cpp b/wled00/src/font/unicodetool.cpp index a0d63ce4..37bae2a4 100644 --- a/wled00/src/font/unicodetool.cpp +++ b/wled00/src/font/unicodetool.cpp @@ -53,7 +53,9 @@ const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen) { if (length < 1) return nullptr; // we are at end of input unsigned char ch0 = *utf8; // get leading character - size_t codeLength = 1; // default: 1-byte ASCII + + // Calculate code length based on lead byte + size_t codeLength = 1; // default: 1-byte ASCII if (ch0 >= 0x80) { if ((ch0 & 0b11100000) == 0b11000000) codeLength = 2; // 2-byte sequence else if ((ch0 & 0b11110000) == 0b11100000) codeLength = 3; // 3-byte sequence @@ -61,8 +63,13 @@ const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen) { else codeLength = 1; // Skip single invalid byte and try to resync } - if (length < codeLength) return nullptr; // Check if we have enough bytes - else return utf8 + codeLength; // success: advance stream + // handle invalid continuation bytes + if ((codeLength >= 2) && (length < 2 || !isValidContinuation(utf8[1]))) codeLength = 1; // try to re-sync + if ((codeLength >= 3) && (length < 3 || !isValidContinuation(utf8[2]))) codeLength = 1; // try to re-sync + if ((codeLength >= 4) && (length < 4 || !isValidContinuation(utf8[3]))) codeLength = 1; // try to re-sync + + if (length < codeLength) return nullptr; // Check if we have enough bytes + else return utf8 + codeLength; // success: advance stream } #endif