From 56218f7af458232e1eec0fc613451b42903c1e68 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sat, 10 Aug 2013 15:26:50 +0300 Subject: [PATCH] Gfx: Improve line trimming with D2D when one line is visible --- Common/Gfx/TextFormatD2D.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index f0bfef39..916d7ab7 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -70,15 +70,30 @@ void TextFormatD2D::CreateLayout( CanvasD2D::c_DWFactory->CreateTextLayout( str, strLen, m_TextFormat.Get(), maxW, maxH, m_TextLayout.ReleaseAndGetAddressOf()); - if (gdiEmulation && m_TextLayout) + if (m_TextLayout) { - Microsoft::WRL::ComPtr textLayout1; - m_TextLayout.As(&textLayout1); + if (gdiEmulation) + { + Microsoft::WRL::ComPtr textLayout1; + m_TextLayout.As(&textLayout1); - const float xOffset = m_TextFormat->GetFontSize() / 6.0f; - const float emOffset = xOffset / 24.0f; - const DWRITE_TEXT_RANGE range = {0, strLen}; - textLayout1->SetCharacterSpacing(emOffset, emOffset, 0.0f, range); + const float xOffset = m_TextFormat->GetFontSize() / 6.0f; + const float emOffset = xOffset / 24.0f; + const DWRITE_TEXT_RANGE range = {0, strLen}; + textLayout1->SetCharacterSpacing(emOffset, emOffset, 0.0f, range); + } + + UINT32 lineCount = 0; + DWRITE_LINE_METRICS lineMetrics[2]; + HRESULT hr = m_TextLayout->GetLineMetrics(lineMetrics, _countof(lineMetrics), &lineCount); + if (SUCCEEDED(hr) && + lineMetrics[0].isTrimmed && + lineMetrics[1].isTrimmed && + lineMetrics[1].height == 0.0f) + { + m_TextLayout->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP); + return; + } } } }