]> 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 3ddba74c42ab0a7bd2b41488428e580be9da4708..bf9817b8064d83bcdbc4075a7a1896350f6e79ef 100644 (file)
  * 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'},
@@ -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)
     {
@@ -184,5 +203,6 @@ main (int argc, char **argv)
        }
        FcFontSetDestroy (fs);
     }
+    FcFini ();
     return 0;
 }