FcValue fcvalue_from_caml(value c) { FcValue res; if(Is_block(c)) { switch(Tag_val(c)) { case 0: /* Integer */ res.type = FcTypeInteger; res.u.i = Int_val(Field(c, 0)); break; case 1: /* Double */ res.type = FcTypeDouble; res.u.d = Double_val(Field(c, 0)); break; case 2: /* String */ res.type = FcTypeString; res.u.s = FcStrCopy((FcChar8 *)String_val(Field(c, 0))); break; case 3: /* Bool */ res.type = FcTypeBool; res.u.b = Bool_val(Field(c, 0)) ? FcTrue : FcFalse; break; case 4: /* Matrix */ res.type = FcTypeMatrix; res.u.m = fcmatrix_from_caml(Field(c, 0)); break; } } else { /* C'est void */ res.type = FcTypeVoid; } return res; }
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; }
static FcObjectType * FcObjectFindByName (const char *object, FcBool insert) { FcChar32 hash = FcStringHash ((const FcChar8 *) object); FcObjectBucket **p; FcObjectBucket *b; FcObjectType *o; if (!FcObjectsInited) FcObjectInit (); for (p = &FcObjectBuckets[hash%OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) { o = FcObjects + b->id - 1; if (b->hash == hash && !strcmp (object, (o->object))) return o; } if (!insert) return NULL; /* * Hook it into the hash chain */ b = malloc (sizeof(FcObjectBucket)); if (!b) return NULL; object = (const char *) FcStrCopy ((FcChar8 *) object); if (!object) { free (b); return NULL; } o = FcObjectInsert (object, -1); b->next = NULL; b->hash = hash; b->id = FcObjectId (o); *p = b; return o; }
int main (int argc, char **argv) { FcStrSet *dirs, *updateDirs; FcStrList *list; FcBool verbose = FcFalse; FcBool force = FcFalse; FcBool really_force = FcFalse; FcBool systemOnly = FcFalse; FcBool error_on_no_fonts = FcFalse; FcConfig *config; FcChar8 *sysroot = NULL; int i; int changed; int ret; #if HAVE_GETOPT_LONG || HAVE_GETOPT int c; #if HAVE_GETOPT_LONG while ((c = getopt_long (argc, argv, "Efrsy:Vvh", longopts, NULL)) != -1) #else while ((c = getopt (argc, argv, "Efrsy:Vvh")) != -1) #endif { switch (c) { case 'E': error_on_no_fonts = FcTrue; break; case 'r': really_force = FcTrue; /* fall through */ case 'f': force = FcTrue; break; case 's': systemOnly = FcTrue; break; case 'y': sysroot = FcStrCopy ((const FcChar8 *)optarg); break; case 'V': fprintf (stderr, "fontconfig version %d.%d.%d\n", FC_MAJOR, FC_MINOR, FC_REVISION); exit (0); case 'v': verbose = FcTrue; break; case 'h': usage (argv[0], 0); default: usage (argv[0], 1); } } i = optind; #else i = 1; #endif if (systemOnly) FcConfigEnableHome (FcFalse); if (sysroot) { FcConfigSetSysRoot (NULL, sysroot); FcStrFree (sysroot); config = FcConfigGetCurrent(); } else { config = FcInitLoadConfig (); } if (!config) { fprintf (stderr, "%s: Can't init font config library\n", argv[0]); return 1; } FcConfigSetCurrent (config); if (argv[i]) { dirs = FcStrSetCreate (); if (!dirs) { fprintf (stderr, "%s: Can't create list of directories\n", argv[0]); return 1; } while (argv[i]) { if (!FcStrSetAddFilename (dirs, (FcChar8 *) argv[i])) { fprintf (stderr, "%s: Can't add directory\n", argv[0]); return 1; } i++; } list = FcStrListCreate (dirs); FcStrSetDestroy (dirs); } else list = FcConfigGetConfigDirs (config); if ((processed_dirs = FcStrSetCreate()) == NULL) { fprintf(stderr, "Cannot malloc\n"); return 1; } updateDirs = FcStrSetCreate (); changed = 0; ret = scanDirs (list, config, force, really_force, verbose, FcTrue, error_on_no_fonts, &changed, updateDirs); /* Update the directory cache again to avoid the race condition as much as possible */ FcStrListDone (list); list = FcStrListCreate (updateDirs); if (list) { ret += scanDirs (list, config, FcTrue, FcFalse, verbose, FcFalse, error_on_no_fonts, &changed, NULL); FcStrListDone (list); } FcStrSetDestroy (updateDirs); /* * Try to create CACHEDIR.TAG anyway. * This expects the fontconfig cache directory already exists. * If it doesn't, it won't be simply created. */ FcCacheCreateTagFile (config); FcStrSetDestroy (processed_dirs); cleanCacheDirectories (config, verbose); FcConfigDestroy (config); FcFini (); /* * Now we need to sleep a second (or two, to be extra sure), to make * sure that timestamps for changes after this run of fc-cache are later * then any timestamps we wrote. We don't use gettimeofday() because * sleep(3) can't be interrupted by a signal here -- this isn't in the * library, and there aren't any signals flying around here. */ /* the resolution of mtime on FAT is 2 seconds */ if (changed) sleep (2); if (verbose) printf ("%s: %s\n", argv[0], ret ? "failed" : "succeeded"); return ret; }