]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcxml.c
Proper config path for static libraries in win32
[fontconfig.git] / src / fcxml.c
index d91e52275161bab71913ac24bb3c12b0e6b44e4c..a2cc02eae263fda248693bb18c932439123df290 100644 (file)
@@ -545,6 +545,8 @@ FcTypecheckValue (FcConfigParse *parse, FcType value, FcType type)
        if ((value == FcTypeLangSet && type == FcTypeString) ||
            (value == FcTypeString && type == FcTypeLangSet))
            return;
+       if (type == (FcType) -1)
+           return;
        FcConfigMessage (parse, FcSevereWarning, "saw %s, expected %s",
                         FcTypeName (value), FcTypeName (type));
     }
@@ -556,6 +558,10 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
     const FcObjectType *o;
     const FcConstant   *c;
     
+    /* If parsing the expression failed, some nodes may be NULL */
+    if (!expr)
+       return;
+
     switch (expr->op) {
     case FcOpInteger:
     case FcOpDouble:
@@ -962,7 +968,12 @@ FcPStackPush (FcConfigParse *parse, FcElement element, const XML_Char **attr)
     {
        new->attr = FcConfigSaveAttr (attr);
        if (!new->attr)
+       {
            FcConfigMessage (parse, FcSevereError, "out of memory");
+           FcMemFree (FC_MEM_PSTACK, sizeof (FcPStack));
+           free (new);
+           return FcFalse;
+       }
     }
     else
        new->attr = 0;
@@ -1282,6 +1293,33 @@ FcParseBool (FcConfigParse *parse)
     FcStrFree (s);
 }
 
+static FcBool
+FcConfigLexBinding (FcConfigParse   *parse,
+                   const FcChar8   *binding_string,
+                   FcValueBinding  *binding_ret)
+{
+    FcValueBinding binding;
+    
+    if (!binding_string)
+       binding = FcValueBindingWeak;
+    else
+    {
+       if (!strcmp ((char *) binding_string, "weak"))
+           binding = FcValueBindingWeak;
+       else if (!strcmp ((char *) binding_string, "strong"))
+           binding = FcValueBindingStrong;
+       else if (!strcmp ((char *) binding_string, "same"))
+           binding = FcValueBindingSame;
+       else
+       {
+           FcConfigMessage (parse, FcSevereWarning, "invalid binding \"%s\"", binding_string);
+           return FcFalse;
+       }
+    }
+    *binding_ret = binding;
+    return FcTrue;
+}
+
 static void
 FcParseFamilies (FcConfigParse *parse, FcVStackTag tag)
 {
@@ -1351,7 +1389,10 @@ FcParseAlias (FcConfigParse *parse)
     FcEdit     *edit = 0, *next;
     FcVStack   *vstack;
     FcTest     *test;
+    FcValueBinding  binding;
 
+    if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
+       return;
     while ((vstack = FcVStackPop (parse))) 
     {
        switch (vstack->tag) {
@@ -1413,7 +1454,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpPrepend,
                             prefer,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = 0;
        else
@@ -1426,7 +1467,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpAppend,
                             accept,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1439,7 +1480,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpAppendLast,
                             def,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1644,7 +1685,6 @@ FcConfigLexCompare (const FcChar8 *compare)
     return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS);
 }
 
-
 static void
 FcParseTest (FcConfigParse *parse)
 {
@@ -1751,7 +1791,6 @@ FcParseEdit (FcConfigParse *parse)
 {
     const FcChar8   *name;
     const FcChar8   *mode_string;
-    const FcChar8   *binding_string;
     FcOp           mode;
     FcValueBinding  binding;
     FcExpr         *expr;
@@ -1775,23 +1814,9 @@ FcParseEdit (FcConfigParse *parse)
            return;
        }
     }
-    binding_string = FcConfigGetAttribute (parse, "binding");
-    if (!binding_string)
-       binding = FcValueBindingWeak;
-    else
-    {
-       if (!strcmp ((char *) binding_string, "weak"))
-           binding = FcValueBindingWeak;
-       else if (!strcmp ((char *) binding_string, "strong"))
-           binding = FcValueBindingStrong;
-       else if (!strcmp ((char *) binding_string, "same"))
-           binding = FcValueBindingSame;
-       else
-       {
-           FcConfigMessage (parse, FcSevereWarning, "invalid edit binding \"%s\"", binding_string);
-           return;
-       }
-    }
+    if (!FcConfigLexBinding (parse, FcConfigGetAttribute (parse, "binding"), &binding))
+       return;
+
     expr = FcPopBinary (parse, FcOpComma);
     edit = FcEditCreate (parse, FcObjectFromName ((char *) name),
                         mode, expr, binding);
@@ -1843,6 +1868,12 @@ FcParseMatch (FcConfigParse *parse)
            vstack->u.edit->next = edit;
            edit = vstack->u.edit;
            vstack->tag = FcVStackNone;
+           if (kind == FcMatchScan && edit->object > FC_MAX_BASE_OBJECT)
+           {
+               FcConfigMessage (parse, FcSevereError, 
+                                "<match target=\"scan\"> cannot edit user-defined object \"%s\"",
+                                FcObjectName(edit->object));
+           }
            break;
        default:
            FcConfigMessage (parse, FcSevereWarning, "invalid match element");
@@ -2027,7 +2058,27 @@ FcEndElement(void *userData, const XML_Char *name)
            break;
        }
 #ifdef _WIN32
