From 955b1c81ecf44b74e7bd470503f3fab37fff54f7 Mon Sep 17 00:00:00 2001 From: ms-jihua Date: Mon, 23 Jan 2017 17:13:09 -0800 Subject: [PATCH] Allow return of non-GDI-compatible family/subfamily names from CTFontCopy(Family)Name et al (#1778) Fixes #1758 --- Frameworks/CoreText/DWriteWrapper_CTFont.mm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Frameworks/CoreText/DWriteWrapper_CTFont.mm b/Frameworks/CoreText/DWriteWrapper_CTFont.mm index b5ec527747..ea93eaba18 100644 --- a/Frameworks/CoreText/DWriteWrapper_CTFont.mm +++ b/Frameworks/CoreText/DWriteWrapper_CTFont.mm @@ -294,9 +294,26 @@ CFStringRef _DWriteFontCopyName(const ComPtr& 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 dwriteFontFace3; + RETURN_NULL_IF_FAILED(fontFace.As(&dwriteFontFace3)); + ComPtr name; + RETURN_NULL_IF_FAILED(dwriteFontFace3->GetFamilyNames(&name)); + return static_cast(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 dwriteFontFace3; RETURN_NULL_IF_FAILED(fontFace.As(&dwriteFontFace3));