summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm')
-rw-r--r--Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm306
1 files changed, 153 insertions, 153 deletions
diff --git a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm
index 6d818a0f386..92b11245a7e 100644
--- a/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm
+++ b/Build/source/texk/web2c/xetexdir/XeTeXFontMgr_Mac.mm
@@ -45,168 +45,168 @@ extern "C" {
CTFontDescriptorRef findFontWithName(CFStringRef name, CFStringRef key)
{
- CFStringRef keys[] = { key };
- CFTypeRef values[] = { name };
- CFDictionaryRef attributes = CFDictionaryCreate(NULL, (const void **) &keys, (const void **) &values, 1,
- &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
- CTFontDescriptorRef descriptor = CTFontDescriptorCreateWithAttributes(attributes);
- CFRelease(attributes);
-
- CFSetRef mandatoryAttributes = CFSetCreate(NULL, (const void **) &keys, 1, &kCFTypeSetCallBacks);
- CFArrayRef matches = CTFontDescriptorCreateMatchingFontDescriptors(descriptor, mandatoryAttributes);
- CFRelease(mandatoryAttributes);
- CFRelease(descriptor);
-
- CTFontDescriptorRef matched = NULL;
- if (matches) {
- if (CFArrayGetCount(matches)) {
- matched = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matches, 0);
- CFRetain(matched);
- }
- CFRelease(matches);
- }
- return matched;
+ CFStringRef keys[] = { key };
+ CFTypeRef values[] = { name };
+ CFDictionaryRef attributes = CFDictionaryCreate(NULL, (const void **) &keys, (const void **) &values, 1,
+ &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+ CTFontDescriptorRef descriptor = CTFontDescriptorCreateWithAttributes(attributes);
+ CFRelease(attributes);
+
+ CFSetRef mandatoryAttributes = CFSetCreate(NULL, (const void **) &keys, 1, &kCFTypeSetCallBacks);
+ CFArrayRef matches = CTFontDescriptorCreateMatchingFontDescriptors(descriptor, mandatoryAttributes);
+ CFRelease(mandatoryAttributes);
+ CFRelease(descriptor);
+
+ CTFontDescriptorRef matched = NULL;
+ if (matches) {
+ if (CFArrayGetCount(matches)) {
+ matched = (CTFontDescriptorRef) CFArrayGetValueAtIndex(matches, 0);
+ CFRetain(matched);
+ }
+ CFRelease(matches);
+ }
+ return matched;
}
void
XeTeXFontMgr_Mac::appendNameToList(CTFontRef font,
- std::list<std::string>* nameList,
- CFStringRef nameKey)
+ std::list<std::string>* nameList,
+ CFStringRef nameKey)
{
- CFStringRef name = CTFontCopyName(font, nameKey);
- if (name) {
- appendToList(nameList, [(NSString *) name UTF8String]);
- CFRelease(name);
- }
- CFStringRef language;
- name = CTFontCopyLocalizedName(font, nameKey, &language);
- if (name) {
- appendToList(nameList, [(NSString *) name UTF8String]);
- CFRelease(name);
- }
+ CFStringRef name = CTFontCopyName(font, nameKey);
+ if (name) {
+ appendToList(nameList, [(NSString *) name UTF8String]);
+ CFRelease(name);
+ }
+ CFStringRef language;
+ name = CTFontCopyLocalizedName(font, nameKey, &language);
+ if (name) {
+ appendToList(nameList, [(NSString *) name UTF8String]);
+ CFRelease(name);
+ }
}
XeTeXFontMgr::NameCollection*
XeTeXFontMgr_Mac::readNames(CTFontDescriptorRef fontRef)
{
- NameCollection* names = new NameCollection;
+ NameCollection* names = new NameCollection;
- CFStringRef psName = (CFStringRef) CTFontDescriptorCopyAttribute(fontRef, kCTFontNameAttribute);
- if (!psName)
- return names;
+ CFStringRef psName = (CFStringRef) CTFontDescriptorCopyAttribute(fontRef, kCTFontNameAttribute);
+ if (!psName)
+ return names;
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
- names->psName = [(NSString *) psName UTF8String];
- CFRelease(psName);
+ names->psName = [(NSString *) psName UTF8String];
+ CFRelease(psName);
- CTFontRef font = CTFontCreateWithFontDescriptor(fontRef, 0.0, 0);
- appendNameToList(font, &names->fullNames, kCTFontFullNameKey);
- appendNameToList(font, &names->familyNames, kCTFontFamilyNameKey);
- appendNameToList(font, &names->styleNames, kCTFontStyleNameKey);
- CFRelease(font);
+ CTFontRef font = CTFontCreateWithFontDescriptor(fontRef, 0.0, 0);
+ appendNameToList(font, &names->fullNames, kCTFontFullNameKey);
+ appendNameToList(font, &names->familyNames, kCTFontFamilyNameKey);
+ appendNameToList(font, &names->styleNames, kCTFontStyleNameKey);
+ CFRelease(font);
- [pool release];
+ [pool release];
- return names;
+ return names;
}
void
XeTeXFontMgr_Mac::addFontsToCaches(CFArrayRef fonts)
{
- NSEnumerator* enumerator = [(NSArray*)fonts objectEnumerator];
- while (id aFont = [enumerator nextObject]) {
- CTFontDescriptorRef fontRef = findFontWithName((CFStringRef)[aFont objectAtIndex: 0], kCTFontNameAttribute);
- NameCollection* names = readNames(fontRef);
- addToMaps(fontRef, names);
- delete names;
- }
+ NSEnumerator* enumerator = [(NSArray*)fonts objectEnumerator];
+ while (id aFont = [enumerator nextObject]) {
+ CTFontDescriptorRef fontRef = findFontWithName((CFStringRef)[aFont objectAtIndex: 0], kCTFontNameAttribute);
+ NameCollection* names = readNames(fontRef);
+ addToMaps(fontRef, names);
+ delete names;
+ }
}
void
XeTeXFontMgr_Mac::addFamilyToCaches(CTFontDescriptorRef familyRef)
{
- CFStringRef nameStr = (CFStringRef) CTFontDescriptorCopyAttribute(familyRef, kCTFontFamilyNameAttribute);
- if (nameStr) {
- NSArray* members = [[NSFontManager sharedFontManager]
- availableMembersOfFontFamily: (NSString*)nameStr];
- CFRelease(nameStr);
- addFontsToCaches((CFArrayRef)members);
- }
+ CFStringRef nameStr = (CFStringRef) CTFontDescriptorCopyAttribute(familyRef, kCTFontFamilyNameAttribute);
+ if (nameStr) {
+ NSArray* members = [[NSFontManager sharedFontManager]
+ availableMembersOfFontFamily: (NSString*)nameStr];
+ CFRelease(nameStr);
+ addFontsToCaches((CFArrayRef)members);
+ }
}
void
XeTeXFontMgr_Mac::addFontAndSiblingsToCaches(CTFontDescriptorRef fontRef)
{
- CFStringRef name = (CFStringRef) CTFontDescriptorCopyAttribute(fontRef, kCTFontNameAttribute);
- if (name) {
- NSFont* font = [NSFont fontWithName:(NSString*)name size:10.0];
- CFRelease(name);
- NSArray* members = [[NSFontManager sharedFontManager]
- availableMembersOfFontFamily: [font familyName]];
- addFontsToCaches((CFArrayRef)members);
- }
+ CFStringRef name = (CFStringRef) CTFontDescriptorCopyAttribute(fontRef, kCTFontNameAttribute);
+ if (name) {
+ NSFont* font = [NSFont fontWithName:(NSString*)name size:10.0];
+ CFRelease(name);
+ NSArray* members = [[NSFontManager sharedFontManager]
+ availableMembersOfFontFamily: [font familyName]];
+ addFontsToCaches((CFArrayRef)members);
+ }
}
void
XeTeXFontMgr_Mac::searchForHostPlatformFonts(const std::string& name)
{
- // the name might be:
- // FullName
- // Family-Style (if there's a hyphen)
- // PSName
- // Family
- // ...so we need to try it as each of these
-
- CFStringRef nameStr = CFStringCreateWithCString(kCFAllocatorDefault, name.c_str(), kCFStringEncodingUTF8);
- CTFontDescriptorRef matched = findFontWithName(nameStr, kCTFontDisplayNameAttribute);
- if (matched) {
- // found it, so locate the family, and add all members to the caches
- addFontAndSiblingsToCaches(matched);
- CFRelease(matched);
- return;
- }
-
- int hyph = name.find('-');
- if (hyph > 0 && hyph < name.length() - 1) {
- std::string family(name.begin(), name.begin() + hyph);
- CFStringRef familyStr = CFStringCreateWithCString(kCFAllocatorDefault, family.c_str(), kCFStringEncodingUTF8);
-
- NSArray* familyMembers = [[NSFontManager sharedFontManager]
- availableMembersOfFontFamily: (NSString*)familyStr];
- if ([familyMembers count] > 0) {
- addFontsToCaches((CFArrayRef)familyMembers);
- return;
- }
-
- matched = findFontWithName(familyStr, kCTFontFamilyNameAttribute);
- if (matched) {
- addFamilyToCaches(matched);
- CFRelease(matched);
- return;
- }
- }
-
- matched = findFontWithName(nameStr, kCTFontNameAttribute);
- if (matched) {
- addFontAndSiblingsToCaches(matched);
- CFRelease(matched);
- return;
- }
-
- NSArray* familyMembers = [[NSFontManager sharedFontManager]
- availableMembersOfFontFamily: (NSString*)nameStr];
- if ([familyMembers count] > 0) {
- addFontsToCaches((CFArrayRef)familyMembers);
- return;
- }
-
- matched = findFontWithName(nameStr, kCTFontFamilyNameAttribute);
- if (matched) {
- addFamilyToCaches(matched);
- CFRelease(matched);
- return;
- }
+ // the name might be:
+ // FullName
+ // Family-Style (if there's a hyphen)
+ // PSName
+ // Family
+ // ...so we need to try it as each of these
+
+ CFStringRef nameStr = CFStringCreateWithCString(kCFAllocatorDefault, name.c_str(), kCFStringEncodingUTF8);
+ CTFontDescriptorRef matched = findFontWithName(nameStr, kCTFontDisplayNameAttribute);
+ if (matched) {
+ // found it, so locate the family, and add all members to the caches
+ addFontAndSiblingsToCaches(matched);
+ CFRelease(matched);
+ return;
+ }
+
+ int hyph = name.find('-');
+ if (hyph > 0 && hyph < name.length() - 1) {
+ std::string family(name.begin(), name.begin() + hyph);
+ CFStringRef familyStr = CFStringCreateWithCString(kCFAllocatorDefault, family.c_str(), kCFStringEncodingUTF8);
+
+ NSArray* familyMembers = [[NSFontManager sharedFontManager]
+ availableMembersOfFontFamily: (NSString*)familyStr];
+ if ([familyMembers count] > 0) {
+ addFontsToCaches((CFArrayRef)familyMembers);
+ return;
+ }
+
+ matched = findFontWithName(familyStr, kCTFontFamilyNameAttribute);
+ if (matched) {
+ addFamilyToCaches(matched);
+ CFRelease(matched);
+ return;
+ }
+ }
+
+ matched = findFontWithName(nameStr, kCTFontNameAttribute);
+ if (matched) {
+ addFontAndSiblingsToCaches(matched);
+ CFRelease(matched);
+ return;
+ }
+
+ NSArray* familyMembers = [[NSFontManager sharedFontManager]
+ availableMembersOfFontFamily: (NSString*)nameStr];
+ if ([familyMembers count] > 0) {
+ addFontsToCaches((CFArrayRef)familyMembers);
+ return;
+ }
+
+ matched = findFontWithName(nameStr, kCTFontFamilyNameAttribute);
+ if (matched) {
+ addFamilyToCaches(matched);
+ CFRelease(matched);
+ return;
+ }
}
NSAutoreleasePool* pool = NULL;
@@ -214,44 +214,44 @@ NSAutoreleasePool* pool = NULL;
void
XeTeXFontMgr_Mac::initialize()
{
- pool = [[NSAutoreleasePool alloc] init];
+ pool = [[NSAutoreleasePool alloc] init];
}
void
XeTeXFontMgr_Mac::terminate()
{
- if (pool != NULL) {
- [pool release];
- }
+ if (pool != NULL) {
+ [pool release];
+ }
}
std::string
XeTeXFontMgr_Mac::getPlatformFontDesc(PlatformFontRef descriptor) const
{
- std::string path;
- CTFontRef ctFont = CTFontCreateWithFontDescriptor(descriptor, 0.0, 0);
- if (ctFont) {
- CFURLRef url = NULL;
+ std::string path;
+ CTFontRef ctFont = CTFontCreateWithFontDescriptor(descriptor, 0.0, 0);
+ if (ctFont) {
+ CFURLRef url = NULL;
#if !defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
- /* kCTFontURLAttribute was not avialable before 10.6 */
- FSRef fsref;
- ATSFontRef atsFont = CTFontGetPlatformFont(ctFont, NULL);
- OSStatus status = ATSFontGetFileReference(atsFont, &fsref);
- if (status == noErr)
- url = CFURLCreateFromFSRef(NULL, &fsref);
+ /* kCTFontURLAttribute was not avialable before 10.6 */
+ FSRef fsref;
+ ATSFontRef atsFont = CTFontGetPlatformFont(ctFont, NULL);
+ OSStatus status = ATSFontGetFileReference(atsFont, &fsref);
+ if (status == noErr)
+ url = CFURLCreateFromFSRef(NULL, &fsref);
#else
- url = (CFURLRef) CTFontCopyAttribute(ctFont, kCTFontURLAttribute);
+ url = (CFURLRef) CTFontCopyAttribute(ctFont, kCTFontURLAttribute);
#endif
- if (url) {
- UInt8 posixPath[PATH_MAX];
- if (CFURLGetFileSystemRepresentation(url, true, posixPath, PATH_MAX)) {
- path = (char*)posixPath;
- }
- CFRelease(url);
- }
- CFRelease(ctFont);
- }
- if (path.length() == 0)
- path = "[unknown]";
- return path;
+ if (url) {
+ UInt8 posixPath[PATH_MAX];
+ if (CFURLGetFileSystemRepresentation(url, true, posixPath, PATH_MAX)) {
+ path = (char*)posixPath;
+ }
+ CFRelease(url);
+ }
+ CFRelease(ctFont);
+ }
+ if (path.length() == 0)
+ path = "[unknown]";
+ return path;
}