-       if (strcmp (data, "WINDOWSFONTDIR") == 0)
+       if (strcmp (data, "CUSTOMFONTDIR") == 0)
+       {
+               FcStrFree (data);
+               data = malloc (1000);
+               if (!data)
+               {
+                       FcConfigMessage (parse, FcSevereError, "out of memory");
+                       break;
+               }
+               FcMemAlloc (FC_MEM_STRING, 1000);
+               if(!GetModuleFileName(NULL, data, 1000))
+               {
+                       FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
+                       FcStrFree (data);
+                       break;
+               }
+               char *p = strrchr (data, '\\');
+               if (p) *p = '\0';
+               strcat (data, "\\fonts");
+       }
+       else if (strcmp (data, "WINDOWSFONTDIR") == 0)
        {
            int rc;
            FcStrFree (data);
@@ -2064,6 +2115,30 @@ FcEndElement(void *userData, const XML_Char *name)
            FcConfigMessage (parse, FcSevereError, "out of memory");
            break;
        }
+#ifdef _WIN32
+       if (strcmp (data, "WINDOWSTEMPDIR_FONTCONFIG_CACHE") == 0)
+       {
+           int rc;
+           FcStrFree (data);
+           data = malloc (1000);
+           if (!data)
+           {
+               FcConfigMessage (parse, FcSevereError, "out of memory");
+               break;
+           }
+           FcMemAlloc (FC_MEM_STRING, 1000);
+           rc = GetTempPath (800, data);
+           if (rc == 0 || rc > 800)
+           {
+               FcConfigMessage (parse, FcSevereError, "GetWindowsDirectory failed");
+               FcStrFree (data);
+               break;
+           }
+           if (data [strlen (data) - 1] != '\\')
+               strcat (data, "\\");
+           strcat (data, "fontconfig\\cache");
+       }
+#endif
        if (!FcStrUsesHome (data) || FcConfigHome ())
        {
            if (!FcConfigAddCacheDir (parse->config, data))
@@ -2279,6 +2354,14 @@ FcEndDoctypeDecl (void *userData)
 
 #endif /* ENABLE_LIBXML2 */
 
+static int
+FcSortCmpStr (const void *a, const void *b)
+{
+    const FcChar8    *as = *((FcChar8 **) a);
+    const FcChar8    *bs = *((FcChar8 **) b);
+    return FcStrCmp (as, bs);
+}
+
 static FcBool
 FcConfigParseAndLoadDir (FcConfig      *config,
                         const FcChar8  *name,
@@ -2348,7 +2431,7 @@ FcConfigParseAndLoadDir (FcConfig *config,
     {
        int i;
        qsort (files->strs, files->num, sizeof (FcChar8 *), 
-              (int (*)(const void *, const void *)) FcStrCmp);
+              (int (*)(const void *, const void *)) FcSortCmpStr);
        for (i = 0; ret && i < files->num; i++)
            ret = FcConfigParseAndLoad (config, files->strs[i], complain);
     }
@@ -2491,3 +2574,6 @@ bail0:
     }
     return FcTrue;
 }
+#define __fcxml__
+#include "fcaliastail.h"
+#undef __fcxml__