X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fswfoutput.cc;h=a386b64a5d08f527fa3a3e91cc471eef8fbcda2c;hb=74f1c40282224d5679178d01231dcb802e25f52a;hp=301f80899c661a490f7b252d10a8a653db033c08;hpb=979c1dc6e9391d5c29b8b48f8ebfb5d52600f6f5;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index 301f808..a386b64 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -77,6 +77,7 @@ typedef struct _swfoutput_internal int config_drawonlyshapes; int config_jpegquality; int config_storeallcharacters; + int config_generate_fake_tags; int config_enablezlib; int config_insertstoptag; int config_flashversion; @@ -152,6 +153,9 @@ typedef struct _swfoutput_internal RGBA fillrgb; int drawmode; + int shapeposx; + int shapeposy; + } swfoutput_internal; static void swf_fillbitmap(gfxdevice_t*driver, gfxline_t*line, gfximage_t*img, gfxmatrix_t*move, gfxcxform_t*cxform); @@ -211,8 +215,9 @@ static swfoutput_internal* init_internal_struct() i->config_jpegquality=85; i->config_storeallcharacters=0; i->config_enablezlib=0; + i->config_generate_fake_tags=0; i->config_insertstoptag=0; - i->config_flashversion=5; + i->config_flashversion=6; i->config_splinemaxerror=1; i->config_fontsplinemaxerror=1; i->config_filloverlap=0; @@ -658,9 +663,9 @@ static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix*m, return 0; } /*if(swffont->glyph[charid].shape->bitlen <= 16) { - msg(" Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty", - FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars); - return 0; + msg(" Glyph %d in current charset (%s, %d characters) is empty", + charid, FIXNULL((char*)swffont->name), swffont->numchars); + return 1; }*/ if(i->shapeid>=0) @@ -1035,6 +1040,8 @@ static void endshape_noput(gfxdevice_t*dev) i->shape=0; } i->fill=0; + i->shapeposx=0; + i->shapeposy=0; } static void endshape(gfxdevice_t*dev) @@ -1068,14 +1075,19 @@ static void endshape(gfxdevice_t*dev) msg(" Placing shape id %d", i->shapeid); i->tag = swf_InsertTag(i->tag,ST_PLACEOBJECT2); - swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&i->page_matrix,NULL,NULL); + MATRIX m = i->page_matrix; + m.tx += i->shapeposx; + m.ty += i->shapeposy; + swf_ObjectPlace(i->tag,i->shapeid,getNewDepth(dev),&m,NULL,NULL); swf_ShapeFree(i->shape); i->shape = 0; i->shapeid = -1; i->bboxrectpos = -1; - i->fill=0; + i->fill=0; + i->shapeposx=0; + i->shapeposy=0; } void wipeSWF(SWF*swf) @@ -1332,7 +1344,8 @@ void swf_drawlink(gfxdevice_t*dev, gfxline_t*points, char*url) if(url[t]<'0' || url[t]>'9') nodigit = 1; if(!nodigit) { - int page = atoi(&url[4]); + int page = atoi(&url[4]) - 1; + if(page<0) page = 0; swfoutput_linktopage(dev, page, points); } } else { @@ -1641,6 +1654,8 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value) i->config_insertstoptag = atoi(value); } else if(!strcmp(name, "protected")) { i->config_protect = atoi(value); + } else if(!strcmp(name, "faketags")) { + i->config_generate_fake_tags = atoi(value); } else if(!strcmp(name, "flashversion")) { i->config_flashversion = atoi(value); } else if(!strcmp(name, "minlinewidth")) { @@ -1706,7 +1721,7 @@ static ArtVpath* gfxline_to_ArtVpath(gfxline_t*line) double x=0,y=0; /* factor which determines into how many line fragments a spline is converted */ - double subfraction = 1.2;//0.3 + double subfraction = 2.4;//0.3 l2 = line; while(l2) { @@ -1857,8 +1872,6 @@ static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int return -1; /* TODO: cache images */ - *newwidth = sizex; - *newheight = sizey; if(newsizex Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey); @@ -1866,7 +1879,9 @@ static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int *newwidth = sizex = newsizex; *newheight = sizey = newsizey; mem = newpic; - + } else { + *newwidth = newsizex = sizex; + *newheight = newsizey = sizey; } int num_colors = swf_ImageGetNumberOfPaletteEntries(mem,sizex,sizey,0); @@ -2133,6 +2148,21 @@ static void show_path(ArtSVP*path) printf("\n"); } +gfxline_t* gfxline_move(gfxline_t*line, double x, double y) +{ + gfxline_t*l = line = gfxline_clone(line); + + while(l) { + l->x += x; + l->y += y; + l->sx += x; + l->sy += y; + l = l->next; + } + return line; +} + +#define NORMALIZE_POLYGON_POSITIONS static 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) { @@ -2147,15 +2177,9 @@ static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcol if(!has_dots && (width <= i->config_caplinewidth || (cap_style == gfx_capRound && joint_style == gfx_joinRound) - || (cap_style == gfx_capRound && type<=2))) { - msg(" draw as stroke, type=%d dots=%d", type, has_dots); - endtext(dev); - swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a); - swfoutput_setlinewidth(dev, width); - startshape(dev); - stopFill(dev); - drawgfxline(dev, line); - } else { + || (cap_style == gfx_capRound && type<=2))) {} else + { + /* convert line to polygon */ msg(" draw as polygon, type=%d dots=%d", type, has_dots); if(has_dots) gfxline_fix_short_edges(line); @@ -2165,7 +2189,34 @@ static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcol dev->fill(dev, gfxline, color); free(gfxline); art_svp_free(svp); + return; } + + msg(" draw as stroke, type=%d dots=%d", type, has_dots); + endtext(dev); + +#ifdef NORMALIZE_POLYGON_POSITIONS + endshape(dev); + double startx = 0, starty = 0; + if(line && line->type == gfx_moveTo) { + startx = line->x; + starty = line->y; + } + line = gfxline_move(line, -startx, -starty); + i->shapeposx = (int)(startx*20); + i->shapeposy = (int)(starty*20); +#endif + + swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a); + swfoutput_setlinewidth(dev, width); + startshape(dev); + stopFill(dev); + drawgfxline(dev, line); + +#ifdef NORMALIZE_POLYGON_POSITIONS + free(line); //account for _move +#endif + } static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) { @@ -2176,12 +2227,29 @@ static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) endtext(dev); if(!i->config_ignoredraworder) endshape(dev); + +#ifdef NORMALIZE_POLYGON_POSITIONS + endshape(dev); + double startx = 0, starty = 0; + if(line && line->type == gfx_moveTo) { + startx = line->x; + starty = line->y; + } + line = gfxline_move(line, -startx, -starty); + i->shapeposx = (int)(startx*20); + i->shapeposy = (int)(starty*20); +#endif + swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a); startshape(dev); startFill(dev); i->fill=1; drawgfxline(dev, line); msg(" end of swf_fill (shapeid=%d)", i->shapeid); + +#ifdef NORMALIZE_POLYGON_POSITIONS + free(line); //account for _move +#endif } static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix) {