| @@ -57,10 +57,38 @@ struct FontStyleHelpers | |||||
| || family == Font::getDefaultMonospacedFontName(); | || family == Font::getDefaultMonospacedFontName(); | ||||
| } | } | ||||
| static String getConcreteFamilyNameFromPlaceholder (const String& family) | |||||
| struct ConcreteFamilyNames | |||||
| { | { | ||||
| const Font f (family, Font::getDefaultStyle(), 15.0f); | |||||
| return Font::getDefaultTypefaceForFont (f)->getName(); | |||||
| ConcreteFamilyNames() | |||||
| : sans (findName (Font::getDefaultSansSerifFontName())), | |||||
| serif (findName (Font::getDefaultSerifFontName())), | |||||
| mono (findName (Font::getDefaultMonospacedFontName())) | |||||
| { | |||||
| } | |||||
| String lookUp (const String& placeholder) | |||||
| { | |||||
| if (placeholder == Font::getDefaultSansSerifFontName()) return sans; | |||||
| if (placeholder == Font::getDefaultSerifFontName()) return serif; | |||||
| if (placeholder == Font::getDefaultMonospacedFontName()) return mono; | |||||
| return findName (placeholder); | |||||
| } | |||||
| private: | |||||
| static String findName (const String& placeholder) | |||||
| { | |||||
| const Font f (placeholder, Font::getDefaultStyle(), 15.0f); | |||||
| return Font::getDefaultTypefaceForFont (f)->getName(); | |||||
| } | |||||
| String sans, serif, mono; | |||||
| }; | |||||
| static String getConcreteFamilyNameFromPlaceholder (const String& placeholder) | |||||
| { | |||||
| static ConcreteFamilyNames names; | |||||
| return names.lookUp (placeholder); | |||||
| } | } | ||||
| static String getConcreteFamilyName (const Font& font) | static String getConcreteFamilyName (const Font& font) | ||||
| @@ -221,9 +221,11 @@ namespace DirectWriteTypeLayout | |||||
| if (const Font* const font = attr.getFont()) | if (const Font* const font = attr.getFont()) | ||||
| { | { | ||||
| const String familyName (FontStyleHelpers::getConcreteFamilyName (*font)); | |||||
| BOOL fontFound = false; | BOOL fontFound = false; | ||||
| uint32 fontIndex; | uint32 fontIndex; | ||||
| fontCollection->FindFamilyName (FontStyleHelpers::getConcreteFamilyName (*font).toWideCharPointer(), | |||||
| fontCollection->FindFamilyName (familyName.toWideCharPointer(), | |||||
| &fontIndex, &fontFound); | &fontIndex, &fontFound); | ||||
| if (! fontFound) | if (! fontFound) | ||||
| @@ -244,7 +246,7 @@ namespace DirectWriteTypeLayout | |||||
| break; | break; | ||||
| } | } | ||||
| textLayout->SetFontFamilyName (attr.getFont()->getTypefaceName().toWideCharPointer(), range); | |||||
| textLayout->SetFontFamilyName (familyName.toWideCharPointer(), range); | |||||
| textLayout->SetFontWeight (dwFont->GetWeight(), range); | textLayout->SetFontWeight (dwFont->GetWeight(), range); | ||||
| textLayout->SetFontStretch (dwFont->GetStretch(), range); | textLayout->SetFontStretch (dwFont->GetStretch(), range); | ||||
| textLayout->SetFontStyle (dwFont->GetStyle(), range); | textLayout->SetFontStyle (dwFont->GetStyle(), range); | ||||
| @@ -153,10 +153,13 @@ public: | |||||
| { | { | ||||
| hr = dwFontFamily->GetFont (i, dwFont.resetAndGetPointerAddress()); | hr = dwFontFamily->GetFont (i, dwFont.resetAndGetPointerAddress()); | ||||
| if (i == 0) | |||||
| break; | |||||
| ComSmartPtr<IDWriteLocalizedStrings> faceNames; | ComSmartPtr<IDWriteLocalizedStrings> faceNames; | ||||
| hr = dwFont->GetFaceNames (faceNames.resetAndGetPointerAddress()); | hr = dwFont->GetFaceNames (faceNames.resetAndGetPointerAddress()); | ||||
| if (i == 0 || font.getTypefaceStyle() == getLocalisedName (faceNames)) | |||||
| if (font.getTypefaceStyle() == getLocalisedName (faceNames)) | |||||
| break; | break; | ||||
| } | } | ||||