const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { SimpleFontData* fontData = 0; fontData = getCachedFontData(font.fontDescription(), font.family().family()); if (!fontData->containsCharacters(characters, length)) fontData = getSimilarFontPlatformData(font); if (!fontData->containsCharacters(characters, length)) fontData = getLastResortFallbackFont(font.fontDescription()); ASSERT(fontData); return fontData; }
const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { #if defined(USE_FREETYPE) FcResult fresult; FontPlatformData* prim = const_cast<FontPlatformData*>(&font.primaryFont()->platformData()); if (!prim->m_fallbacks) prim->m_fallbacks = FcFontSort(NULL, prim->m_pattern, FcTrue, NULL, &fresult); FcFontSet* fs = prim->m_fallbacks; for (int i = 0; i < fs->nfont; i++) { FcPattern* fin = FcFontRenderPrepare(NULL, prim->m_pattern, fs->fonts[i]); cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_pattern(fin); FontPlatformData alternateFont(fontFace, font.fontDescription().computedPixelSize(), false, false); cairo_font_face_destroy(fontFace); alternateFont.m_pattern = fin; SimpleFontData* sfd = getCachedFontData(&alternateFont); if (sfd->containsCharacters(characters, length)) return sfd; } #endif return 0; }
const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length) { FcResult fresult; // Avoid copying FontPlatformData. FontPlatformData* prim = const_cast<FontPlatformData*>(&font.primaryFont()->m_font); if (!prim->m_fallbacks) prim->m_fallbacks = FcFontSort(NULL, prim->m_pattern, FcTrue, NULL, &fresult); FcFontSet* fs = prim->m_fallbacks; FT_Library library = FontPlatformData::m_library; FcChar8* fc_filename; char* filename; int id; FT_Face face; for (int i = 0; i < fs->nfont; i++) { FcPattern* fin = FcFontRenderPrepare(0, prim->m_pattern, fs->fonts[i]); if (FcPatternGetString(fin, FC_FILE, 0, &fc_filename) != FcResultMatch) continue; filename = (char *) fc_filename; // Use C cast as FcChar is a fontconfig type. if (FcPatternGetInteger(fin, FC_INDEX, 0, &id) != FcResultMatch) continue; if (FT_Error error = FT_New_Face(library, filename, id, &face)) continue; // FIXME: is it really necessary ? FT_Set_Pixel_Sizes(face, 0, static_cast<uint> (font.fontDescription().computedSize())); FontPlatformData alternateFont(face, font.fontDescription().computedPixelSize(), false, false); // FIXME: FT_Done_Face(face); we should clean the face correctly the FT_Face but we can't do that here... alternateFont.m_pattern = fin; SimpleFontData* sfd = getCachedFontData(&alternateFont); if (sfd->containsCharacters(characters, length)) return sfd; } return 0; }