From 180adbc7599265344692bd573dc87b7c30bbf155 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 11 Aug 2013 11:42:23 +0300 Subject: [PATCH] Gfx: Fix text Y position for D2D with vertical Center/Bottom alignments --- Common/Gfx/CanvasD2D.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Common/Gfx/CanvasD2D.cpp b/Common/Gfx/CanvasD2D.cpp index ecbf9216..306e5746 100644 --- a/Common/Gfx/CanvasD2D.cpp +++ b/Common/Gfx/CanvasD2D.cpp @@ -316,7 +316,6 @@ void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& forma str, strLen, rect.Width, rect.Height, !m_AccurateText && m_TextAntiAliasing); D2D1_POINT_2F drawPosition; - drawPosition.y = rect.Y - formatD2D.m_LineGap; drawPosition.x = [&]() { if (!m_AccurateText) @@ -332,6 +331,19 @@ void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& forma return rect.X; } (); + drawPosition.y = [&]() + { + // GDI+ compatibility. + float yPos = rect.Y - formatD2D.m_LineGap; + switch (formatD2D.GetVerticalAlignment()) + { + case VerticalAlignment::Bottom: yPos -= formatD2D.m_ExtraHeight; break; + case VerticalAlignment::Center: yPos -= formatD2D.m_ExtraHeight / 2; break; + } + + return yPos; + } (); + DWRITE_OVERHANG_METRICS overhangMetrics; formatD2D.m_TextLayout->GetOverhangMetrics(&overhangMetrics);