From 5fcf4b785d3946cc943ac9f68a4bcca32f48fd91 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 4 Aug 2013 21:46:59 +0300 Subject: [PATCH] Gfx: Fix that empty strings have a width and/or height with D2D --- Common/Gfx/Util/DWriteHelpers.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Common/Gfx/Util/DWriteHelpers.cpp b/Common/Gfx/Util/DWriteHelpers.cpp index b01fa228..1ab3c941 100644 --- a/Common/Gfx/Util/DWriteHelpers.cpp +++ b/Common/Gfx/Util/DWriteHelpers.cpp @@ -29,12 +29,20 @@ DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( DWRITE_TEXT_METRICS metrics; textLayout->GetMetrics(&metrics); - if (gdiEmulation) + if (metrics.width > 0.0f) { - float size = 0.0f; - textLayout->GetFontSize(0, &size); - metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f); - metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f); + if (gdiEmulation) + { + float size = 0.0f; + textLayout->GetFontSize(0, &size); + metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f); + metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f); + } + } + else + { + // Get rid of the height that DirectWrite assigns to zero-width strings. + metrics.height = 0.0f; } return metrics;