Common::SeekableReadStream *AndroidFontProvider::createReadStreamForFont(const Common::String &name, uint32 style) { // Android stores its system fonts, appropriately in /system/fonts Common::FSNode fontNode("/system/fonts"); if (!fontNode.exists() || !fontNode.isDirectory()) { warning("Failed to find fonts directory"); return 0; } Graphics::FontProperties property(name, Graphics::getFontStyleString(style)); Graphics::FontPropertyMap fontMap = Graphics::scanDirectoryForTTF(fontNode.getPath()); Graphics::FontPropertyMap::iterator it = fontMap.find(property); if (it != fontMap.end()) { Common::FSNode child(it->_value); return child.createReadStream(); } // Failed to find the font return 0; }
Common::SeekableReadStream *FontconfigFontProvider::createReadStreamForFont(const Common::String &name, uint32 style) { if (!_config) return 0; Common::String styleName = makeStyleString(style); FcPattern *pattern = FcPatternCreate(); // Match on the family name FcValue value; value.type = FcTypeString; value.u.s = reinterpret_cast<const FcChar8 *>(name.c_str()); if (!FcPatternAdd(pattern, FC_FAMILY, value, FcFalse)) { FcPatternDestroy(pattern); return 0; } // Match on the style string value.u.s = reinterpret_cast<const FcChar8 *>(styleName.c_str()); if (!FcPatternAdd(pattern, FC_STYLE, value, FcFalse)) { FcPatternDestroy(pattern); return 0; } // Only allow TrueType fonts // Might change in the future. value.u.s = reinterpret_cast<const FcChar8 *>("TrueType"); if (!FcPatternAdd(pattern, FC_FONTFORMAT, value, FcFalse)) { FcPatternDestroy(pattern); return 0; } // Call these functions // Might be doing pattern matching. Documentation is awful. FcConfigSubstitute(0, pattern, FcMatchPattern); FcDefaultSubstitute(pattern); // Fetch the match FcResult result; FcFontSet* fontSet = FcFontSort(0, pattern, 0, 0, &result); FcPatternDestroy(pattern); if (!fontSet) return 0; for (int i = 0; i < fontSet->nfont; i++) { FcPattern *foundPattern = fontSet->fonts[i]; // Get the family name of the font FcChar8 *familyName; if (FcPatternGetString(foundPattern, FC_FAMILY, 0, &familyName) != FcResultMatch) continue; // If we don't actually match, bail out. We don't want to end // up with the default fontconfig font, which would look horrible. if (!name.equalsIgnoreCase(reinterpret_cast<const char *>(familyName))) continue; // Get the name of the font FcChar8 *fileName; if (FcPatternGetString(foundPattern, FC_FILE, 0, &fileName) != FcResultMatch) continue; // Let's make sure we can actually get that Common::FSNode fontNode(reinterpret_cast<const char *>(fileName)); if (!fontNode.exists() || !fontNode.isReadable()) continue; debug(1, "Matched %s %s -> '%s'", name.c_str(), styleName.c_str(), fontNode.getPath().c_str()); FcFontSetDestroy(fontSet); return fontNode.createReadStream(); } // We ain't found s#&t FcFontSetDestroy(fontSet); return 0; }