From 6d705f5c95e45113c6497581d38b89587f24284a Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Sun, 13 Oct 2013 16:28:57 +0300 Subject: [PATCH] String: Strip carriage returns in strings for compatibility between GDI+ and D2D --- Library/MeterString.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 80be085b..48160a30 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -387,18 +387,25 @@ bool MeterString::Update() break; } - // Ugly hack to make D2D render trailing spaces followed by a non-breaking space correctly. - // By default, D2D ignores all trailing whitespace. Both GDI+ and D2D, however, acknowledge the - // presense of the zero-width space (and give it a width of 0px), so we append the zero-width - // space after each non-breaking space. for (size_t i = 0; i < m_String.length(); ++i) { if (m_String[i] == L'\u00A0' || // No-Break Space m_String[i] == L'\u205F') // Medium Mathematical Space { + // Ugly hack to make D2D render trailing spaces followed by a non-breaking space + // correctly. By default, D2D ignores all trailing whitespace. Both GDI+ and D2D, + // however, acknowledge the presense of the zero-width space (and give it a width + // of 0px), so we append the zero-width space after each non-breaking space. ++i; m_String.insert(i, 1, L'\u200B'); } + else if (m_String[i] == L'\r') + { + // GDI+ seems to ignore carriage returns, so strip it entirely to make it behave + // similarly with D2D as well. + m_String.erase(i, 1); + --i; + } } if (!m_WDefined || !m_HDefined)