From 1e82a1659ffdf7311d97d96114c11042bace6fa4 Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Fri, 2 Aug 2013 15:42:37 -0600 Subject: [PATCH] D2D: Undo recent W/H calculations and revert back to 37fd105 calculations --- Common/Gfx/CanvasD2D.cpp | 5 ++--- Common/Gfx/Util/DWriteHelpers.cpp | 12 +++--------- Common/Gfx/Util/DWriteHelpers.h | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Common/Gfx/CanvasD2D.cpp b/Common/Gfx/CanvasD2D.cpp index 1b067375..6b22ed1d 100644 --- a/Common/Gfx/CanvasD2D.cpp +++ b/Common/Gfx/CanvasD2D.cpp @@ -350,9 +350,8 @@ bool CanvasD2D::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& fo textLayout.GetAddressOf()); if (SUCCEEDED(hr)) { - std::wstring s = str; const DWRITE_TEXT_METRICS metrics = - Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText, s.rfind(L"\n") != std::wstring::npos); + Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText); rect.Width = metrics.width; rect.Height = metrics.height; return true; @@ -376,7 +375,7 @@ bool CanvasD2D::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextForma if (SUCCEEDED(hr)) { const DWRITE_TEXT_METRICS metrics = - Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText, false); + Util::GetAdjustedDWriteTextLayoutMetrics(textLayout.Get(), !m_AccurateText); rect.Width = metrics.width; lines = metrics.lineCount; diff --git a/Common/Gfx/Util/DWriteHelpers.cpp b/Common/Gfx/Util/DWriteHelpers.cpp index 635730d4..b01fa228 100644 --- a/Common/Gfx/Util/DWriteHelpers.cpp +++ b/Common/Gfx/Util/DWriteHelpers.cpp @@ -24,7 +24,7 @@ namespace Gfx { namespace Util { DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( - IDWriteTextLayout* textLayout, bool gdiEmulation, bool containsNewLine) + IDWriteTextLayout* textLayout, bool gdiEmulation) { DWRITE_TEXT_METRICS metrics; textLayout->GetMetrics(&metrics); @@ -33,14 +33,8 @@ DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( { float size = 0.0f; textLayout->GetFontSize(0, &size); - metrics.width = floor(metrics.width + ((size / 3.0f) * 2.0f) + ((size * 3.0f / 4.0f) / 17.5f) + 0.255f); - - if (containsNewLine) - { - metrics.width -= ((size * 3.0f / 4.0f) / 4.0f); - } - - metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f); + metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f); + metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f); } return metrics; diff --git a/Common/Gfx/Util/DWriteHelpers.h b/Common/Gfx/Util/DWriteHelpers.h index c7ef3f0d..278f0b36 100644 --- a/Common/Gfx/Util/DWriteHelpers.h +++ b/Common/Gfx/Util/DWriteHelpers.h @@ -27,7 +27,7 @@ namespace Util { // If |gdiEmulation| is true, the returns metrics have similar characteristics to those provided // by GDI+. DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics( - IDWriteTextLayout* textLayout, bool gdiEmulation, bool containsNewLine); + IDWriteTextLayout* textLayout, bool gdiEmulation); // Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style, // and stretch.