Gfx: Handle failed creation of D2D text layout

This commit is contained in:
Birunthan Mohanathas 2013-10-15 17:08:40 +03:00
parent 6d243711a6
commit ca41a4575c
3 changed files with 81 additions and 82 deletions

View File

@ -318,11 +318,11 @@ void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& forma
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solidBrush;
HRESULT hr = m_Target->CreateSolidColorBrush(ToColorF(color), solidBrush.GetAddressOf());
if (SUCCEEDED(hr))
{
if (FAILED(hr)) return;
TextFormatD2D& formatD2D = (TextFormatD2D&)format;
formatD2D.CreateLayout(
str, strLen, rect.Width, rect.Height, !m_AccurateText && m_TextAntiAliasing);
if (!formatD2D.CreateLayout(
str, strLen, rect.Width, rect.Height, !m_AccurateText && m_TextAntiAliasing)) return;
D2D1_POINT_2F drawPosition;
drawPosition.x = [&]()
@ -382,7 +382,6 @@ void CanvasD2D::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& forma
m_Target->PopLayer();
}
}
}
}
bool CanvasD2D::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect)

View File

@ -43,7 +43,7 @@ void TextFormatD2D::Dispose()
m_LineGap = 0.0f;
}
void TextFormatD2D::CreateLayout(
bool TextFormatD2D::CreateLayout(
const WCHAR* str, UINT strLen, float maxW, float maxH, bool gdiEmulation)
{
bool strChanged = false;
@ -84,9 +84,8 @@ void TextFormatD2D::CreateLayout(
{
CanvasD2D::c_DWFactory->CreateTextLayout(
str, strLen, m_TextFormat.Get(), maxW, maxH, m_TextLayout.ReleaseAndGetAddressOf());
if (!m_TextLayout) return false;
if (m_TextLayout)
{
if (gdiEmulation)
{
Microsoft::WRL::ComPtr<IDWriteTextLayout1> textLayout1;
@ -115,7 +114,8 @@ void TextFormatD2D::CreateLayout(
}
}
}
}
return true;
}
void TextFormatD2D::SetProperties(

View File

@ -55,8 +55,8 @@ private:
// Creates a new DirectWrite text layout if |str| has changed since last call. Since creating
// the layout is costly, it is more efficient to keep reusing the text layout until the text
// changes.
void CreateLayout(const WCHAR* str, UINT strLen, float maxW, float maxH, bool gdiEmulation);
// changes. Returns true if the layout is valid for use.
bool CreateLayout(const WCHAR* str, UINT strLen, float maxW, float maxH, bool gdiEmulation);
DWRITE_TEXT_METRICS GetMetrics(
const WCHAR* str, UINT strLen, bool gdiEmulation, float maxWidth = 10000.0f);