[Fontconfig] fontconfig: Branch 'master' - 3 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Jun 20 08:55:53 PDT 2011


 doc/fcformat.fncs   |    7 +++++++
 fc-cat/fc-cat.c     |   39 +++++++++++----------------------------
 fc-list/fc-list.c   |   17 ++++-------------
 fc-match/fc-match.c |   38 +++++++++-----------------------------
 src/fcformat.c      |    7 +++++--
 src/fcname.c        |    3 +--
 6 files changed, 37 insertions(+), 74 deletions(-)

New commits:
commit e61eba94efffbdbec6f9e08f3fb04b75f0ba2a3f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Jun 20 11:55:25 2011 -0400

    Switch fc-cat to use FcPatternFormat()
    
    Added the a builtin "fccat" to FcPatternFormat().

diff --git a/doc/fcformat.fncs b/doc/fcformat.fncs
index 125e6b4..c136e8c 100644
--- a/doc/fcformat.fncs
+++ b/doc/fcformat.fncs
@@ -202,6 +202,13 @@ command on the pattern, without the final newline.
 </para></listitem></varlistentry>
 
 <varlistentry><term>
+fccat
+</term><listitem><para>
+Expands to the output of the default output format of the fc-cat
+command on the pattern, without the final newline.
+</para></listitem></varlistentry>
+
+<varlistentry><term>
 pkgkit
 </term><listitem><para>
 Expands to the list of PackageKit font() tags for the pattern.
diff --git a/fc-cat/fc-cat.c b/fc-cat/fc-cat.c
index c6c3993..5ee947e 100644
--- a/fc-cat/fc-cat.c
+++ b/fc-cat/fc-cat.c
@@ -194,11 +194,9 @@ file_base_name (const FcChar8 *cache, const FcChar8 *file)
 static FcBool
 cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBool verbose)
 {
-    FcChar8	    *name, *dir;
-    const FcChar8   *file, *base;
-    int		    ret;
+    FcChar8	    *dir;
+    const FcChar8   *base;
     int		    n;
-    int		    id;
     int		    ndir = 0;
     FcStrList	    *list;
 
@@ -227,37 +225,22 @@ cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBoo
     for (n = 0; n < set->nfont; n++)
     {
 	FcPattern   *font = set->fonts[n];
+	FcChar8 *s;
 
-	if (FcPatternGetString (font, FC_FILE, 0, (FcChar8 **) &file) != FcResultMatch)
-	    goto bail3;
-	base = file_base_name (base_name, file);
-	if (FcPatternGetInteger (font, FC_INDEX, 0, &id) != FcResultMatch)
-	    goto bail3;
-	if (!write_string (stdout, base))
-	    goto bail3;
-	if (PUTC (' ', stdout) == EOF)
-	    goto bail3;
-	if (!write_int (stdout, id))
-	    goto bail3;
-        if (PUTC (' ', stdout) == EOF)
-	    goto bail3;
-	name = FcNameUnparse (font);
-	if (!name)
-	    goto bail3;
-	ret = write_string (stdout, name);
-	FcStrFree (name);
-	if (!ret)
-	    goto bail3;
-	if (PUTC ('\n', stdout) == EOF)
-	    goto bail3;
+	s = FcPatternFormat (font, "%{=fccat}\n");
+	if (s)
+	{
+	    printf ("%s", s);
+	    free (s);
+	}
     }
     if (verbose && !set->nfont && !ndir)
 	printf ("<empty>\n");
-    
+
     FcStrListDone (list);
 
     return FcTrue;
-    
+
 bail3:
     FcStrListDone (list);
 bail2:
diff --git a/src/fcformat.c b/src/fcformat.c
index 4a850ee..d8518f4 100644
--- a/src/fcformat.c
+++ b/src/fcformat.c
@@ -62,6 +62,7 @@
  * unparse	FcNameUnparse
  * fcmatch	fc-match default
  * fclist	fc-list default
+ * fccat	fc-cat default
  * pkgkit	PackageKit package tag format
  *
  *
@@ -74,6 +75,7 @@
  */
 
 
+#define FCCAT_FORMAT	"\"%{file|basename|cescape}\" %{index} \"%{-file{%{=unparse|cescape}}}\""
 #define FCMATCH_FORMAT	"%{file:-<unknown filename>|basename}: \"%{family[0]:-<unknown family>}\" \"%{style[0]:-<unknown style>}\""
 #define FCLIST_FORMAT	"%{?file{%{file}: }}%{-file{%{=unparse}}}"
 #define PKGKIT_FORMAT	"%{[]family{font(%{family|downcase|delete( )})\n}}%{[]lang{font(:lang=%{lang|downcase|translate(_,-)})\n}}"
@@ -304,6 +306,7 @@ interpret_builtin (FcFormatContext *c,
 #define BUILTIN(name, format) \
     else if (0 == strcmp ((const char *) c->word, name))\
 	ret = FcPatternFormatToBuf (pat, (const FcChar8 *) format, buf)
+    BUILTIN ("fccat",    FCCAT_FORMAT);
     BUILTIN ("fcmatch",  FCMATCH_FORMAT);
     BUILTIN ("fclist",   FCLIST_FORMAT);
     BUILTIN ("pkgkit",   PKGKIT_FORMAT);
commit a15ac5d3840552528874f1d5ad166eb00906ce80
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Jun 20 11:32:46 2011 -0400

    Switch fc-match to use FcPatternFormat()
    
    Fix small bug in FcPatternFormat that was letting element-default to
    consume the convertor sequence.

diff --git a/fc-match/fc-match.c b/fc-match/fc-match.c
index 48ba6cf..e64b4bc 100644
--- a/fc-match/fc-match.c
+++ b/fc-match/fc-match.c
@@ -195,6 +195,14 @@ main (int argc, char **argv)
     }
     FcPatternDestroy (pat);
 
+    if (!format)
+    {
+	if (os)
+	    format = "%{=unparse}\n";
+	else
+	    format = "%{=fcmatch}\n";
+    }
+
     if (fs)
     {
 	int	j;
@@ -209,7 +217,7 @@ main (int argc, char **argv)
 	    {
 		FcPatternPrint (font);
 	    }
-	    else if (format)
+	    else
 	    {
 	        FcChar8 *s;
 
@@ -220,34 +228,6 @@ main (int argc, char **argv)
 		    free (s);
 		}
 	    }
-	    else if (os)
-	    {
-		FcChar8 *str;
-		str = FcNameUnparse (font);
-		printf ("%s\n", str);
-		free (str);
-	    }
-	    else
-	    {
-		FcChar8	*family;
-		FcChar8	*style;
-		FcChar8	*file;
-
-		if (FcPatternGetString (font, FC_FILE, 0, &file) != FcResultMatch)
-		    file = (FcChar8 *) "<unknown filename>";
-		else
-		{
-		    FcChar8 *slash = (FcChar8 *) strrchr ((char *) file, '/');
-		    if (slash)
-			file = slash+1;
-		}
-		if (FcPatternGetString (font, FC_FAMILY, 0, &family) != FcResultMatch)
-		    family = (FcChar8 *) "<unknown family>";
-		if (FcPatternGetString (font, FC_STYLE, 0, &style) != FcResultMatch)
-		    style = (FcChar8 *) "<unknown style>";
-
-		printf ("%s: \"%s\" \"%s\"\n", file, family, style);
-	    }
 
 	    FcPatternDestroy (font);
 	}
