[Scummvm-cvs-logs] CVS: scummvm/scumm/smush smush_font.cpp,1.12,1.13 smush_font.h,1.7,1.8 smush_player.cpp,1.27,1.28

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Mon Jun 9 05:25:02 CEST 2003


Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1:/tmp/cvs-serv27838

Modified Files:
	smush_font.cpp smush_font.h smush_player.cpp 
Log Message:
Fixed text-positioning regressions in the Full Throttle intro and in The
Dig's "Spacetime Six" movie.

Also rewrote drawStringCentered() to be more like drawStringAbsolute(). It
makes sense to me, but let me know if it causes any new regressions.


Index: smush_font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- smush_font.cpp	8 Jun 2003 00:39:08 -0000	1.12
+++ smush_font.cpp	9 Jun 2003 12:24:04 -0000	1.13
@@ -137,6 +137,12 @@
 }
 
 void SmushFont::drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y) {
+	// This happens in the Full Throttle intro. I don't know if our
+	// text-drawing functions are buggy, or if this function is supposed
+	// to have to check for it.
+	if (x < 0)
+		x = 0;
+
 	for (int i = 0; str[i] != 0; i++) {
 		if ((byte)str[i] >= 0x80 && _vm->_CJKMode) {
 			x += draw2byte(buffer, dst_width, x, y, (byte)str[i] + 256 * (byte)str[i+1]);
@@ -168,69 +174,23 @@
 	}
 }
 
-void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
-	debug(9, "SmushFont::drawStringCentered(%s, %d, %d, %d, %d)", str, x, y, left, right);
-
-	const int width = right - left;
-	char *s = strdup(str);
-	char *words[MAX_WORDS];
-	int word_count = 0;
-
-	char *tmp = s;
-	while (tmp) {
-		assert(word_count < MAX_WORDS);
-		words[word_count++] = tmp;
-		tmp = strpbrk(tmp, " \t\r\n");
-		if (tmp == 0)
-			break;
-		*tmp++ = 0;
-	}
-
-	int i = 0, max_width = 0, height = 0, line_count = 0;
-
-	char *substrings[MAX_WORDS];
-	int substr_widths[MAX_WORDS];
-	const int space_width = getCharWidth(' ');
-
-	i = 0;
-	while (i < word_count) {
-		char *substr = words[i++];
-		int substr_width = getStringWidth(substr);
+void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y) {
+	debug(9, "SmushFont::drawStringCentered(%s, %d, %d)", str, x, y);
 
-		while (i < word_count) {
-			int word_width = getStringWidth(words[i]);
-			if ((substr_width + space_width + word_width) >= width)
-				break;
-			substr_width += word_width + space_width;
-			*(words[i]-1) = ' ';	// Convert 0 byte back to space
-			i++;
+	while (str) {
+		char line[256];
+		char *pos = strchr(str, '\n');
+		if (pos) {
+			memcpy(line, str, pos - str - 1);
+			line[pos - str - 1] = 0;
+			str = pos + 1;
+		} else {
+			strcpy(line, str);
+			str = 0;
 		}
-
-		substrings[line_count] = substr;
-		substr_widths[line_count++] = substr_width;
-		if (max_width < substr_width)
-			max_width = substr_width;
-		height += getStringHeight(substr);
-	}
-
-	if (y > dst_height - height) {
-		y = dst_height - height;
-	}
-
-	max_width = (max_width + 1) >> 1;
-	x = left + width / 2;
-
-	if (x < left + max_width)
-		x = left + max_width;
-	if (x > right - max_width)
-		x = right - max_width;
-
-	for (i = 0; i < line_count; i++) {
-		drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
-		y += getStringHeight(substrings[i]);
+		drawSubstring(line, buffer, dst_width, x - getStringWidth(line) / 2, y);
+		y += getStringHeight(line);
 	}
-	
-	free(s);
 }
 
 void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {

Index: smush_font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- smush_font.h	8 Jun 2003 00:39:08 -0000	1.7
+++ smush_font.h	9 Jun 2003 12:24:04 -0000	1.8
@@ -44,7 +44,7 @@
 
 	void setColor(byte c) { _color = c; }
 	void drawStringAbsolute    (const char *str, byte *buffer, int dst_width, int x, int y);
-	void drawStringCentered    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
+	void drawStringCentered    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y);
 	void drawStringWrap        (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
 	void drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
 };

Index: smush_player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- smush_player.cpp	9 Jun 2003 01:32:36 -0000	1.27
+++ smush_player.cpp	9 Jun 2003 12:24:05 -0000	1.28
@@ -561,13 +561,25 @@
 			sf->drawStringAbsolute(str, _data, _width, pos_x, pos_y);
 			break;
 		case 1:
-			sf->drawStringCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
+			sf->drawStringCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top));
 			break;
 		case 8:
+			// FIXME: Is 'right' the maximum line width here, just
+			// as it is in the next case? It's used several times
+			// in The Dig's intro, where 'left' and 'right' are
+			// always 0 and 321 respectively. Someone will have to
+			// compare it to the original to see if we draw them
+			// correctly.
 			sf->drawStringWrap(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
 			break;
 		case 9:
-			sf->drawStringWrapCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
+			// In this case, the 'right' parameter is actually the
+			// maximum line width. This explains why it's sometimes
+			// smaller than 'left'.
+			//
+			// Note that in The Dig's "Spacetime Six" movie it's
+			// 621. I have no idea what that means.
+			sf->drawStringWrapCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width));
 			break;
 		default:
 			warning("SmushPlayer::handleTextResource. Not handled flags: %d", flags);





More information about the Scummvm-git-logs mailing list