[Scummvm-git-logs] scummvm master -> c6c80b93135c270626a7dbb4950c6e75137e62b0

sev- noreply at scummvm.org
Wed Mar 13 16:39:27 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:
c6c80b9313 GRAPHICS: MACGUI: Process extra long words (#5703)


Commit: c6c80b93135c270626a7dbb4950c6e75137e62b0
    https://github.com/scummvm/scummvm/commit/c6c80b93135c270626a7dbb4950c6e75137e62b0
Author: hecmar007 (hecbr at hotmail.es)
Date: 2024-03-13T17:39:21+01:00

Commit Message:
GRAPHICS: MACGUI: Process extra long words (#5703)

GRAPHICS:  MACGUI: Process extra long words

Added functionality to rewrap words that split into different lines.

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


diff --git a/graphics/font.cpp b/graphics/font.cpp
index 96f018c8351..0668f1d35a9 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -139,32 +139,37 @@ void drawStringImpl(const Font &font, SurfaceType *dst, const StringType &str, i
 template<class StringType>
 struct WordWrapper {
 	Common::Array<StringType> &lines;
+	Common::Array<bool> &lineContinuation;
 	int actualMaxLineWidth;
 
-	WordWrapper(Common::Array<StringType> &l) : lines(l), actualMaxLineWidth(0) {
+	WordWrapper(Common::Array<StringType> &l, Common::Array<bool> &lC) : lines(l), lineContinuation(lC), actualMaxLineWidth(0) {
 	}
 
-	void add(StringType &line, int &w) {
+	void add(StringType &line, bool &wordContinuation, int &w) {
 		if (actualMaxLineWidth < w)
 			actualMaxLineWidth = w;
 
 		lines.push_back(line);
+		lineContinuation.push_back(wordContinuation);
 
 		line.clear();
+		wordContinuation = false;
 		w = 0;
 	}
 
 	void clear() {
 		lines.clear();
+		lineContinuation.clear();
 		actualMaxLineWidth = 0;
 	}
 };
 
 template<class StringType>
-int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Common::Array<StringType> &lines, int initWidth, uint32 mode) {
-	WordWrapper<StringType> wrapper(lines);
+int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Common::Array<StringType> &lines, Common::Array<bool> &lineContinuation, int initWidth, uint32 mode) {
+	WordWrapper<StringType> wrapper(lines, lineContinuation);
 	StringType line;
 	StringType tmpStr;
+	bool wordContinuation = false;
 	int lineWidth = initWidth;
 	int tmpWidth = 0;
 	int fullTextWidthEWL = initWidth; // this replaces new line characters (if any) with single spaces - it is used in Even Width Lines mode
@@ -276,7 +281,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 				// If we encounter a line break (\n), or if the new space would
 				// cause the line to overflow: start a new line
 				if (((mode & kWordWrapOnExplicitNewLines) && c == '\n') || wouldExceedWidth) {
-					wrapper.add(line, lineWidth);
+					wrapper.add(line, wordContinuation, lineWidth);
 					continue;
 				}
 			}
@@ -288,7 +293,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 				// If line is empty, then we are looking at a word
 				// which exceeds the maximum line width.
 				if (lineWidth > 0) {
-					wrapper.add(line, lineWidth);
+					wrapper.add(line, wordContinuation, lineWidth);
 					// Trim left side
 					while (tmpStr.size() && Common::isSpace(tmpStr[0])) {
 						tmpStr.deleteChar(0);
@@ -306,7 +311,8 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 						continue;
 					}
 				} else {
-					wrapper.add(tmpStr, tmpWidth);
+					wordContinuation = true;
+					wrapper.add(tmpStr, wordContinuation, tmpWidth);
 				}
 			}
 
@@ -318,7 +324,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 		line += tmpStr;
 		lineWidth += tmpWidth;
 		if (lineWidth > 0) {
-			wrapper.add(line, lineWidth);
+			wrapper.add(line, wordContinuation, lineWidth);
 		}
 	} while ((mode & kWordWrapEvenWidthLines)
 	         && (targetMaxLineWidth > maxWidth));
@@ -490,11 +496,17 @@ void Font::drawString(ManagedSurface *dst, const Common::U32String &str, int x,
 }
 
 int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth, uint32 mode) const {
-	return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, mode);
+	Common::Array<bool> dummyLineContinuation;
+	return wordWrapTextImpl(*this, str, maxWidth, lines, dummyLineContinuation, initWidth, mode);
 }
 
 int Font::wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth, uint32 mode) const {
-	return wordWrapTextImpl(*this, str, maxWidth, lines, initWidth, mode);
+	Common::Array<bool> dummyLineContinuation;
+	return wordWrapTextImpl(*this, str, maxWidth, lines, dummyLineContinuation, initWidth, mode);
+}
+
+int Font::wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, Common::Array<bool> &lineContinuation, int initWidth, uint32 mode) const {
+	return wordWrapTextImpl(*this, str, maxWidth, lines, lineContinuation, initWidth, mode);
 }
 
 TextAlign convertTextAlignH(TextAlign alignH, bool rtl) {
diff --git a/graphics/font.h b/graphics/font.h
index 87f1ca8cc48..e9697d85cf3 100644
--- a/graphics/font.h
+++ b/graphics/font.h
@@ -269,6 +269,15 @@ public:
 	int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
 	/** @overload */
 	int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
+	/**
+	 * @overload
+	 * Word-wrap a text, and returns in lineCountination a list of lines where a word has
+	 * been splitted into the next line.
+	 *
+	 * @param lineContinuation	Bool list. If the ith element of the list is true, then the ith
+	 * line in lines contains a splitted word.
+	 */
+	int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, Common::Array<bool> &lineContinuation, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
 
 	/**
 	 * Scales the single gylph at @p chr the given the @p scale and the pointer @p grayScaleMap to the grayscale array. It fills @p scaleSurface surface 
diff --git a/graphics/macgui/mactext-canvas.cpp b/graphics/macgui/mactext-canvas.cpp
index 27ebff61ac4..3e7f843ad5e 100644
--- a/graphics/macgui/mactext-canvas.cpp
+++ b/graphics/macgui/mactext-canvas.cpp
@@ -75,11 +75,14 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 	}
 
 	Common::Array<Common::U32String> text;
+	Common::Array<bool> lineContinuations;
 
 	int w = getLineWidth(curLine, true);
 	D(9, "** chopChunk before wrap \"%s\"", Common::toPrintable(str.encode()).c_str());
 
-	chunk->getFont()->wordWrapText(str, maxWidth, text, w);
+	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);
@@ -93,6 +96,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		D(9, "** chopChunk result %d \"%s\"", i, toPrintable(text[i].encode()).c_str());
 	}
 	chunk->text += text[0];
+	_text[curLine].wordContinuation = lineContinuations[0];
 
 	// Recalc dims
 	getLineWidth(curLine, true);
@@ -114,6 +118,7 @@ void MacTextCanvas::chopChunk(const Common::U32String &str, int *curLinePtr, int
 		_text[curLine].chunks.push_back(newchunk);
 		_text[curLine].indent = indent;
 		_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());
 	}




More information about the Scummvm-git-logs mailing list