From 52b5e2584a7369795e8cab6e358f168f8fd35e28 Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Sun, 28 Jul 2013 01:10:19 -0600 Subject: [PATCH] D2D: Removed centering of text within W/H (from 481442b) due to conflict with different alignments and a meter's defined W/H. --- Common/Gfx/CanvasD2D.cpp | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/Common/Gfx/CanvasD2D.cpp b/Common/Gfx/CanvasD2D.cpp index bdf19385..3ab6ae6a 100644 --- a/Common/Gfx/CanvasD2D.cpp +++ b/Common/Gfx/CanvasD2D.cpp @@ -309,40 +309,18 @@ void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& forma if (SUCCEEDED(hr)) { TextFormatD2D& formatD2D = (TextFormatD2D&)format; + const bool right = formatD2D.GetHorizontalAlignment() == Gfx::HorizontalAlignment::Right; + const bool bottom = formatD2D.GetVerticalAlignment() == Gfx::VerticalAlignment::Bottom; formatD2D.CreateLayout(str, strLen, rect.Width, rect.Height); - // Center text inside rect - DWRITE_TEXT_METRICS metrics; - formatD2D.m_TextLayout->GetMetrics(&metrics); - - float xOffset = (rect.Width - metrics.width) / 2.0f; - float yOffset = (rect.Height - metrics.height) / 2.0f; - - switch (formatD2D.GetHorizontalAlignment()) - { - case Gfx::HorizontalAlignment::Center: - xOffset = xOffset / 2.0f; - break; - - case Gfx::HorizontalAlignment::Right: - xOffset = -xOffset; - break; - } - - switch (formatD2D.GetVerticalAlignment()) - { - case Gfx::VerticalAlignment::Center: - yOffset = yOffset / 2.0f; - break; - - case Gfx::VerticalAlignment::Bottom: - yOffset = -yOffset; - break; - } + float xOffset = 0.0f; + formatD2D.m_TextLayout->GetFontSize(0, &xOffset); + xOffset /= 6.0f; m_Target->DrawTextLayout( - D2D1::Point2F(m_AccurateText ? rect.X : rect.X + xOffset, rect.Y + yOffset), + D2D1::Point2F(m_AccurateText ? rect.X : right ? rect.X - xOffset : rect.X + xOffset, + m_AccurateText || !bottom ? rect.Y : rect.Y - 1.0f), formatD2D.m_TextLayout.Get(), solidBrush.Get()); }