From bf851cc5251c61efe449b3b049c1f1b130d96cae Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Mon, 5 Sep 2016 18:41:40 +0200 Subject: GRAPHICS: Handle Windows and Mac line breaks when word-wrapping text This seems like the right place to do it. Hopefully it's also the right way. It fixes line breaks in the MacVenture engine, where the text apparently uses Mac line breaks. --- graphics/font.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'graphics/font.cpp') diff --git a/graphics/font.cpp b/graphics/font.cpp index 97662dc15d..7768b7362d 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -164,7 +164,16 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm typename StringType::unsigned_type last = 0; for (typename StringType::const_iterator x = str.begin(); x != str.end(); ++x) { - const typename StringType::unsigned_type c = *x; + typename StringType::unsigned_type c = *x; + + // Convert Windows and Mac line breaks into plain \n + if (c == '\r') { + if (x != str.end() && *(x + 1) == '\n') { + ++x; + } + c = '\n'; + } + const int w = font.getCharWidth(c) + font.getKerningOffset(last, c); last = c; const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth); -- cgit v1.2.3