]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Insert newly created caches into reference data structure.
[fontconfig.git] / src / fccfg.c
index bcc3bd28d5525839c600b574beace725967648b9..01d381c5f33ea118ad42adf3c8c4cc3b937065e8 100644 (file)
@@ -85,12 +85,11 @@ FcConfigCreate (void)
 
     config->substPattern = 0;
     config->substFont = 0;
+    config->substScan = 0;
     config->maxObjects = 0;
     for (set = FcSetSystem; set <= FcSetApplication; set++)
        config->fonts[set] = 0;
 
-    config->caches = NULL;
-
     config->rescanTime = time(0);
     config->rescanInterval = 30;    
     
@@ -196,7 +195,6 @@ void
 FcConfigDestroy (FcConfig *config)
 {
     FcSetName  set;
-    FcCacheList        *cl, *cl_next;
 
     if (config == _fcConfig)
        _fcConfig = 0;
@@ -215,102 +213,125 @@ FcConfigDestroy (FcConfig *config)
 
     FcSubstDestroy (config->substPattern);
     FcSubstDestroy (config->substFont);
+    FcSubstDestroy (config->substScan);
     for (set = FcSetSystem; set <= FcSetApplication; set++)
        if (config->fonts[set])
            FcFontSetDestroy (config->fonts[set]);
 
-    for (cl = config->caches; cl; cl = cl_next)
-    {
-       cl_next = cl->next;
-       FcDirCacheUnmap (cl->cache);
-       free (cl);
-    }
-
     free (config);
     FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
 }
 
 /*
- * Scan the current list of directories in the configuration
- * and build the set of available fonts. Update the
- * per-user cache file to reflect the new configuration
+ * Add cache to configuration, adding fonts and directories
  */
 
 FcBool
-FcConfigBuildFonts (FcConfig *config)
+FcConfigAddCache (FcConfig *config, FcCache *cache)
 {
-    FcFontSet      *fonts, *cached_fonts;
-    FcStrList      *list;
-    FcStrSet       *oldDirs;
-    FcChar8        *dir;
-
-    fonts = FcFontSetCreate ();
-    if (!fonts)
-       goto bail0;
-    
-    oldDirs = FcStrSetCreate ();
-    if (!oldDirs)
-        goto bail2;
-
-    cached_fonts = FcCacheRead(config);
-    if (!cached_fonts)
+    FcFontSet  *fs;
+    intptr_t   *dirs;
+    int                i;
+
+    /*
+     * Add fonts
+     */
+    fs = FcCacheSet (cache);
+    if (fs)
     {
-       list = FcConfigGetFontDirs (config);
-       if (!list)
-           goto bail3;
+       int     nref = 0;
        
-       while ((dir = FcStrListNext (list)))
+       for (i = 0; i < fs->nfont; i++)
        {
-           if (FcDebug () & FC_DBG_FONTSET)
-               printf ("build scan dir %s\n", dir);
-           FcDirScanConfig (fonts, config->fontDirs,
-                            config->blanks, dir, FcFalse, config);
+           FcPattern   *font = FcFontSetFont (fs, i);
+           FcChar8     *font_file;
+
+           /*
+            * Check to see if font is banned by filename
+            */
+           if (FcPatternObjectGetString (font, FC_FILE_OBJECT,
+                                         0, &font_file) == FcResultMatch &&
+               !FcConfigAcceptFilename (config, font_file))
+           {
+               continue;
+           }
+               
+           /*
+            * Check to see if font is banned by pattern
+            */
+           if (!FcConfigAcceptFont (config, font))
+               continue;
+               
+           nref++;
+           FcFontSetAdd (config->fonts[FcSetSystem], font);
        }
-       
-       FcStrListDone (list);
+       FcDirCacheReference (cache, nref);
     }
-    else
+
+    /*
+     * Add directories
+     */
+    dirs = FcCacheDirs (cache);
+    if (dirs)
     {
-       int i;
-
-        for (i = 0; i < oldDirs->num; i++)
-        {
-           if (FcDebug () & FC_DBG_FONTSET)
-               printf ("scan dir %s\n", oldDirs->strs[i]);
-           FcDirScanConfig (fonts, config->fontDirs,
-                            config->blanks, oldDirs->strs[i], 
-                             FcFalse, config);
+       for (i = 0; i < cache->dirs_count; i++)
+       {
+           FcChar8     *dir = FcOffsetToPtr (dirs, dirs[i], FcChar8);
+           if (FcConfigAcceptFilename (config, dir))
+               FcConfigAddFontDir (config, dir);
        }
+    }
+    return FcTrue;
+}
 
-       for (i = 0; i < cached_fonts->nfont; i++)
-       {
-           FcChar8     *cfn; 
-           FcPattern   *font = cached_fonts->fonts[i];
-           FcPatternObjectGetString (font, FC_FILE_OBJECT, 0, &cfn);
+/*
+ * Scan the current list of directories in the configuration
+ * and build the set of available fonts.
+ */
 
-           if (FcConfigAcceptFont (config, font) &&
-                (cfn && FcConfigAcceptFilename (config, cfn)))
-               FcFontSetAdd (fonts, font);
+FcBool
+FcConfigBuildFonts (FcConfig *config)
+{
+    FcFontSet      *fonts;
+    FcStrList      *dirlist;
+    FcChar8        *dir;
+    FcCache        *cache;
 
-           cached_fonts->fonts[i] = 0; /* prevent free in FcFontSetDestroy */
-       }
-       cached_fonts->nfont = 0;
-       FcFontSetDestroy (cached_fonts);
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return FcFalse;
     }
+       
+    fonts = FcFontSetCreate ();
+    if (!fonts)
+       goto bail;
+    
+    FcConfigSetFonts (config, fonts, FcSetSystem);
+    
+    dirlist = FcStrListCreate (config->fontDirs);
+    if (!dirlist)
+        goto bail;
+       
+    while ((dir = FcStrListNext (dirlist)))
+    {
+       if (FcDebug () & FC_DBG_FONTSET)
+           printf ("adding fonts from%s\n", dir);
+       cache = FcDirCacheRead (dir, FcFalse, config);
+       if (!cache)
+           continue;
+       FcConfigAddCache (config, cache);
+       FcDirCacheUnload (cache);
+    }
+    
+    FcStrListDone (dirlist);
     
     if (FcDebug () & FC_DBG_FONTSET)
        FcFontSetPrint (fonts);
 
-    FcStrSetDestroy (oldDirs);
-
-    FcConfigSetFonts (config, fonts, FcSetSystem);
-    
     return FcTrue;
-bail3:
-    FcStrSetDestroy (oldDirs);
-bail2:
-    FcFontSetDestroy (fonts);
-bail0:
+bail:
     return FcFalse;
 }
 
