FcPattern* BC_Resources::find_similar_font(FT_ULong char_code, FcPattern *oldfont) { FcPattern *pat, *font; FcFontSet *fs; FcObjectSet *os; FcCharSet *fcs; FcChar8 *file; double dval; int ival; // Do not search control codes if(char_code < ' ') return 0; fontconfig_lock.lock("BC_Resources::find_similar_font"); pat = FcPatternCreate(); os = FcObjectSetBuild(FC_FILE, FC_CHARSET, FC_SCALABLE, FC_FAMILY, FC_SLANT, FC_WEIGHT, FC_WIDTH, (char *)0); FcPatternAddBool(pat, FC_SCALABLE, true); fcs = FcCharSetCreate(); if(FcCharSetAddChar(fcs, char_code)) FcPatternAddCharSet(pat, FC_CHARSET, fcs); FcCharSetDestroy(fcs); for(int i = 0; i < LEN_FCPROP; i++) { if(FcPatternGetInteger(oldfont, fc_properties[i], 0, &ival) == FcResultMatch) FcPatternAddInteger(pat, fc_properties[i], ival); } fs = FcFontList(0, pat, os); for(int i = LEN_FCPROP - 1; i >= 0 && fs->nfont == 0; i--) { FcFontSetDestroy(fs); FcPatternDel(pat, fc_properties[i]); fs = FcFontList(0, pat, os); } FcPatternDestroy(pat); FcObjectSetDestroy(os); pat = 0; for (int i = 0; i < fs->nfont; i++) { font = fs->fonts[i]; if(FcPatternGetCharSet(font, FC_CHARSET, 0, &fcs) == FcResultMatch) { if(FcCharSetHasChar(fcs, char_code)) { pat = FcPatternDuplicate(font); break; } } } FcFontSetDestroy(fs); fontconfig_lock.unlock(); return pat; }
SkDataTable* SkFontConfigInterfaceDirect::getFamilyNames() { SkAutoMutexAcquire ac(mutex_); FcPattern* pat = FcPatternCreate(); SkAutoTCallVProc<FcPattern, FcPatternDestroy> autoDestroyPat(pat); if (NULL == pat) { return NULL; } FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, (char *)0); SkAutoTCallVProc<FcObjectSet, FcObjectSetDestroy> autoDestroyOs(os); if (NULL == os) { return NULL; } FcFontSet* fs = FcFontList(NULL, pat, os); SkAutoTCallVProc<FcFontSet, FcFontSetDestroy> autoDestroyFs(fs); if (NULL == fs) { return NULL; } SkTDArray<const char*> names; SkTDArray<size_t> sizes; for (int i = 0; i < fs->nfont; ++i) { FcPattern* match = fs->fonts[i]; const char* famName = get_name(match, FC_FAMILY); if (famName && !find_name(names, famName)) { *names.append() = famName; *sizes.append() = strlen(famName) + 1; } } return SkDataTable::NewCopyArrays((const void*const*)names.begin(), sizes.begin(), names.count()); }
static void findfont(char *fontname, char *fontpath) { FcPattern *p = NULL; FcChar8 *strval = NULL; FcObjectSet *attr = NULL; if (!FcInit()) return; attr = FcObjectSetBuild (FC_FILE, (char *) 0); p = FcNameParse((FcChar8*)fontname); if (p == NULL) return; FcFontSet *fs = FcFontList (0, p, attr); if (fs->nfont == 0) return; if (FcPatternGetString(fs->fonts[0], FC_FILE, 0, &strval) == FcResultTypeMismatch || strval == NULL) return; strcpy(fontpath, strval); FcFontSetDestroy(fs); FcObjectSetDestroy(attr); FcPatternDestroy(p); FcFini(); return; }
void XeTeXFontMgr_FC::initialize() { if (FcInit() == FcFalse) { fprintf(stderr, "fontconfig initialization failed!\n"); exit(9); } if (gFreeTypeLibrary == 0 && FT_Init_FreeType(&gFreeTypeLibrary) != 0) { fprintf(stderr, "FreeType initialization failed!\n"); exit(9); } UErrorCode err = U_ZERO_ERROR; macRomanConv = ucnv_open("macintosh", &err); utf16beConv = ucnv_open("UTF16BE", &err); utf8Conv = ucnv_open("UTF8", &err); if (err != 0) { fprintf(stderr, "internal error; cannot read font names\n"); exit(3); } FcPattern* pat = FcNameParse((const FcChar8*)":outline=true"); FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_FILE, FC_INDEX, FC_FULLNAME, FC_WEIGHT, FC_WIDTH, FC_SLANT, NULL); allFonts = FcFontList(FcConfigGetCurrent(), pat, os); FcObjectSetDestroy(os); FcPatternDestroy(pat); cachedAll = false; }
static FcBool _claro_ft2_list_families(claro_ft2_backend * backend) { FcPattern * pattern; FcFontSet * set; FcObjectSet * os; int i; pattern = FcPatternCreate(); g_return_val_if_fail(pattern != NULL, FALSE); os = FcObjectSetCreate(); g_return_val_if_fail(FcObjectSetAdd(os, FC_FAMILY), FALSE); set = FcFontList(backend->config, pattern, os); g_return_val_if_fail(set != NULL, FALSE); qsort((void *)set->fonts, set->nfont, sizeof(void *), _cmp_font_family); for(i = 0; i < set->nfont; i++) { FcChar8 * family; FcPattern * font = set->fonts[i]; FcPatternGetString (font, FC_FAMILY, 0, &family); claro_list_append(backend->font_families, sstrdup(family)); } FcFontSetDestroy(set); FcObjectSetDestroy(os); FcPatternDestroy(pattern); return TRUE; }
GeeArrayList * FcListFiles(void) { int i; FcPattern * pattern; FcFontSet * fontset; FcObjectSet * objectset = 0; GeeArrayList * filelist = gee_array_list_new(G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free0, NULL, NULL, NULL); g_assert(FcInit()); pattern = FcNameParse((FcChar8 *) ":"); objectset = FcObjectSetBuild (FC_FILE, NULL); fontset = FcFontList(NULL, pattern, objectset); for (i = 0; i < fontset->nfont; i++) { FcChar8 * file; if (FcPatternGetString(fontset->fonts[i], FC_FILE, 0, &file) == FcResultMatch) gee_abstract_collection_add((GeeAbstractCollection *) filelist, file); } if (objectset) FcObjectSetDestroy(objectset); if (pattern) FcPatternDestroy(pattern); if (fontset) FcFontSetDestroy(fontset); return filelist; }
gchar* find_font_with_property (FcConfig* fontconfig, const gchar* characters, const gchar* property) { FcPattern* pattern; FcCharSet* character_set; FcObjectSet* font_properties; FcFontSet* fonts; FcPattern* font; FcChar8* path; gchar* result; gchar* remaining_characters; gunichar character; if (fontconfig == NULL) { g_warning("Font config not loaded."); return NULL; } result = NULL; pattern = FcPatternCreate (); character_set = FcCharSetCreate (); remaining_characters = (gchar*) characters; while (TRUE) { character = g_utf8_get_char (remaining_characters); if (character == '\0') { break; } FcCharSetAddChar(character_set, character); remaining_characters = g_utf8_next_char (remaining_characters); } FcPatternAddCharSet (pattern, FC_CHARSET, character_set); FcCharSetDestroy (character_set); FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN); FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); font_properties = FcObjectSetBuild (property, NULL); fonts = FcFontList (fontconfig, pattern, font_properties); if (fonts && fonts->nfont > 0) { font = fonts->fonts[0]; if (FcPatternGetString(font, property, 0, &path) == FcResultMatch) { result = g_strdup ((gchar*) path); } } if (fonts) { FcFontSetDestroy(fonts); } if (pattern) { FcPatternDestroy(pattern); } return result; }
FcFontSet * XftListFontsPatternObjects (Display *dpy, int screen, FcPattern *pattern, FcObjectSet *os) { return FcFontList (0, pattern, os); }
///////////////////////////////// // font_config_magic_class methods font_config_magic_class:: font_config_magic_class(void) { FcPattern *fc_pattern; FcObjectSet *fc_object_set; /* require those fonts that are both scalable and outline fonts. */ fc_pattern=FcPatternCreate(); FcPatternAddBool(fc_pattern, FC_OUTLINE, FcTrue); FcPatternAddBool(fc_pattern, FC_SCALABLE, FcTrue); /* add the properties we care about to fc_object_set */ const char *fc_properties[]= { FC_FAMILY, FC_WEIGHT, FC_SLANT, FC_FILE, FC_INDEX, FC_FOUNDRY, FC_SCALABLE, FC_OUTLINE, FC_LANG, FC_STYLE, NULL }; fc_object_set=FcObjectSetCreate(); for(const char **iter=fc_properties; *iter!=NULL; ++iter) { FcObjectSetAdd(fc_object_set, *iter); } /* get a list of fonts from the default font configuration which are scalable outline fonts. */ m_fc_font_list=FcFontList(NULL, fc_pattern, fc_object_set); for(int i=0; i<m_fc_font_list->nfont; ++i) { add_entry(m_fc_font_list->fonts[i]); } FcPatternDestroy(fc_pattern); FcObjectSetDestroy(fc_object_set); /* for(FontList::const_iterator iter=m_font_list.begin(), end=m_font_list.end(); iter!=end; ++iter) { print_pretty_formatted(std::cout, iter->second); } */ }
/* make sure the font list is valid */ static void ensure_font_list (FontViewModel *self) { FcPattern *pat; FcObjectSet *os; gint i; FcChar8 *file; gchar *font_name, *collation_key; GdkPixbuf *pix; if (self->priv->font_list) { FcFontSetDestroy (self->priv->font_list); self->priv->font_list = NULL; } gtk_list_store_clear (GTK_LIST_STORE (self)); /* always reinitialize the font database */ if (!FcInitReinitialize()) return; pat = FcPatternCreate (); os = FcObjectSetBuild (FC_FILE, FC_FAMILY, FC_WEIGHT, FC_SLANT, NULL); self->priv->font_list = FcFontList (NULL, pat, os); FcPatternDestroy (pat); FcObjectSetDestroy (os); if (!self->priv->font_list) return; for (i = 0; i < self->priv->font_list->nfont; i++) { FcPatternGetString (self->priv->font_list->fonts[i], FC_FILE, 0, &file); font_name = font_utils_get_font_name_for_file (self->priv->library, (const gchar *) file); if (!font_name) continue; pix = get_fallback_icon (); collation_key = g_utf8_collate_key (font_name, -1); gtk_list_store_insert_with_values (GTK_LIST_STORE (self), NULL, -1, COLUMN_NAME, font_name, COLUMN_POINTER, self->priv->font_list->fonts[i], COLUMN_PATH, file, COLUMN_ICON, pix, COLUMN_COLLATION_KEY, collation_key, -1); ensure_thumbnail (self, (const gchar *) file); g_free (font_name); g_free (collation_key); g_object_unref (pix); } }
static gboolean language_has_font (const gchar *locale) { const FcCharSet *charset; FcPattern *pattern; FcObjectSet *object_set; FcFontSet *font_set; gchar *language_code; gboolean is_displayable; is_displayable = FALSE; pattern = NULL; object_set = NULL; font_set = NULL; if (!gdm_parse_language_name (locale, &language_code, NULL, NULL, NULL)) return FALSE; charset = FcLangGetCharSet ((FcChar8 *) language_code); if (!charset) { /* fontconfig does not know about this language */ is_displayable = TRUE; } else { /* see if any fonts support rendering it */ pattern = FcPatternBuild (NULL, FC_LANG, FcTypeString, language_code, NULL); if (pattern == NULL) goto done; object_set = FcObjectSetCreate (); if (object_set == NULL) goto done; font_set = FcFontList (NULL, pattern, object_set); if (font_set == NULL) goto done; is_displayable = (font_set->nfont > 0); } done: if (font_set != NULL) FcFontSetDestroy (font_set); if (object_set != NULL) FcObjectSetDestroy (object_set); if (pattern != NULL) FcPatternDestroy (pattern); g_free (language_code); return is_displayable; }
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, SetFallbackFontCallback *callback) { if (!FcInit()) return false; bool ret = false; /* Fontconfig doesn't handle full language isocodes, only the part * before the _ of e.g. en_GB is used, so "remove" everything after * the _. */ char lang[16]; seprintf(lang, lastof(lang), ":lang=%s", language_isocode); char *split = strchr(lang, '_'); if (split != NULL) *split = '\0'; /* First create a pattern to match the wanted language. */ FcPattern *pat = FcNameParse((FcChar8*)lang); /* We only want to know the filename. */ FcObjectSet *os = FcObjectSetBuild(FC_FILE, NULL); /* Get the list of filenames matching the wanted language. */ FcFontSet *fs = FcFontList(NULL, pat, os); /* We don't need these anymore. */ FcObjectSetDestroy(os); FcPatternDestroy(pat); if (fs != NULL) { for (int i = 0; i < fs->nfont; i++) { FcPattern *font = fs->fonts[i]; FcChar8 *file = NULL; FcResult res = FcPatternGetString(font, FC_FILE, 0, &file); if (res != FcResultMatch || file == NULL) { continue; } strecpy(settings->small_font, (const char*)file, lastof(settings->small_font)); strecpy(settings->medium_font, (const char*)file, lastof(settings->medium_font)); strecpy(settings->large_font, (const char*)file, lastof(settings->large_font)); bool missing = callback(NULL); DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no"); if (!missing) { ret = true; break; } } /* Clean up the list of filenames. */ FcFontSetDestroy(fs); } FcFini(); return ret; }
int fontconf() { FcFontSet* fs = NULL; FcPattern* pat = NULL; FcObjectSet* os = NULL; FcChar8* strpat = (FcChar8*) ":lang=ja"; pat = FcNameParse(strpat); os = FcObjectSetBuild(FC_FAMILY, FC_CHARSET, FC_FILE, (char *) 0); fs = FcFontList(0, pat, os); if (os) FcObjectSetDestroy(os); os = NULL; FcPatternDestroy(pat); pat = NULL; if (!fs || fs->nfont <= 0) goto nofont; FcChar8 *family; FcChar8 *file; FcCharSet* cs; FcChar32 ch; FcUtf8ToUcs4((FcChar8*) "��", &ch, 3); int i; for (i = 0; i < fs->nfont; i++) { if (FcPatternGetCharSet(fs->fonts[i], FC_CHARSET, 0, &cs) != FcResultMatch) { fprintf(stderr, "no match\n"); FcPatternPrint(fs->fonts[i]); goto nofont; } if(FcPatternGetString(fs->fonts[i], FC_FAMILY, 1, &family) !=FcResultMatch) if(FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, &family) != FcResultMatch) goto nofont; printf("[%d] %s ", i, (char *)family); if(FcPatternGetString(fs->fonts[i], FC_FILE, 0, &file) != FcResultMatch) goto nofont; printf("(%s): ", (char *)file); if(FcCharSetHasChar(cs, ch)){ puts("Yes"); }else{ puts("No"); } } FcFontSetDestroy(fs); return 0; nofont: return 1; }
FcFontSet * fcinfo(const FcConfig *config, const FcPattern *pattern, FcBool remove_duplicities, int argnum, ...) { va_list va; const char *elements[argnum + 1]; int a; FcFontSet *fontset; FcObjectSet *objectset; FcInit(); objectset = FcObjectSetCreate(); va_start(va, argnum); for (a = 0; a < argnum; a++) { elements[a] = va_arg(va, const char *); FcObjectSetAdd(objectset, elements[a]); } va_end(va); fontset = FcFontList((FcConfig *)config, (FcPattern *)pattern, objectset); elements[argnum] = NULL; font_set_sort(fontset, elements); FcObjectSetDestroy(objectset); if (remove_duplicities) { FcFontSet *result = FcFontSetCreate(); int f; FcPattern *added = NULL; /* fontlist is linearly ordered */ f = 0; while (f < fontset->nfont) { FcFontSetAdd(result, FcPatternDuplicate(fontset->fonts[f])); added = fontset->fonts[f++]; while (f < fontset->nfont && !pattern_compare(&fontset->fonts[f], &added, elements)) f++; } FcFontSetDestroy(fontset); return result; } return fontset; }
int lltxplatform_get_installed_fonts_impl(struct lltxplatform_fontinfo **const fonts, unsigned int *const count) { int status = -1; FcPattern *const pattern = FcPatternCreate(); if (pattern != NULL) { FcObjectSet *const objects = FcObjectSetBuild(FC_FULLNAME, FC_FILE, NULL); if (objects != NULL) { FcFontSet *const list = FcFontList(NULL, pattern, objects); if (list != NULL) { if (list->nfont > 0) { const unsigned int cnt = (unsigned int) list->nfont; struct lltxplatform_fontinfo *const array = (struct lltxplatform_fontinfo *) calloc((size_t) cnt, sizeof(struct lltxplatform_fontinfo)); if (array != NULL) { unsigned int i; status = 0; for (i = 0; i < cnt; ++i) { struct lltxplatform_fontinfo *const info = &array[i]; FcPattern *const font = list->fonts[i]; FcChar8 *value; if (FcPatternGetString(font, FC_FULLNAME, 0, &value) == FcResultMatch) { info->name = strdup((char *) value); } else { info->name = NULL; } if (FcPatternGetString(font, FC_FILE, 0, &value) == FcResultMatch) { info->path = strdup((char *) value); } else { info->path = NULL; } } *count = cnt; *fonts = array; } } else { status = 0; *count = 0; *fonts = NULL; } FcFontSetDestroy(list); } FcObjectSetDestroy(objects); } FcPatternDestroy(pattern); } return status; }
void *gp_enumerate_fonts_init(gs_memory_t *mem) { #ifdef HAVE_FONTCONFIG unix_fontenum_t *state; FcPattern *pat; FcObjectSet *os; state = (unix_fontenum_t *)malloc(sizeof(unix_fontenum_t)); if (state == NULL) return NULL; /* Failed to allocate state */ state->index = 0; state->fc = NULL; state->font_list = NULL; /* Load the fontconfig library */ state->fc = FcInitLoadConfigAndFonts(); if (state->fc == NULL) { free(state); state = NULL; dlprintf("destroyed state - fontconfig init failed"); return NULL; /* Failed to open fontconfig library */ } /* load the font set that we'll iterate over */ pat = FcPatternBuild(NULL, FC_OUTLINE, FcTypeBool, 1, FC_SCALABLE, FcTypeBool, 1, NULL); os = FcObjectSetBuild(FC_FILE, FC_OUTLINE, FC_FAMILY, FC_WEIGHT, FC_SLANT, NULL); state->font_list = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); if (state->font_list == NULL) { free(state); state = NULL; return NULL; /* Failed to generate font list */ } return (void *)state; #else return NULL; #endif }
GeeArrayList * FcListFonts(gchar * family_name) { int i; FcPattern * pattern; FcFontSet * fontset; FcObjectSet * objectset = 0; GeeArrayList * fontlist = gee_array_list_new(G_TYPE_OBJECT, NULL, NULL, NULL, NULL, NULL); g_assert(FcInit()); if (family_name) pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, family_name, NULL); else pattern = FcNameParse((FcChar8 *) ":"); objectset = FcObjectSetBuild (FC_FILE, FC_INDEX, FC_FAMILY, FC_STYLE, FC_SLANT, FC_WEIGHT, FC_WIDTH, FC_SPACING, NULL); fontset = FcFontList(NULL, pattern, objectset); for (i = 0; i < fontset->nfont; i++) { FontConfigFont * font = font_config_font_new(); get_font_details_from_pattern(font, fontset->fonts[i]); gee_abstract_collection_add((GeeAbstractCollection *) fontlist, font); } if (objectset) FcObjectSetDestroy(objectset); if (pattern) FcPatternDestroy(pattern); if (fontset) FcFontSetDestroy(fontset); return fontlist; }
void configureFontConfig() { if (fontConfigHasBeenInitialized) return ; fontConfigHasBeenInitialized = true; if (!FcInit()) { INCD_ERROR("could not initialize fontconfig."); return ; } fontConfigConfig = FcConfigGetCurrent(); FcConfigSetRescanInterval(fontConfigConfig, 0); fontConfigPattern = FcPatternCreate(); fontConfigObjectSet = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char *)0); fontConfigFontSet = FcFontList(fontConfigConfig, fontConfigPattern, fontConfigObjectSet); }
/** Find a font file from its family name. * @param font_config fontconfig instance * @param font_name name of the font * @return full path to the font file */ gchar* find_font_file (FcConfig* font_config, const gchar* font_name) { const FcChar8* name; FcPattern* search_pattern; FcPattern* font; FcChar8* file; gchar* path; FcObjectSet* font_properties; FcFontSet* fonts; int i; if (font_config == NULL) { g_warning("Font config not loaded."); return NULL; } path = NULL; name = font_name; search_pattern = FcPatternCreate (); FcPatternAddString (search_pattern, FC_FAMILY, name); FcPatternAddBool (search_pattern, FC_SCALABLE, FcTrue); FcPatternAddInteger (search_pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM); FcPatternAddInteger (search_pattern, FC_SLANT, FC_SLANT_ROMAN); font_properties = FcObjectSetBuild (FC_FILE, NULL); fonts = FcFontList (font_config, search_pattern, font_properties); if (fonts->nfont > 0) { for (i = 0; i < fonts->nfont; i++) { font = fonts->fonts[i]; if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { path = g_strdup ((gchar*) file); break; } } FcPatternDestroy (font); } FcPatternDestroy (search_pattern); return path; }
Vector<String> FontCache::systemFontFamilies() { RefPtr<FcPattern> scalablesOnlyPattern = adoptRef(FcPatternCreate()); FcPatternAddBool(scalablesOnlyPattern.get(), FC_SCALABLE, FcTrue); FcUniquePtr<FcObjectSet> familiesOnly(FcObjectSetBuild(FC_FAMILY, nullptr)); FcUniquePtr<FcFontSet> fontSet(FcFontList(nullptr, scalablesOnlyPattern.get(), familiesOnly.get())); Vector<String> fontFamilies; for (int i = 0; i < fontSet->nfont; i++) { FcPattern* pattern = fontSet->fonts[i]; FcChar8* family = nullptr; FcPatternGetString(pattern, FC_FAMILY, 0, &family); if (family) fontFamilies.appendVector(patternToFamilies(*pattern)); } return fontFamilies; }
FcStrSet *fcinfo_languages(const FcPattern *filter) { FcObjectSet *objectset; FcFontSet *fontset; FcLangSet *union_langset; FcStrSet *result; int f; FcInit(); objectset = FcObjectSetBuild(FC_LANG, NULL); fontset = FcFontList(NULL, (FcPattern *)filter, objectset); FcObjectSetDestroy(objectset); union_langset = FcLangSetCreate(); for (f = 0; f < fontset->nfont; f++) { FcLangSet *langset; FcStrList *strlist; FcChar8 *lang; if (FcPatternGetLangSet(fontset->fonts[f], FC_LANG, 0, &langset) != FcResultMatch) continue; if (! langset) continue; strlist = FcStrListCreate(FcLangSetGetLangs(langset)); while ((lang = FcStrListNext(strlist))) if (FcLangSetHasLang(union_langset, lang)) FcLangSetAdd(union_langset, FcStrCopy(lang)); } result = FcLangSetGetLangs(union_langset); FcFontSetDestroy(fontset); FcLangSetDestroy(union_langset); return result; }
// coverity[+alloc : arg-*0] GpStatus GdipNewInstalledFontCollection (GpFontCollection **font_collection) { if (!font_collection) return InvalidParameter; /* * Ensure we leak this data only a single time, because: * (a) there is no API to free it; * (b) other libgdiplus structures depends on that allocated data; */ if (!system_fonts) { FcObjectSet *os = FcObjectSetBuild (FC_FAMILY, FC_FOUNDRY, NULL); FcPattern *pat = FcPatternCreate (); FcValue val; FcFontSet *col; /* Only Scalable fonts for now */ val.type = FcTypeBool; val.u.b = FcTrue; FcPatternAdd (pat, FC_SCALABLE, val, TRUE); FcObjectSetAdd (os, FC_SCALABLE); col = FcFontList (0, pat, os); FcPatternDestroy (pat); FcObjectSetDestroy (os); system_fonts = (GpFontCollection *) GdipAlloc (sizeof (GpFontCollection)); if (system_fonts) { system_fonts->fontset = col; system_fonts->config = NULL; } } *font_collection = system_fonts; return Ok; }
static void gimp_font_list_load_names (GimpFontList *list, PangoFontMap *fontmap, PangoContext *context) { FcObjectSet *os; FcPattern *pat; FcFontSet *fontset; gint i; os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_SLANT, FC_WEIGHT, FC_WIDTH, NULL); pat = FcPatternCreate (); fontset = FcFontList (NULL, pat, os); FcPatternDestroy (pat); FcObjectSetDestroy (os); for (i = 0; i < fontset->nfont; i++) { PangoFontDescription *desc; desc = pango_fc_font_description_from_pattern (fontset->fonts[i], FALSE); gimp_font_list_add_font (list, context, desc); pango_font_description_free (desc); } /* only create aliases if there is at least one font available */ if (fontset->nfont > 0) gimp_font_list_load_aliases (list, context); FcFontSetDestroy (fontset); }
MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, ExceptionInfo *exception) { #if !defined(FC_FULLNAME) #define FC_FULLNAME "fullname" #endif char extension[MaxTextExtent], name[MaxTextExtent]; FcChar8 *family, *file, *fullname, *style; FcConfig *font_config; FcFontSet *font_set; FcObjectSet *object_set; FcPattern *pattern; FcResult status; int slant, width, weight; register ssize_t i; TypeInfo *type_info; /* Load system fonts. */ (void) exception; font_config=FcInitLoadConfigAndFonts(); if (font_config == (FcConfig *) NULL) return(MagickFalse); font_set=(FcFontSet *) NULL; object_set=FcObjectSetBuild(FC_FULLNAME,FC_FAMILY,FC_STYLE,FC_SLANT, FC_WIDTH,FC_WEIGHT,FC_FILE,(char *) NULL); if (object_set != (FcObjectSet *) NULL) { pattern=FcPatternCreate(); if (pattern != (FcPattern *) NULL) { font_set=FcFontList(0,pattern,object_set); FcPatternDestroy(pattern); } FcObjectSetDestroy(object_set); } if (font_set == (FcFontSet *) NULL) { FcConfigDestroy(font_config); return(MagickFalse); } for (i=0; i < (ssize_t) font_set->nfont; i++) { status=FcPatternGetString(font_set->fonts[i],FC_FAMILY,0,&family); if (status != FcResultMatch) continue; status=FcPatternGetString(font_set->fonts[i],FC_FILE,0,&file); if (status != FcResultMatch) continue; *extension='\0'; GetPathComponent((const char *) file,ExtensionPath,extension); if ((*extension != '\0') && (LocaleCompare(extension,"gz") == 0)) continue; type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) continue; (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString("System Fonts"); type_info->signature=MagickSignature; (void) CopyMagickString(name,"Unknown",MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_FULLNAME,0,&fullname); if ((status == FcResultMatch) && (fullname != (FcChar8 *) NULL)) (void) CopyMagickString(name,(const char *) fullname,MaxTextExtent); else { if (family != (FcChar8 *) NULL) (void) CopyMagickString(name,(const char *) family,MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_STYLE,0,&style); if ((status == FcResultMatch) && (style != (FcChar8 *) NULL) && (LocaleCompare((const char *) style,"Regular") != 0)) { (void) ConcatenateMagickString(name," ",MaxTextExtent); (void) ConcatenateMagickString(name,(const char *) style, MaxTextExtent); } } type_info->name=ConstantString(name); (void) SubstituteString(&type_info->name," ","-"); type_info->family=ConstantString((const char *) family); status=FcPatternGetInteger(font_set->fonts[i],FC_SLANT,0,&slant); type_info->style=NormalStyle; if (slant == FC_SLANT_ITALIC) type_info->style=ItalicStyle; if (slant == FC_SLANT_OBLIQUE) type_info->style=ObliqueStyle; status=FcPatternGetInteger(font_set->fonts[i],FC_WIDTH,0,&width); type_info->stretch=NormalStretch; if (width >= FC_WIDTH_ULTRACONDENSED) type_info->stretch=UltraCondensedStretch; if (width >= FC_WIDTH_EXTRACONDENSED) type_info->stretch=ExtraCondensedStretch; if (width >= FC_WIDTH_CONDENSED) type_info->stretch=CondensedStretch; if (width >= FC_WIDTH_SEMICONDENSED) type_info->stretch=SemiCondensedStretch; if (width >= FC_WIDTH_NORMAL) type_info->stretch=NormalStretch; if (width >= FC_WIDTH_SEMIEXPANDED) type_info->stretch=SemiExpandedStretch; if (width >= FC_WIDTH_EXPANDED) type_info->stretch=ExpandedStretch; if (width >= FC_WIDTH_EXTRAEXPANDED) type_info->stretch=ExtraExpandedStretch; if (width >= FC_WIDTH_ULTRAEXPANDED) type_info->stretch=UltraExpandedStretch; type_info->weight=400; status=FcPatternGetInteger(font_set->fonts[i],FC_WEIGHT,0,&weight); if (weight >= FC_WEIGHT_THIN) type_info->weight=100; if (weight >= FC_WEIGHT_EXTRALIGHT) type_info->weight=200; if (weight >= FC_WEIGHT_LIGHT) type_info->weight=300; if (weight >= FC_WEIGHT_NORMAL) type_info->weight=400; if (weight >= FC_WEIGHT_MEDIUM) type_info->weight=500; if (weight >= FC_WEIGHT_DEMIBOLD) type_info->weight=600; if (weight >= FC_WEIGHT_BOLD) type_info->weight=700; if (weight >= FC_WEIGHT_EXTRABOLD) type_info->weight=800; if (weight >= FC_WEIGHT_BLACK) type_info->weight=900; type_info->glyphs=ConstantString((const char *) file); (void) AddValueToSplayTree(type_list,type_info->name,type_info); } FcFontSetDestroy(font_set); FcConfigDestroy(font_config); return(MagickTrue); }
int BC_Resources::init_fontconfig(const char *search_path) { if( fontlist ) return 0; fontlist = new ArrayList<BC_FontEntry*>; #define get_str(str,sep,ptr,cond) do { char *out = str; \ while( *ptr && !strchr(sep,*ptr) && (cond) ) *out++ = *ptr++; \ *out = 0; \ } while(0) #define skip_str(sep, ptr) do { \ while( *ptr && strchr(sep,*ptr) ) ++ptr; \ } while(0) char find_command[BCTEXTLEN]; sprintf(find_command, "find %s -name 'fonts.dir' -print -exec cat {} \\;", search_path); FILE *in = popen(find_command, "r"); FT_Library freetype_library = 0; // FT_Face freetype_face = 0; // FT_Init_FreeType(&freetype_library); char line[BCTEXTLEN], current_dir[BCTEXTLEN]; current_dir[0] = 0; while( !feof(in) && fgets(line, BCTEXTLEN, in) ) { if(!strlen(line)) break; char *in_ptr = line; // Get current directory if(line[0] == '/') { get_str(current_dir, "\n", in_ptr,1); for( int i=strlen(current_dir); --i>=0 && current_dir[i]!='/'; ) current_dir[i] = 0; continue; } //printf("TitleMain::build_fonts %s\n", line); BC_FontEntry *entry = new BC_FontEntry; char string[BCTEXTLEN]; // Path get_str(string, "\n", in_ptr, in_ptr[0]!=' ' || in_ptr[1]!='-'); entry->path = cstrcat(2, current_dir, string); // Foundary skip_str(" -", in_ptr); get_str(string, " -\n", in_ptr, 1); if( !string[0] ) { delete entry; continue; } entry->foundry = cstrdup(string); if(*in_ptr == '-') in_ptr++; // Family get_str(string, "-\n", in_ptr, 1); if( !string[0] ) { delete entry; continue; } entry->family = cstrdup(string); if(*in_ptr == '-') in_ptr++; // Weight get_str(string, "-\n", in_ptr, 1); entry->weight = cstrdup(string); if(*in_ptr == '-') in_ptr++; // Slant get_str(string, "-\n", in_ptr, 1); entry->slant = cstrdup(string); if(*in_ptr == '-') in_ptr++; // SWidth get_str(string, "-\n", in_ptr, 1); entry->swidth = cstrdup(string); if(*in_ptr == '-') in_ptr++; // Adstyle get_str(string, "-\n", in_ptr, 1); entry->adstyle = cstrdup(string); if(*in_ptr == '-') in_ptr++; // pixelsize get_str(string, "-\n", in_ptr, 1); entry->pixelsize = atol(string); if(*in_ptr == '-') in_ptr++; // pointsize get_str(string, "-\n", in_ptr, 1); entry->pointsize = atol(string); if(*in_ptr == '-') in_ptr++; // xres get_str(string, "-\n", in_ptr, 1); entry->xres = atol(string); if(*in_ptr == '-') in_ptr++; // yres get_str(string, "-\n", in_ptr, 1); entry->yres = atol(string); if(*in_ptr == '-') in_ptr++; // spacing get_str(string, "-\n", in_ptr, 1); entry->spacing = cstrdup(string); if(*in_ptr == '-') in_ptr++; // avg_width get_str(string, "-\n", in_ptr, 1); entry->avg_width = atol(string); if(*in_ptr == '-') in_ptr++; // registry get_str(string, "-\n", in_ptr, 1); entry->registry = cstrdup(string); if(*in_ptr == '-') in_ptr++; // encoding get_str(string, "-\n", in_ptr, 1); entry->encoding = cstrdup(string); if(*in_ptr == '-') in_ptr++; // Add to list //printf("TitleMain::build_fonts 1 %s\n", entry->path); // This takes a real long time to do. Instead just take all fonts // if(!load_freetype_face(freetype_library, // freetype_face, entry->path) ) // Fix parameters sprintf(line, "%s (%s)", entry->family, entry->foundry); entry->displayname = cstrdup(line); if(!strcasecmp(entry->weight, "demibold")) { entry->fixed_style |= BC_FONT_BOLD; entry->style |= FL_WEIGHT_DEMIBOLD; } else if(!strcasecmp(entry->weight, "bold")) { entry->fixed_style |= BC_FONT_BOLD; entry->style |= FL_WEIGHT_BOLD; } else { entry->style |= FL_WEIGHT_NORMAL; } if(!strcasecmp(entry->slant, "r")) { entry->style |= FL_SLANT_ROMAN; } else if(!strcasecmp(entry->slant, "i")) { entry->style |= FL_SLANT_ITALIC; entry->fixed_style |= BC_FONT_ITALIC; } else if(!strcasecmp(entry->slant, "o")) { entry->style |= FL_SLANT_OBLIQUE; entry->fixed_style |= BC_FONT_ITALIC; } if(!strcasecmp(entry->swidth, "normal")) entry->style = FL_WIDTH_NORMAL; else if(!strcasecmp(entry->swidth, "ultracondensed")) entry->style = FL_WIDTH_ULTRACONDENSED; else if(!strcasecmp(entry->swidth, "extracondensed")) entry->style = FL_WIDTH_EXTRACONDENSED; else if(!strcasecmp(entry->swidth, "condensed")) entry->style = FL_WIDTH_CONDENSED; else if(!strcasecmp(entry->swidth, "semicondensed")) entry->style = FL_WIDTH_SEMICONDENSED; else if(!strcasecmp(entry->swidth, "semiexpanded")) entry->style = FL_WIDTH_SEMIEXPANDED; else if(!strcasecmp(entry->swidth, "expanded")) entry->style = FL_WIDTH_EXPANDED; else if(!strcasecmp(entry->swidth, "extraexpanded")) entry->style = FL_WIDTH_EXTRAEXPANDED; else if(!strcasecmp(entry->swidth, "ultraexpanded")) entry->style = FL_WIDTH_ULTRAEXPANDED; else entry->style = FL_WIDTH_NORMAL; fontlist->append(entry); // printf("TitleMain::build_fonts %s: success\n", entry->path); //printf("TitleMain::build_fonts 2\n"); } pclose(in); // Load all the fonts from fontconfig FcPattern *pat; FcFontSet *fs; FcObjectSet *os; FcChar8 *family, *file, *foundry, *style, *format; int slant, spacing, width, weight; int force_style = 0; // if you want limit search to TrueType put 1 int limit_to_trutype = 1; FcConfig *config; int i; char tmpstring[BCTEXTLEN]; if(!FcInit()) return 1; config = FcConfigGetCurrent(); FcConfigSetRescanInterval(config, 0); pat = FcPatternCreate(); os = FcObjectSetBuild ( FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT, FC_WIDTH, FC_SLANT, FC_FONTFORMAT, FC_SPACING, FC_STYLE, (char *) 0); FcPatternAddBool(pat, FC_SCALABLE, true); if(language[0]) { char langstr[LEN_LANG * 3]; strcpy(langstr, language); if(region[0]) { strcat(langstr, "-"); strcat(langstr, region); } FcLangSet *ls = FcLangSetCreate(); if(FcLangSetAdd(ls, (const FcChar8*)langstr)) if(FcPatternAddLangSet(pat, FC_LANG, ls)) FcLangSetDestroy(ls); } fs = FcFontList(config, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); for (i = 0; fs && i < fs->nfont; i++) { FcPattern *font = fs->fonts[i]; force_style = 0; FcPatternGetString(font, FC_FONTFORMAT, 0, &format); //on this point you can limit font search if(limit_to_trutype && strcmp((char *)format, "TrueType")) continue; sprintf(tmpstring, "%s", format); BC_FontEntry *entry = new BC_FontEntry; if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) { entry->path = cstrdup((char*)file); } if(FcPatternGetString(font, FC_FOUNDRY, 0, &foundry) == FcResultMatch) { entry->foundry = cstrdup((char*)foundry); } if(FcPatternGetInteger(font, FC_WEIGHT, 0, &weight) == FcResultMatch) { switch(weight) { case FC_WEIGHT_THIN: case FC_WEIGHT_EXTRALIGHT: case FC_WEIGHT_LIGHT: case FC_WEIGHT_BOOK: force_style = 1; entry->weight = cstrdup("medium"); break; case FC_WEIGHT_NORMAL: case FC_WEIGHT_MEDIUM: default: entry->weight = cstrdup("medium"); break; case FC_WEIGHT_BLACK: case FC_WEIGHT_SEMIBOLD: case FC_WEIGHT_BOLD: entry->weight = cstrdup("bold"); entry->fixed_style |= BC_FONT_BOLD; break; case FC_WEIGHT_EXTRABOLD: case FC_WEIGHT_EXTRABLACK: force_style = 1; entry->weight = cstrdup("bold"); entry->fixed_style |= BC_FONT_BOLD; break; } } if(FcPatternGetString(font, FC_FAMILY, 0, &family) == FcResultMatch) entry->family = cstrdup((char*)family); if(FcPatternGetInteger(font, FC_SLANT, 0, &slant) == FcResultMatch) { switch(slant) { case FC_SLANT_ROMAN: default: entry->slant = cstrdup("r"); entry->style |= FL_SLANT_ROMAN; break; case FC_SLANT_ITALIC: entry->slant = cstrdup("i"); entry->style |= FL_SLANT_ITALIC; entry->fixed_style |= BC_FONT_ITALIC; break; case FC_SLANT_OBLIQUE: entry->slant = cstrdup("o"); entry->style |= FL_SLANT_OBLIQUE; entry->fixed_style |= BC_FONT_ITALIC; break; } } if(FcPatternGetInteger(font, FC_WIDTH, 0, &width) == FcResultMatch) { switch(width) { case FC_WIDTH_ULTRACONDENSED: entry->swidth = cstrdup("ultracondensed"); break; case FC_WIDTH_EXTRACONDENSED: entry->swidth = cstrdup("extracondensed"); break; case FC_WIDTH_CONDENSED: entry->swidth = cstrdup("condensed"); break; case FC_WIDTH_SEMICONDENSED: entry->swidth = cstrdup("semicondensed"); break; case FC_WIDTH_NORMAL: default: entry->swidth = cstrdup("normal"); break; case FC_WIDTH_SEMIEXPANDED: entry->swidth = cstrdup("semiexpanded"); break; case FC_WIDTH_EXPANDED: entry->swidth = cstrdup("expanded"); break; case FC_WIDTH_EXTRAEXPANDED: entry->swidth = cstrdup("extraexpanded"); break; case FC_WIDTH_ULTRAEXPANDED: entry->swidth = cstrdup("ultraexpanded"); break; } } if(FcPatternGetInteger(font, FC_SPACING, 0, &spacing) == FcResultMatch) { switch(spacing) { case 0: default: entry->spacing = cstrdup("p"); break; case 90: entry->spacing = cstrdup("d"); break; case 100: entry->spacing = cstrdup("m"); break; case 110: entry->spacing = cstrdup("c"); break; } } // Add fake stuff for compatibility entry->adstyle = cstrdup(" "); entry->pixelsize = 0; entry->pointsize = 0; entry->xres = 0; entry->yres = 0; entry->avg_width = 0; entry->registry = cstrdup("utf"); entry->encoding = cstrdup("8"); if(!FcPatternGetString(font, FC_STYLE, 0, &style) == FcResultMatch) force_style = 0; // If font has a style unmanaged by titler plugin, force style to be displayed on name // in this way we can shown all available fonts styles. if(force_style) { sprintf(tmpstring, "%s (%s)", entry->family, style); entry->displayname = cstrdup(tmpstring); } else { if(strcmp(entry->foundry, "unknown")) { sprintf(tmpstring, "%s (%s)", entry->family, entry->foundry); entry->displayname = cstrdup(tmpstring); } else { sprintf(tmpstring, "%s", entry->family); entry->displayname = cstrdup(tmpstring); } } fontlist->append(entry); } FcFontSetDestroy(fs); if(freetype_library) FT_Done_FreeType(freetype_library); // for(int i = 0; i < fonts->total; i++) // fonts->values[i]->dump(); FcConfigAppFontAddDir(0, (const FcChar8*)search_path); FcConfigSetRescanInterval(0, 0); os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FOUNDRY, FC_WEIGHT, FC_WIDTH, FC_SLANT, FC_SPACING, FC_STYLE, (char *)0); pat = FcPatternCreate(); FcPatternAddBool(pat, FC_SCALABLE, true); if(language[0]) { char langstr[LEN_LANG * 3]; strcpy(langstr, language); if(region[0]) { strcat(langstr, "-"); strcat(langstr, region); } FcLangSet *ls = FcLangSetCreate(); if(FcLangSetAdd(ls, (const FcChar8*)langstr)) if(FcPatternAddLangSet(pat, FC_LANG, ls)) FcLangSetDestroy(ls); } fs = FcFontList(0, pat, os); FcPatternDestroy(pat); FcObjectSetDestroy(os); for(int i = 0; i < fs->nfont; i++) { FcPattern *font = fs->fonts[i]; BC_FontEntry *entry = new BC_FontEntry; FcChar8 *strvalue; if(FcPatternGetString(font, FC_FILE, 0, &strvalue) == FcResultMatch) { entry->path = new char[strlen((char*)strvalue) + 1]; strcpy(entry->path, (char*)strvalue); } if(FcPatternGetString(font, FC_FOUNDRY, 0, &strvalue) == FcResultMatch) { entry->foundry = new char[strlen((char*)strvalue) + 1]; strcpy(entry->foundry, (char *)strvalue); } if(FcPatternGetString(font, FC_FAMILY, 0, &strvalue) == FcResultMatch) { entry->family = new char[strlen((char*)strvalue) + 2]; strcpy(entry->family, (char*)strvalue); } int intvalue; if(FcPatternGetInteger(font, FC_SLANT, 0, &intvalue) == FcResultMatch) { switch(intvalue) { case FC_SLANT_ROMAN: default: entry->style |= FL_SLANT_ROMAN; break; case FC_SLANT_ITALIC: entry->style |= FL_SLANT_ITALIC; break; case FC_SLANT_OBLIQUE: entry->style |= FL_SLANT_OBLIQUE; break; } } if(FcPatternGetInteger(font, FC_WEIGHT, 0, &intvalue) == FcResultMatch) { switch(intvalue) { case FC_WEIGHT_THIN: entry->style |= FL_WEIGHT_THIN; break; case FC_WEIGHT_EXTRALIGHT: entry->style |= FL_WEIGHT_EXTRALIGHT; break; case FC_WEIGHT_LIGHT: entry->style |= FL_WEIGHT_LIGHT; break; case FC_WEIGHT_BOOK: entry->style |= FL_WEIGHT_BOOK; break; case FC_WEIGHT_NORMAL: default: entry->style |= FL_WEIGHT_NORMAL; break; case FC_WEIGHT_MEDIUM: entry->style |= FL_WEIGHT_MEDIUM; break; case FC_WEIGHT_DEMIBOLD: entry->style |= FL_WEIGHT_DEMIBOLD; break; case FC_WEIGHT_BOLD: entry->style |= FL_WEIGHT_BOLD; break; case FC_WEIGHT_EXTRABOLD: entry->style |= FL_WEIGHT_EXTRABOLD; break; case FC_WEIGHT_BLACK: entry->style |= FL_WEIGHT_BLACK; break; case FC_WEIGHT_EXTRABLACK: entry->style |= FL_WEIGHT_EXTRABLACK; break; } } if(FcPatternGetInteger(font, FC_WIDTH, 0, &intvalue) == FcResultMatch) { switch(intvalue) { case FC_WIDTH_ULTRACONDENSED: entry->style |= FL_WIDTH_ULTRACONDENSED; break; case FC_WIDTH_EXTRACONDENSED: entry->style |= FL_WIDTH_EXTRACONDENSED; break; case FC_WIDTH_CONDENSED: entry->style |= FL_WIDTH_CONDENSED; break; case FC_WIDTH_SEMICONDENSED: entry->style = FL_WIDTH_SEMICONDENSED; break; case FC_WIDTH_NORMAL: default: entry->style |= FL_WIDTH_NORMAL; break; case FC_WIDTH_SEMIEXPANDED: entry->style |= FL_WIDTH_SEMIEXPANDED; break; case FC_WIDTH_EXPANDED: entry->style |= FL_WIDTH_EXPANDED; break; case FC_WIDTH_EXTRAEXPANDED: entry->style |= FL_WIDTH_EXTRAEXPANDED; break; case FC_WIDTH_ULTRAEXPANDED: entry->style |= FL_WIDTH_ULTRAEXPANDED; break; } } if(FcPatternGetInteger(font, FC_SPACING, 0, &intvalue) == FcResultMatch) { switch(intvalue) { case FC_PROPORTIONAL: default: entry->style |= FL_PROPORTIONAL; break; case FC_DUAL: entry->style |= FL_DUAL; break; case FC_MONO: entry->style |= FL_MONO; break; case FC_CHARCELL: entry->style |= FL_CHARCELL; break; } } if(entry->foundry && strcmp(entry->foundry, "unknown")) { char tempstr[BCTEXTLEN]; sprintf(tempstr, "%s (%s)", entry->family, entry->foundry); entry->displayname = new char[strlen(tempstr) + 1]; strcpy(entry->displayname, tempstr); } else { entry->displayname = new char[strlen(entry->family) + 1]; strcpy(entry->displayname, entry->family); } fontlist->append(entry); } FcFontSetDestroy(fs); return 0; }
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; }
nsresult gfxQtPlatform::ResolveFontName(const nsAString& aFontName, FontResolverCallback aCallback, void *aClosure, PRBool& aAborted) { nsAutoString name(aFontName); ToLowerCase(name); nsRefPtr<FontFamily> ff; if (gPlatformFonts->Get(name, &ff) || gPlatformFontAliases->Get(name, &ff)) { aAborted = !(*aCallback)(ff->Name(), aClosure); return NS_OK; } nsCAutoString utf8Name = NS_ConvertUTF16toUTF8(aFontName); FcPattern *npat = FcPatternCreate(); FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get()); FcObjectSet *nos = FcObjectSetBuild(FC_FAMILY, NULL); FcFontSet *nfs = FcFontList(NULL, npat, nos); for (int k = 0; k < nfs->nfont; k++) { FcChar8 *str; if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))); ToLowerCase(altName); if (gPlatformFonts->Get(altName, &ff)) { printf("Adding alias: %s -> %s\n", utf8Name.get(), str); gPlatformFontAliases->Put(name, ff); aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure); goto DONE; } } FcPatternDestroy(npat); FcObjectSetDestroy(nos); FcFontSetDestroy(nfs); { npat = FcPatternCreate(); FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get()); FcPatternDel(npat, FC_LANG); FcConfigSubstitute(NULL, npat, FcMatchPattern); FcDefaultSubstitute(npat); nos = FcObjectSetBuild(FC_FAMILY, NULL); nfs = FcFontList(NULL, npat, nos); FcResult fresult; FcPattern *match = FcFontMatch(NULL, npat, &fresult); if (match) FcFontSetAdd(nfs, match); for (int k = 0; k < nfs->nfont; k++) { FcChar8 *str; if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))); ToLowerCase(altName); if (gPlatformFonts->Get(altName, &ff)) { printf("Adding alias: %s -> %s\n", utf8Name.get(), str); gPlatformFontAliases->Put(name, ff); aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure); goto DONE; } } } DONE: FcPatternDestroy(npat); FcObjectSetDestroy(nos); FcFontSetDestroy(nfs); return NS_OK; }
void QFontconfigDatabase::populateFontDatabase() { FcInitReinitialize(); FcFontSet *fonts; { FcObjectSet *os = FcObjectSetCreate(); FcPattern *pattern = FcPatternCreate(); const char *properties [] = { FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_SPACING, FC_FILE, FC_INDEX, FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WIDTH, #if FC_VERSION >= 20297 FC_CAPABILITY, #endif (const char *)0 }; const char **p = properties; while (*p) { FcObjectSetAdd(os, *p); ++p; } fonts = FcFontList(0, pattern, os); FcObjectSetDestroy(os); FcPatternDestroy(pattern); } for (int i = 0; i < fonts->nfont; i++) populateFromPattern(fonts->fonts[i]); FcFontSetDestroy (fonts); struct FcDefaultFont { const char *qtname; const char *rawname; bool fixed; }; const FcDefaultFont defaults[] = { { "Serif", "serif", false }, { "Sans Serif", "sans-serif", false }, { "Monospace", "monospace", true }, { 0, 0, false } }; const FcDefaultFont *f = defaults; // aliases only make sense for 'common', not for any of the specials QSupportedWritingSystems ws; ws.setSupported(QFontDatabase::Latin); while (f->qtname) { QString familyQtName = QString::fromLatin1(f->qtname); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); ++f; } //Lighthouse has very lazy population of the font db. We want it to be initialized when //QApplication is constructed, so that the population procedure can do something like this to //set the default font // const FcDefaultFont *s = defaults; // QFont font("Sans Serif"); // font.setPointSize(9); // QApplication::setFont(font); }
void QFontconfigDatabase::populateFontDatabase() { FcFontSet *fonts; QString familyName; FcChar8 *value = 0; int weight_value; int slant_value; int spacing_value; FcChar8 *file_value; int indexValue; FcChar8 *foundry_value; FcChar8 *style_value; FcBool scalable; FcBool antialias; { FcObjectSet *os = FcObjectSetCreate(); FcPattern *pattern = FcPatternCreate(); const char *properties [] = { FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_SPACING, FC_FILE, FC_INDEX, FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT, FC_WIDTH, #if FC_VERSION >= 20297 FC_CAPABILITY, #endif (const char *)0 }; const char **p = properties; while (*p) { FcObjectSetAdd(os, *p); ++p; } fonts = FcFontList(0, pattern, os); FcObjectSetDestroy(os); FcPatternDestroy(pattern); } for (int i = 0; i < fonts->nfont; i++) { if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch) continue; // capitalize(value); familyName = QString::fromUtf8((const char *)value); slant_value = FC_SLANT_ROMAN; weight_value = FC_WEIGHT_REGULAR; spacing_value = FC_PROPORTIONAL; file_value = 0; indexValue = 0; scalable = FcTrue; if (FcPatternGetInteger (fonts->fonts[i], FC_SLANT, 0, &slant_value) != FcResultMatch) slant_value = FC_SLANT_ROMAN; if (FcPatternGetInteger (fonts->fonts[i], FC_WEIGHT, 0, &weight_value) != FcResultMatch) weight_value = FC_WEIGHT_REGULAR; if (FcPatternGetInteger (fonts->fonts[i], FC_SPACING, 0, &spacing_value) != FcResultMatch) spacing_value = FC_PROPORTIONAL; if (FcPatternGetString (fonts->fonts[i], FC_FILE, 0, &file_value) != FcResultMatch) file_value = 0; if (FcPatternGetInteger (fonts->fonts[i], FC_INDEX, 0, &indexValue) != FcResultMatch) indexValue = 0; if (FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &scalable) != FcResultMatch) scalable = FcTrue; if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch) foundry_value = 0; if (FcPatternGetString(fonts->fonts[i], FC_STYLE, 0, &style_value) != FcResultMatch) style_value = 0; if(FcPatternGetBool(fonts->fonts[i],FC_ANTIALIAS,0,&antialias) != FcResultMatch) antialias = true; QSupportedWritingSystems writingSystems; FcLangSet *langset = 0; FcResult res = FcPatternGetLangSet(fonts->fonts[i], FC_LANG, 0, &langset); if (res == FcResultMatch) { bool hasLang = false; for (int j = 1; j < QFontDatabase::WritingSystemsCount; ++j) { const FcChar8 *lang = (const FcChar8*) languageForWritingSystem[j]; if (lang) { FcLangResult langRes = FcLangSetHasLang(langset, lang); if (langRes != FcLangDifferentLang) { writingSystems.setSupported(QFontDatabase::WritingSystem(j)); hasLang = true; } } } if (!hasLang) // none of our known languages, add it to the other set writingSystems.setSupported(QFontDatabase::Other); } else { // we set Other to supported for symbol fonts. It makes no // sense to merge these with other ones, as they are // special in a way. writingSystems.setSupported(QFontDatabase::Other); } #if FC_VERSION >= 20297 for (int j = 1; j < QFontDatabase::WritingSystemsCount; ++j) { if (writingSystems.supported(QFontDatabase::WritingSystem(j)) && requiresOpenType(j) && openType[j]) { FcChar8 *cap; res = FcPatternGetString (fonts->fonts[i], FC_CAPABILITY, 0, &cap); if (res != FcResultMatch || !strstr((const char *)cap, openType[j])) writingSystems.setSupported(QFontDatabase::WritingSystem(j),false); } } #endif FontFile *fontFile = new FontFile; fontFile->fileName = QLatin1String((const char *)file_value); fontFile->indexValue = indexValue; QFont::Style style = (slant_value == FC_SLANT_ITALIC) ? QFont::StyleItalic : ((slant_value == FC_SLANT_OBLIQUE) ? QFont::StyleOblique : QFont::StyleNormal); QFont::Weight weight = QFont::Weight(getFCWeight(weight_value)); double pixel_size = 0; if (!scalable) { int width = 100; FcPatternGetInteger (fonts->fonts[i], FC_WIDTH, 0, &width); FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size); } bool fixedPitch = spacing_value >= FC_MONO; QFont::Stretch stretch = QFont::Unstretched; QString styleName = style_value ? QString::fromUtf8((const char *) style_value) : QString(); QPlatformFontDatabase::registerFont(familyName,styleName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile); // qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size; for (int k = 1; FcPatternGetString(fonts->fonts[i], FC_FAMILY, k, &value) == FcResultMatch; ++k) QPlatformFontDatabase::registerAliasToFontFamily(familyName, QString::fromUtf8((const char *)value)); } FcFontSetDestroy (fonts); struct FcDefaultFont { const char *qtname; const char *rawname; bool fixed; }; const FcDefaultFont defaults[] = { { "Serif", "serif", false }, { "Sans Serif", "sans-serif", false }, { "Monospace", "monospace", true }, { 0, 0, false } }; const FcDefaultFont *f = defaults; // aliases only make sense for 'common', not for any of the specials QSupportedWritingSystems ws; ws.setSupported(QFontDatabase::Latin); while (f->qtname) { QString familyQtName = QString::fromLatin1(f->qtname); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); ++f; } //Lighthouse has very lazy population of the font db. We want it to be initialized when //QApplication is constructed, so that the population procedure can do something like this to //set the default font // const FcDefaultFont *s = defaults; // QFont font("Sans Serif"); // font.setPointSize(9); // QApplication::setFont(font); }
nsresult gfxQtPlatform::UpdateFontList() { FcPattern *pat = NULL; FcObjectSet *os = NULL; FcFontSet *fs = NULL; PRInt32 result = -1; pat = FcPatternCreate(); os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_INDEX, FC_WEIGHT, FC_SLANT, FC_WIDTH, NULL); fs = FcFontList(NULL, pat, os); for (int i = 0; i < fs->nfont; i++) { char *str; if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch) continue; printf("Family: %s\n", str); nsAutoString name(NS_ConvertUTF8toUTF16(nsDependentCString(str)).get()); nsAutoString key(name); ToLowerCase(key); nsRefPtr<FontFamily> ff; if (!gPlatformFonts->Get(key, &ff)) { ff = new FontFamily(name); gPlatformFonts->Put(key, ff); } FontEntry *fe = new FontEntry(ff->Name()); ff->AddFontEntry(fe); if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, (FcChar8 **) &str) == FcResultMatch) { fe->mFilename = nsDependentCString(str); printf(" - file: %s\n", str); } int x; if (FcPatternGetInteger(fs->fonts[i], FC_INDEX, 0, &x) == FcResultMatch) { printf(" - index: %d\n", x); fe->mFTFontIndex = x; } else { fe->mFTFontIndex = 0; } if (FcPatternGetInteger(fs->fonts[i], FC_WEIGHT, 0, &x) == FcResultMatch) { switch(x) { case 0: fe->mWeight = 100; break; case 40: fe->mWeight = 200; break; case 50: fe->mWeight = 300; break; case 75: case 80: fe->mWeight = 400; break; case 100: fe->mWeight = 500; break; case 180: fe->mWeight = 600; break; case 200: fe->mWeight = 700; break; case 205: fe->mWeight = 800; break; case 210: fe->mWeight = 900; break; default: // rough estimate fe->mWeight = (((x * 4) + 100) / 100) * 100; break; } printf(" - weight: %d\n", fe->mWeight); } fe->mItalic = PR_FALSE; if (FcPatternGetInteger(fs->fonts[i], FC_SLANT, 0, &x) == FcResultMatch) { switch (x) { case FC_SLANT_ITALIC: case FC_SLANT_OBLIQUE: fe->mItalic = PR_TRUE; } printf(" - slant: %d\n", x); } if (FcPatternGetInteger(fs->fonts[i], FC_WIDTH, 0, &x) == FcResultMatch) printf(" - width: %d\n", x); // XXX deal with font-stretch stuff later } if (pat) FcPatternDestroy(pat); if (os) FcObjectSetDestroy(os); if (fs) FcFontSetDestroy(fs); return sFontconfigUtils->UpdateFontList(); }