static void load_font_from_fontconfig(void) { FcConfig* config = FcInitLoadConfigAndFonts(); FcFontSet* fontset = NULL; // get application fonts fontset = FcConfigGetFonts(config, FcSetApplication); if (fontset) { FcValue fvalue, dvalue; for (int i = 0; i < fontset->nfont; i++) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FAMILY, 0, &fvalue)) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FILE, 0, &dvalue)) { font_item* font = get_font_item((const char*)fvalue.u.s, (const char*)dvalue.u.s); g_font_map.add(font); } } } } // get system fonts fontset = FcConfigGetFonts(config, FcSetSystem); if (fontset) { FcValue fvalue, dvalue; for (int i = 0; i < fontset->nfont; i++) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FAMILY, 0, &fvalue)) { if (FcResultMatch == FcPatternGet(fontset->fonts[i], FC_FILE, 0, &dvalue)) { font_item* font = get_font_item((const char*)fvalue.u.s, (const char*)dvalue.u.s); g_font_map.add(font); } } } } FcConfigDestroy(config); }
// ----------------------------------------- font_manager_match_description --- char * font_manager_match_description( font_manager_t * self, const char * family, const float size, const int bold, const int italic ) { // Use of fontconfig is disabled by default. #if 1 return 0; #else # if defined _WIN32 || defined _WIN64 fprintf( stderr, "\"font_manager_match_description\" not implemented for windows.\n" ); return 0; # endif char *filename = 0; int weight = FC_WEIGHT_REGULAR; int slant = FC_SLANT_ROMAN; if ( bold ) { weight = FC_WEIGHT_BOLD; } if( italic ) { slant = FC_SLANT_ITALIC; } FcInit(); FcPattern *pattern = FcPatternCreate(); FcPatternAddDouble( pattern, FC_SIZE, size ); FcPatternAddInteger( pattern, FC_WEIGHT, weight ); FcPatternAddInteger( pattern, FC_SLANT, slant ); FcPatternAddString( pattern, FC_FAMILY, (FcChar8*) family ); FcConfigSubstitute( 0, pattern, FcMatchPattern ); FcDefaultSubstitute( pattern ); FcResult result; FcPattern *match = FcFontMatch( 0, pattern, &result ); FcPatternDestroy( pattern ); if ( !match ) { fprintf( stderr, "fontconfig error: could not match family '%s'", family ); return 0; } else { FcValue value; FcResult result = FcPatternGet( match, FC_FILE, 0, &value ); if ( result ) { fprintf( stderr, "fontconfig error: could not match family '%s'", family ); } else { filename = strdup( (char *)(value.u.s) ); } } FcPatternDestroy( match ); return filename; #endif }
static AliasStrength strengthOfFirstAlias(const FcPattern& original) { // Ideally there would exist a call like // FcResult FcPatternIsWeak(pattern, object, id, FcBool* isWeak); // // However, there is no such call and as of Fc 2.11.0 even FcPatternEquals ignores the weak bit. // Currently, the only reliable way of finding the weak bit is by its effect on matching. // The weak bit only affects the matching of FC_FAMILY and FC_POSTSCRIPT_NAME object values. // A element with the weak bit is scored after FC_LANG, without the weak bit is scored before. // Note that the weak bit is stored on the element, not on the value it holds. FcValue value; FcResult result = FcPatternGet(&original, FC_FAMILY, 0, &value); if (result != FcResultMatch) return AliasStrength::Done; RefPtr<FcPattern> pattern = adoptRef(FcPatternDuplicate(&original)); FcBool hasMultipleFamilies = true; while (hasMultipleFamilies) hasMultipleFamilies = FcPatternRemove(pattern.get(), FC_FAMILY, 1); // Create a font set with two patterns. // 1. the same FC_FAMILY as pattern and a lang object with only 'nomatchlang'. // 2. a different FC_FAMILY from pattern and a lang object with only 'matchlang'. FcUniquePtr<FcFontSet> fontSet(FcFontSetCreate()); FcUniquePtr<FcLangSet> strongLangSet(FcLangSetCreate()); FcLangSetAdd(strongLangSet.get(), reinterpret_cast<const FcChar8*>("nomatchlang")); // Ownership of this FcPattern will be transferred with FcFontSetAdd. FcPattern* strong = FcPatternDuplicate(pattern.get()); FcPatternAddLangSet(strong, FC_LANG, strongLangSet.get()); FcUniquePtr<FcLangSet> weakLangSet(FcLangSetCreate()); FcLangSetAdd(weakLangSet.get(), reinterpret_cast<const FcChar8*>("matchlang")); // Ownership of this FcPattern will be transferred via FcFontSetAdd. FcPattern* weak = FcPatternCreate(); FcPatternAddString(weak, FC_FAMILY, reinterpret_cast<const FcChar8*>("nomatchstring")); FcPatternAddLangSet(weak, FC_LANG, weakLangSet.get()); FcFontSetAdd(fontSet.get(), strong); FcFontSetAdd(fontSet.get(), weak); // Add 'matchlang' to the copy of the pattern. FcPatternAddLangSet(pattern.get(), FC_LANG, weakLangSet.get()); // Run a match against the copy of the pattern. // If the first element was weak, then we should match the pattern with 'matchlang'. // If the first element was strong, then we should match the pattern with 'nomatchlang'. // Note that this config is only used for FcFontRenderPrepare, which we don't even want. // However, there appears to be no way to match/sort without it. RefPtr<FcConfig> config = adoptRef(FcConfigCreate()); FcFontSet* fontSets[1] = { fontSet.get() }; RefPtr<FcPattern> match = adoptRef(FcFontSetMatch(config.get(), fontSets, 1, pattern.get(), &result)); FcLangSet* matchLangSet; FcPatternGetLangSet(match.get(), FC_LANG, 0, &matchLangSet); return FcLangEqual == FcLangSetHasLang(matchLangSet, reinterpret_cast<const FcChar8*>("matchlang")) ? AliasStrength::Weak : AliasStrength::Strong; }
static Bool hasProperty(FcPattern *pattern, const char *property) { FcValue val; if (FcPatternGet(pattern, property, 0, &val)==FcResultMatch) { return True; } return False; }
// ------------------------------------------------------ match_description --- char * //match_description( char * description ) match_description( const char * face, bool bold=false, bool italic=false ) { #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) fprintf( stderr, "\"font_manager_match_description\" " "not implemented for windows.\n" ); return 0; #endif char *filename = 0; FcInit(); //FcPattern *pattern = FcNameParse((const FcChar8*)description); FcPattern *pattern = FcPatternCreate(); if(!pattern) { fprintf( stderr, "fontconfig error: could not match face '%s'", face ); return 0; } FcPatternAddString(pattern, FC_FAMILY, (const FcChar8*)face); FcPatternAddInteger(pattern, FC_WEIGHT, bold?FC_WEIGHT_BOLD:FC_WEIGHT_REGULAR); FcPatternAddInteger(pattern, FC_SLANT, italic?FC_SLANT_ITALIC:FC_SLANT_ROMAN); FcConfigSubstitute( 0, pattern, FcMatchPattern ); FcDefaultSubstitute( pattern ); FcResult result; FcPattern *match = FcFontMatch( 0, pattern, &result ); FcPatternDestroy( pattern ); if ( !match ) { fprintf( stderr, "fontconfig error: could not match face '%s'", face ); return 0; } else { FcValue value; FcResult result = FcPatternGet( match, FC_FILE, 0, &value ); if ( result ) { fprintf( stderr, "fontconfig error: could not match face '%s'", face ); } else { filename = strdup( (char *)(value.u.s) ); } } FcPatternDestroy( match ); return filename; }
static VALUE shoes_make_font_list(FcFontSet *fonts, VALUE ary) { int i = 0; for (i = 0; i < fonts->nfont; i++) { FcValue val; FcPattern *p = fonts->fonts[i]; if (FcPatternGet(p, FC_FAMILY, 0, &val) == FcResultMatch) rb_ary_push(ary, rb_str_new2((char *)val.u.s)); } rb_funcall(ary, rb_intern("uniq!"), 0); rb_funcall(ary, rb_intern("sort!"), 0); return ary; }
CAMLprim value pattern_get(value pat, value prop, value id) { CAMLparam0(); CAMLlocal1(res); FcResult result; FcValue val; result = FcPatternGet(FcPattern_val(pat), String_val(prop), Int_val(id), &val); switch(result) { case FcResultMatch: res = caml_from_fcvalue(val); break; case FcResultNoId: caml_invalid_argument("pattern object id"); break; default: caml_invalid_argument("pattern object unsupported type"); break; } CAMLreturn(res); }
static void * evas_load_fontconfig(Evas *evas, FcFontSet *set, int size) { void *font = NULL; int i; /* Do loading for all in family */ for (i = 0; i < set->nfont; i++) { FcValue filename; FcPatternGet(set->fonts[i], FC_FILE, 0, &filename); if (font) evas->engine.func->font_add(evas->engine.data.output, font, (char *)filename.u.s, size); else font = evas->engine.func->font_load(evas->engine.data.output, (char *)filename.u.s, size); } return font; }
static Evas_Font_Set * _evas_load_fontconfig(Evas_Font_Set *font, Evas *eo_evas, FcFontSet *set, int size, Font_Rend_Flags wanted_rend) { Evas_Public_Data *evas = eo_data_scope_get(eo_evas, EVAS_CLASS); int i; /* Do loading for all in family */ for (i = 0; i < set->nfont; i++) { FcValue filename; FcPatternGet(set->fonts[i], FC_FILE, 0, &filename); if (font) evas->engine.func->font_add(evas->engine.data.output, font, (char *)filename.u.s, size, wanted_rend); else font = evas->engine.func->font_load(evas->engine.data.output, (char *)filename.u.s, size, wanted_rend); } return font; }
void SkScalerContext_CairoFT::resolvePattern(FcPattern* pattern) { if (!pattern) { return; } FcValue value; if (FcPatternGet(pattern, FC_PIXEL_SIZE, 0, &value) == FcResultNoMatch) { SkAutoTUnref<FcPattern> scalePattern(FcPatternDuplicate(pattern)); if (scalePattern && FcPatternAddDouble(scalePattern, FC_PIXEL_SIZE, fScaleY) && FcConfigSubstitute(nullptr, scalePattern, FcMatchPattern)) { FcDefaultSubstitute(scalePattern); FcResult result; SkAutoTUnref<FcPattern> resolved(FcFontMatch(nullptr, scalePattern, &result)); if (resolved) { parsePattern(resolved); return; } } } parsePattern(pattern); }
/* Ask the fontgod for a generic, standard issue "Arial" font */ const char *graph_init_fontconfig(void) { /* Offer fontgod sacrificial pointers to hold his highness */ FcConfig *fc_config = FcInitLoadConfigAndFonts(); FcPattern *fc_pattern = FcPatternCreate(); /* Ask the deity for a user-specified gift of typography */ FcPatternAddString(fc_pattern, FC_FAMILY, (const FcChar8 *)option->fontname); /* Ask fontgod not to blind our eyes for our insolence */ FcPatternAddBool(fc_pattern, FC_ANTIALIAS, 1); /* Summon a fontdemon which shall transmit the gifts of our god */ FcResult fc_result; /* Incantation for our omnipotence to recognize our request: */ FcDefaultSubstitute(fc_pattern); FcConfigSubstitute(fc_config, fc_pattern, FcMatchPattern); /* "We ask you, oh you in the sky, for your attention..." */ FcPattern *fc_font_chosen = FcFontMatch(fc_config, fc_pattern, &fc_result); FcValue fc_value; /* SHOW US YOUR POWER, INVOKE ANCIENT KNOWLEDGE, GIVE US THE LOCATION! */ FcPatternGet(fc_font_chosen, "file", 0, &fc_value); /* Fontgod has given us a sacred filename, hail FONTCONFIG! */ pprintf(PRI_SPAM, "[FC] Font path received = %s\n", (char *)fc_value.u.s); return (const char *)fc_value.u.s; }
std::string PdfFontCache::GetFontConfigFontPath( FcConfig* pConfig, const char* pszFontName, bool bBold, bool bItalic ) { FcPattern* pattern; FcPattern* matched; FcResult result = FcResultMatch; FcValue v; std::string sPath; // Build a pattern to search using fontname, bold and italic pattern = FcPatternBuild (0, FC_FAMILY, FcTypeString, pszFontName, FC_WEIGHT, FcTypeInteger, (bBold ? FC_WEIGHT_BOLD : FC_WEIGHT_MEDIUM), FC_SLANT, FcTypeInteger, (bItalic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN), static_cast<char*>(0)); FcDefaultSubstitute( pattern ); if( !FcConfigSubstitute( pConfig, pattern, FcMatchFont ) ) { FcPatternDestroy( pattern ); return sPath; } matched = FcFontMatch( pConfig, pattern, &result ); if( result != FcResultNoMatch ) { result = FcPatternGet( matched, FC_FILE, 0, &v ); sPath = reinterpret_cast<const char*>(v.u.s); #ifdef PODOFO_VERBOSE_DEBUG printf("Got Font %s for for %s\n", sPath.c_str(), pszFontname ); #endif // PODOFO_DEBUG } FcPatternDestroy( pattern ); FcPatternDestroy( matched ); return sPath; }
static TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles) { TTF_Font *font = (TTF_Font *)NULL; FcConfig *config; FcPattern *pat; FcObjectSet *os; FcFontSet *fontset; FcValue val; config = FcConfigGetCurrent(); pat = FcPatternCreate(); os = FcObjectSetCreate(); FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); // try and get a font with the requested styles baked-in if (bold) { if (italic) { FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold Italic"); } else { FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Bold"); } } else if (italic) { FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Italic"); } else { FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); } FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); FcObjectSetAdd(os, FC_FILE); fontset = FcFontList(config, pat, os); for (int i = 0; i < fontset->nfont; i++) { if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) { continue; } if (val.type != FcTypeString) { continue; } mame_printf_verbose("Matching font: %s\n", val.u.s); { astring match_name((const char*)val.u.s); font = TTF_OpenFont_Magic(match_name, POINT_SIZE); } if (font) { bakedstyles = true; break; } } // didn't get a font above? try again with no baked-in styles if (!font) { FcPatternDestroy(pat); FcFontSetDestroy(fontset); pat = FcPatternCreate(); FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *)name.cstr()); FcPatternAddString(pat, FC_STYLE, (const FcChar8 *)"Regular"); FcPatternAddString(pat, FC_FONTFORMAT, (const FcChar8 *)"TrueType"); fontset = FcFontList(config, pat, os); for (int i = 0; i < fontset->nfont; i++) { if (FcPatternGet(fontset->fonts[i], FC_FILE, 0, &val) != FcResultMatch) { continue; } if (val.type != FcTypeString) { continue; } mame_printf_verbose("Matching unstyled font: %s\n", val.u.s); { astring match_name((const char*)val.u.s); font = TTF_OpenFont_Magic(match_name, POINT_SIZE); } if (font) { break; } } } FcPatternDestroy(pat); FcObjectSetDestroy(os); FcFontSetDestroy(fontset); return font; }
XftResult XftPatternGet (XftPattern *p, const char *object, int id, XftValue *v) { return FcPatternGet (p, object, id, v); }