X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=pdf2swf%2Fswfoutput.cc;h=728b2b2f3720fde37b245e361a07a01907d2834c;hb=914bf80496d7fb81b0df3c5287f9ebbba16850a5;hp=1b08b82cf4674612c48909d8406673cd96d8f8c0;hpb=edaf4fc18535763b54c741a12a257700e4aba1f1;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index 1b08b82..728b2b2 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -61,7 +61,7 @@ struct fontlist_t double config_ppmsubpixels=0; double config_jpegsubpixels=0; -int config_opennewwindow=0; +int config_opennewwindow=1; int config_ignoredraworder=0; int config_drawonlyshapes=0; int config_jpegquality=85; @@ -137,6 +137,8 @@ typedef struct _swfoutput_internal int firstpage; char pagefinished; + char overflow; + /* during the transition to the gfxdevice interface: a device which uses this swfoutput as target */ gfxdevice_t device; @@ -151,7 +153,7 @@ void swf_endclip(gfxdevice_t*dev); void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit); void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color); void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform); -void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix); +void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix); static swfoutput_internal* init_internal_struct() { @@ -161,6 +163,7 @@ static swfoutput_internal* init_internal_struct() i->storefont = 0; i->currentswfid = 0; i->depth = 0; + i->overflow = 0; i->startdepth = 0; i->linewidth = 0; i->shapeid = -1; @@ -206,9 +209,21 @@ static U16 getNewID(struct swfoutput* obj) if(!id_error) msg(" ID Table overflow"); id_error=1; + i->overflow = 1; } return ++i->currentswfid; } +static U16 getNewDepth(struct swfoutput* obj) +{ + swfoutput_internal*i = (swfoutput_internal*)obj->internal; + if(i->depth == 65535) { + if(!id_error) + msg(" Depth Table overflow"); + id_error=1; + i->overflow = 1; + } + return ++i->depth; +} static void startshape(struct swfoutput* obj); static void starttext(struct swfoutput* obj); @@ -793,14 +808,15 @@ static void endtext(swfoutput*obj) swf_GetMatrix(0, &m); /* set unit matrix- the real matrix is in the placeobject */ swf_SetMatrix(i->tag,&m); + msg(" Placing text (%d characters) as ID %d", i->chardatapos, i->textid); + 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++,&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); + swf_ObjectPlace(i->tag,i->textid,getNewDepth(obj),&m2,NULL,NULL); i->textid = -1; } @@ -916,10 +932,10 @@ void swfoutput_setfont(struct swfoutput*obj, char*fontid, char*filename) if(getScreenLogLevel() >= LOGLEVEL_DEBUG) { // print font information - msg(" Font %s (%s)",swffont->name, filename); + msg(" Font %s (%s)",fontid, filename); msg(" | ID: %d", swffont->id); msg(" | Version: %d", swffont->version); - msg(" | Name: %s", fontid); + msg(" | Name: %s", swffont->name); msg(" | Numchars: %d", swffont->numchars); msg(" | Maxascii: %d", swffont->maxascii); msg(" | Style: %d", swffont->style); @@ -1070,9 +1086,9 @@ static void setBackground(struct swfoutput*obj, int x1, int y1, int x2, int y2) swf_ShapeSetEnd(i->tag); swf_ShapeFree(s); i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2); - swf_ObjectPlace(i->tag,shapeid,++i->depth,0,0,0); + swf_ObjectPlace(i->tag,shapeid,getNewDepth(obj),0,0,0); i->tag = swf_InsertTag(i->tag, ST_PLACEOBJECT2); - swf_ObjectPlaceClip(i->tag,shapeid,++i->depth,0,0,0,65535); + swf_ObjectPlaceClip(i->tag,shapeid,getNewDepth(obj),0,0,0,65535); i->cliptag = i->tag; } @@ -1333,7 +1349,7 @@ static void endshape(swfoutput*obj) msg(" Placing shape id %d", i->shapeid); i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); - swf_ObjectPlace(i->tag,i->shapeid,/*depth*/++i->depth,&i->page_matrix,NULL,NULL); + swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(obj),&i->page_matrix,NULL,NULL); swf_ShapeFree(i->shape); i->shape = 0; @@ -1391,6 +1407,10 @@ void swfoutput_finalize(struct swfoutput*obj) swf_DeleteTag(tag); tag = prev; } + + if(i->overflow) { + wipeSWF(&i->swf); + } } SWF* swfoutput_get(struct swfoutput*obj) @@ -1411,6 +1431,20 @@ void swfoutput_getdimensions(struct swfoutput*obj, int*x1, int*y1, int*x2, int*y if(y2) *y2 = i->swf.movieSize.ymax/20; } +void wipeSWF(SWF*swf) +{ + TAG*tag = swf->firstTag; + while(tag) { + TAG*next = tag->next; + if(tag->id != ST_SETBACKGROUNDCOLOR && + tag->id != ST_END && + tag->id != ST_SHOWFRAME) { + swf_DeleteTag(tag); + } + tag = next; + } +} + int swfoutput_save(struct swfoutput* obj, char*filename) { swfoutput_internal*i = (swfoutput_internal*)obj->internal; @@ -1437,7 +1471,6 @@ int swfoutput_save(struct swfoutput* obj, char*filename) if(filename) close(fi); - msg(" SWF written\n"); return 1; } @@ -1530,7 +1563,7 @@ void swfoutput_linktourl(struct swfoutput*obj, char*url, swfcoord*points) if(i->textid>=0) endtext(obj); - if(config_opennewwindow) + if(!config_opennewwindow) actions = action_GetUrl(0, url, "_parent"); else actions = action_GetUrl(0, url, "_this"); @@ -1738,9 +1771,9 @@ static void drawlink(struct swfoutput*obj, ActionTAG*actions1, ActionTAG*actions m = i->page_matrix; m.tx = p.x; m.ty = p.y; - swf_ObjectPlace(i->tag, buttonid, ++i->depth,&m,0,0); + swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&m,0,0); } else { - swf_ObjectPlace(i->tag, buttonid, ++i->depth,&i->page_matrix,0,0); + swf_ObjectPlace(i->tag, buttonid, getNewDepth(obj),&i->page_matrix,0,0); } } @@ -2096,12 +2129,20 @@ gfxline_t* SVPtogfxline(ArtSVP*svp) } } +/* TODO */ +static int imageInCache(swfoutput*obj, void*data, int width, int height) +{ + return -1; +} +static void addImageToCache(swfoutput*obj, void*data, int width, int height) +{ +} + static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int targetheight, int* newwidth, int* newheight) { swfoutput*obj = i->obj; RGBA*newpic = 0; RGBA*mem = (RGBA*)img->data; - int bitid = getNewID(obj); int sizex = img->width; int sizey = img->height; @@ -2128,6 +2169,7 @@ static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int *newheight = sizey; if(newsizex Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey); newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey); *newwidth = sizex = newsizex; *newheight = sizey = newsizey; @@ -2158,11 +2200,19 @@ static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int } printf("\n");*/ - i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality); + int bitid = -1; + int cacheid = imageInCache(obj, mem, sizex, sizey); + + if(cacheid<=0) { + bitid = getNewID(obj); + i->tag = swf_AddImage(i->tag, bitid, mem, sizex, sizey, config_jpegquality); + addImageToCache(obj, mem, sizex, sizey); + } else { + bitid = cacheid; + } if(newpic) free(newpic); - return bitid; } @@ -2223,7 +2273,7 @@ void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); CXFORM cxform2 = gfxcxform_to_cxform(cxform); - swf_ObjectPlace(i->tag,myshapeid,/*depth*/++i->depth,&i->page_matrix,&cxform2,NULL); + swf_ObjectPlace(i->tag,myshapeid,getNewDepth(obj),&i->page_matrix,&cxform2,NULL); } void swf_startclip(gfxdevice_t*dev, gfxline_t*line) @@ -2264,7 +2314,7 @@ void swf_startclip(gfxdevice_t*dev, gfxline_t*line) i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); i->cliptags[i->clippos] = i->tag; i->clipshapes[i->clippos] = myshapeid; - i->clipdepths[i->clippos] = ++i->depth; + i->clipdepths[i->clippos] = getNewDepth(obj); i->clippos++; } @@ -2406,6 +2456,8 @@ void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*co ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit); gfxline_t*gfxline = SVPtogfxline(svp); dev->fill(dev, gfxline, color); + free(gfxline); + art_svp_free(svp); } } void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) @@ -2422,7 +2474,7 @@ void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) drawgfxline(obj, line); msg(" end of swf_fill (shapeid=%d)", i->shapeid); } -void swf_fillgradient(gfxdevice_t*dev, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix) +void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix) { msg(" Gradient filling not implemented yet"); }