Description: Completely implement the switch to font selection
 based on fontconfig patterns instead of file names.
Author: Fabian Greffrath <fabian+debian@greffrath.com>

--- cups-filters-1.0.4.orig/filter/pdf.utf-8.heavy
+++ cups-filters-1.0.4/filter/pdf.utf-8.heavy
@@ -28,13 +28,13 @@ charset utf8
 # printing.
 #
 
-0000 00FF ltor single COUR.TTF COURBD.TTF COURI.TTF COURBI.TTF
-0100 02FF ltor single DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf DejaVuSansMono-Oblique.ttf DejaVuSansMono-BoldOblique.ttf
-0300 03FF ltor single DejaVuSansMono.ttf
-0400 04FF ltor single DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf DejaVuSansMono-Oblique.ttf DejaVuSansMono-BoldOblique.ttf
-0500 05FF rtol single FreeMono.ttf
-1E00 1EFF ltor single COUR.TTF COURBD.TTF COURI.TTF COURBI.TTF
-2000 21FF ltor single DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf DejaVuSansMono-Oblique.ttf DejaVuSansMono-BoldOblique.ttf
-2200 23FF ltor single SYMBOL.TTF
-3000 9FFF ltor double uming.ttc/0
-#0400 04FF ltor single FreeMono.ttf FreeMonoBold.ttf FreeMonoOblique.ttf FreeMonoBoldOblique.ttf
+0000 00FF ltor single CourierNew CourierNew:bold CourierNew:italic CourierNew:bold:italic
+0100 02FF ltor single DejaVuSansMono DejaVuSansMono:bold DejaVuSansMono:oblique DejaVuSansMono:bold:oblique
+0300 03FF ltor single DejaVuSansMono
+0400 04FF ltor single DejaVuSansMono DejaVuSansMono:bold DejaVuSansMono:oblique DejaVuSansMono:bold:oblique
+0500 05FF rtol single FreeMono
+1E00 1EFF ltor single CourierNew CourierNew:bold CourierNew:italic CourierNew:bold:italic
+2000 21FF ltor single DejaVuSansMono DejaVuSansMono:bold DejaVuSansMono:oblique DejaVuSansMono:bold:oblique
+2200 23FF ltor single Symbol
+3000 9FFF ltor double ARPLUMingCN
+#0400 04FF ltor single FreeMono FreeMono:bold FreeMono:oblique FreeMono:bold:oblique
--- cups-filters-1.0.4.orig/filter/pdf.utf-8.simple
+++ cups-filters-1.0.4/filter/pdf.utf-8.simple
@@ -28,5 +28,5 @@ charset utf8
 # printing.
 #
 
-0000 04FF ltor single FreeMono.ttf FreeMonoBold.ttf FreeMonoOblique.ttf FreeMonoBoldOblique.ttf
-0500 05FF rtol single FreeMono.ttf
+0000 04FF ltor single FreeMono FreeMono:bold FreeMono:oblique FreeMono:bold:oblique
+0500 05FF rtol single FreeMono
--- cups-filters-1.0.4.orig/filter/texttopdf.c
+++ cups-filters-1.0.4/filter/texttopdf.c
@@ -33,7 +33,6 @@
 #include <assert.h>
 #include "fontembed/sfnt.h"
 #include <fontconfig/fontconfig.h>
-#include <string.h>
 
 /*
  * Globals...
@@ -43,51 +42,40 @@
 int     UTF8 = 1;               /* Use UTF-8 encoding? */
 #endif /* CUPS_1_4 */
 
-EMB_PARAMS *font_load(const char *datadir,const char *font);
+EMB_PARAMS *font_load(const char *font);
 
-EMB_PARAMS *font_load(const char *datadir,const char *font)
+EMB_PARAMS *font_load(const char *font)
 {
-  char		filename[1024];	/* Glyph filenames */
-  snprintf(filename, sizeof(filename), "%s/fonts/%s", datadir, font);
-
-  OTF_FILE *otf=otf_load(filename);
-
-  if (!otf) {
+  OTF_FILE *otf;
 
-    FcPattern *pattern;
-    FcFontSet *candidates;
-    FcChar8   *fontformat, *fontname = NULL;
-    int i, spacing;
-
-    /* Remove extension from the passed file name
-       to turn it into a minimal "pattern" in the fontconfig sense */
-    if (strrchr(filename, '.'))
-       *strrchr(filename, '.') = '\0';
-
-    FcInit ();
-    pattern = FcNameParse (filename);
-    FcConfigSubstitute (0, pattern, FcMatchPattern);
-    FcDefaultSubstitute (pattern);
-
-    /* Receive a sorted list of fonts matching our pattern */
-    candidates = FcFontSort (0, pattern, FcTrue, 0, 0);
-    FcPatternDestroy (pattern);
-
-    /* In the list of fonts returned by FcFontSort()
-       find the first one that is both in TrueType format and monospaced */
-    for (i = 0; i < candidates->nfont; i++) {
-      FcPatternGetString  (candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat);
-      FcPatternGetInteger (candidates->fonts[i], FC_SPACING,    0, &spacing);
-
-      if ((strcmp(fontformat, "TrueType") == 0) && (spacing == FC_MONO)) {
-        fontname = FcPatternFormat (candidates->fonts[i], "%{file|cescape}");
-        break;
-      }
+  FcPattern *pattern;
+  FcFontSet *candidates;
+  FcChar8   *fontformat, *fontname = NULL;
+  int i, spacing;
+
+  FcInit ();
+  pattern = FcNameParse (font);
+  FcConfigSubstitute (0, pattern, FcMatchPattern);
+  FcDefaultSubstitute (pattern);
+
+  /* Receive a sorted list of fonts matching our pattern */
+  candidates = FcFontSort (0, pattern, FcTrue, 0, 0);
+  FcPatternDestroy (pattern);
+
+  /* In the list of fonts returned by FcFontSort()
+     find the first one that is both in TrueType format and monospaced */
+  for (i = 0; i < candidates->nfont; i++) {
+    FcPatternGetString  (candidates->fonts[i], FC_FONTFORMAT, 0, &fontformat);
+    FcPatternGetInteger (candidates->fonts[i], FC_SPACING,    0, &spacing);
+
+    if ((strcmp(fontformat, "TrueType") == 0) && (spacing == FC_MONO)) {
+      fontname = FcPatternFormat (candidates->fonts[i], "%{file|cescape}/%{index}");
+      break;
     }
-    FcFontSetDestroy (candidates);
-
-    otf = otf_load(fontname);
   }
+  FcFontSetDestroy (candidates);
+
+  otf = otf_load(fontname);
 
   if (!otf) {
     // TODO: try /usr/share/fonts/*/*/%s.ttf
@@ -560,7 +548,7 @@ WriteProlog(const char *title,		/* I - T
               }
 
             if (k==num_fonts) {  // not found
-	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(datadir,valptr);
+	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(valptr);
               if (!fonts[num_fonts]) { // font missing/corrupt, replace by first
                 fprintf(stderr,"WARNING: Ignored bad font \"%s\"\n",valptr);
                 break;
@@ -744,7 +732,7 @@ WriteProlog(const char *title,		/* I - T
               }
 
             if (k==num_fonts) {  // not found
-	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(datadir,valptr);
+	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(valptr);
               if (!fonts[num_fonts]) { // font missing/corrupt, replace by first
                 fprintf(stderr,"WARNING: Ignored bad font \"%s\"\n",valptr);
                 break;
