void populateFontDatabase() { static bool initialized; if (initialized) return; initialized = true; if (wkCanCreateCGFontWithLOGFONT()) return; RetainPtr<CFPropertyListRef> propertyList = readFontPlist(); RetainPtr<CFArrayRef> lastFilenamesFromRegistry; if (propertyList && CFGetTypeID(propertyList.get()) == CFDictionaryGetTypeID()) { CFDictionaryRef dictionary = static_cast<CFDictionaryRef>(propertyList.get()); CFArrayRef array = static_cast<CFArrayRef>(CFDictionaryGetValue(dictionary, fontFilenamesFromRegistryKey())); if (array && CFGetTypeID(array) == CFArrayGetTypeID()) lastFilenamesFromRegistry = array; } RetainPtr<CFArrayRef> currentFilenamesFromRegistry = fontFilenamesFromRegistry(); bool registryChanged = !lastFilenamesFromRegistry || !CFEqual(lastFilenamesFromRegistry.get(), currentFilenamesFromRegistry.get()); if (!registryChanged && !systemHasFontsNewerThanFontsPlist()) { if (populateFontDatabaseFromPlist(propertyList.get())) return; } if (populateFontDatabaseFromFileSystem()) { wkAddFontsFromRegistry(); RetainPtr<CFPropertyListRef> cgFontDBPropertyList(AdoptCF, wkCreateFontsPlist()); writeFontDatabaseToPlist(cgFontDBPropertyList.get(), currentFilenamesFromRegistry.get()); } }
static bool populateFontDatabaseFromPlist() { RetainPtr<CFPropertyListRef> plist = readFontPlist(); if (!plist) return false; RetainPtr<CFDataRef> data(AdoptCF, CFPropertyListCreateXMLData(0, plist.get())); if (!data) return false; wkAddFontsFromPlistRepresentation(data.get()); return true; }