-
-
Save yuanhao/7ac82ab64d49fe2406d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <CoreText/CTFont.h> | |
| #include <CoreText/CTFontCollection.h> | |
| #include <CoreFoundation/CFString.h> | |
| #include <CoreFoundation/CFBase.h> | |
| void callBack(const void *value, void *context) { | |
| CTFontDescriptorRef pDesc = static_cast<CTFontDescriptorRef>(value); | |
| CFStringRef pFamilyName = (CFStringRef)CTFontDescriptorCopyAttribute(pDesc, kCTFontFamilyNameAttribute); | |
| CFStringRef lang = CFSTR("ja"); | |
| CFStringRef pLocalizedName = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(pDesc, kCTFontFamilyNameAttribute, &lang); | |
| CFShow(pFamilyName); | |
| char buf[128]; | |
| CFStringGetCString(pLocalizedName, buf, 128, kCFStringEncodingUTF8); | |
| std::cout << buf << std::endl; | |
| } | |
| int main(int argc, const char * argv[]) | |
| { | |
| static const int nMaxDictEntries = 8; | |
| CFMutableDictionaryRef pCFDict = CFDictionaryCreateMutable(NULL, | |
| nMaxDictEntries, | |
| &kCFTypeDictionaryKeyCallBacks, | |
| &kCFTypeDictionaryValueCallBacks); | |
| CFDictionaryAddValue( pCFDict, kCTFontCollectionRemoveDuplicatesOption, kCFBooleanTrue ); | |
| CTFontCollectionRef pCollection = CTFontCollectionCreateFromAvailableFonts( pCFDict ); | |
| CFRelease( pCFDict ); | |
| CFArrayRef pFontArray = CTFontCollectionCreateMatchingFontDescriptors(pCollection); | |
| const long nFont = CFArrayGetCount(pFontArray); | |
| const CFRange aFullRange = CFRangeMake(0, nFont); | |
| CFArrayApplyFunction(pFontArray, aFullRange, callBack, 0); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment