Gfx: Improve line trimming with D2D when one line is visible

This commit is contained in:
Birunthan Mohanathas 2013-08-10 15:26:50 +03:00
parent 34abccc29b
commit 56218f7af4

View File

@ -70,7 +70,9 @@ void TextFormatD2D::CreateLayout(
CanvasD2D::c_DWFactory->CreateTextLayout(
str, strLen, m_TextFormat.Get(), maxW, maxH, m_TextLayout.ReleaseAndGetAddressOf());
if (gdiEmulation && m_TextLayout)
if (m_TextLayout)
{
if (gdiEmulation)
{
Microsoft::WRL::ComPtr<IDWriteTextLayout1> textLayout1;
m_TextLayout.As(&textLayout1);
@ -80,6 +82,19 @@ void TextFormatD2D::CreateLayout(
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;
}
}
}
}