Browse Source

Ignore carriage returns (\r) in print and friends (issue #1114)

--HG--
branch : minor
Bart van Strien 9 years ago
parent
commit
6533665f15
1 changed files with 16 additions and 2 deletions
  1. 16 2
      src/modules/graphics/opengl/Font.cpp

+ 16 - 2
src/modules/graphics/opengl/Font.cpp

@@ -444,6 +444,10 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
 			continue;
 			continue;
 		}
 		}
 
 
+		// Ignore carriage returns
+		if (g == '\r')
+			continue;
+
 		uint32 cacheid = textureCacheID;
 		uint32 cacheid = textureCacheID;
 
 
 		const Glyph &glyph = findGlyph(g);
 		const Glyph &glyph = findGlyph(g);
@@ -521,7 +525,7 @@ std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &c
 		info->width = maxwidth - offset.x;;
 		info->width = maxwidth - offset.x;;
 		info->height = (int) dy + (dx > 0.0f ? floorf(getHeight() * getLineHeight() + 0.5f) : 0) - offset.y;
 		info->height = (int) dy + (dx > 0.0f ? floorf(getHeight() * getLineHeight() + 0.5f) : 0) - offset.y;
 	}
 	}
-	
+
 	return commands;
 	return commands;
 }
 }
 
 
@@ -534,7 +538,6 @@ std::vector<Font::DrawCommand> Font::generateVertices(const std::string &text, s
 
 
 std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info)
 std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info)
 {
 {
-	
 	wrap = std::max(wrap, 0.0f);
 	wrap = std::max(wrap, 0.0f);
 
 
 	uint32 cacheid = textureCacheID;
 	uint32 cacheid = textureCacheID;
@@ -733,6 +736,10 @@ int Font::getWidth(const std::string &str)
 			{
 			{
 				uint32 c = *i++;
 				uint32 c = *i++;
 
 
+				// Ignore carriage returns
+				if (c == '\r')
+					continue;
+
 				const Glyph &g = findGlyph(c);
 				const Glyph &g = findGlyph(c);
 				width += g.spacing + getKerning(prevglyph, c);
 				width += g.spacing + getKerning(prevglyph, c);
 
 
@@ -813,6 +820,13 @@ void Font::getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::ve
 			continue;
 			continue;
 		}
 		}
 
 
+		// Ignore carriage returns
+		if (c == '\r')
+		{
+			i++;
+			continue;
+		}
+
 		const Glyph &g = findGlyph(c);
 		const Glyph &g = findGlyph(c);
 		float charwidth = g.spacing + getKerning(prevglyph, c);
 		float charwidth = g.spacing + getKerning(prevglyph, c);
 		float newwidth = width + charwidth;
 		float newwidth = width + charwidth;