[Scummvm-git-logs] scummvm master -> 83a4a6002a9ec3bd1bdaa152ad4d205624dee147

sev- noreply at scummvm.org
Thu Oct 26 01:40:38 UTC 2023


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
68e6f3a8ef GRAPHICS: MACGUI: Rewrote reshuffleParagraph() in MacTextCanvas to use chunks
33c2fcfbf2 GRAPHCIS: MACGUI: Added debug printing methods to MacTextCanvas
58f05eeb24 GRAPHICS: MACGUI: Added more debug output to MacTextCanvas
83a4a6002a GRAPHICS: MACGUI: Fix text reshuffling in MacTextCanvas


Commit: 68e6f3a8efbbfc9cdd0bc2b8e1aa61b6298fc375
    https://github.com/scummvm/scummvm/commit/68e6f3a8efbbfc9cdd0bc2b8e1aa61b6298fc375
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-26T03:39:49+02:00

Commit Message:
GRAPHICS: MACGUI: Rewrote reshuffleParagraph() in MacTextCanvas to use chunks

Changed paths:
    graphics/macgui/mactext-canvas.cpp
    graphics/macgui/mactext-canvas.h


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 77e94891ea2..e91071c3437 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -907,10 +907,12 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 	// First, we looking for the paragraph start and end
 	int start = *row, end = *row;
 
-	while (start && !_text[start - 1].paragraphEnd)
+	// Since one previous line could be affected, compute it
+	if (start && !_text[start - 1].paragraphEnd)
 		start--;
 
-	while (end < (int)_text.size() - 1 && !_text[end].paragraphEnd) // stop at last line
+	// Find end of the paragraph
+	while (end < (int)_text.size() - 1 && !_text[end].paragraphEnd)
 		end++;
 
 	// Get character pos within paragraph
@@ -921,24 +923,53 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 
 	ppos += *col;
 
-	// Get whole paragraph
-	Common::U32String paragraph = getTextChunk(start, 0, end, getLineCharWidth(end, true), true, true);
+	// Assemble all chunks to chop, combining the matching ones
+	Common::Array<MacFontRun> chunks;
 
-	// Remove it from the text
+	for (int i = 0; i < end; i++) {
+		for (auto &ch : _text[i].chunks) {
+			if (!chunks.size()) {
+				chunks.push_back(ch);
+			} else {
+				if (chunks.back().equals(ch))
+					chunks.back().text += ch.text;
+				else
+					chunks.push_back(ch);
+			}
+		}
+	}
+
+	int curLine = start;
+	int indent = _text[curLine].indent;
+	int firstLineIndent = _text[curLine].firstLineIndent;
+
+	// Remove paragraph from the text
 	for (int i = start; i <= end; i++) {
 		_text.remove_at(start);
 	}
 
 	// And now read it
 	D(9, "start %d end %d", start, end);
-	splitString(paragraph, start, defaultFormatting);
+
+	_text.insert_at(curLine, MacTextLine());
+	_text[curLine].indent = indent;
+	_text[curLine].firstLineIndent = firstLineIndent;
+
+	for (auto &ch : chunks) {
+		_text[curLine].chunks.push_back(ch);
+		_text[curLine].chunks.back().text.clear(); // We wil add it later
+		chopChunk(ch.text, &curLine, indent, _maxWidth);
+	}
 
 	// Find new pos within paragraph after reshuffling
 	*row = start;
 
-	warning("FIXME, bad design");
 	while (ppos > getLineCharWidth(*row, true)) {
 		ppos -= getLineCharWidth(*row, true);
+
+		if (*row == _text.size() - 1)
+			break;
+
 		(*row)++;
 	}
 	*col = ppos;
diff --git a/graphics/macgui/mactext-canvas.h b/graphics/macgui/mactext-canvas.h
index 89dfdfd727e..2e0470c53d7 100644
--- a/graphics/macgui/mactext-canvas.h
+++ b/graphics/macgui/mactext-canvas.h
@@ -97,14 +97,14 @@ struct MacFontRun {
 	bool plainByteMode();
 	Common::String getEncodedText();
 
-	bool equals(const MacFontRun *x, const MacFontRun *y) {
-		return (x->fontId    == y->fontId &&
-				x->textSlant == y->textSlant &&
-				x->fontSize  == y->fontSize &&
-				x->palinfo1  == y->palinfo1 &&
-				x->palinfo2  == y->palinfo2 &&
-				x->palinfo3  == y->palinfo3 &&
-				x->fgcolor   == y->fgcolor);
+	bool equals(const MacFontRun *y) {
+		return (fontId    == y->fontId &&
+				textSlant == y->textSlant &&
+				fontSize  == y->fontSize &&
+				palinfo1  == y->palinfo1 &&
+				palinfo2  == y->palinfo2 &&
+				palinfo3  == y->palinfo3 &&
+				fgcolor   == y->fgcolor);
 	}
 
 };


Commit: 33c2fcfbf20d67ccbbb037f081562e194b523155
    https://github.com/scummvm/scummvm/commit/33c2fcfbf20d67ccbbb037f081562e194b523155
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-26T03:39:49+02:00

Commit Message:
GRAPHCIS: MACGUI: Added debug printing methods to MacTextCanvas

Changed paths:
    graphics/macgui/mactext-canvas.cpp
    graphics/macgui/mactext-canvas.h


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index e91071c3437..deabd4ac6af 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -469,15 +469,7 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 	}
 
 #if DEBUG
