X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fswfoutput.cc;h=8eaacd349f7704378f5392c4a20e2dd1d2d81a72;hb=3cdc844531091d6e19ae9d973c8b8de311ebff85;hp=81cf8b08b180fb7958cff823d092938041b664e0;hpb=332894030d2bfae848441ed7e6e909a16b40ab96;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index 81cf8b0..8eaacd3 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; @@ -87,6 +88,7 @@ typedef struct _swfoutput_internal int config_bboxvars; float config_minlinewidth; double config_caplinewidth; + char* config_linktarget; SWF* swf; @@ -152,6 +154,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); @@ -170,8 +175,6 @@ static void swf_startframe(gfxdevice_t*dev, int width, int height); static void swf_endframe(gfxdevice_t*dev); static gfxresult_t* swf_finish(gfxdevice_t*driver); -int getCharID(SWFFONT *font, int charnr, char *charname, int u); - static swfoutput_internal* init_internal_struct() { swfoutput_internal*i = (swfoutput_internal*)malloc(sizeof(swfoutput_internal)); @@ -213,8 +216,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; @@ -222,6 +226,7 @@ static swfoutput_internal* init_internal_struct() i->config_bboxvars=0; i->config_minlinewidth=0.05; i->config_caplinewidth=1; + i->config_linktarget=0; return i; }; @@ -660,9 +665,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) @@ -715,52 +720,6 @@ static void endtext(gfxdevice_t*dev) i->textid = -1; } -int getCharID(SWFFONT *font, int charnr, char *charname, int u) -{ - int t; - if(charname && font->glyphnames) { - for(t=0;tnumchars;t++) { - if(font->glyphnames[t] && !strcmp(font->glyphnames[t],charname)) { - msg(" Char [%d,>%s<,%d] maps to %d\n", charnr, charname, u, t); - return t; - } - } - /* if we didn't find the character, maybe - we can find the capitalized version */ - for(t=0;tnumchars;t++) { - if(font->glyphnames[t] && !strcasecmp(font->glyphnames[t],charname)) { - msg(" Char [%d,>>%s<<,%d] maps to %d\n", charnr, charname, u, t); - return t; - } - } - } - - if(u>0 && font->encoding != 255) { - /* try to use the unicode id */ - if(u>=0 && umaxascii && font->ascii2glyph[u]>=0) { - msg(" Char [%d,%s,>%d<] maps to %d\n", charnr, charname, u, font->ascii2glyph[u]); - return font->ascii2glyph[u]; - } - } - - if(font->encoding != FONT_ENCODING_UNICODE) { - /* the following only works if the font encoding - is US-ASCII based. It's needed for fonts which return broken unicode - indices */ - if(charnr>=0 && charnrmaxascii && font->ascii2glyph[charnr]>=0) { - msg(" Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, font->ascii2glyph[charnr]); - return font->ascii2glyph[charnr]; - } - } - - if(charnr>=0 && charnrnumchars) { - msg(" Char [>%d<,%s,%d] maps to %d\n", charnr, charname, u, charnr); - return charnr; - } - - return -1; -} - /* set's the matrix which is to be applied to characters drawn by swfoutput_drawchar() */ static void swfoutput_setfontmatrix(gfxdevice_t*dev,double m11,double m21, double m12,double m22) @@ -1083,6 +1042,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) @@ -1116,14 +1077,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) @@ -1184,8 +1150,10 @@ void swfoutput_finalize(gfxdevice_t*dev) TAG*mtag = i->swf->firstTag; if(iterator->swffont) { mtag = swf_InsertTag(mtag, ST_DEFINEFONT2); - if(!i->config_storeallcharacters) + if(!i->config_storeallcharacters) { + msg(" Reducing font %s", iterator->swffont->name); swf_FontReduce(iterator->swffont); + } swf_FontSetDefine2(mtag, iterator->swffont); } @@ -1249,6 +1217,10 @@ void* swfresult_get(gfxresult_t*gfx, char*name) return (void*)(swf->movieSize.xmax/20); } else if(!strcmp(name, "ymax")) { return (void*)(swf->movieSize.ymax/20); + } else if(!strcmp(name, "width")) { + return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20); + } else if(!strcmp(name, "height")) { + return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20); } return 0; } @@ -1270,6 +1242,11 @@ gfxresult_t* swf_finish(gfxdevice_t* dev) swfoutput_internal*i = (swfoutput_internal*)dev->internal; gfxresult_t*result; + if(i->config_linktarget) { + free(i->config_linktarget); + i->config_linktarget = 0; + } + swfoutput_finalize(dev); SWF* swf = i->swf;i->swf = 0; swfoutput_destroy(dev); @@ -1339,15 +1316,17 @@ static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a) i->strokergb.a = a; } +//#define ROUND_UP 19 +//#define ROUND_UP 10 + static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth) { swfoutput_internal*i = (swfoutput_internal*)dev->internal; - if(i->linewidth == (U16)(_linewidth*20)) + if(i->linewidth == (U16)(_linewidth*20+19.0/20.0)) return; - if(i->shapeid>=0) endshape(dev); - i->linewidth = (U16)(_linewidth*20); + i->linewidth = (U16)(_linewidth*20+19.0/20.0); } @@ -1380,7 +1359,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 { @@ -1395,11 +1375,15 @@ void swfoutput_linktourl(gfxdevice_t*dev, char*url, gfxline_t*points) endshape(dev); if(i->textid>=0) endtext(dev); - - if(!i->config_opennewwindow) - actions = action_GetUrl(0, url, "_parent"); - else - actions = action_GetUrl(0, url, "_this"); + + if(!i->config_linktarget) { + if(!i->config_opennewwindow) + actions = action_GetUrl(0, url, "_parent"); + else + actions = action_GetUrl(0, url, "_this"); + } else { + actions = action_GetUrl(0, url, i->config_linktarget); + } actions = action_End(actions); drawlink(dev, actions, 0, points,0); @@ -1687,14 +1671,24 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value) i->config_bboxvars = atoi(value); } else if(!strcmp(name, "insertstop")) { i->config_insertstoptag = atoi(value); - } else if(!strcmp(name, "protected")) { + } else if(!strcmp(name, "protect")) { i->config_protect = atoi(value); + if(i->config_protect && i->tag) { + i->tag = swf_InsertTag(i->tag, ST_PROTECT); + } + } else if(!strcmp(name, "faketags")) { + i->config_generate_fake_tags = atoi(value); } else if(!strcmp(name, "flashversion")) { i->config_flashversion = atoi(value); + if(i->swf) { + i->swf->fileVersion = i->config_flashversion; + } } else if(!strcmp(name, "minlinewidth")) { i->config_minlinewidth = atof(value); } else if(!strcmp(name, "caplinewidth")) { i->config_caplinewidth = atof(value); + } else if(!strcmp(name, "linktarget")) { + i->config_linktarget = strdup(value); } else if(!strcmp(name, "dumpfonts")) { i->config_dumpfonts = atoi(value); } else if(!strcmp(name, "next_bitmap_is_jpeg")) { @@ -1754,7 +1748,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) { @@ -1905,8 +1899,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); @@ -1914,7 +1906,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); @@ -2181,6 +2175,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) { @@ -2195,15 +2204,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); @@ -2213,7 +2216,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) { @@ -2224,12 +2254,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) { @@ -2383,5 +2430,16 @@ static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*col m.m22 = i->fontm22; m.m31 = matrix->tx; m.m32 = matrix->ty; + +/* printf("%f %f\n", m.m31, m.m32); + { + static int xpos = 40; + static int ypos = 200; + m.m31 = xpos; + m.m32 = ypos; + xpos += 10; + }*/ + + drawchar(dev, i->swffont, glyph, &m, color); }