]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Bump libtool revision in preparation for release
[fontconfig.git] / src / fccfg.c
index b55770d4b6244e1d678f115a6d51a770f837bf0f..0f89b57a415f61cca22418e8cdcc52fd82c7bccd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
+ * fontconfig/src/fccfg.c
  *
  * Copyright © 2000 Keith Packard
  *
@@ -13,9 +13,9 @@
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@@ -92,6 +92,10 @@ FcConfigCreate (void)
 
     config->rescanTime = time(0);
     config->rescanInterval = 30;    
+
+    config->expr_pool = NULL;
+
+    config->ref = 1;
     
     return config;
 
@@ -127,7 +131,7 @@ FcConfigNewestFile (FcStrSet *files)
     if (list)
     {
        while ((file = FcStrListNext (list)))
-           if (stat ((char *) file, &statb) == 0)
+           if (FcStat ((char *) file, &statb) == 0)
                if (!newest.set || statb.st_mtime - newest.time > 0)
                {
                    newest.set = FcTrue;
@@ -156,7 +160,18 @@ FcConfigUptoDate (FcConfig *config)
        (config_dir_time.set && (config_dir_time.time - config->rescanTime) > 0) ||
        (font_time.set && (font_time.time - config->rescanTime) > 0))
     {
-       return FcFalse;
+       /* We need to check for potential clock problems here (OLPC ticket #6046) */
+       if ((config_time.set && (config_time.time - now) > 0) ||
+       (config_dir_time.set && (config_dir_time.time - now) > 0) ||
+        (font_time.set && (font_time.time - now) > 0))
+       {
+           fprintf (stderr,
+                    "Fontconfig warning: Directory/file mtime in the future. New fonts may not be detected\n");
+           config->rescanTime = now;
+           return FcTrue;
+       }
+       else
+           return FcFalse;
     }
     config->rescanTime = now;
     return FcTrue;
@@ -180,10 +195,49 @@ FcSubstDestroy (FcSubst *s)
     }
 }
 
+FcExpr *
+FcConfigAllocExpr (FcConfig *config)
+{
+  if (!config->expr_pool || config->expr_pool->next == config->expr_pool->end)
+  {
+    FcExprPage *new_page;
+
+    new_page = malloc (sizeof (FcExprPage));
+    if (!new_page)
+      return 0;
+    FcMemAlloc (FC_MEM_EXPR, sizeof (FcExprPage));
+
+    new_page->next_page = config->expr_pool;
+    new_page->next = new_page->exprs;
+    config->expr_pool = new_page;
+  }
+
+  return config->expr_pool->next++;
+}
+
+FcConfig *
+FcConfigReference (FcConfig *config)
+{
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return 0;
+    }
+
+    config->ref++;
+
+    return config;
+}
+
 void
 FcConfigDestroy (FcConfig *config)
 {
     FcSetName  set;
+    FcExprPage *page;
+
+    if (--config->ref > 0)
+       return;
 
     if (config == _fcConfig)
        _fcConfig = 0;
@@ -207,6 +261,15 @@ FcConfigDestroy (FcConfig *config)
        if (config->fonts[set])
            FcFontSetDestroy (config->fonts[set]);
 
+    page = config->expr_pool;
+    while (page)
+    {
+      FcExprPage *next = page->next_page;
+      FcMemFree (FC_MEM_EXPR, sizeof (FcExprPage));
+      free (page);
+      page = next;
+    }
+
     free (config);
     FcMemFree (FC_MEM_CONFIG, sizeof (FcConfig));
 }
