Browse Source

Ignore last space in justified text

Ron Tseytlin 8 months ago
parent
commit
d4a2c460de
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/modules/graphics/Font.cpp

+ 5 - 1
src/modules/graphics/Font.cpp

@@ -507,8 +507,12 @@ std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const love::font:
 				auto start = text.cps.begin() + range.getOffset();
 				auto end = start + range.getSize();
 				float numspaces = std::count(start, end, ' ');
+
+				if (text.cps[range.last] == ' ')
+					--numspaces;
+
 				if (width < wrap && numspaces >= 1)
-					extraspacing = (wrap - width) / (numspaces - 1);
+					extraspacing = (wrap - width) / numspaces;
 				else
 					extraspacing = 0.0f;
 				break;