Gfx: Add support for local fonts with D2D

This does not yet work with family names containing e.g. 'Light'.
This commit is contained in:
Birunthan Mohanathas 2013-04-12 18:12:45 +03:00
parent 4b95f07ca6
commit d50c2ed33f
2 changed files with 15 additions and 2 deletions

View File

@ -121,10 +121,23 @@ void TextFormatD2D::SetProperties(
if (FAILED(hr))
{
IDWriteFontCollection* dwriteFontCollection = nullptr;
auto fontCollectionD2D = (FontCollectionD2D*)fontCollection;
// If |fontFamily| is not in the system collection, use the font collection from
// |fontCollectionD2D| if possible.
//
// TODO: Need to check GDI family names of the collection in |fontCollectionD2D|.
if (!Util::IsFamilyInSystemFontCollection(CanvasD2D::c_DWFactory, fontFamily) &&
(fontCollectionD2D && fontCollectionD2D->InitializeCollection()))
{
dwriteFontCollection = fontCollectionD2D->m_Collection;
}
// Fallback in case above fails.
hr = CanvasD2D::c_DWFactory->CreateTextFormat(
fontFamily,
nullptr,
dwriteFontCollection,
bold ? DWRITE_FONT_WEIGHT_BOLD : DWRITE_FONT_WEIGHT_REGULAR,
italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,

View File

@ -138,7 +138,7 @@ bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* family
BOOL familyNameFound;
HRESULT hr = systemFontCollection->FindFamilyName(
familyName, &familyNameIndex, &familyNameFound);
if (SUCCEEDED(hr) && !familyNameFound)
if (SUCCEEDED(hr) && familyNameFound)
{
result = true;
}