[Scummvm-cvs-logs] CVS: scummvm/graphics font.cpp,1.10,1.11
Max Horn
fingolfin at users.sourceforge.net
Tue May 17 16:15:26 CEST 2005
Update of /cvsroot/scummvm/scummvm/graphics
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19096
Modified Files:
font.cpp
Log Message:
Fix word wrapping: do not generate spaces at the start/end of the wrapped lines
Index: font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/graphics/font.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- font.cpp 15 May 2005 16:13:52 -0000 1.10
+++ font.cpp 17 May 2005 23:14:13 -0000 1.11
@@ -197,6 +197,7 @@
for (Common::String::const_iterator x = str.begin(); x != str.end(); ++x) {
const char c = *x;
const int w = getCharWidth(c);
+ const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth);
// If this char is a whitespace, then it represents a potential
// 'wrap point' where wrapping could take place. Everything that
@@ -208,22 +209,28 @@
tmpStr.clear();
tmpWidth = 0;
- }
- // If we encounter a line break (\n), the line is complete.
- if (c == '\n') {
- wrapper.add(line, lineWidth);
- continue;
+ // If we encounter a line break (\n), or if the new space would
+ // cause the line to overflow: start a new line
+ if (c == '\n' || wouldExceedWidth) {
+ wrapper.add(line, lineWidth);
+ continue;
+ }
}
// If the max line width would be exceeded by adding this char,
// insert a line break.
- if (lineWidth + tmpWidth + w > maxWidth) {
+ if (wouldExceedWidth) {
// Commit what we have so far, *if* we have anything.
// If line is empty, then we are looking at a word
// which exceeds the maximum line width.
if (lineWidth > 0) {
wrapper.add(line, lineWidth);
+ // Trim left side
+ while (tmpStr.size() && isspace(tmpStr[0])) {
+ tmpWidth -= getCharWidth(tmpStr[0]);
+ tmpStr.deleteChar(0);
+ }
} else {
wrapper.add(tmpStr, tmpWidth);
}
More information about the Scummvm-git-logs
mailing list