X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=sidebyside;f=pdf2swf%2FSWFOutputDev.cc;h=4ee30d7a2a1df4e1f65b487e9a4b321b7ace2f17;hb=6fa3168316941d0cfd703d598e4f33257cd87a38;hp=b0fd6cb39341f2c686130a966c9daee195f96a72;hpb=242870f51bcada26c934f5229f1d7aac9117eee5;p=swftools.git diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index b0fd6cb..4ee30d7 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -144,7 +144,6 @@ typedef struct _fontlist } fontlist_t; class SWFOutputDev: public OutputDev { - int outputstarted; public: gfxdevice_t* output; @@ -158,7 +157,13 @@ public: void setClip(int x1,int y1,int x2,int y2); int save(char*filename); - void pagefeed(); + + // Start a page. + void startFrame(int width, int height); + + virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ; + + void endframe(); void* getSWF(); void getDimensions(int*x1,int*y1,int*x2,int*y2); @@ -181,9 +186,6 @@ public: void setXRef(PDFDoc*doc, XRef *xref); - // Start a page. - virtual void startPage(int pageNum, GfxState *state, double x1, double y1, double x2, double y2) ; - //----- link borders virtual void drawLink(Link *link, Catalog *catalog) ; @@ -367,7 +369,6 @@ SWFOutputDev::SWFOutputDev() pbminfo = 0; type3active = 0; statepos = 0; - outputstarted = 0; xref = 0; substitutepos = 0; type3Warning = 0; @@ -383,7 +384,13 @@ SWFOutputDev::SWFOutputDev() result = 0; outer_clip_box = 0; output = (gfxdevice_t*)malloc(sizeof(gfxdevice_t)); - memset(output, 0, sizeof(output)); + gfxdevice_swf_init(output); + /* configure device */ + parameter_t*p = device_config; + while(p) { + output->setparameter(output, p->name, p->value); + p = p->next; + } }; void SWFOutputDev::setMove(int x,int y) @@ -789,6 +796,7 @@ void SWFOutputDev::strokeGfxline(GfxState *state, gfxline_t*line) line2 = gfxtool_dash_line(line, dash, dashphase); line = line2; + free(dash); msg(" After dashing:"); } @@ -892,31 +900,22 @@ void SWFOutputDev::eoClip(GfxState *state) gfxline_free(line); } -/* pass through functions for swf_output */ -int SWFOutputDev::save(char*filename) -{ - finish(); - return result->save(result, filename); -} -void SWFOutputDev::pagefeed() +void SWFOutputDev::endframe() { if(outer_clip_box) { output->endclip(output); outer_clip_box = 0; } - swfoutput_pagefeed(output); -} -void* SWFOutputDev::getSWF() -{ - finish(); - return result->get(result, "swf"); + output->endpage(output); } void SWFOutputDev::finish() { if(outer_clip_box) { - output->endclip(output); + if(output) { + output->endclip(output); + } outer_clip_box = 0; } if(output) { @@ -925,10 +924,20 @@ void SWFOutputDev::finish() } } +int SWFOutputDev::save(char*filename) +{ + finish(); + return result->save(result, filename); +} +void* SWFOutputDev::getSWF() +{ + finish(); + return result->get(result, "swf"); +} + SWFOutputDev::~SWFOutputDev() { finish(); - outputstarted = 0; if(this->result) { this->result->destroy(this->result); @@ -945,10 +954,10 @@ SWFOutputDev::~SWFOutputDev() free(l); l = next; } + this->fontlist = 0; }; GBool SWFOutputDev::upsideDown() { - msg(" upsidedown? yes"); return gTrue; }; GBool SWFOutputDev::useDrawChar() @@ -1233,6 +1242,11 @@ void SWFOutputDev::endType3Char(GfxState *state) msg(" endType3Char"); } +void SWFOutputDev::startFrame(int width, int height) +{ + output->startpage(output, width, height); +} + void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) { this->currentpage = pageNum; @@ -1244,10 +1258,6 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl white.r = white.g = white.b = white.a = 255; - msg(" startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2); - if(rot!=0) - msg(" page is rotated %d degrees\n", rot); - /* state->transform(state->getX1(),state->getY1(),&x1,&y1); state->transform(state->getX2(),state->getY2(),&x2,&y2); Use CropBox, not MediaBox, as page size @@ -1257,12 +1267,13 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl y1 = crop_y1; x2 = crop_x2; y2 = crop_y2;*/ - state->transform(crop_x1,crop_y1,&x1,&y1); - state->transform(crop_x2,crop_y2,&x2,&y2); + state->transform(crop_x1,crop_y1,&x1,&y1); //x1 += user_movex; y1 += user_movey; + state->transform(crop_x2,crop_y2,&x2,&y2); //x2 += user_movex; y2 += user_movey; if(x2 x1)*/ x1 = user_clipx1; @@ -1271,29 +1282,16 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl /*if(user_clipy2 < y2)*/ y2 = user_clipy2; } - if(!outputstarted) { - msg(" Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2); - - gfxdevice_swf_init(output); - - /* configure device */ - parameter_t*p = device_config; - while(p) { - output->setparameter(output, p->name, p->value); - p = p->next; - } - - outputstarted = 1; - } - + //msg(" Bounding box is (%f,%f)-(%f,%f) [shifted by %d/%d]", x1,y1,x2,y2, user_movex, user_movey); + if(outer_clip_box) { output->endclip(output); outer_clip_box = 0; } - msg(" processing page %d (%dx%d:%d:%d)", pageNum, (int)x2-(int)x1,(int)y2-(int)y1, (int)x1, (int)y1); - - swfoutput_newpage(output, (int)x1, (int)y1, (int)x2, (int)y2); + msg(" processing PDF page %d (%dx%d:%d:%d) (move:%d:%d)", pageNum, (int)x2-(int)x1,(int)y2-(int)y1, (int)x1, (int)y1, user_movex, user_movey); + if(rot!=0) + msg(" page is rotated %d degrees\n", rot); clippath[0].type = gfx_moveTo;clippath[0].x = x1; clippath[0].y = y1; clippath[0].next = &clippath[1]; clippath[1].type = gfx_lineTo;clippath[1].x = x2; clippath[1].y = y1; clippath[1].next = &clippath[2]; @@ -1950,6 +1948,7 @@ void SWFOutputDev::updateFont(GfxState *state) char * fontname = getFontName(gfxFont); fileName = searchFont(fontname); if(!fileName) showFontError(gfxFont,0); + free(fontname); } if(!fileName) { char * fontname = getFontName(gfxFont); @@ -2591,7 +2590,7 @@ pdf_doc_t* pdf_init(char*filename, char*userPassword) return pdf_doc; } -void pdfswf_preparepage(int page) +static void pdfswf_preparepage(int page) { /*FIXME*/ if(!pages) { @@ -2621,7 +2620,6 @@ void pdf_destroy(pdf_doc_t*pdf_doc) { pdf_doc_internal_t*i= (pdf_doc_internal_t*)pdf_doc->internal; - msg(" pdfswf.cc: pdfswf_close()"); delete i->doc; i->doc=0; free(pages); pages = 0; //FIXME @@ -2666,16 +2664,22 @@ swf_output_t* swf_output_init() return swf_output; } -void swf_output_setparameter(swf_output_t*swf_output, char*name, char*value) +void swf_output_setparameter(swf_output_t*swf, char*name, char*value) { - /* FIXME */ pdfswf_setparameter(name, value); } -void swf_output_pagefeed(swf_output_t*swf) +void swf_output_startframe(swf_output_t*swf, int width, int height) +{ + swf_output_internal_t*i= (swf_output_internal_t*)swf->internal; + i->outputDev->startFrame(width, height); + i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2); +} + +void swf_output_endframe(swf_output_t*swf) { swf_output_internal_t*i= (swf_output_internal_t*)swf->internal; - i->outputDev->pagefeed(); + i->outputDev->endframe(); i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2); }