From 176a9414f5904cc7d07b29b1ca141cc9b0b3f6e3 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 11 Aug 2013 12:08:19 +0300 Subject: [PATCH] Gfx: Make D2D acknowledge trailing whitespace followed by a NBSP/MMSP This hacky workaround makes D2D behavior consistent with GDI+. --- Library/MeterString.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index ac35bbac..6c60e26d 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -387,6 +387,26 @@ 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. + size_t pos = 0; + while (true) + { + const WCHAR spaceChars[] = + { + L'\u00A0', // No-Break Space + L'\u205F' // Medium Mathematical Space + }; + + pos = m_String.find_first_of(spaceChars, pos, _countof(spaceChars)); + if (pos == std::wstring::npos) break; + + m_String.insert(pos + 1, 1, L'\u200B'); + pos += 2; + } + if (!m_WDefined || !m_HDefined) { // Calculate the text size