-	for (uint i = 0; i < _text.size(); i++) {
-		debugN(9, "** splitString: %2d ", i);
-
-		for (uint j = 0; j < _text[i].chunks.size(); j++)
-			debugN(9, "[%d] \"%s\"", _text[i].chunks[j].text.size(), Common::toPrintable(_text[i].chunks[j].text.encode()).c_str());
-
-		debugN(9, "\n");
-	}
-	debug(9, "** splitString: done");
+	debugPrint("** splitString");
 #endif
 
 	return s;
@@ -622,9 +614,9 @@ void MacTextCanvas::render(int from, int to) {
 		debugN(9, "MacTextCanvas::render: %2d (firstInd: %d indent: %d) ", i, _text[i].firstLineIndent, _text[i].indent);
 
 		for (uint j = 0; j < _text[i].chunks.size(); j++)
-			debugN(9, "[%d (%d)] \"%s\" ", _text[i].chunks[j].fontId, _text[i].chunks[j].textSlant, _text[i].chunks[j].text.encode().c_str());
+			_text[i].chunks[j].debugPrint();
 
-		debug(9, "%s", "");
+		debug(9, "");
 	}
 }
 
@@ -1129,4 +1121,25 @@ void MacTextCanvas::processTable(int line, int maxWidth) {
 	}
 }
 
+void MacFontRun::debugPrint() {
+	debugN("{%d}[%d (%d)] \"%s\" ", fontId, textSlant, text.size(), Common::toPrintable(text.encode()).c_str());
+}
+
+void MacTextCanvas::debugPrint(const char *prefix) {
+	for (uint i = 0; i < _text.size(); i++) {
+		if (prefix)
+			debugN("%s: ", prefix);
+		debugN("%2d ", i);
+
+		for (uint j = 0; j < _text[i].chunks.size(); j++)
+			_text[i].chunks[j].debugPrint();
+
+		debugN("\n");
+	}
+
+	if (prefix)
+		debugN("%s: ", prefix);
+	debug("[done]");
+}
+
 } // End of namespace Graphics
diff --git a/graphics/macgui/mactext-canvas.h b/graphics/macgui/mactext-canvas.h
index 2e0470c53d7..86be583baa7 100644
--- a/graphics/macgui/mactext-canvas.h
+++ b/graphics/macgui/mactext-canvas.h
@@ -107,6 +107,7 @@ struct MacFontRun {
 				fgcolor   == y->fgcolor);
 	}
 
+	void debugPrint();
 };
 
 struct MacTextLine;
@@ -167,6 +168,8 @@ public:
 	void reshuffleParagraph(int *row, int *col, MacFontRun &defaultFormatting);
 
 	void processTable(int line, int maxWidth);
+
+	void debugPrint(const char *prefix = nullptr);
 };
 
 struct MacTextTableRow {


Commit: 58f05eeb2440cf1780f75997f0cc5245fd8936e1
    https://github.com/scummvm/scummvm/commit/58f05eeb2440cf1780f75997f0cc5245fd8936e1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-26T03:39:49+02:00

Commit Message:
GRAPHICS: MACGUI: Added more debug output to MacTextCanvas

Changed paths:
    graphics/macgui/mactext-canvas.cpp


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index deabd4ac6af..890f35f9bc4 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -610,14 +610,7 @@ void MacTextCanvas::render(int from, int to) {
 
 	render(from, to, 0);
 
-	for (uint i = 0; i < _text.size(); i++) {
-		debugN(9, "MacTextCanvas::render: %2d (firstInd: %d indent: %d) ", i, _text[i].firstLineIndent, _text[i].indent);
-
-		for (uint j = 0; j < _text[i].chunks.size(); j++)
-			_text[i].chunks[j].debugPrint();
-
-		debug(9, "");
-	}
+	debugPrint("MacTextCanvas::render");
 }
 
 int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
@@ -915,6 +908,10 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 
 	ppos += *col;
 
+#if DEBUG
+	debugPrint("MacTextCanvas::reshuffleParagraph(1)");
+#endif
+
 	// Assemble all chunks to chop, combining the matching ones
 	Common::Array<MacFontRun> chunks;
 
@@ -931,6 +928,14 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 		}
 	}
 
+#if DEBUG
+	debugN(9, "Chunks: ");
+	for (auto &ch : chunks)
+		ch.debugPrint();
+
+	debug(9, "");
+#endif
+
 	int curLine = start;
 	int indent = _text[curLine].indent;
 	int firstLineIndent = _text[curLine].firstLineIndent;
