[Scummvm-git-logs] scummvm master -> 558167eaa2f3c7a260e02235d2fb54c71d626585

sev- noreply at scummvm.org
Mon Apr 1 16:21:32 UTC 2024


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

Summary:
558167eaa2 MACGUI WAGE: Handle \n in end of string case


Commit: 558167eaa2f3c7a260e02235d2fb54c71d626585
    https://github.com/scummvm/scummvm/commit/558167eaa2f3c7a260e02235d2fb54c71d626585
Author: hecmar007 (hecbr at hotmail.es)
Date: 2024-04-01T18:21:24+02:00

Commit Message:
MACGUI WAGE: Handle \n in end of string case

Add logic to correctly add new line when a \n is present at the end of a string.

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


diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 3e7f843ad5e..35701aadd9c 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -82,8 +82,6 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 
 	chunk->getFont()->wordWrapText(str, maxWidth, text, lineContinuations, w);
 
-	warning("Current line: %d, and localLineCount size is: %d", curLine, lineContinuations.size());
-
 	if (text.size() == 0) {
 		warning("chopChunk: too narrow width, >%d", maxWidth);
 		chunk->text += str;
@@ -95,6 +93,7 @@ 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];
 	_text[curLine].wordContinuation = lineContinuations[0];
 
@@ -243,6 +242,9 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 	int firstLineIndent = 0;
 	bool inTable = false;
 
+
+	bool lineBreakOnLineEnd = false;
+
 	while (*s) {
 		firstLineIndent = 0;
 
@@ -257,9 +259,14 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 			while (*s && *s != '\001') {
 				if (*s == '\r') {
 					s++;
-					if (*s == '\n')	// Skip whole '\r\n'
+
+					if (*s == '\n') { // Skip whole '\r\n'
 						s++;
 
+						if (!*s)
+							lineBreakOnLineEnd = true;
+					}
+
 					endOfLine = true;
 
 					break;
@@ -270,6 +277,10 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 					s++;
 
 					endOfLine = true;
+
+					if (!*s)
+						lineBreakOnLineEnd = true;
+
 					break;
 				}
 
@@ -566,11 +577,12 @@ const Common::U32String::value_type *MacTextCanvas::splitString(const Common::U3
 			curTextLine->chunks.push_back(_defaultFormatting);
 		}
 
-		if (*s) {
+		if (*s || lineBreakOnLineEnd) {
 			// Add new line
 			D(9, "** splitString: new line");
 
 			curLine++;
+
 			_text.insert_at(curLine, MacTextLine());
 			_text[curLine].chunks.push_back(chunk);
 
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index ec2b97c9dab..f6903c45950 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -755,6 +755,8 @@ void MacText::appendText(const Common::U32String &str, const Font *font, uint16
 }
 
 void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
+	clearChunkInput();
+
 	_canvas.splitString(strWithFont, -1, _defaultFormatting);
 	recalcDims();
 
@@ -791,6 +793,17 @@ void MacText::appendTextDefault(const Common::String &str, bool skipAdd) {
 	appendTextDefault(Common::U32String(str), skipAdd);
 }
 
+void MacText::clearChunkInput() {
+	int canvasTextSize = _canvas._text.size() - 1;
+
+	if (canvasTextSize >= 0 && _editable) {
+		int lastChunkIdx = _canvas._text[canvasTextSize].chunks.size() - 1;
+
+		if (lastChunkIdx >= 0)
+			_canvas._text[canvasTextSize].chunks[lastChunkIdx].text = "";
+	}
+}
+
 void MacText::clearText() {
 	_contentIsDirty = true;
 	_canvas._text.clear();
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 1e0dfb2c545..b87f038d7a9 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -198,6 +198,11 @@ private:
 	void startMarking(int x, int y);
 	void updateTextSelection(int x, int y);
 
+	/**
+	 * Clears the text of the last chunk.
+	 */
+	void clearChunkInput();
+
 public:
 	int _cursorX, _cursorY;
 	bool _cursorState;




More information about the Scummvm-git-logs mailing list