summaryrefslogtreecommitdiff
path: root/glcdgraphics
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-06-23 16:47:55 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-06-23 16:47:55 +0200
commitd7b7ae09a995d8ceab70a9d7904a7b9e25beba00 (patch)
tree215fb2c970a2115b6c38499c8b21c7ccbeb0300b /glcdgraphics
parent99a603c7e73df46d1f7c4c5bef0825b90450e69e (diff)
downloadgraphlcd-base-d7b7ae09a995d8ceab70a9d7904a7b9e25beba00.tar.gz
graphlcd-base-d7b7ae09a995d8ceab70a9d7904a7b9e25beba00.tar.bz2
more bug fixes for WrapText() (should now be UTF8-proof too); deactivate imagemagick quantising (sometimes led to erraneous images)
Diffstat (limited to 'glcdgraphics')
-rw-r--r--glcdgraphics/extformats.c10
-rw-r--r--glcdgraphics/font.c69
2 files changed, 31 insertions, 48 deletions
diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c
index 75d3693..666c954 100644
--- a/glcdgraphics/extformats.c
+++ b/glcdgraphics/extformats.c
@@ -74,13 +74,9 @@ bool cExtFormatFile::Load(cImage & image, const string & fileName)
for (it = extimages.begin(); it != extimages.end(); ++it) {
bool ignoreImage = false;
- //if (colors != 0){
- //(*it).opacity(OpaqueOpacity);
- //(*it).backgroundColor( Color ( 0,0,0,0) );
- (*it).quantizeColorSpace( RGBColorspace );
- (*it).quantizeColors( 256*256*256 /*colors*/ );
- (*it).quantize();
- //}
+ //(*it).quantizeColorSpace( RGBColorspace );
+ //(*it).quantizeColors( 256*256*256 /*colors*/ );
+ //(*it).quantize();
if (firstImage) {
width = (uint16_t)((*it).columns());
diff --git a/glcdgraphics/font.c b/glcdgraphics/font.c
index 2c6e3fa..ff42514 100644
--- a/glcdgraphics/font.c
+++ b/glcdgraphics/font.c
@@ -563,26 +563,31 @@ void cFont::WrapText(int Width, int Height, std::string & Text,
int lineCount;
int textWidth;
std::string::size_type start;
- std::string::size_type pos;
+ unsigned int pos;
std::string::size_type posLast;
+ uint32_t c;
Lines.clear();
- maxLines = 2000;
+ maxLines = 100;
if (Height > 0)
{
maxLines = Height / LineHeight();
- if (maxLines == 0)
- maxLines = 1;
+ //if (maxLines == 0)
+ maxLines += 1;
}
- lineCount = 0;
+ lineCount = 0;
pos = 0;
start = 0;
posLast = 0;
textWidth = 0;
- while (pos < Text.length() && (Height == 0 || lineCount < maxLines))
+
+ while ((pos < Text.length()) && (lineCount <= maxLines))
{
- if (Text[pos] == '\n')
+ unsigned int posraw = pos;
+ encodedCharAdjustCounter(IsUTF8(), Text, c, posraw);
+
+ if (c == '\n')
{
Lines.push_back(trim(Text.substr(start, pos - start)));
start = pos /*+ 1*/;
@@ -590,7 +595,7 @@ void cFont::WrapText(int Width, int Height, std::string & Text,
textWidth = 0;
lineCount++;
}
- else if (textWidth >= Width && (lineCount + 1) < maxLines)
+ else if (textWidth + this->Width(c) > Width && (lineCount + 1) < maxLines)
{
if (posLast > start)
{
@@ -604,56 +609,38 @@ void cFont::WrapText(int Width, int Height, std::string & Text,
Lines.push_back(trim(Text.substr(start, pos - start)));
start = pos /*+ 1*/;
posLast = start;
- textWidth = this->Width(Text[pos]) + spaceBetween;
+ textWidth = this->Width(c) + spaceBetween;
}
lineCount++;
}
- else if (Text[pos] == ' ')
+ else if (isspace(c))
{
posLast = pos;
- textWidth += this->Width(Text[pos]) + spaceBetween;
+ textWidth += this->Width(c) + spaceBetween;
+ }
+ else if ( (c < 0x80) && strchr("-.,:;!?_", (int)c) )
+ {
+ posLast = pos+1;
+ textWidth += this->Width(c) + spaceBetween;
}
else
{
- textWidth += this->Width(Text[pos]) + spaceBetween;
+ textWidth += this->Width(c) + spaceBetween;
}
+ pos = posraw;
pos++;
}
+ if (start < Text.length()) {
+ Lines.push_back(trim(Text.substr(start)));
+ }
- if (Height == 0 || lineCount < maxLines)
- {
- if (textWidth >= Width && (lineCount + 1) < maxLines)
- {
- if (posLast > start)
- {
- Lines.push_back(trim(Text.substr(start, posLast - start)));
- start = posLast /*+ 1*/;
- posLast = start;
- textWidth = this->Width(Text.substr(start, pos - start + 1)) + spaceBetween;
- }
- else
- {
- Lines.push_back(trim(Text.substr(start, pos - start)));
- start = pos /*+ 1*/;
- posLast = start;
- textWidth = this->Width(Text[pos]) + spaceBetween;
- }
- lineCount++;
- }
- if (pos > start)
- {
- Lines.push_back(trim(Text.substr(start)));
- lineCount++;
- }
+ if (ActualWidth) {
textWidth = 0;
for (int i = 0; i < lineCount; i++)
textWidth = std::max(textWidth, this->Width(Lines[i]));
textWidth = std::min(textWidth, Width);
- }
- else
- textWidth = Width;
- if (ActualWidth)
*ActualWidth = textWidth;
+ }
}
} // end of namespace