X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fdevices%2Fpdf.c;h=16bb6cf7cebf8b0499e13edf4d90d951e5c7349c;hp=5ab55fa2975ed4bd2e7b1a34c6bdddfa7108fdad;hb=8589e0d1f5e47c05458033e750fd6182ca704fbe;hpb=b27d77f8a6343e60e2d3ae2c22a8096a6357a927 diff --git a/lib/devices/pdf.c b/lib/devices/pdf.c index 5ab55fa..16bb6cf 100644 --- a/lib/devices/pdf.c +++ b/lib/devices/pdf.c @@ -59,19 +59,25 @@ typedef struct _internal { double m00, m01, m10, m11; } internal_t; -static void set_matrix(internal_t*i, double m00, double m01, double m10, double m11) +static void restore_matrix(internal_t*i) { if(i->has_matrix) { PDF_restore(i->p); + i->has_matrix=0; } +} +static void set_matrix(internal_t*i, double m00, double m01, double m10, double m11) +{ + restore_matrix(i); + i->m00 = m00; i->m01 = m01; i->m10 = m10; i->m11 = m11; - i->has_matrix = 1; PDF_save(i->p); - PDF_setmatrix(i->p, m00, -m01, m10, -m11, 0, i->height); + PDF_setmatrix(i->p, m00, -m01, m10, -m11, 0, i->height+2*i->config_ypad); + i->has_matrix = 1; } static void reset_matrix(internal_t*i) { @@ -94,7 +100,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); @@ -184,17 +190,21 @@ static int mkline(gfxline_t*line, PDF*p, double mx, double my, double scale, cha void pdf_startclip(gfxdevice_t*dev, gfxline_t*line) { internal_t*i = (internal_t*)dev->internal; - reset_matrix(i); + + restore_matrix(i); PDF_save(i->p); + if(mkline(line, i->p, i->config_xpad, i->config_ypad, 1.0, 1)) PDF_clip(i->p); else ; // TODO: strictly speaking, an empty clip clears everything - + + reset_matrix(i); } void pdf_endclip(gfxdevice_t*dev) { internal_t*i = (internal_t*)dev->internal; + restore_matrix(i); PDF_restore(i->p); } void pdf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit) @@ -271,14 +281,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); @@ -325,13 +335,14 @@ void pdf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, g internal_t*i = (internal_t*)dev->internal; } -static const char type3 = 1; -static const char ttf = 0; +static const char type3 = 0; +static const char ttf = 1; void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font) { internal_t*i = (internal_t*)dev->internal; + int num = font->num_glyphs<256-32?font->num_glyphs:256-32; if(type3) { int fontid = 0; if(!gfxfontlist_hasfont(i->fontlist, font)) { @@ -348,7 +359,6 @@ void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font) } PDF_begin_font(i->p, fontname2, l*2, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, ""); - int num = font->num_glyphs<256-32?font->num_glyphs:256-32; for(t=0;tglyphs[t]; gfxbbox_t bbox = gfxline_getbbox(g->line); @@ -375,18 +385,35 @@ void pdf_addfont(gfxdevice_t*dev, gfxfont_t*font) fontnr++; const char*old_id = font->id; font->id = fontname; + int t; + for(t=0;tglyphs[t].unicode = 32+t; + } + font->max_unicode = 0; + 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]; + sprintf(cmd, "mv %s.ttf test.ttf", fontname);system(cmd); + system("rm -f test.ttx"); + if(system("ttx test.ttf")&0xff00) exit(1); + sprintf(cmd, "mv test.ttf %s.old.ttf", fontname, fontname);system(cmd); + sprintf(cmd, "ttx test.ttx;mv test.ttf %s.ttf", fontname);system(cmd); + sprintf(cmd, "rm -f test.ttx");system(cmd); +#endif - int l = strlen(font->id); - int t; + int l = strlen(fontname); for(t=0;tp, fontname2, l*2, "host", ""); + + fontid = PDF_load_font(i->p, fontname2, l*2, "host", "embedding=true"); i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid); - unlink(fontname); + unlink(filename); } } } @@ -417,10 +444,15 @@ void pdf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color int fontid = (int)(ptroff_t)gfxfontlist_getuserdata(i->fontlist, font->id); gfxmatrix_t m = *matrix; + m.m00*=64; m.m01*=64; m.m10*=64; m.m11*=64; + if(ttf) { + m.m10 = -m.m10; + m.m11 = -m.m11; + } if(!(fabs(m.m00 - i->m00) < 1e-6 && fabs(m.m01 - i->m01) < 1e-6 && @@ -431,8 +463,7 @@ void pdf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color double tx, ty; transform_back(i, m.tx+i->config_xpad, m.ty+i->config_ypad, &tx, &ty); - //PDF_setfont(i->p, fontid, 1.0/64.0); // downscaling is done in glyph itself - PDF_setfont(i->p, fontid, 1.0); + PDF_setfont(i->p, fontid, ttf?16.0:1.0); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); char name[32]; @@ -457,9 +488,7 @@ void pdf_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action) void pdf_endpage(gfxdevice_t*dev) { internal_t*i = (internal_t*)dev->internal; - if(i->has_matrix) { - PDF_restore(i->p); i->has_matrix = 0; - } + restore_matrix(i); PDF_end_page(i->p); } @@ -562,4 +591,3 @@ void gfxdevice_pdf_init(gfxdevice_t*dev) i->has_matrix = 0; i->p = PDF_new(); } -