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()); }