[Scummvm-git-logs] scummvm master -> 8bc2db262fa15ca01ba30fbf9344efc9e056ec20

bluegr noreply at scummvm.org
Sat Oct 26 07:08:58 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:
8bc2db262f GRAPHICS: Add wrapping mode that ignores trailing space


Commit: 8bc2db262fa15ca01ba30fbf9344efc9e056ec20
    https://github.com/scummvm/scummvm/commit/8bc2db262fa15ca01ba30fbf9344efc9e056ec20
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2024-10-26T10:08:56+03:00

Commit Message:
GRAPHICS: Add wrapping mode that ignores trailing space

The DGDS engine word wrapping algorithm appends any amount of whitepsace on the
end of the line before wrapping, allowing the nominal line length to go beyond
the limit specified. The drawn length will still be within the limit.

Add a WordWrapMode flag that does the same.

Changed paths:
    graphics/font.cpp
    graphics/font.h


diff --git a/graphics/font.cpp b/graphics/font.cpp
index 0668f1d35a9..38cb0482767 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -265,7 +265,9 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 			const int currentCharWidth = font.getCharWidth(c);
 			const int w = currentCharWidth + font.getKerningOffset(last, c);
 			last = c;
-			const bool wouldExceedWidth = (lineWidth + tmpWidth + w > targetMaxLineWidth);
+			const bool wouldExceedWidth =
+				(lineWidth + tmpWidth + w > targetMaxLineWidth) &&
+				!(mode & kWordWrapAllowTrailingWhitespace && Common::isSpace(c));
 
 			// If this char is a whitespace, then it represents a potential
 			// 'wrap point' where wrapping could take place. Everything that
diff --git a/graphics/font.h b/graphics/font.h
index e9697d85cf3..58c7fa6b3fb 100644
--- a/graphics/font.h
+++ b/graphics/font.h
@@ -56,9 +56,10 @@ enum TextAlign {
 
 /** Word wrapping modes. */
 enum WordWrapMode {
-	kWordWrapDefault			= 0,		///< Default wrapping mode.
-	kWordWrapEvenWidthLines 	= 1 << 0,	///< Make the resulting line segments close to the same width.
-	kWordWrapOnExplicitNewLines	= 1 << 1	///< Text is wrapped on new lines. Otherwise, treats them as single whitespace.
+	kWordWrapDefault				 = 0,		///< Default wrapping mode.
+	kWordWrapEvenWidthLines 		 = 1 << 0,	///< Make the resulting line segments close to the same width.
+	kWordWrapOnExplicitNewLines		 = 1 << 1,	///< Text is wrapped on new lines. Otherwise, treats them as single whitespace.
+	kWordWrapAllowTrailingWhitespace = 1 << 2 	///< Allow any amount of trailing whitespace before wrapping as it won't be drawn.
 };
 
 /**




More information about the Scummvm-git-logs mailing list