]> git.wh0rd.org - fontconfig.git/blobdiff - fc-match/fc-match.c
Make fc-match --sort call FcFontRenderPrepare.
[fontconfig.git] / fc-match / fc-match.c
index 635c883c17059d3ac2ec65d30fb06b556e965f7f..bf9817b8064d83bcdbc4075a7a1896350f6e79ef 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: xc/lib/fontconfig/fc-list/fc-list.c,v 1.5 2002/06/30 23:45:40 keithp Exp $
  *
- * Copyright © 2003 Keith Packard
+ * Copyright Â© 2003 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <fontconfig/fontconfig.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #else
 #define HAVE_GETOPT 1
 #endif
 
+#include <fontconfig/fontconfig.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
 #ifndef HAVE_GETOPT
 #define HAVE_GETOPT 0
 #endif
@@ -47,7 +48,7 @@
 #undef  _GNU_SOURCE
 #define _GNU_SOURCE
 #include <getopt.h>
-const struct option longopts[] = {
+static const struct option longopts[] = {
     {"sort", 0, 0, 's'},
     {"version", 0, 0, 'V'},
     {"verbose", 0, 0, 'v'},
@@ -99,7 +100,7 @@ main (int argc, char **argv)
     int                c;
 
 #if HAVE_GETOPT_LONG
-    while ((c = getopt_long (argc, argv, "Vv?", longopts, NULL)) != -1)
+    while ((c = getopt_long (argc, argv, "sVv?", longopts, NULL)) != -1)
 #else
     while ((c = getopt (argc, argv, "sVv?")) != -1)
 #endif
@@ -134,21 +135,39 @@ main (int argc, char **argv)
     else
        pat = FcPatternCreate ();
 
+    if (!pat)
+       return 1;
+
     FcConfigSubstitute (0, pat, FcMatchPattern);
     FcDefaultSubstitute (pat);
     
+    fs = FcFontSetCreate ();
+
     if (sort)
-       fs = FcFontSort (0, pat, FcTrue, 0, &result);
+    {
+       FcFontSet       *font_patterns;
+       int     j;
+       font_patterns = FcFontSort (0, pat, FcTrue, 0, &result);
+
+       for (j = 0; j < font_patterns->nfont; j++)
+       {
+           FcPattern  *font_pattern;
+
+           font_pattern = FcFontRenderPrepare (NULL, pat, font_patterns->fonts[j]);
+           if (font_pattern)
+               FcFontSetAdd (fs, font_pattern);
+       }
+
+       FcFontSetSortDestroy (font_patterns);
+    }
     else
     {
        FcPattern   *match;
-       fs = FcFontSetCreate ();
        match = FcFontMatch (0, pat, &result);
        if (match)
            FcFontSetAdd (fs, match);
     }
-    if (pat)
-       FcPatternDestroy (pat);
+    FcPatternDestroy (pat);
 
     if (fs)
     {
@@ -167,22 +186,23 @@ main (int argc, char **argv)
                FcChar8 *file;
 
                if (FcPatternGetString (fs->fonts[j], FC_FILE, 0, &file) != FcResultMatch)
-                   file = "<unknown filename>";
+                   file = (FcChar8 *) "<unknown filename>";
                else
                {
-                   FcChar8 *slash = strrchr (file, '/');
+                   FcChar8 *slash = (FcChar8 *) strrchr ((char *) file, '/');
                    if (slash)
                        file = slash+1;
                }
                if (FcPatternGetString (fs->fonts[j], FC_FAMILY, 0, &family) != FcResultMatch)
-                   family = "<unknown family>";
+                   family = (FcChar8 *) "<unknown family>";
                if (FcPatternGetString (fs->fonts[j], FC_STYLE, 0, &style) != FcResultMatch)
-                   file = "<unknown style>";
+                   file = (FcChar8 *) "<unknown style>";
 
                printf ("%s: \"%s\" \"%s\"\n", file, family, style);
            }
        }
        FcFontSetDestroy (fs);
     }
+    FcFini ();
     return 0;
 }