@@ -457,19 +478,6 @@ FcConfigSetFonts (FcConfig *config,
     config->fonts[set] = fonts;
 }
 
-FcBool
-FcConfigAddCache (FcConfig *config, FcCache *cache)
-{
-    FcCacheList        *cl = malloc (sizeof (FcCacheList));
-
-    if (!cl)
-       return FcFalse;
-    cl->cache = cache;
-    cl->next = config->caches;
-    config->caches = cl;
-    return FcTrue;
-}
-
 FcBlanks *
 FcConfigGetBlanks (FcConfig    *config)
 {
@@ -540,14 +548,23 @@ FcConfigAddEdit (FcConfig *config,
     FcTest     *t;
     int                num;
 
+    switch (kind) {
+    case FcMatchPattern:
+       prev = &config->substPattern;
+       break;
+    case FcMatchFont:
+       prev = &config->substFont;
+       break;
+    case FcMatchScan:
+       prev = &config->substScan;
+       break;
+    default:
+       return FcFalse;
+    }
     subst = (FcSubst *) malloc (sizeof (FcSubst));
     if (!subst)
        return FcFalse;
     FcMemAlloc (FC_MEM_SUBST, sizeof (FcSubst));
-    if (kind == FcMatchPattern)
-       prev = &config->substPattern;
-    else
-       prev = &config->substFont;
     for (; *prev; prev = &(*prev)->next);
     *prev = subst;
     subst->next = 0;
@@ -1269,6 +1286,20 @@ FcConfigSubstituteWithPat (FcConfig    *config,
            return FcFalse;
     }
 
+    switch (kind) {
+    case FcMatchPattern:
+       s = config->substPattern;
+       break;
+    case FcMatchFont:
+       s = config->substFont;
+       break;
+    case FcMatchScan:
+       s = config->substScan;
+       break;
+    default:
+       return FcFalse;
+    }
+
     st = (FcSubState *) malloc (config->maxObjects * sizeof (FcSubState));
     if (!st && config->maxObjects)
        return FcFalse;
@@ -1279,10 +1310,6 @@ FcConfigSubstituteWithPat (FcConfig    *config,
        printf ("FcConfigSubstitute ");
        FcPatternPrint (p);
     }
-    if (kind == FcMatchPattern)
-       s = config->substPattern;
-    else
-       s = config->substFont;
     for (; s; s = s->next)
     {
        /*
@@ -1750,7 +1777,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
        FcConfigSetFonts (config, set, FcSetApplication);
     }
        
-    if (!FcFileScanConfig (set, subdirs, config->blanks, file, FcFalse, config))
+    if (!FcFileScanConfig (set, subdirs, config->blanks, file, config))
     {
        FcStrSetDestroy (subdirs);
        return FcFalse;
@@ -1937,3 +1964,6 @@ FcConfigAcceptFont (FcConfig          *config,
        return FcFalse;
     return FcTrue;
 }
+#define __fccfg__
+#include "fcaliastail.h"
+#undef __fccfg__