X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fdevices%2Fswf.c;h=b090c7bfe52e10b261da2963eea36c703f37f148;hp=a3f57e9add05d376726f8c2eec7a7bab57d96b65;hb=7fb4a4ac393f19a0b8a8998a2f1deac88c97eda0;hpb=e633c982297e1728e8373f80d25533776a9b92b0 diff --git a/lib/devices/swf.c b/lib/devices/swf.c index a3f57e9..b090c7b 100644 --- a/lib/devices/swf.c +++ b/lib/devices/swf.c @@ -42,7 +42,7 @@ #include "../gfxtools.h" #include "swf.h" #include "../gfxpoly.h" -#include "../png.h" +#include "../gfximage.h" #define CHARDATAMAX 1024 #define CHARMIDX 0 @@ -102,6 +102,7 @@ typedef struct _swfoutput_internal int config_storeallcharacters; int config_enablezlib; int config_insertstoptag; + int config_showimages; int config_watermark; int config_noclips; int config_flashversion; @@ -114,6 +115,7 @@ typedef struct _swfoutput_internal int config_bboxvars; int config_disable_polygon_conversion; int config_normalize_polygon_positions; + int config_alignfonts; char config_disablelinks; RGBA config_linkcolor; float config_minlinewidth; @@ -738,12 +740,6 @@ static void chararray_writetotag(chararray_t*_chardata, TAG*tag) lastx = chr->x; lasty = chr->y; lastsize = chr->size; - } else { - assert(lastchar>=0); - if(pass==1 && lastchar!=chr->charid) { - swf_FontUsePair(chr->font, lastchar, chr->charid); - swf_FontUsePair(chr->font, chr->charid, lastchar); - } } if(islast) @@ -960,6 +956,7 @@ static void endpage(gfxdevice_t*dev) swfoutput_internal*i = (swfoutput_internal*)dev->internal; if(i->pagefinished) return; + if(i->shapeid>=0) endshape(dev); if(i->textmode) @@ -1476,13 +1473,10 @@ void swfoutput_finalize(gfxdevice_t*dev) endpage(dev); fontlist_t *iterator = i->fontlist; char use_font3 = i->config_flashversion>=8 && !NO_FONT3; + while(iterator) { TAG*mtag = i->swf->firstTag; if(iterator->swffont) { - if(use_font3) { - // needs to be done before the reduce - swf_FontCreateAlignZones(iterator->swffont); - } if(!i->config_storeallcharacters) { msg(" Reducing font %s", iterator->swffont->name); swf_FontReduce(iterator->swffont); @@ -1495,19 +1489,19 @@ void swfoutput_finalize(gfxdevice_t*dev) } else { mtag = swf_InsertTag(mtag, ST_DEFINEFONT3); swf_FontSetDefine2(mtag, iterator->swffont); - if(iterator->swffont->alignzones) { - mtag = swf_InsertTag(mtag, ST_DEFINEFONTALIGNZONES); - swf_FontSetAlignZones(mtag, iterator->swffont); - } } } } iterator = iterator->next; } - + i->tag = swf_InsertTag(i->tag,ST_END); TAG* tag = i->tag->prev; + + if(use_font3 && i->config_storeallcharacters && i->config_alignfonts) { + swf_FontPostprocess(i->swf); // generate alignment information + } /* remove the removeobject2 tags between the last ST_SHOWFRAME and the ST_END- they confuse the flash player */ @@ -2128,6 +2122,10 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value) i->config_dumpfonts = atoi(value); } else if(!strcmp(name, "animate")) { i->config_animate = atoi(value); + } else if(!strcmp(name, "linknameurl")) { + i->config_linknameurl = atoi(value); + } else if(!strcmp(name, "showimages")) { + i->config_showimages = atoi(value); } else if(!strcmp(name, "disablelinks")) { i->config_disablelinks = atoi(value); } else if(!strcmp(name, "simpleviewer")) { @@ -2263,7 +2261,9 @@ static int add_image(swfoutput_internal*i, gfximage_t*img, int targetwidth, int if(newsizex Scaling %dx%d image to %dx%d", sizex, sizey, newsizex, newsizey); - newpic = swf_ImageScale(mem, sizex, sizey, newsizex, newsizey); + gfximage_t*ni = gfximage_rescale(img, newsizex, newsizey); + newpic = (RGBA*)ni->data; + free(ni); *newwidth = sizex = newsizex; *newheight = sizey = newsizey; mem = newpic; @@ -2365,6 +2365,11 @@ static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxm SHAPE*shape; swf_ShapeNew(&shape); int fsid = swf_ShapeAddBitmapFillStyle(shape,&m,bitid,1); + int lsid = 0; + if(i->config_showimages) { + RGBA pink = {255,255,0,255}; + lsid = swf_ShapeAddLineStyle(shape, 20, &pink); + } swf_SetU16(i->tag, myshapeid); SRECT r = gfxline_getSWFbbox(line); r = swf_ClipRect(i->pagebbox, r); @@ -2372,7 +2377,7 @@ static void swf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxm swf_SetShapeStyles(i->tag,shape); swf_ShapeCountBits(shape,NULL,NULL); swf_SetShapeBits(i->tag,shape); - swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,0,fsid,0); + swf_ShapeSetAll(i->tag,shape,UNDEFINED_COORD,UNDEFINED_COORD,lsid,fsid,0); i->swflastx = i->swflasty = UNDEFINED_COORD; drawgfxline(dev, line, 1); swf_ShapeSetEnd(i->tag); @@ -2821,21 +2826,26 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version) swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars); swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars); swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars); - for(t=0;tmax_unicode;t++) { - swffont->ascii2glyph[t] = font->unicode2glyph[t]; - } + SRECT max = {0,0,0,0}; for(t=0;tnum_glyphs;t++) { drawer_t draw; gfxline_t*line; double advance = 0; - swffont->glyph2ascii[t] = font->glyphs[t].unicode; - if(swffont->glyph2ascii[t] == 0xffff || swffont->glyph2ascii[t] == 0x0000) { + int u = font->glyphs[t].unicode; + int s; + char twice=0; + for(s=0;snum_glyphs;s++) { + if(swffont->glyph2ascii[s]==u) + twice=1; + } + if(u >= 0xe000 || u == 0x0000 || twice) { /* flash 8 flashtype requires unique unicode IDs for each character. We use the Unicode private user area to assign characters, hoping that the font doesn't contain more than 2048 glyphs */ - swffont->glyph2ascii[t] = 0xe000 + (t&0x1fff); + u = 0xe000 + (t&0x1fff); } + swffont->glyph2ascii[t] = u; if(font->glyphs[t].name) { swffont->glyphnames[t] = strdup(font->glyphs[t].name); @@ -2853,6 +2863,11 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version) c.x = line->sx * scale; c.y = -line->sy * scale; //to.x = floor(line->x * scale); to.y = floor(-line->y * scale); to.x = line->x * scale; to.y = -line->y * scale; + + /*if(strstr(swffont->name, "BIRNU") && t==90) { + to.x += 1; + }*/ + if(line->type == gfx_moveTo) { draw.moveTo(&draw, &to); } else if(line->type == gfx_lineTo) { @@ -2881,6 +2896,7 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version) swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]); } + for(t=0;tnum_glyphs;t++) { SRECT bbox = swffont->layout->bounds[t]; @@ -2920,6 +2936,7 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version) if(font->descent*20 > swffont->layout->descent) swffont->layout->descent = font->descent*20; + swf_FontSort(swffont); return swffont; } @@ -2966,11 +2983,6 @@ static void swf_addfont(gfxdevice_t*dev, gfxfont_t*font) l->swffont->layout->bounds[iii].xmax/20.0, l->swffont->layout->bounds[iii].ymax/20.0 ); - int t; - for(t=0;tswffont->maxascii;t++) { - if(l->swffont->ascii2glyph[t] == iii) - msg(" | - maps to %d",t); - } } } } @@ -3074,6 +3086,7 @@ static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t* msg(" No character %d in font %s (%d chars)", glyph, FIXNULL((char*)i->swffont->name), i->swffont->numchars); return; } + glyph = i->swffont->glyph2glyph[glyph]; setfontscale(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11, matrix->tx, matrix->ty, 0);