Skip to content

Commit

Permalink
Allow return of non-GDI-compatible family/subfamily names from CTFont…
Browse files Browse the repository at this point in the history
…Copy(Family)Name et al (#1778)

Fixes #1758
  • Loading branch information
ms-jihua authored Jan 24, 2017
1 parent 5a85799 commit 955b1c8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Frameworks/CoreText/DWriteWrapper_CTFont.mm
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,26 @@ CFStringRef _DWriteFontCopyName(const ComPtr<IDWriteFontFace>& fontFace, CFStrin
if (CFEqual(nameKey, kCTFontCopyrightNameKey)) {
informationalStringId = DWRITE_INFORMATIONAL_STRING_COPYRIGHT_NOTICE;
} else if (CFEqual(nameKey, kCTFontFamilyNameKey)) {
informationalStringId = DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES;
// Instead of using DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES here, use GetFamilyNames(),
// WIN32_FAMILY_NAMES may return a more specific name than needed (ie: Arial Narrow instead of Arial)
// As it is limited by GDI allowing a maximum of four fonts per family
ComPtr<IDWriteFontFace3> dwriteFontFace3;
RETURN_NULL_IF_FAILED(fontFace.As(&dwriteFontFace3));
ComPtr<IDWriteLocalizedStrings> name;
RETURN_NULL_IF_FAILED(dwriteFontFace3->GetFamilyNames(&name));
return static_cast<CFStringRef>(CFRetain(_CFStringFromLocalizedString(name.Get())));

} else if (CFEqual(nameKey, kCTFontSubFamilyNameKey)) {
// Similar to above, WIN32_SUBFAMILY_NAMES is limited to four fonts per family,
// but PREFERRED_SUBFAMILY_NAMES is only sometimes present (if it differs from WIN32_SUBFAMILY_NAMES)
// Try PREFERRED first
CFStringRef ret = _DWriteFontCopyInformationalString(fontFace, DWRITE_INFORMATIONAL_STRING_PREFERRED_SUBFAMILY_NAMES);
if (ret) {
return ret;
}

informationalStringId = DWRITE_INFORMATIONAL_STRING_WIN32_SUBFAMILY_NAMES;

} else if (CFEqual(nameKey, kCTFontStyleNameKey)) {
ComPtr<IDWriteFontFace3> dwriteFontFace3;
RETURN_NULL_IF_FAILED(fontFace.As(&dwriteFontFace3));
Expand Down

0 comments on commit 955b1c8

Please sign in to comment.