static void SecSystemAnchorSourceInit(void) { SecSystemAnchorSourceRef result = (SecSystemAnchorSourceRef) malloc(sizeof(*result)); result->base.copyParents = SecSystemAnchorSourceCopyParents; result->base.contains = SecSystemAnchorSourceContains; CFDataRef xmlData = SecFrameworkCopyResourceContents( CFSTR("SystemAnchors"), CFSTR("plist"), NULL); CFPropertyListRef plist = CFPropertyListCreateFromXMLData( kCFAllocatorDefault, xmlData, kCFPropertyListImmutable, NULL); if (plist) { if (CFGetTypeID(plist) == CFDictionaryGetTypeID()) { result->digests = (CFSetRef)plist; } else { secwarning("SystemAnchors plist is wrong type."); CFRelease(plist); } } if (!result->digests) { result->digests = CFSetCreate(kCFAllocatorDefault, NULL, 0, &kCFTypeSetCallBacks); } kSecSystemAnchorSource = (SecCertificateSourceRef)result; }
CFSetRef CFSetCreateCopy(CFAllocatorRef allocator, CFSetRef set) { CFSetRef result; const CFSetCallBacks *cb; CFIndex numValues = CFSetGetCount(set); const void **list, *buffer[256]; list = (numValues <= 256) ? buffer : CFAllocatorAllocate(allocator, numValues * sizeof(void *), 0); if (list != buffer && __CFOASafe) __CFSetLastAllocationEventName(list, "CFSet (temp)"); CFSetGetValues(set, list); cb = CF_IS_OBJC(__kCFSetTypeID, set) ? &kCFTypeSetCallBacks : __CFSetGetCallBacks(set); result = CFSetCreate(allocator, list, numValues, cb); if (list != buffer) CFAllocatorDeallocate(allocator, list); return result; }
CFSetRef CFSetCreateCopy (CFAllocatorRef allocator, CFSetRef set) { if (CF_IS_OBJC (_kCFSetTypeID, set)) { CFSetRef result; const CFIndex count = CFSetGetCount (set); void **values = (void **) CFAllocatorAllocate (allocator, sizeof (void *) * count, 0); CFSetGetValues (set, (const void **) values); result = CFSetCreate (allocator, (const void **) values, count, &kCFTypeSetCallBacks); CFAllocatorDeallocate (allocator, (void *) values); return result; } return (CFSetRef) GSHashTableCreateCopy (allocator, (GSHashTableRef) set); }
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback) { bool result = false; #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (MacOSVersionIsAtLeast(10, 5, 0)) { /* Determine fallback font using CoreText. This uses the language isocode * to find a suitable font. CoreText is available from 10.5 onwards. */ char lang[16]; if (strcmp(language_isocode, "zh_TW") == 0) { /* Traditional Chinese */ strecpy(lang, "zh-Hant", lastof(lang)); } else if (strcmp(language_isocode, "zh_CN") == 0) { /* Simplified Chinese */ strecpy(lang, "zh-Hans", lastof(lang)); } else { /* Just copy the first part of the isocode. */ strecpy(lang, language_isocode, lastof(lang)); char *sep = strchr(lang, '_'); if (sep != NULL) *sep = '\0'; } /* Create a font descriptor matching the wanted language and latin (english) glyphs. */ CFStringRef lang_codes[2]; lang_codes[0] = CFStringCreateWithCString(kCFAllocatorDefault, lang, kCFStringEncodingUTF8); lang_codes[1] = CFSTR("en"); CFArrayRef lang_arr = CFArrayCreate(kCFAllocatorDefault, (const void **)lang_codes, lengthof(lang_codes), &kCFTypeArrayCallBacks); CFDictionaryRef lang_attribs = CFDictionaryCreate(kCFAllocatorDefault, (const void**)&kCTFontLanguagesAttribute, (const void **)&lang_arr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CTFontDescriptorRef lang_desc = CTFontDescriptorCreateWithAttributes(lang_attribs); CFRelease(lang_arr); CFRelease(lang_attribs); CFRelease(lang_codes[0]); /* Get array of all font descriptors for the wanted language. */ CFSetRef mandatory_attribs = CFSetCreate(kCFAllocatorDefault, (const void **)&kCTFontLanguagesAttribute, 1, &kCFTypeSetCallBacks); CFArrayRef descs = CTFontDescriptorCreateMatchingFontDescriptors(lang_desc, mandatory_attribs); CFRelease(mandatory_attribs); CFRelease(lang_desc); for (CFIndex i = 0; descs != NULL && i < CFArrayGetCount(descs); i++) { CTFontDescriptorRef font = (CTFontDescriptorRef)CFArrayGetValueAtIndex(descs, i); /* Get font traits. */ CFDictionaryRef traits = (CFDictionaryRef)CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute); CTFontSymbolicTraits symbolic_traits; CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(traits, kCTFontSymbolicTrait), kCFNumberIntType, &symbolic_traits); CFRelease(traits); /* Skip symbol fonts and vertical fonts. */ if ((symbolic_traits & kCTFontClassMaskTrait) == (CTFontStylisticClass)kCTFontSymbolicClass || (symbolic_traits & kCTFontVerticalTrait)) continue; /* Skip bold fonts (especially Arial Bold, which looks worse than regular Arial). */ if (symbolic_traits & kCTFontBoldTrait) continue; /* Select monospaced fonts if asked for. */ if (((symbolic_traits & kCTFontMonoSpaceTrait) == kCTFontMonoSpaceTrait) != callback->Monospace()) continue; /* Get font name. */ char name[128]; CFStringRef font_name = (CFStringRef)CTFontDescriptorCopyAttribute(font, kCTFontDisplayNameAttribute); CFStringGetCString(font_name, name, lengthof(name), kCFStringEncodingUTF8); CFRelease(font_name); /* There are some special fonts starting with an '.' and the last * resort font that aren't usable. Skip them. */ if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue; /* Save result. */ callback->SetFontNames(settings, name); if (!callback->FindMissingGlyphs(NULL)) { DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name); result = true; break; } } if (descs != NULL) CFRelease(descs); } else #endif { /* Create a font iterator and iterate over all fonts that * are available to the application. */ ATSFontIterator itr; ATSFontRef font; ATSFontIteratorCreate(kATSFontContextLocal, NULL, NULL, kATSOptionFlagsDefaultScope, &itr); while (!result && ATSFontIteratorNext(itr, &font) == noErr) { /* Get font name. */ char name[128]; CFStringRef font_name; ATSFontGetName(font, kATSOptionFlagsDefault, &font_name); CFStringGetCString(font_name, name, lengthof(name), kCFStringEncodingUTF8); bool monospace = IsMonospaceFont(font_name); CFRelease(font_name); /* Select monospaced fonts if asked for. */ if (monospace != callback->Monospace()) continue; /* We only want the base font and not bold or italic variants. */ if (strstr(name, "Italic") != NULL || strstr(name, "Bold")) continue; /* Skip some inappropriate or ugly looking fonts that have better alternatives. */ if (name[0] == '.' || strncmp(name, "Apple Symbols", 13) == 0 || strncmp(name, "LastResort", 10) == 0) continue; /* Save result. */ callback->SetFontNames(settings, name); if (!callback->FindMissingGlyphs(NULL)) { DEBUG(freetype, 2, "ATS-Font for %s: %s", language_isocode, name); result = true; break; } } ATSFontIteratorRelease(&itr); } if (!result) { /* For some OS versions, the font 'Arial Unicode MS' does not report all languages it * supports. If we didn't find any other font, just try it, maybe we get lucky. */ callback->SetFontNames(settings, "Arial Unicode MS"); result = !callback->FindMissingGlyphs(NULL); } callback->FindMissingGlyphs(NULL); return result; }
static CFTypeRef decode_cfvalue_sb(stream_buffer_t *sb) { trait_t trait; long number_long_long; double number_double; CFAbsoluteTime absolute_time; CFTypeRef *keys, *values; CFIndex count, i; CFTypeRef cfvalue; stream_buffer_read(sb, &trait, sizeof(trait)); if (trait == trait_string) { return decode_simple_cfstring(sb); } else if (trait == trait_data) { stream_buffer_read(sb, &count, sizeof(count)); cfvalue = stream_buffer_read_cfdata(sb, count); if (cfvalue == NULL) { return CFRetain(kCFNull); } return cfvalue; } else if (trait == trait_number_long_long || trait == trait_number_double) { if (trait == trait_number_long_long) { stream_buffer_read(sb, &number_long_long, sizeof(number_long_long)); return CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &number_long_long); } else { stream_buffer_read(sb, &number_double, sizeof(number_double)); return CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &number_double); } } else if (trait == trait_boolean_true || trait == trait_boolean_false) { return CFRetain((trait == trait_boolean_true) ? kCFBooleanTrue : kCFBooleanFalse); } else if (trait == trait_date) { stream_buffer_read(sb, &absolute_time, sizeof(absolute_time)); return CFDateCreate(kCFAllocatorDefault, absolute_time); } else if (trait == trait_dictionary) { stream_buffer_read(sb, &count, sizeof(count)); keys = (CFTypeRef *)malloc(sizeof(CFTypeRef) * count); values = (CFTypeRef *)malloc(sizeof(CFTypeRef) * count); for (i = 0; i < count; i++) { stream_buffer_move_cursor(sb, sizeof(trait)); keys[i] = decode_simple_cfstring(sb); values[i] = decode_cfvalue_sb(sb); } cfvalue = CFDictionaryCreate(kCFAllocatorDefault, keys, values, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); free(keys); free(values); return cfvalue; } else if (trait == trait_array || trait == trait_set) { stream_buffer_read(sb, &count, sizeof(count)); values = (CFTypeRef *)malloc(sizeof(CFTypeRef) * count); for (i = 0; i < count; i++) { values[i] = decode_cfvalue_sb(sb); } if (trait == trait_array) { cfvalue = CFArrayCreate(kCFAllocatorDefault, values, count, &kCFTypeArrayCallBacks); } else { cfvalue = CFSetCreate(kCFAllocatorDefault, values, count, &kCFTypeSetCallBacks); } free(values); return cfvalue; } else { return CFRetain(kCFNull); } }