]> git.wh0rd.org Git - fontconfig.git/commitdiff
Respect "binding" attribute in <alias> entries.
authorKeith Packard <keithp@koto.keithp.com>
Fri, 26 Oct 2007 05:30:49 +0000 (22:30 -0700)
committerKeith Packard <keithp@koto.keithp.com>
Fri, 26 Oct 2007 05:30:49 +0000 (22:30 -0700)
This makes creating "same" aliases for renamed font families far easier.

fonts.dtd
src/fcxml.c

index a5c54f98352ad3d5808b5f4896fbeac40664ca84..cbdfdab3fb5675e159b482a1f5ed21f87e71156b 100644 (file)
--- a/fonts.dtd
+++ b/fonts.dtd
          name CDATA    #REQUIRED>
 
 <!ELEMENT alias (family*, prefer?, accept?, default?)>
+<!ATTLIST alias
+         binding (weak|strong|same) "weak">
 <!ELEMENT prefer (family)*>
 <!ELEMENT accept (family)*>
 <!ELEMENT default (family)*>
index 3b08fea593eb46db055cdcaf03014a8b549d5604..e8cfe1fbdbaa078d2c74a139196f5fdd86639c2d 100644 (file)
@@ -1288,6 +1288,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)
 {
@@ -1357,7 +1384,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) {
@@ -1419,7 +1449,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpPrepend,
                             prefer,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = 0;
        else
@@ -1432,7 +1462,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpAppend,
                             accept,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1445,7 +1475,7 @@ FcParseAlias (FcConfigParse *parse)
                             FC_FAMILY_OBJECT,
                             FcOpAppendLast,
                             def,
-                            FcValueBindingWeak);
+                            binding);
        if (edit)
            edit->next = next;
        else
@@ -1650,7 +1680,6 @@ FcConfigLexCompare (const FcChar8 *compare)
     return FcConfigLexOp (compare, fcCompareOps, NUM_COMPARE_OPS);
 }
 
-
 static void
 FcParseTest (FcConfigParse *parse)
 {
@@ -1757,7 +1786,6 @@ FcParseEdit (FcConfigParse *parse)
 {
     const FcChar8   *name;
     const FcChar8   *mode_string;
-    const FcChar8   *binding_string;
     FcOp           mode;
     FcValueBinding  binding;
     FcExpr         *expr;
@@ -1781,23 +1809,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);