[Pkg-cups-devel] r829 - in cupsys/trunk/debian: . local/filters/pdf-filters/filter local/filters/pdf-filters/filter/fontembed

Till Kamppeter till-guest at alioth.debian.org
Sun Aug 17 16:30:17 UTC 2008


Author: till-guest
Date: Sun Aug 17 16:30:16 2008
New Revision: 829

Log:
Fixed segfaults of texttopdf when fonts are bad or missing


Modified:
   cupsys/trunk/debian/changelog
   cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c
   cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h
   cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed_sfnt.c
   cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c

Modified: cupsys/trunk/debian/changelog
==============================================================================
--- cupsys/trunk/debian/changelog	(original)
+++ cupsys/trunk/debian/changelog	Sun Aug 17 16:30:16 2008
@@ -1,3 +1,14 @@
+cups (1.3.8-6) UNRELEASED; urgency=low
+
+  [ Till Kamppeter ]
+  * debian/local/filters/pdf-filters/filter/texttopdf.c,
+    debian/local/filters/pdf-filters/filter/fontembed/embed.h,
+    debian/local/filters/pdf-filters/filter/fontembed/embed_sfnt.c,
+    debian/local/filters/pdf-filters/filter/fontembed/embed.c:
+    Fixed crashes of texttopdf on bad or missing fonts.
+
+ -- Till Kamppeter <tkamppeter at gmail.com>  Sun, 17 Aug 2008 18:11:36 +0200
+
 cups (1.3.8-5) experimental; urgency=low
 
   [ Till Kamppeter ]

Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c	(original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.c	Sun Aug 17 16:30:16 2008
@@ -13,6 +13,7 @@
 const char *emb_otf_get_fontname(OTF_FILE *otf);
 EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_widths(OTF_FILE *otf,const unsigned short *encoding,int len,const BITSET glyphs);
 EMB_PDF_FONTWIDTHS *emb_otf_get_pdf_cidwidths(OTF_FILE *otf,const BITSET glyph);
+int emb_otf_ps(OTF_FILE *otf,unsigned short *encoding,int len,unsigned short *to_unicode,OUTPUT_FN output,void *context);
 
 void emb_otf_get_pdf_fontdescr(OTF_FILE *otf,EMB_PDF_FONTDESCR *ret);
 
@@ -146,6 +147,23 @@
 {
   assert(emb);
 
+  if (emb->outtype==EMB_DEST_PS) {
+    int ret=0;
+    const char *fontname=emb_otf_get_fontname(emb->font->sfnt); // TODO!!
+    (*output)("%%BeginFont: ",13,context);
+    (*output)(fontname,strlen(fontname),context);
+    (*output)("\n",1,context);
+    if (emb->intype==EMB_INPUT_TTF) {
+      // do Type42
+      ret=emb_otf_ps(emb->font->sfnt,NULL,4,NULL,output,context); // TODO?
+    } else {
+      assert(0);
+      ret=-1;
+    }
+    (*output)("%%EndFont\n",10,context);
+    return ret;
+  }
+
   if (emb->intype==EMB_INPUT_TTF) {
     assert(emb->font->sfnt);
     if (emb->plan&EMB_A_SUBSET) {

Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h	(original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed.h	Sun Aug 17 16:30:16 2008
@@ -14,8 +14,8 @@
                EMB_OUTPUT_SFNT   // OpenType (cff or glyf)
                } EMB_OUTPUT_FORMAT;
 typedef enum { EMB_DEST_NATIVE,  // just subsetting/conversion
-//  TODO       EMB_DEST_PS, 
-               EMB_DEST_PDF16
+               EMB_DEST_PS, 
+               EMB_DEST_PDF16  // TODO? PDF13
                } EMB_DESTINATION;
 
 typedef enum { EMB_RIGHT_FULL=0, EMB_RIGHT_NONE=0x02,

Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed_sfnt.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed_sfnt.c	(original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/fontembed/embed_sfnt.c	Sun Aug 17 16:30:16 2008
@@ -378,13 +378,18 @@
 // NOTE: statically allocated string
 const char *get_glyphname(const char *post,unsigned short *to_unicode,unsigned short gid)
 {
+  if (gid==0) {
+    return ".notdef";
+  }
   /*
   ... TODO: consult post table, if there.
   ... otherwise consult fallback table
   ... otherwise generate "uni...".
   ... otherwise unique name c01...
   */
-  return "";
+  static char ret[255];
+  snprintf(ret,250,"c%d",gid);
+  return ret;
 }
 
 struct OUTFILTER_PS {
@@ -399,7 +404,7 @@
   OUTPUT_FN out=of->out;
   int iA;
 
-  if (len*2+of->len > 64000) {
+  if ((of->len/64000)!=(len*2+of->len)/64000) {
     (*out)("00>\n",4,of->ctx);
     (*out)("<",1,of->ctx);
     of->len+=5;
@@ -407,11 +412,12 @@
   char tmp[256];
   while (len>0) {
     for (iA=0;(iA<40)&&(len>0);iA++,len--) {
-      sprintf(tmp+2*iA,"%02x",buf[iA]);
+      sprintf(tmp+2*iA,"%02x",(unsigned char)buf[iA]);
     }
-    tmp[iA]='\n';
+    tmp[2*iA]='\n';
     (*out)(tmp,iA*2+1,of->ctx);
     of->len+=iA*2+1;
+    buf+=iA;
   }
 }
 // }}}
@@ -423,6 +429,7 @@
 
   char tmp[100];
   const int l=sprintf(tmp,"%d RD ",len);
+
   (*out)(tmp,l,of->ctx);
   of->len+=l;
 
@@ -508,9 +515,11 @@
   }
   if (binary) {
     dyn_printf(&ds,"/RD { string currentfile exch readstring pop } executeonly def\n");
+    dyn_printf(&ds,"/sfnts[");
+  } else {
+    dyn_printf(&ds,"/sfnts[<");
   }
 
-  dyn_printf(&ds,"/sfnts[");
   if (ds.len<0) {
     free(post);
     free(ds.buf);
@@ -554,17 +563,22 @@
   }
   ret+=of.len;
 
-  dyn_printf(&ds,"] def\n");
+  if (binary) {
+    dyn_printf(&ds,"] def\n");
+  } else {
+    dyn_printf(&ds,">] def\n");
+  }
   // }}} done copying
 
-  const int num_chars=0;
+  const int num_chars=1;
   dyn_printf(&ds,"/CharStrings %d dict dup begin\n",num_chars);
   for (iA=0;iA<num_chars;iA++) {
     const int gid=(encoding)?encoding[iA]:iA;
     dyn_printf(&ds,"/%s %d def\n",get_glyphname(post,to_unicode,gid),gid);
 // ... from cmap [respecting subsetting...]
   }
-  dyn_printf(&ds,"Fontname currentdict end definefont pop\n");
+  dyn_printf(&ds,"end readonly def\n");
+  dyn_printf(&ds,"FontName currentdict end definefont pop\n");
   free(post);
 
   if (ds.len<0) {

Modified: cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c
==============================================================================
--- cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c	(original)
+++ cupsys/trunk/debian/local/filters/pdf-filters/filter/texttopdf.c	Sun Aug 17 16:30:16 2008
@@ -524,6 +524,7 @@
             if (k==num_fonts) {  // not found
 	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(datadir,valptr);
               if (!fonts[num_fonts]) { // font missing/corrupt, replace by first
+                fprintf(stderr,"WARNING: Ignored bad font \"%s\"\n",valptr);
                 break;
               }
               fontnames[num_fonts++] = strdup(valptr);
@@ -706,11 +707,20 @@
 
             if (k==num_fonts) {  // not found
 	      fonts[num_fonts] = Fonts[NumFonts][i] = font_load(datadir,valptr);
+              if (!fonts[num_fonts]) { // font missing/corrupt, replace by first
+                fprintf(stderr,"WARNING: Ignored bad font \"%s\"\n",valptr);
+                break;
+              }
               fontnames[num_fonts++] = strdup(valptr);
             }
           }
 	}
 
+        /* ignore complete range, when the first font is not available */
+        if (i==0) {
+          continue;
+        }
+
        /*
 	* Fill in remaining fonts as needed...
 	*/
@@ -755,9 +765,18 @@
     NumFonts = 1;
 
     Fonts[0][ATTR_NORMAL]     = font_load(datadir,"Courier");
+    if (!Fonts[0][ATTR_NORMAL]) {
+      fprintf(stderr, _("ERROR: No usable font available\n"));
+      exit(1);
+    }
     Fonts[0][ATTR_BOLD]       = font_load(datadir,"Courier-Bold");
     Fonts[0][ATTR_ITALIC]     = font_load(datadir,"Courier-Oblique");
     Fonts[0][ATTR_BOLDITALIC] = font_load(datadir,"Courier-BoldOblique");
+    for (j = 1; j < 4; j ++) {
+      if (!Fonts[0][j]) {
+        Fonts[0][j]=Fonts[0][0];
+      }
+    }
 
     Widths[0]     = 1;
     Directions[0] = 1;
@@ -774,6 +793,11 @@
   }
   // }}}
 
+  if (NumFonts==0) {
+    fprintf(stderr, _("ERROR: No usable font available\n"));
+    exit(1);
+  }
+
   FontScaleX=120.0 / CharsPerInch;
   FontScaleY=68.0 / LinesPerInch;
 



More information about the Pkg-cups-devel mailing list