]> git.wh0rd.org - fontconfig.git/commitdiff
[fcformat] Support indexing simple tags
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 12 Feb 2009 04:44:36 +0000 (23:44 -0500)
committerBehdad Esfahbod <behdad@behdad.org>
Sun, 15 Feb 2009 21:40:30 +0000 (13:40 -0800)
The format '%{family[0]}' will only output the first value for element family.

src/fcformat.c
src/fcint.h
src/fcname.c

index 334eee6a71bc09ab27cde3a62d9d9eb5649e4f9e..898ee324151371476cfd8fba1e9d8efe42d7c99d 100644 (file)
@@ -39,9 +39,8 @@
  */
 
 
-/* fc-match needs '<unknown filename>', etc handling, as well as printing
- * printing first value only. */
-#define FCMATCH_FORMAT "%{file|basename}: \"%{family}\" \"%{style}\""
+/* fc-match needs '<unknown filename>', etc handling. */
+#define FCMATCH_FORMAT "%{file|basename}: \"%{family[0]}\" \"%{style[0]}\""
 #define FCLIST_FORMAT  "%{?file{%{file}: }}%{=unparse}"
 
 
@@ -543,6 +542,7 @@ interpret_simple (FcFormatContext *c,
     FcPatternElt *e;
     FcBool        add_colon = FcFalse;
     FcBool        add_elt_name = FcFalse;
+    int           idx;
 
     if (consume_char (c, ':'))
        add_colon = FcTrue;
@@ -550,6 +550,19 @@ interpret_simple (FcFormatContext *c,
     if (!read_word (c))
        return FcFalse;
 
+    idx = -1;
+    if (consume_char (c, '['))
+    {
+       idx = strtol ((const char *) c->format, (char **) &c->format, 10);
+       if (idx < 0)
+       {
+           message ("expected non-negative number at %d",
+                    c->format-1 - c->format_orig + 1);
+           return FcFalse;
+       }
+       expect_char (c, ']');
+    }
+
     if (consume_char (c, '='))
        add_elt_name = FcTrue;
 
@@ -568,7 +581,29 @@ interpret_simple (FcFormatContext *c,
        }
 
        l = FcPatternEltValues(e);
-       FcNameUnparseValueList (buf, l, '\0');
+
+       if (idx != -1)
+       {
+           while (l && idx > 0)
+           {
+               l = FcValueListNext(l);
+               idx--;
+           }
+           if (l && idx == 0)
+           {
+               if (!FcNameUnparseValue (buf, &l->value, '\0'))
+                   return FcFalse;
+           }
+           else goto notfound;
+        }
+       else
+       {
+           FcNameUnparseValueList (buf, l, '\0');
+       }
+    }
+    else
+notfound:
+    {
     }
 
     return FcTrue;
index 0b41d593ce97bd66bf88459ca164a1e4c6e3ac15..b667e5476b4c9dc62c53eef570758c49ab974d9a 100644 (file)
@@ -645,6 +645,11 @@ FcNameUnparseCharSet (FcStrBuf *buf, const FcCharSet *c);
 FcPrivate FcCharSet *
 FcNameParseCharSet (FcChar8 *string);
 
+FcPrivate FcBool
+FcNameUnparseValue (FcStrBuf    *buf,
+                    FcValue     *v0,
+                   FcChar8     *escape);
+
 FcPrivate FcBool
 FcNameUnparseValueList (FcStrBuf       *buf,
                        FcValueListPtr  v,
index 02a2b82e0ae1aef1f9c9d0660a6de72e1b13dc29..dd05bc3b4fe35c492e5a98c4caab5c3598d59536 100644 (file)
@@ -783,7 +783,7 @@ FcNameUnparseString (FcStrBuf           *buf,
     return FcTrue;
 }
 
-static FcBool
+FcBool
 FcNameUnparseValue (FcStrBuf   *buf,
                    FcValue     *v0,
                    FcChar8     *escape)