diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index df9ee0b6..f0bfef39 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -37,6 +37,9 @@ void TextFormatD2D::Dispose() m_TextFormat.Reset(); m_TextLayout.Reset(); m_InlineEllipsis.Reset(); + + m_ExtraHeight = 0.0f; + m_LineGap = 0.0f; } void TextFormatD2D::CreateLayout( @@ -160,23 +163,28 @@ void TextFormatD2D::SetProperties( SetHorizontalAlignment(GetHorizontalAlignment()); SetVerticalAlignment(GetVerticalAlignment()); - // TODO: Clean this up and check for errors. - Microsoft::WRL::ComPtr collection; - m_TextFormat->GetFontCollection(collection.GetAddressOf()); + // Get the family name to in case CreateTextFormat() fallbacked on some other family name. + hr = m_TextFormat->GetFontFamilyName(dwriteFamilyName, _countof(dwriteFamilyName)); + if (FAILED(hr)) return; + Microsoft::WRL::ComPtr collection; + Microsoft::WRL::ComPtr fontFamily; UINT32 familyNameIndex; BOOL exists; - collection->FindFamilyName(dwriteFamilyName, &familyNameIndex, &exists); - - Microsoft::WRL::ComPtr fontFamily; - collection->GetFontFamily(familyNameIndex, fontFamily.GetAddressOf()); + if (FAILED(m_TextFormat->GetFontCollection(collection.GetAddressOf())) || + FAILED(collection->FindFamilyName(dwriteFamilyName, &familyNameIndex, &exists)) || + FAILED(collection->GetFontFamily(familyNameIndex, fontFamily.GetAddressOf()))) + { + return; + } Microsoft::WRL::ComPtr font; - fontFamily->GetFirstMatchingFont( + hr = fontFamily->GetFirstMatchingFont( m_TextFormat->GetFontWeight(), m_TextFormat->GetFontStretch(), m_TextFormat->GetFontStyle(), font.GetAddressOf()); + if (FAILED(hr)) return; DWRITE_FONT_METRICS fmetrics; font->GetMetrics(&fmetrics);