diff --git a/src/fcformat.c b/src/fcformat.c
index 796957d..4a850ee 100644
--- a/src/fcformat.c
+++ b/src/fcformat.c
@@ -732,7 +732,7 @@ interpret_simple (FcFormatContext *c,
 	c->word = c->word + strlen ((const char *) c->word) + 1;
 	/* for now we just support 'default value' */
 	if (!expect_char (c, '-') ||
-	    !read_chars (c, '\0'))
+	    !read_chars (c, '|'))
 	{
 	    c->word = orig;
 	    return FcFalse;
commit e0be405a1dd5765e36152c754a47c8ad7ff0ab85
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Jun 20 11:22:17 2011 -0400

    Bug 26718 - "fc-match sans file" doesn't work
    
    - Do not throw away FC_FILE in FcNameUnparse
    - Update the builtin "fclist" format to remove FC_FILE properly instead
    - Switch fc-list to use FcPatternFormat()
    
    Note that I had previously broken fc-list and it was not showing the
    file name anymore.  No one noticed that it seems!  Now fixed.

diff --git a/fc-list/fc-list.c b/fc-list/fc-list.c
index 12c2ca5..ad38332 100644
--- a/fc-list/fc-list.c
+++ b/fc-list/fc-list.c
@@ -156,7 +156,9 @@ main (int argc, char **argv)
     if (quiet && !os)
 	os = FcObjectSetCreate ();
     if (!verbose && !format && !os)
-	os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, (char *) 0);
+	os = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_FILE, (char *) 0);
+    if (!format)
+        format = "%{=fclist}\n";
     fs = FcFontList (0, pat, os);
     if (os)
 	FcObjectSetDestroy (os);
@@ -173,7 +175,7 @@ main (int argc, char **argv)
 	    {
 		FcPatternPrint (fs->fonts[j]);
 	    }
-	    else if (format)
+	    else
 	    {
 	        FcChar8 *s;
 
@@ -184,17 +186,6 @@ main (int argc, char **argv)
 		    free (s);
 		}
 	    }
-	    else
-	    {
-		FcChar8 *str;
-		FcChar8 *file;
-
-		str = FcNameUnparse (fs->fonts[j]);
-		if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch)
-		    printf ("%s: ", file);
-		printf ("%s\n", str);
-		free (str);
-	    }
 	}
     }
 
diff --git a/src/fcformat.c b/src/fcformat.c
index 1368b71..796957d 100644
--- a/src/fcformat.c
+++ b/src/fcformat.c
@@ -75,7 +75,7 @@
 
 
 #define FCMATCH_FORMAT	"%{file:-<unknown filename>|basename}: \"%{family[0]:-<unknown family>}\" \"%{style[0]:-<unknown style>}\""
-#define FCLIST_FORMAT	"%{?file{%{file}: }}%{=unparse}"
+#define FCLIST_FORMAT	"%{?file{%{file}: }}%{-file{%{=unparse}}}"
 #define PKGKIT_FORMAT	"%{[]family{font(%{family|downcase|delete( )})\n}}%{[]lang{font(:lang=%{lang|downcase|translate(_,-)})\n}}"
 
 
diff --git a/src/fcname.c b/src/fcname.c
index 86c10b6..d77eff6 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -874,8 +874,7 @@ FcNameUnparseEscaped (FcPattern *pat, FcBool escape)
 	{
 	    o = &l->types[i];
 	    if (!strcmp (o->object, FC_FAMILY) ||
-		!strcmp (o->object, FC_SIZE) ||
-		!strcmp (o->object, FC_FILE))
+		!strcmp (o->object, FC_SIZE))
 		continue;
 	
 	    e = FcPatternObjectFindElt (pat, FcObjectFromName (o->object));


More information about the Fontconfig mailing list