Am 07.03.2012 16:28, schrieb Fabian Greffrath:
It is, I have attached two more patches.

Description: Do not even attempt to directly load font files from $datadir/fonts/ anymore.
 Query fontconfig instead to return a valid font based on the *fontconfig patterns* in pdf.utf-8.*.
Author: Fabian Greffrath <[email protected]>

--- cups-filters-1.0.4.orig/filter/texttopdf.c
+++ cups-filters-1.0.4/filter/texttopdf.c
@@ -43,29 +43,19 @@
 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, index, 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);
+    pattern = FcNameParse (font);
     FcConfigSubstitute (0, pattern, FcMatchPattern);
     FcDefaultSubstitute (pattern);
 
@@ -88,7 +78,6 @@ EMB_PARAMS *font_load(const char *datadi
     FcFontSetDestroy (candidates);
 
     otf = otf_load(fontname);
-  }
 
   if (!otf) {
     // TODO: try /usr/share/fonts/*/*/%s.ttf
@@ -561,7 +550,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;
@@ -745,7 +734,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;
Description: Always append the index of the font within the font file to the font file name.
 It is ignored (and always "0" anyway) by otf_load() for .ttf files but crucial for .ttc files.
Author: Fabian Greffrath <[email protected]>

--- cups-filters-1.0.4.orig/filter/texttopdf.c
+++ cups-filters-1.0.4/filter/texttopdf.c
@@ -57,7 +57,7 @@ EMB_PARAMS *font_load(const char *datadi
     FcPattern *pattern;
     FcFontSet *candidates;
     FcChar8   *fontformat, *fontname = NULL;
-    int i, spacing;
+    int i, index, spacing;
 
     /* Remove extension from the passed file name
        to turn it into a minimal "pattern" in the fontconfig sense */
@@ -77,10 +77,11 @@ EMB_PARAMS *font_load(const char *datadi
        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_INDEX,      0, &index);
       FcPatternGetInteger (candidates->fonts[i], FC_SPACING,    0, &spacing);
 
       if ((strcmp(fontformat, "TrueType") == 0) && (spacing == FC_MONO)) {
-        fontname = FcPatternFormat (candidates->fonts[i], "%{file|cescape}");
+        fontname = FcPatternFormat (candidates->fonts[i], "%{file|cescape}/%{index}");
         break;
       }
     }

Reply via email to