[Scummvm-git-logs] scummvm master -> 3c8be58fbc4ff85fb1284dace7994d998f1ea145

sev- noreply at scummvm.org
Fri Apr 25 10:32:57 UTC 2025


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

Summary:
65d49792e4 MACGUI: Improve chunk handling and add inline documentation in mactext-canvas.cpp
da1b772ca9 MACGUI: Null pointer and empty chunks tests in mactext , change cursor restoration issue in getmaxwidth.
aec6e60066 JANITORIAL: Remove excessive vertical whitespaces
6b7e566818 JANITORIAL: Cleaned up mactext-canvas
3c8be58fbc JANITORIAL: Fix comment indentation


Commit: 65d49792e4f148fbe47b4e7fab45d36d2d275265
    https://github.com/scummvm/scummvm/commit/65d49792e4f148fbe47b4e7fab45d36d2d275265
Author: dasbidyendu (143386290+dasbidyendu at users.noreply.github.com)
Date: 2025-04-25T18:32:49+08:00

Commit Message:
MACGUI: Improve chunk handling and add inline documentation in mactext-canvas.cpp

Added some checks to make sure The line continuations are not empty before adding them to the current line's word continuation to ensure consistency.

Also added some comments on previous code.

Made sure to append the chunks if it is within bounds.

Added the newChunk as a pointer to the current chunk.

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 0cab7992e3a..604e2e9050a 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -68,6 +68,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		return;
 	}
 
