fixed bug in pdf2pdf
[swftools.git] / lib / devices / pdf.c
index b96cda3..c1484bb 100644 (file)
@@ -64,6 +64,10 @@ static void restore_matrix(internal_t*i)
     if(i->has_matrix) {
        PDF_restore(i->p);
        i->has_matrix=0;
+       i->m00 = 0;
+       i->m01 = 0;
+       i->m10 = 0;
+       i->m11 = 0;
     }
 }
 static void set_matrix(internal_t*i, double m00, double m01, double m10, double m11)
@@ -100,7 +104,7 @@ void pdf_startpage(gfxdevice_t*dev, int width, int height)
     internal_t*i = (internal_t*)dev->internal;
 
     if(!i->tempfile) {
-       i->tempfile = strdup(mktempname(0));
+       i->tempfile = strdup(mktempname(0, "pdf"));
 
        PDF_begin_document(i->p, i->tempfile, 0, "");
        //PDF_set_value(i->p, "compress", 0);
@@ -281,14 +285,14 @@ void pdf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t
     }
 
     char tempfile[128];
-    mktempname(tempfile);
+    mktempname(tempfile, "jpg");
 
     gfximage_save_jpeg(img, tempfile, 96);
 
     int imgid=-1;
     if(has_alpha) {
        char tempfile2[128];
-       mktempname(tempfile2);
+       mktempname(tempfile2, "jpg");
        int t;
        int size = img->width*img->height;
        unsigned char*alpha = malloc(size);
@@ -393,7 +397,7 @@ void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font)
            font->unicode2glyph = 0;
            gfxfont_save(font, filename);
            font->id=old_id;
-         
+           
 #ifdef RUN_TTX
            /* for testing the generated fonts: run everything through ttx (fonttools) */
            char cmd[256];
@@ -405,13 +409,15 @@ void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font)
            sprintf(cmd, "rm -f test.ttx");system(cmd);
 #endif
           
-           int l = strlen(font->id);
+           int l = strlen(fontname);
            for(t=0;t<l+1;t++) {
                fontname2[t*2+0] = fontname[t];
                fontname2[t*2+1] = 0;
            }
+           
            fontid = PDF_load_font(i->p, fontname2, l*2, "host", "embedding=true");
            i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid);
+           unlink(filename);
        }
     }
 }