X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=pdf2swf%2Fswfoutput.cc;h=dcba00745b75a6585a89bd02c68f1de42362c082;hb=79bc71eef9020ca26a9b427073d92e184f407e2a;hp=b0c5f16a217f86c9351818c1af753dd5196091c7;hpb=c61f68266148205e5ba6f0c6550408e619566c5c;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index b0c5f16..dcba007 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -75,8 +75,9 @@ typedef struct _swfoutput_internal fontlist_t* fontlist; char storefont; - - SWF swf; + + MATRIX page_matrix; + TAG *tag; int currentswfid; int depth; @@ -1155,7 +1156,11 @@ static void endtext(swfoutput*obj) putcharacters(obj, i->tag); swf_SetU8(i->tag,0); i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); - swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&obj->fontmatrix,NULL,NULL); + //swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL); + MATRIX m2; + swf_MatrixJoin(&m2,&obj->fontmatrix, &i->page_matrix); + + swf_ObjectPlace(i->tag,i->textid,/*depth*/i->depth++,&m2,NULL,NULL); i->textid = -1; } @@ -1290,7 +1295,7 @@ void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename) swf_FontSetID(swffont, ++i->currentswfid); - if(screenloglevel >= LOGLEVEL_DEBUG) { + if(getScreenLogLevel() >= LOGLEVEL_DEBUG) { // print font information msg(" Font %s (%s)",swffont->name, filename); msg(" | ID: %d", swffont->id); @@ -1403,12 +1408,16 @@ static void endpage(struct swfoutput*obj) i->tag = swf_InsertTag(i->tag,ST_SHOWFRAME); } -void swfoutput_newpage(struct swfoutput*obj, int pageNum, int x1, int y1, int x2, int y2) +void swfoutput_newpage(struct swfoutput*obj, int pageNum, int movex, int movey, int x1, int y1, int x2, int y2) { swfoutput_internal*i = (swfoutput_internal*)obj->internal; if(!i->firstpage) endpage(obj); + swf_GetMatrix(0, &i->page_matrix); + i->page_matrix.tx = movex*20; + i->page_matrix.ty = movey*20; + for(i->depth--;i->depth>=i->startdepth;i->depth--) { i->tag = swf_InsertTag(i->tag,ST_REMOVEOBJECT2); swf_SetU16(i->tag,i->depth); @@ -1469,7 +1478,7 @@ void swfoutput_newpage(struct swfoutput*obj, int pageNum, int x1, int y1, int x2 i->lastpagesize.xmax = x2; i->lastpagesize.ymin = y1; i->lastpagesize.ymax = y2; - swf_ExpandRect2(&i->swf.movieSize, &i->lastpagesize); + swf_ExpandRect2(&obj->swf.movieSize, &i->lastpagesize); i->firstpage = 0; } @@ -1490,18 +1499,18 @@ void swfoutput_init(struct swfoutput* obj) obj->swffont = 0; obj->drawmode = -1; - memset(&i->swf,0x00,sizeof(SWF)); + memset(&obj->swf,0x00,sizeof(SWF)); memset(&i->lastpagesize,0x00,sizeof(SRECT)); - i->swf.fileVersion = config_flashversion; - i->swf.frameRate = 0x0040; // 1 frame per 4 seconds - i->swf.movieSize.xmin = 0; - i->swf.movieSize.ymin = 0; - i->swf.movieSize.xmax = 0; - i->swf.movieSize.ymax = 0; + obj->swf.fileVersion = config_flashversion; + obj->swf.frameRate = 0x0040; // 1 frame per 4 seconds + obj->swf.movieSize.xmin = 0; + obj->swf.movieSize.ymin = 0; + obj->swf.movieSize.xmax = 0; + obj->swf.movieSize.ymax = 0; - i->swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - i->tag = i->swf.firstTag; + obj->swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + i->tag = obj->swf.firstTag; rgb.a = rgb.r = rgb.g = rgb.b = 0xff; swf_SetRGB(i->tag,&rgb); @@ -1675,10 +1684,11 @@ static void endshape(swfoutput*obj, int clipdepth) changeRect(obj, i->tag, i->bboxrectpos, &i->bboxrect); i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); + if(clipdepth) - swf_ObjectPlaceClip(i->tag,i->shapeid,i->depth++,NULL,NULL,NULL,clipdepth); + swf_ObjectPlaceClip(i->tag,i->shapeid,i->depth++,&i->page_matrix,NULL,NULL,clipdepth); else - swf_ObjectPlace(i->tag,i->shapeid,/*depth*/i->depth++,NULL,NULL,NULL); + swf_ObjectPlace(i->tag,i->shapeid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL); swf_ShapeFree(i->shape); i->shape = 0; @@ -1686,13 +1696,13 @@ static void endshape(swfoutput*obj, int clipdepth) i->bboxrectpos = -1; } -void swfoutput_save(struct swfoutput* obj, char*filename) +int swfoutput_save(struct swfoutput* obj, char*filename) { swfoutput_internal*i = (swfoutput_internal*)obj->internal; endpage(obj); fontlist_t *tmp,*iterator = i->fontlist; while(iterator) { - TAG*mtag = i->swf.firstTag; + TAG*mtag = obj->swf.firstTag; if(iterator->swffont) { mtag = swf_InsertTag(mtag, ST_DEFINEFONT2); /*if(!storeallcharacters) @@ -1711,39 +1721,44 @@ void swfoutput_save(struct swfoutput* obj, char*filename) if(fi<=0) { msg(" Could not create \"%s\". ", FIXNULL(filename)); - exit(1); + return 0; } i->tag = swf_InsertTag(i->tag,ST_END); if(config_enablezlib || config_flashversion>=6) { - if FAILED(swf_WriteSWC(fi,&i->swf)) + if FAILED(swf_WriteSWC(fi,&obj->swf)) msg(" WriteSWC() failed.\n"); } else { - if FAILED(swf_WriteSWF(fi,&i->swf)) + if FAILED(swf_WriteSWF(fi,&obj->swf)) msg(" WriteSWF() failed.\n"); } if(filename) close(fi); msg(" SWF written\n"); + return 1; } /* Perform cleaning up, complete the swf, and write it out. */ void swfoutput_destroy(struct swfoutput* obj) { swfoutput_internal*i = (swfoutput_internal*)obj->internal; + if(!i) { + /* not initialized yet- nothing to destroy */ + return; + } fontlist_t *tmp,*iterator = i->fontlist; while(iterator) { if(iterator->swffont) { - swf_FontFree(iterator->swffont); + swf_FontFree(iterator->swffont);iterator->swffont=0; } tmp = iterator; iterator = iterator->next; delete tmp; } - swf_FreeTags(&i->swf); + swf_FreeTags(&obj->swf); free(i);i=0; memset(obj, 0, sizeof(swfoutput)); @@ -1852,7 +1867,7 @@ void swfoutput_endclip(swfoutput*obj) return; } i->clippos--; - swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],NULL,NULL,NULL,i->depth++); + swf_ObjectPlaceClip(i->cliptags[i->clippos],i->clipshapes[i->clippos],i->clipdepths[i->clippos],&i->page_matrix,NULL,NULL,i->depth++); } static void drawlink(struct swfoutput*obj, ActionTAG*,ActionTAG*, swfcoord*points, char mouseover); @@ -2076,14 +2091,18 @@ static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); if(posx!=0 || posy!=0) { + SPOINT p; + p.x = (int)(posx*20); + p.y = (int)(posy*20); + p = swf_TurnPoint(p, &i->page_matrix); MATRIX m; - swf_GetMatrix(0,&m); - m.tx = (int)(posx*20); - m.ty = (int)(posy*20); + m = i->page_matrix; + m.tx = p.x; + m.ty = p.y; swf_ObjectPlace(i->tag, buttonid, i->depth++,&m,0,0); } else { - swf_ObjectPlace(i->tag, buttonid, i->depth++,0,0,0); + swf_ObjectPlace(i->tag, buttonid, i->depth++,&i->page_matrix,0,0); } } @@ -2171,7 +2190,8 @@ static void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey, /* instance */ i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); - swf_ObjectPlace(i->tag,myshapeid,/*depth*/i->depth++,NULL,NULL,NULL); + + swf_ObjectPlace(i->tag,myshapeid,/*depth*/i->depth++,&i->page_matrix,NULL,NULL); } int swfoutput_drawimagejpeg_old(struct swfoutput*obj, char*filename, int sizex,int sizey,