scrolling text scrolling, unicode-aware strlen
This commit is contained in:
@@ -10,6 +10,10 @@
|
|||||||
#include "FX.h"
|
#include "FX.h"
|
||||||
#include "fcn_declare.h"
|
#include "fcn_declare.h"
|
||||||
|
|
||||||
|
#if defined(WLED_ENABLE_FULL_FONTS)
|
||||||
|
#include "src/font/codepages.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WLEDMM_FASTPATH
|
#ifdef WLEDMM_FASTPATH
|
||||||
#undef SEGMENT
|
#undef SEGMENT
|
||||||
#undef SEGENV
|
#undef SEGENV
|
||||||
@@ -6861,11 +6865,16 @@ uint16_t mode_2Dscrollingtext(void) {
|
|||||||
else if ((!strncmp_P(text,PSTR("#AMP"),4)) || (!strncmp_P(text,PSTR("#POW"),4))) sprintf_P(text, PSTR("%3.1fA"), float(strip.currentMilliamps)/1000.0f); // WLEDMM
|
else if ((!strncmp_P(text,PSTR("#AMP"),4)) || (!strncmp_P(text,PSTR("#POW"),4))) sprintf_P(text, PSTR("%3.1fA"), float(strip.currentMilliamps)/1000.0f); // WLEDMM
|
||||||
else sprintf_P(text, PSTR("%s %d, %d %d:%02d%s"), monthShortStr(month(localTime)), day(localTime), year(localTime), AmPmHour, minute(localTime), sec);
|
else sprintf_P(text, PSTR("%s %d, %d %d:%02d%s"), monthShortStr(month(localTime)), day(localTime), year(localTime), AmPmHour, minute(localTime), sec);
|
||||||
} else drawShadow = false; // static text does not require shadow
|
} else drawShadow = false; // static text does not require shadow
|
||||||
const int numberOfLetters = strlen(text);
|
|
||||||
|
const int numberOfChars = strlen(text);
|
||||||
|
#if defined(WLED_ENABLE_FULL_FONTS)
|
||||||
|
const int numberOfLetters = strlenUC((unsigned char *)text); // get the mumber of unicode letters
|
||||||
|
#else
|
||||||
|
const int numberOfLetters = numberOfChars;
|
||||||
|
#endif
|
||||||
|
|
||||||
long delayTime = long(strip.now) - long(SEGENV.step);
|
long delayTime = long(strip.now) - long(SEGENV.step);
|
||||||
if ((delayTime >= 0) || (abs(delayTime) > 1500)) { // WLEDMM keep on scrolling if timebase jumps (supersync, or brightness off, or wifi delay)
|
if ((delayTime >= 0) || (abs(delayTime) > 1500)) { // WLEDMM keep on scrolling if timebase jumps (supersync, or brightness off, or wifi delay)
|
||||||
//WLEDMM ToDO: adjust scolling logic for unicode (single UTF-8 letters need up to 4 chars)
|
|
||||||
if ((numberOfLetters * letterWidth) > cols) ++SEGENV.aux0 %= (numberOfLetters * letterWidth) + cols; // offset
|
if ((numberOfLetters * letterWidth) > cols) ++SEGENV.aux0 %= (numberOfLetters * letterWidth) + cols; // offset
|
||||||
else SEGENV.aux0 = (cols + (numberOfLetters * letterWidth))/2;
|
else SEGENV.aux0 = (cols + (numberOfLetters * letterWidth))/2;
|
||||||
SEGENV.aux1 = (SEGENV.aux1 + 1) & 0xFF; // color shift // WLEDMM changed to prevent overflow
|
SEGENV.aux1 = (SEGENV.aux1 + 1) & 0xFF; // color shift // WLEDMM changed to prevent overflow
|
||||||
@@ -6900,12 +6909,12 @@ uint16_t mode_2Dscrollingtext(void) {
|
|||||||
col1 = SEGCOLOR(0);
|
col1 = SEGCOLOR(0);
|
||||||
col2 = SEGCOLOR(2);
|
col2 = SEGCOLOR(2);
|
||||||
}
|
}
|
||||||
SEGMENT.drawText((unsigned char*)text, maxLen, numberOfLetters, int(cols) - int(SEGENV.aux0), yoffset, letterWidth, letterHeight, col1, col2, drawShadow);
|
SEGMENT.drawText((unsigned char*)text, maxLen, numberOfChars, int(cols) - int(SEGENV.aux0), yoffset, letterWidth, letterHeight, col1, col2, drawShadow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size,,Gradient,Overlay;!,!,Gradient;!;2;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0";
|
static const char _data_FX_MODE_2DSCROLLTEXT[] PROGMEM = "Scrolling Text@!,Y Offset,Trail,Font size,,Gradient,Overlay,Soft;!,!,Gradient;!;2;ix=128,c1=0,rev=0,mi=0,rY=0,mY=0";
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ uint16_t unicodeToWchar16(const unsigned char* utf8, size_t maxLen); /
|
|||||||
// return nullptr at end of input
|
// return nullptr at end of input
|
||||||
const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen); // unicodetool.cpp
|
const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen); // unicodetool.cpp
|
||||||
|
|
||||||
|
// unicode-aware string length
|
||||||
|
size_t strlenUC(const unsigned char* utf8);
|
||||||
|
|
||||||
// translates unicode 2-byte (UTF-16) "code point" into corresponding character in codepage 437 (IBM PC aka PC-8)
|
// translates unicode 2-byte (UTF-16) "code point" into corresponding character in codepage 437 (IBM PC aka PC-8)
|
||||||
uint16_t wchar16ToCodepage437(uint16_t wideChar); // codepage437.cpp
|
uint16_t wchar16ToCodepage437(uint16_t wideChar); // codepage437.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -72,4 +72,15 @@ const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen) {
|
|||||||
else return utf8 + codeLength; // success: advance stream
|
else return utf8 + codeLength; // success: advance stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unicode-aware string length
|
||||||
|
size_t strlenUC(const unsigned char* utf8) {
|
||||||
|
if ((utf8 == nullptr) || (utf8[0] == '\0')) return 0;
|
||||||
|
size_t maxLen = strlen((const char *)utf8);
|
||||||
|
size_t letters = 0;
|
||||||
|
for(const unsigned char* now = utf8; now != nullptr && now[0] != '\0'; now = nextUnicode(now, maxLen)) // iterates over utf-8 and count letters
|
||||||
|
letters++;
|
||||||
|
|
||||||
|
return letters;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user