summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glcdgraphics/bitmap.c4
-rw-r--r--glcdgraphics/common.c57
-rw-r--r--glcdgraphics/common.h2
-rw-r--r--glcdgraphics/font.c58
-rw-r--r--glcdgraphics/font.h1
5 files changed, 62 insertions, 60 deletions
diff --git a/glcdgraphics/bitmap.c b/glcdgraphics/bitmap.c
index 46bcdb1..470b208 100644
--- a/glcdgraphics/bitmap.c
+++ b/glcdgraphics/bitmap.c
@@ -598,7 +598,7 @@ int cBitmap::DrawText(int x, int y, int xmax, const std::string & text, const cF
{
while (skipPixels > font->SpaceBetween() + font->Width(text.substr(start), 1 /*text[start]*/))
{
- cFont::EncodedCharAdjustCounter(font->IsUTF8(), text, c, start);
+ encodedCharAdjustCounter(font->IsUTF8(), text, c, start);
skipPixels -= font->Width(c/*text[start]*/);
skipPixels -= font->SpaceBetween();
start++;
@@ -610,7 +610,7 @@ int cBitmap::DrawText(int x, int y, int xmax, const std::string & text, const cF
i = start;
while ( i < (unsigned int)text.length() )
{
- cFont::EncodedCharAdjustCounter(font->IsUTF8(), text, c, i);
+ encodedCharAdjustCounter(font->IsUTF8(), text, c, i);
if (xt > xmax)
{
diff --git a/glcdgraphics/common.c b/glcdgraphics/common.c
index 8942424..7bfcc74 100644
--- a/glcdgraphics/common.c
+++ b/glcdgraphics/common.c
@@ -57,4 +57,61 @@ std::string trim(const std::string & s)
return s.substr(start, end - start + 1);
}
+
+// character to return when erraneous utf-8 sequence (for now: '_')
+#define UTF8_ERRCODE 0x005F
+void encodedCharAdjustCounter(const bool isutf8, const std::string & str, uint32_t & c, unsigned int & i)
+{
+ if (i >= str.length())
+ return;
+
+ if ( isutf8 ) {
+ uint8_t c0,c1,c2,c3;
+ c = str[i];
+ c0 = str[i];
+ c1 = (i+1 < str.length()) ? str[i+1] : 0;
+ c2 = (i+2 < str.length()) ? str[i+2] : 0;
+ c3 = (i+3 < str.length()) ? str[i+3] : 0;
+ //c0 &=0xff; c1 &=0xff; c2 &=0xff; c3 &=0xff;
+
+ if ( (c0 & 0x80) == 0x00) {
+ // one byte: 0xxxxxxx
+ c = c0;
+ } else if ( (c0 & 0xE0) == 0xC0 ) {
+ // two byte utf8: 110yyyyy 10xxxxxx -> 00000yyy yyxxxxxx
+ if ( (c1 & 0xC0) == 0x80 ) {
+ c = ( (c0 & 0x1F) << 6 ) | ( (c1 & 0x3F) );
+ } else {
+ //syslog(LOG_INFO, "GraphLCD: illegal 2-byte UTF-8 sequence found: 0x%02x 0x%02x\n", c0, c1);
+ c = UTF8_ERRCODE;
+ }
+ i += 1;
+ } else if ( (c0 & 0xF0) == 0xE0 ) {
+ // three byte utf8: 1110zzzz 10yyyyyy 10xxxxxx -> zzzzyyyy yyxxxxxx
+ if ( ((c1 & 0xC0) == 0x80) && ((c2 & 0xC0) == 0x80) ) {
+ c = ( (c0 & 0x0F) << 12 ) | ( (c1 & 0x3F) << 6 ) | ( c2 & 0x3F );
+ } else {
+ //syslog(LOG_INFO, "GraphLCD: illegal 3-byte UTF-8 sequence found: 0x%02x 0x%02x 0x%02x\n", c0, c1, c2);
+ c = UTF8_ERRCODE;
+ }
+ i += 2;
+ } else if ( (c0 & 0xF8) == 0xF0 ) {
+ // four byte utf8: 11110www 10zzzzzz 10yyyyyy 10xxxxxx -> 000wwwzz zzzzyyyy yyxxxxxx
+ if ( ((c1 & 0xC0) == 0x80) && ((c2 & 0xC0) == 0x80) && ((c3 & 0xC0) == 0x80) ) {
+ c = ( (c0 & 0x07) << 18 ) | ( (c1 & 0x3F) << 12 ) | ( (c2 & 0x3F) << 6 ) | (c3 & 0x3F);
+ } else {
+ //syslog(LOG_INFO, "GraphLCD: illegal 4-byte UTF-8 sequence found: 0x%02x 0x%02x 0x%02x 0x%02x\n", c0, c1, c2, c3);
+ c = UTF8_ERRCODE;
+ }
+ i += 3;
+ } else {
+ // 1xxxxxxx is invalid!
+ //syslog(LOG_INFO, "GraphLCD: illegal 1-byte UTF-8 char found: 0x%02x\n", c0);
+ c = UTF8_ERRCODE;
+ }
+ } else {
+ c = str[i];
+ }
+}
+
} // end of namespace
diff --git a/glcdgraphics/common.h b/glcdgraphics/common.h
index 2865602..0043390 100644
--- a/glcdgraphics/common.h
+++ b/glcdgraphics/common.h
@@ -13,6 +13,7 @@
#define _GLCDGRAPHICS_COMMON_H_
#include <string>
+#include <stdint.h>
namespace GLCD
{
@@ -20,6 +21,7 @@ namespace GLCD
void clip(int & value, int min, int max);
void sort(int & value1, int & value2);
std::string trim(const std::string & s);
+void encodedCharAdjustCounter(const bool isutf8, const std::string & str, uint32_t & c, unsigned int & i);
} // end of namespace
diff --git a/glcdgraphics/font.c b/glcdgraphics/font.c
index b670262..09d513d 100644
--- a/glcdgraphics/font.c
+++ b/glcdgraphics/font.c
@@ -373,62 +373,6 @@ int cFont::Width(uint32_t ch) const
return 0;
}
-// character to return when erraneous utf-8 sequence (for now: '_')
-#define UTF8_ERRCODE 0x005F
-void cFont::EncodedCharAdjustCounter(const bool isutf8, const std::string & str, uint32_t & c, unsigned int & i)
-{
- if (i >= str.length())
- return;
-
- if ( isutf8 ) {
- uint8_t c0,c1,c2,c3;
- c = str[i];
- c0 = str[i];
- c1 = (i+1 < str.length()) ? str[i+1] : 0;
- c2 = (i+2 < str.length()) ? str[i+2] : 0;
- c3 = (i+3 < str.length()) ? str[i+3] : 0;
- //c0 &=0xff; c1 &=0xff; c2 &=0xff; c3 &=0xff;
-
- if ( (c0 & 0x80) == 0x00) {
- // one byte: 0xxxxxx
- c = c0;
- } else if ( (c0 & 0xE0) == 0xC0 ) {
- // two byte utf8: 110yyyyy 10xxxxxx -> 00000yyy yyxxxxxx
- if ( (c1 & 0xC0) == 0x80 ) {
- c = ( (c0 & 0x1F) << 6 ) | ( (c1 & 0x3F) );
- } else {
- //syslog(LOG_INFO, "GraphLCD: illegal 2-byte UTF-8 sequence found: 0x%02x 0x%02x\n", c0, c1);
- c = UTF8_ERRCODE;
- }
- i += 1;
- } else if ( (c0 & 0xF0) == 0xE0 ) {
- // three byte utf8: 1110zzzz 10yyyyyy 10xxxxxx -> zzzzyyyy yyxxxxxx
- if ( ((c1 & 0xC0) == 0x80) && ((c2 & 0xC0) == 0x80) ) {
- c = ( (c0 & 0x0F) << 12 ) | ( (c1 & 0x3F) << 6 ) | ( c2 & 0x3F );
- } else {
- //syslog(LOG_INFO, "GraphLCD: illegal 3-byte UTF-8 sequence found: 0x%02x 0x%02x 0x%02x\n", c0, c1, c2);
- c = UTF8_ERRCODE;
- }
- i += 2;
- } else if ( (c0 & 0xF8) == 0xF0 ) {
- // four byte utf8: 11110www 10zzzzzz 10yyyyyy 10xxxxxx -> 000wwwzz zzzzyyyy yyxxxxxx
- if ( ((c1 & 0xC0) == 0x80) && ((c2 & 0xC0) == 0x80) && ((c3 & 0xC0) == 0x80) ) {
- c = ( (c0 & 0x07) << 18 ) | ( (c1 & 0x3F) << 12 ) | ( (c2 & 0x3F) << 6 ) | (c3 & 0x3F);
- } else {
- //syslog(LOG_INFO, "GraphLCD: illegal 4-byte UTF-8 sequence found: 0x%02x 0x%02x 0x%02x 0x%02x\n", c0, c1, c2, c3);
- c = UTF8_ERRCODE;
- }
- i += 3;
- } else {
- // 1xxxxxxx is invalid!
- //syslog(LOG_INFO, "GraphLCD: illegal 1-byte UTF-8 char found: 0x%02x\n", c0);
- c = UTF8_ERRCODE;
- }
- } else {
- c = str[i];
- }
-}
-
int cFont::Width(const std::string & str) const
{
return Width(str, (unsigned int) str.length());
@@ -444,7 +388,7 @@ int cFont::Width(const std::string & str, unsigned int len) const
for (i = 0; i < (unsigned int)str.length() && symcount < len; i++)
{
unsigned int tmp = i;
- EncodedCharAdjustCounter(IsUTF8(), str, c, tmp);
+ encodedCharAdjustCounter(IsUTF8(), str, c, tmp);
symcount++;
sum += Width(c);
}
diff --git a/glcdgraphics/font.h b/glcdgraphics/font.h
index 9f4bdf8..1315123 100644
--- a/glcdgraphics/font.h
+++ b/glcdgraphics/font.h
@@ -81,7 +81,6 @@ public:
void WrapText(int Width, int Height, std::string & Text,
std::vector <std::string> & Lines, int * TextWidth = NULL) const;
bool IsUTF8(void) const { return isutf8; }
- static void EncodedCharAdjustCounter(const bool isutf8, const std::string & str, uint32_t & c, unsigned int & i);
};
} // end of namespace