+	 // If maxWidth is not restricted (-1 means possibly invalid width), just append and return
 	if (maxWidth == -1) {
 		chunk->text += str;
 
@@ -80,22 +81,42 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	int w = getLineWidth(curLine, true);
 	D(9, "** chopChunk before wrap \"%s\"", Common::toPrintable(str.encode()).c_str());
 
+	
 	chunk->getFont()->wordWrapText(str, maxWidth, text, lineContinuations, w);
 
-	if (text.size() == 0) {
+	for (int i = 0; i < (int)text.size(); i++) {
+
+		D(9, "Line Continuations [%d] : %d", i, lineContinuations[i]);
+
+	}
+
+	if (text.empty()) {
 		D(5, "chopChunk: too narrow width, >%d", maxWidth);
-		chunk->text += str;
+
+		if (w < maxWidth) {
+			chunk->text += str;	//Only append if within bounds
+		}
+		
 		getLineCharWidth(curLine, true);
 
 		return;
 	}
 
 	for (int i = 0; i < (int)text.size(); i++) {
+
 		D(9, "** chopChunk result %d \"%s\"", i, toPrintable(text[i].encode()).c_str());
+
 	}
 
 	chunk->text += text[0];
-	_text[curLine].wordContinuation = lineContinuations[0];
+
+	//Ensure line continuations is valid before accesing index 0
+	if (!lineContinuations.empty()) {
+
+		_text[curLine].wordContinuation = lineContinuations[0];
+
+	}
+	
 
 	// Recalc dims
 	getLineWidth(curLine, true);
@@ -107,7 +128,9 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		return;
 
 	// Now add rest of the chunks
-	MacFontRun newchunk = _text[curLine].chunks[curChunk];
+	MacFontRun newchunk = *chunk;
+	
+
 
 	for (uint i = 1; i < text.size(); i++) {
 		newchunk.text = text[i];
@@ -119,6 +142,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		_text[curLine].firstLineIndent = 0;
 		_text[curLine].wordContinuation = lineContinuations[i];
 
+
 		D(9, "** chopChunk, added line (firstIndent: %d): \"%s\"", _text[curLine].firstLineIndent, toPrintable(text[i].encode()).c_str());
 	}
 


Commit: da1b772ca91b887004ac66e35d52f96c1313d881
    https://github.com/scummvm/scummvm/commit/da1b772ca91b887004ac66e35d52f96c1313d881
Author: dasbidyendu (143386290+dasbidyendu at users.noreply.github.com)
Date: 2025-04-25T18:32:49+08:00

Commit Message:
MACGUI: Null pointer and empty chunks tests in mactext , change cursor restoration issue in getmaxwidth.

- Check for null pointer before handling any operations in getChunkNum function.
- Check for empty chunks to avoid extra operations.
- avoid signed/unsigned issue in chunk position.
- avoid possible overflow in cursor restoration logic

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 604e2e9050a..8ead027cbca 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -81,7 +81,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	int w = getLineWidth(curLine, true);
 	D(9, "** chopChunk before wrap \"%s\"", Common::toPrintable(str.encode()).c_str());
 
-	
 	chunk->getFont()->wordWrapText(str, maxWidth, text, lineContinuations, w);
 
 	for (int i = 0; i < (int)text.size(); i++) {
@@ -142,7 +141,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		_text[curLine].firstLineIndent = 0;
 		_text[curLine].wordContinuation = lineContinuations[i];
 
-
 		D(9, "** chopChunk, added line (firstIndent: %d): \"%s\"", _text[curLine].firstLineIndent, toPrintable(text[i].encode()).c_str());
 	}
 
@@ -763,6 +761,10 @@ void MacTextCanvas::render(int from, int to) {
 }
 
 int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
+	if (str.empty()) 
+		return 0;
+	
+
 	if (format.plainByteMode()) {
 		Common::StringTokenizer tok(Common::convertFromU32String(str, format.getEncoding()));
 		int maxW = 0;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 33bd9cb7e15..d2539560275 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -83,9 +83,17 @@ Common::String MacFontRun::getEncodedText() {
 }
 
 uint MacTextLine::getChunkNum(int *col) {
+	if (!col)
+		return 0;
+
 	int pos = *col;
 	uint i;
 
+	if (chunks.empty()) {
+		*col = 0;
+		return 0;
+	}
+
 	for (i = 0; i < chunks.size(); i++) {
 		if (pos >= (int)chunks[i].text.size()) {
 			pos -= chunks[i].text.size();
@@ -99,6 +107,9 @@ uint MacTextLine::getChunkNum(int *col) {
 		pos = chunks[i].text.size();
 	}
 
+	if (pos < 0)
+		pos = 0;
+
 	*col = pos;
 
 	return i;
@@ -358,24 +369,31 @@ void MacText::setMaxWidth(int maxWidth) {
 		}
 	}
 
-	// keep the cursor pos
-	int ppos = 0;
-	for (int i = 0; i < _cursorRow; i++)
-		ppos += _canvas.getLineCharWidth(i);
-	ppos += _cursorCol;
+	int absoluteCharOffset = 0;
+	for (int i = 0; i < _cursorRow; ++i)
+		absoluteCharOffset += _canvas.getLineCharWidth(i);
+	absoluteCharOffset += _cursorCol;
 
+	
 	_canvas.setMaxWidth(maxWidth, _defaultFormatting);
 
 	// restore the cursor pos
 	_cursorRow = 0;
-	while (ppos > _canvas.getLineCharWidth(_cursorRow, true)) {
-		ppos -= _canvas.getLineCharWidth(_cursorRow, true);
-
-		if (_cursorRow >= (int)_canvas._text.size() - 1)
+	while (_cursorRow < (int)_canvas._text.size() - 1) {
+		int lineWidth = _canvas.getLineCharWidth(_cursorRow, true);
+		if (absoluteCharOffset <= lineWidth)
 			break;
 
-		_cursorRow++;
+		absoluteCharOffset -= lineWidth;
+		++_cursorRow;
 	}
+	
+	int ppos = 0;
+	if (absoluteCharOffset > _canvas.getLineCharWidth(_cursorRow, true))
+		ppos = _canvas.getLineCharWidth(_cursorRow, true);
+	else
+		ppos = absoluteCharOffset;
+
 	_cursorCol = ppos;
 
 	// after we set maxWidth, we reset the selection


Commit: aec6e600668dbd3c5d7d42d31f42df532982faa3
    https://github.com/scummvm/scummvm/commit/aec6e600668dbd3c5d7d42d31f42df532982faa3
Author: dasbidyendu (143386290+dasbidyendu at users.noreply.github.com)
Date: 2025-04-25T18:32:49+08:00

Commit Message:
JANITORIAL: Remove excessive vertical whitespaces

Remove unnecessary vertical whitespaces from code.

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 8ead027cbca..b1ac8ecee60 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -115,7 +115,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		_text[curLine].wordContinuation = lineContinuations[0];
 
 	}
-	
 
 	// Recalc dims
 	getLineWidth(curLine, true);
@@ -129,8 +128,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	// Now add rest of the chunks
 	MacFontRun newchunk = *chunk;
 	
-
-
 	for (uint i = 1; i < text.size(); i++) {
 		newchunk.text = text[i];
 
@@ -264,7 +261,6 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 	int firstLineIndent = 0;
 	bool inTable = false;
 
-
 	bool lineBreakOnLineEnd = false;
 
 	while (*s) {
@@ -951,7 +947,6 @@ int MacTextCanvas::getLineWidth(int lineNum, bool enforce, int col) {
 		height = MAX(height, line->chunks[i].getFont()->getFontHeight());
 	}
 
-
 	line->width = width;
 	line->minWidth = minWidth;
 	line->height = height;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index d2539560275..05f2664b7f6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -109,7 +109,6 @@ uint MacTextLine::getChunkNum(int *col) {
 
 	if (pos < 0)
 		pos = 0;
-
 	*col = pos;
 
 	return i;
@@ -373,8 +372,6 @@ void MacText::setMaxWidth(int maxWidth) {
 	for (int i = 0; i < _cursorRow; ++i)
 		absoluteCharOffset += _canvas.getLineCharWidth(i);
 	absoluteCharOffset += _cursorCol;
-
-	
 	_canvas.setMaxWidth(maxWidth, _defaultFormatting);
 
 	// restore the cursor pos


Commit: 6b7e56681809375d89d882580bf24c22ba1ff9c2
    https://github.com/scummvm/scummvm/commit/6b7e56681809375d89d882580bf24c22ba1ff9c2
Author: dasbidyendu (143386290+dasbidyendu at users.noreply.github.com)
Date: 2025-04-25T18:32:49+08:00

Commit Message:
JANITORIAL: Cleaned up mactext-canvas

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index b1ac8ecee60..efa80284bbf 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -84,9 +84,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	chunk->getFont()->wordWrapText(str, maxWidth, text, lineContinuations, w);
 
 	for (int i = 0; i < (int)text.size(); i++) {
-
 		D(9, "Line Continuations [%d] : %d", i, lineContinuations[i]);
-
 	}
 
 	if (text.empty()) {
@@ -102,18 +100,14 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	}
 
 	for (int i = 0; i < (int)text.size(); i++) {
-
 		D(9, "** chopChunk result %d \"%s\"", i, toPrintable(text[i].encode()).c_str());
-
 	}
 
 	chunk->text += text[0];
 
 	//Ensure line continuations is valid before accesing index 0
 	if (!lineContinuations.empty()) {
-
 		_text[curLine].wordContinuation = lineContinuations[0];
-
 	}
 
 	// Recalc dims
@@ -127,7 +121,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 
 	// Now add rest of the chunks
 	MacFontRun newchunk = *chunk;
-	
 	for (uint i = 1; i < text.size(); i++) {
 		newchunk.text = text[i];
 
@@ -760,7 +753,6 @@ int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
 	if (str.empty()) 
 		return 0;
 	
-
 	if (format.plainByteMode()) {
 		Common::StringTokenizer tok(Common::convertFromU32String(str, format.getEncoding()));
 		int maxW = 0;


Commit: 3c8be58fbc4ff85fb1284dace7994d998f1ea145
    https://github.com/scummvm/scummvm/commit/3c8be58fbc4ff85fb1284dace7994d998f1ea145
Author: dasbidyendu (143386290+dasbidyendu at users.noreply.github.com)
Date: 2025-04-25T18:32:49+08:00

Commit Message:
JANITORIAL: Fix comment indentation

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index efa80284bbf..e2db3499cde 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -68,7 +68,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		return;
 	}
 
-	 // If maxWidth is not restricted (-1 means possibly invalid width), just append and return
+	// If maxWidth is not restricted (-1 means possibly invalid width), just append and return
 	if (maxWidth == -1) {
 		chunk->text += str;
 
@@ -91,7 +91,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		D(5, "chopChunk: too narrow width, >%d", maxWidth);
 
 		if (w < maxWidth) {
-			chunk->text += str;	//Only append if within bounds
+			chunk->text += str;	// Only append if within bounds
 		}
 		
 		getLineCharWidth(curLine, true);
@@ -105,7 +105,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 
 	chunk->text += text[0];
 
-	//Ensure line continuations is valid before accesing index 0
+	// Ensure line continuations is valid before accesing index 0
 	if (!lineContinuations.empty()) {
 		_text[curLine].wordContinuation = lineContinuations[0];
 	}




More information about the Scummvm-git-logs mailing list