@@ -940,6 +945,10 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 		_text.remove_at(start);
 	}
 
+#if DEBUG
+	debugPrint("MacTextCanvas::reshuffleParagraph(2)");
+#endif
+
 	// And now read it
 	D(9, "start %d end %d", start, end);
 
@@ -953,6 +962,10 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 		chopChunk(ch.text, &curLine, indent, _maxWidth);
 	}
 
+#if DEBUG
+	debugPrint("MacTextCanvas::reshuffleParagraph(3)");
+#endif
+
 	// Find new pos within paragraph after reshuffling
 	*row = start;
 
@@ -1122,14 +1135,14 @@ void MacTextCanvas::processTable(int line, int maxWidth) {
 }
 
 void MacFontRun::debugPrint() {
-	debugN("{%d}[%d (%d)] \"%s\" ", fontId, textSlant, text.size(), Common::toPrintable(text.encode()).c_str());
+	debugN("{%d}[%d (%d)] \"%s\" ", text.size(), fontId, textSlant, Common::toPrintable(text.encode()).c_str());
 }
 
 void MacTextCanvas::debugPrint(const char *prefix) {
 	for (uint i = 0; i < _text.size(); i++) {
 		if (prefix)
 			debugN("%s: ", prefix);
-		debugN("%2d ", i);
+		debugN("%2d, %c fi: %d, i: %d ", i, _text[i].paragraphEnd ? '$' : '.', _text[i].firstLineIndent, _text[i].indent);
 
 		for (uint j = 0; j < _text[i].chunks.size(); j++)
 			_text[i].chunks[j].debugPrint();


Commit: 83a4a6002a9ec3bd1bdaa152ad4d205624dee147
    https://github.com/scummvm/scummvm/commit/83a4a6002a9ec3bd1bdaa152ad4d205624dee147
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-10-26T03:39:49+02:00

Commit Message:
GRAPHICS: MACGUI: Fix text reshuffling in MacTextCanvas

Changed paths:
    graphics/macgui/mactext-canvas.cpp
    graphics/macgui/mactext-canvas.h


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 890f35f9bc4..3bda2a4f019 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -909,13 +909,14 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 	ppos += *col;
 
 #if DEBUG
+	D(9, "MacTextCanvas::reshuffleParagraph: ppos: %d", ppos);
 	debugPrint("MacTextCanvas::reshuffleParagraph(1)");
 #endif
 
 	// Assemble all chunks to chop, combining the matching ones
 	Common::Array<MacFontRun> chunks;
 
-	for (int i = 0; i < end; i++) {
+	for (int i = start; i <= end; i++) {
 		for (auto &ch : _text[i].chunks) {
 			if (!chunks.size()) {
 				chunks.push_back(ch);
@@ -926,6 +927,9 @@ void MacTextCanvas::reshuffleParagraph(int *row, int *col, MacFontRun &defaultFo
 					chunks.push_back(ch);
 			}
 		}
+
+		if (i != end && !_text[i].wordContinuation)
+			chunks.back().text += ' ';
 	}
 
 #if DEBUG
diff --git a/graphics/macgui/mactext-canvas.h b/graphics/macgui/mactext-canvas.h
index 86be583baa7..898e18a6715 100644
--- a/graphics/macgui/mactext-canvas.h
+++ b/graphics/macgui/mactext-canvas.h
@@ -38,8 +38,7 @@ struct MacFontRun {
 	uint16 palinfo2;
 	uint16 palinfo3;
 	uint32 fgcolor;
-	// to determine whether the next word is part of this one
-	bool wordContinuation;
+	bool wordContinuation = false; // FIXME: Removing this leads to illegal memory access
 	const Font *font;
 	MacWindowManager *wm;
 	Common::String link;  // Substitute to return when hover or click
@@ -50,7 +49,6 @@ struct MacFontRun {
 		palinfo1 = palinfo2 = palinfo3 = 0;
 		fgcolor = 0;
 		font = nullptr;
-		wordContinuation = false;
 	}
 
 	MacFontRun(MacWindowManager *wm_) {
@@ -59,20 +57,17 @@ struct MacFontRun {
 		palinfo1 = palinfo2 = palinfo3 = 0;
 		fgcolor = 0;
 		font = nullptr;
-		wordContinuation = false;
 	}
 
 	MacFontRun(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
 			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
 		setValues(wm_, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
-		wordContinuation = false;
 	}
 
 	MacFontRun(MacWindowManager *wm_, const Font *font_, byte textSlant_, uint16 fontSize_,
 			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
 		setValues(wm_, 0, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
 		font = font_;
-		wordContinuation = false;
 	}
 
 	void setValues(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
@@ -184,6 +179,7 @@ struct MacTextLine {
 	int y = 0;
 	int charwidth = -1;
 	bool paragraphEnd = false;
+	bool wordContinuation = false;
 	int indent = 0; // in units
 	int firstLineIndent = 0; // in pixels
 	Common::String picfname;




More information about the Scummvm-git-logs mailing list