@@ -332,6 +395,9 @@ FcConfigBuildFonts (FcConfig *config)
 FcBool
 FcConfigSetCurrent (FcConfig *config)
 {
+    if (config == _fcConfig)
+       return FcTrue;
+
     if (!config->fonts)
        if (!FcConfigBuildFonts (config))
            return FcFalse;
@@ -508,7 +574,7 @@ FcConfigAddBlank (FcConfig  *config,
 }
 
 int
-FcConfigGetRescanInverval (FcConfig *config)
+FcConfigGetRescanInterval (FcConfig *config)
 {
     if (!config)
     {
@@ -520,7 +586,7 @@ FcConfigGetRescanInverval (FcConfig *config)
 }
 
 FcBool
-FcConfigSetRescanInverval (FcConfig *config, int rescanInterval)
+FcConfigSetRescanInterval (FcConfig *config, int rescanInterval)
 {
     if (!config)
     {
@@ -532,6 +598,22 @@ FcConfigSetRescanInverval (FcConfig *config, int rescanInterval)
     return FcTrue;
 }
 
+/*
+ * A couple of typos escaped into the library
+ */
+int
+FcConfigGetRescanInverval (FcConfig *config)
+{
+    return FcConfigGetRescanInterval (config);
+}
+
+FcBool
+FcConfigSetRescanInverval (FcConfig *config, int rescanInterval)
+{
+    return FcConfigSetRescanInterval (config, rescanInterval);
+}
+
+    
 FcBool
 FcConfigAddEdit (FcConfig      *config,
                 FcTest         *test,
@@ -678,7 +760,7 @@ FcConfigCompareValue (const FcValue *left_o,
                ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) != 0;
                break;
            case FcOpNotContains:
-               ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
+               ret = FcStrStrIgnoreCase (left.u.s, right.u.s) == 0;
                break;
            default:
                break;
@@ -802,7 +884,8 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        break;
     case FcOpString:
        v.type = FcTypeString;
-       v.u.s = FcStrStaticName(e->u.sval);
+       v.u.s = e->u.sval;
+       v = FcValueSave (v);
        break;
     case FcOpMatrix:
        v.type = FcTypeMatrix;
@@ -1501,10 +1584,16 @@ FcConfigSubstitute (FcConfig    *config,
     return FcConfigSubstituteWithPat (config, p, 0, kind);
 }
 
-#if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
+#if defined (_WIN32)
+
+#  define WIN32_LEAN_AND_MEAN
+#  define WIN32_EXTRA_LEAN
+#  include <windows.h>
 
 static FcChar8 fontconfig_path[1000] = "";
 
+#  if (defined (PIC) || defined (DLL_EXPORT))
+
 BOOL WINAPI
 DllMain (HINSTANCE hinstDLL,
         DWORD     fdwReason,
@@ -1542,12 +1631,12 @@ DllMain (HINSTANCE hinstDLL,
   return TRUE;
 }
 
+#  endif /* !PIC */
+
 #undef FONTCONFIG_PATH
 #define FONTCONFIG_PATH fontconfig_path
 
-#else /* !(_WIN32 && PIC) */
-
-#endif /* !(_WIN32 && PIC) */
+#endif /* !_WIN32 */
 
 #ifndef FONTCONFIG_FILE
 #define FONTCONFIG_FILE        "fonts.conf"
@@ -1632,6 +1721,17 @@ FcConfigGetPath (void)
        }
     }
     
+#ifdef _WIN32
+       if (fontconfig_path[0] == '\0')
+       {
+               char *p;
+               if(!GetModuleFileName(NULL, fontconfig_path, sizeof(fontconfig_path)))
+                       goto bail1;
+               p = strrchr (fontconfig_path, '\\');
+               if (p) *p = '\0';
+               strcat (fontconfig_path, "\\fonts");
+       }
+#endif
     dir = (FcChar8 *) FONTCONFIG_PATH;
     path[i] = malloc (strlen ((char *) dir) + 1);
     if (!path[i])
@@ -1688,7 +1788,7 @@ FcChar8 *
 FcConfigFilename (const FcChar8 *url)
 {
     FcChar8    *file, *dir, **path, **p;
-    
+
     if (!url || !*url)
     {
        url = (FcChar8 *) getenv ("FONTCONFIG_FILE");