static void writeFontDatabaseToPlist() { RetainPtr<CFDataRef> data(AdoptCF, wkCreateFontsPlistRepresentation()); if (!data) return; safeCreateFile(fontsPlistPath(), data.get()); }
static bool systemHasFontsNewerThanFontsPlist() { WIN32_FILE_ATTRIBUTE_DATA plistAttributes = {0}; if (!GetFileAttributesEx(fontsPlistPath().charactersWithNullTermination(), GetFileExInfoStandard, &plistAttributes)) return true; WIN32_FILE_ATTRIBUTE_DATA fontsDirectoryAttributes = {0}; if (!GetFileAttributesEx(systemFontsDirectory().charactersWithNullTermination(), GetFileExInfoStandard, &fontsDirectoryAttributes)) return true; return CompareFileTime(&plistAttributes.ftLastWriteTime, &fontsDirectoryAttributes.ftLastWriteTime) < 0; }
static void writeFontDatabaseToPlist(CFPropertyListRef cgFontDBPropertyList, CFPropertyListRef filenamesFromRegistry) { if (!cgFontDBPropertyList) return; RetainPtr<CFDataRef> data; if (!filenamesFromRegistry || CFGetTypeID(cgFontDBPropertyList) != CFDictionaryGetTypeID()) data.adoptCF(CFPropertyListCreateXMLData(kCFAllocatorDefault, cgFontDBPropertyList)); else { RetainPtr<CFMutableDictionaryRef> dictionary(AdoptCF, CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 2, static_cast<CFDictionaryRef>(cgFontDBPropertyList))); CFDictionarySetValue(dictionary.get(), fontFilenamesFromRegistryKey(), filenamesFromRegistry); data.adoptCF(CFPropertyListCreateXMLData(kCFAllocatorDefault, dictionary.get())); } if (!data) return; safeCreateFile(fontsPlistPath(), data.get()); }
static RetainPtr<CFPropertyListRef> readFontPlist() { CString plistPath = fontsPlistPath().utf8(); RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, reinterpret_cast<const UInt8*>(plistPath.data()), plistPath.length(), false)); if (!url) return 0; RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, url.get())); if (!stream) return 0; if (!CFReadStreamOpen(stream.get())) return 0; CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0; RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0)); CFReadStreamClose(stream.get()); return plist; }