From: Matthias Kramm Date: Tue, 13 Oct 2009 02:31:24 +0000 (-0700) Subject: synchronized with downstream git X-Git-Tag: version-0-9-1~262 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=fc815311aa1bd67877b404493838dfd85a86f596 synchronized with downstream git --- diff --git a/lib/Makefile.in b/lib/Makefile.in index 630a70f..ef5a16c 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -141,15 +141,19 @@ readers/image.$(O): readers/image.c readers/image.h libocr$(A): $(ocr_objects) devices/ocr.$(O) $(AR) r libocr$(A) $(ocr_objects) devices/ocr.$(O) + $(RANLIB) libocr$(A) libbase$(A): $(base_objects) Makefile $(AR) r libbase$(A) $(base_objects) + $(RANLIB) libbase$(A) libgfxswf$(A): devices/swf.$(O) readers/swf2.$(O) readers/image.$(O) $(AR) r libgfxswf$(A) devices/swf.$(O) readers/swf2.$(O) readers/image.$(O) + $(RANLIB) libgfxswf$(A) libgfx$(A): $(gfx_objects) $(gfxpoly_objects) Makefile $(AR) r libgfx$(A) $(gfx_objects) $(gfxpoly_objects) + $(RANLIB) libgfx$(A) librfxswf$(A): Makefile $(rfxswf_objects) rfxswf.$(O) drawer.$(O) MD5.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects) Makefile $(AR) r librfxswf$(A) $(rfxswf_objects) rfxswf.$(O) drawer.$(O) MD5.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects) diff --git a/lib/bitio.c b/lib/bitio.c index bd54935..c8f1d7d 100644 --- a/lib/bitio.c +++ b/lib/bitio.c @@ -68,9 +68,14 @@ static int reader_fileread(reader_t*reader, void* data, int len) reader->pos += ret; return ret; } +static void reader_fileread_dealloc(reader_t*r) +{ + memset(r, 0, sizeof(reader_t)); +} void reader_init_filereader(reader_t*r, int handle) { r->read = reader_fileread; + r->dealloc = reader_fileread_dealloc; r->internal = (void*)handle; r->type = READER_TYPE_FILE; r->mybyte = 0; diff --git a/lib/devices/swf.c b/lib/devices/swf.c index dbb851e..48b054a 100644 --- a/lib/devices/swf.c +++ b/lib/devices/swf.c @@ -218,6 +218,10 @@ static void swf_addfont(gfxdevice_t*dev, gfxfont_t*font); static void swf_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action); static void swf_startframe(gfxdevice_t*dev, int width, int height); static void swf_endframe(gfxdevice_t*dev); +static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points); +static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points); +static void swfoutput_linktourl(gfxdevice_t*dev, const char*url, gfxline_t*points); + static gfxresult_t* swf_finish(gfxdevice_t*driver); static swfoutput_internal* init_internal_struct() @@ -1531,7 +1535,7 @@ void swfoutput_finalize(gfxdevice_t*dev) /* Add AVM2 actionscript */ if(i->config_flashversion>=9 && - (i->config_insertstoptag || i->hasbuttons)) { + (i->config_insertstoptag || i->hasbuttons) && !i->config_linknameurl) { swf_AddButtonLinks(i->swf, i->config_insertstoptag, i->config_internallinkfunction||i->config_externallinkfunction); } @@ -1670,7 +1674,7 @@ static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth) } -static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover, const char*url); +static void drawlink(gfxdevice_t*dev, ActionTAG*,ActionTAG*, gfxline_t*points, char mouseover, char*type, const char*url); static void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points); static void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points); static void swfoutput_linktourl(gfxdevice_t*dev, const char*url, gfxline_t*points); @@ -1736,8 +1740,8 @@ void swfoutput_linktourl(gfxdevice_t*dev, const char*url, gfxline_t*points) } actions = action_End(actions); - drawlink(dev, actions, 0, points, 0, url); - + drawlink(dev, actions, 0, points, 0, "url", url); + swf_ActionFree(actions); } void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points) @@ -1764,7 +1768,7 @@ void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points) char name[80]; sprintf(name, "page%d", page); - drawlink(dev, actions, 0, points, 0, name); + drawlink(dev, actions, 0, points, 0, "page", name); swf_ActionFree(actions); } @@ -1784,6 +1788,7 @@ void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points) if(i->textmode) endtext(dev); + char*type = 0; if(!strncmp(tmp, "call:", 5)) { char*x = strchr(&tmp[5], ':'); @@ -1802,6 +1807,7 @@ void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points) } actions2 = action_End(0); mouseover = 0; + type = "call"; } else { @@ -1814,9 +1820,10 @@ void swfoutput_namedlink(gfxdevice_t*dev, char*name, gfxline_t*points) actions2 = action_PushString(actions2, ""); actions2 = action_SetVariable(actions2); actions2 = action_End(actions2); + type = "subtitle"; } - drawlink(dev, actions1, actions2, points, mouseover, name); + drawlink(dev, actions1, actions2, points, mouseover, type, name); swf_ActionFree(actions1); swf_ActionFree(actions2); @@ -1863,7 +1870,7 @@ static void drawgfxline(gfxdevice_t*dev, gfxline_t*line, int fill) } -static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover, const char*url) +static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gfxline_t*points, char mouseover, char*type, const char*url) { swfoutput_internal*i = (swfoutput_internal*)dev->internal; RGBA rgb; @@ -1877,6 +1884,11 @@ static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gf int buttonid = getNewID(dev); gfxbbox_t bbox = gfxline_getbbox(points); + if(i->config_linknameurl) { + actions1 = 0; + actions2 = 0; + } + i->hasbuttons = 1; /* shape */ diff --git a/lib/gfxdevice.h b/lib/gfxdevice.h index caaa983..2e508bf 100644 --- a/lib/gfxdevice.h +++ b/lib/gfxdevice.h @@ -114,7 +114,7 @@ typedef struct _gfxdevice void (*fillbitmap)(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*imgcoord2devcoord, gfxcxform_t*cxform); //cxform? tiling? void (*fillgradient)(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*gradcoord2devcoord); //? - /* deprecated */ void (*addfont)(struct _gfxdevice*dev, gfxfont_t*font); + void (*addfont)(struct _gfxdevice*dev, gfxfont_t*font); void (*drawchar)(struct _gfxdevice*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix); diff --git a/lib/gfxpoly.c b/lib/gfxpoly.c index dd97ff4..a687e63 100644 --- a/lib/gfxpoly.c +++ b/lib/gfxpoly.c @@ -911,7 +911,7 @@ static ArtSVP* gfxfillToSVP(gfxline_t*line, int perturb) //#ifdef SHEAR // double shear = find_shear_value(svp); -// gfxline_t*line = gfxpoly_to_gfxline((gfxpoly_t*)svp); +// gfxline_t*line = gfxline_from_gfxpoly((gfxpoly_t*)svp); // gfxline_t*l = line; // while(l) { // l->y += l->x*shear; @@ -963,7 +963,7 @@ ArtSVP* run_intersector(ArtSVP*svp, ArtWindRule rule) return result; } -gfxline_t* gfxpoly_to_gfxline(gfxpoly_t*poly) +gfxline_t* gfxline_from_gfxpoly(gfxpoly_t*poly) { ArtSVP*svp = (ArtSVP*)poly; int size = 0; @@ -998,7 +998,7 @@ gfxline_t* gfxpoly_to_gfxline(gfxpoly_t*poly) } } -gfxpoly_t* gfxpoly_fillToPoly(gfxline_t*line) +gfxpoly_t* gfxpoly_from_fill(gfxline_t*line, double gridsize) { /* I'm not sure whether doing perturbation here is actually a good idea- if that line has been run through the machinery @@ -1098,7 +1098,7 @@ gfxpoly_t* gfxpoly_union(gfxpoly_t*poly1, gfxpoly_t*poly2) return (gfxpoly_t*)svp; } -gfxpoly_t* gfxpoly_strokeToPoly(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit) +gfxpoly_t* gfxpoly_from_stroke(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit, double gridsize) { ArtVpath* vec = gfxline_to_ArtVpath(line, 0); msg(" Casting gfxline of %d segments to a stroke-polygon", gfxline_len(line)); @@ -1122,7 +1122,7 @@ gfxpoly_t* gfxpoly_strokeToPoly(gfxline_t*line, gfxcoord_t width, gfx_capType ca return (gfxpoly_t*)svp; } -gfxline_t* gfxline_circularToEvenOdd(gfxline_t*line) +gfxline_t* gfxpoly_circular_to_evenodd(gfxline_t*line, double gridsize) { msg(" Converting circular-filled gfxline of %d segments to even-odd filled gfxline", gfxline_len(line)); ArtSVP* svp = gfxfillToSVP(line, 1); @@ -1135,13 +1135,13 @@ gfxline_t* gfxline_circularToEvenOdd(gfxline_t*line) return 0; } - gfxline_t* result = gfxpoly_to_gfxline((gfxpoly_t*)svp_rewinded); + gfxline_t* result = gfxline_from_gfxpoly((gfxpoly_t*)svp_rewinded); art_svp_free(svp); art_svp_free(svp_rewinded); return result; } -gfxpoly_t* gfxpoly_createbox(double x1, double y1,double x2, double y2) +gfxpoly_t* gfxpoly_createbox(double x1, double y1,double x2, double y2, double gridsize) { ArtVpath *vec = art_new (ArtVpath, 5+1); vec[0].code = ART_MOVETO; @@ -1167,7 +1167,7 @@ gfxpoly_t* gfxpoly_createbox(double x1, double y1,double x2, double y2) return (gfxpoly_t*)svp; } -void gfxpoly_free(gfxpoly_t*poly) +void gfxpoly_destroy(gfxpoly_t*poly) { ArtSVP*svp = (ArtSVP*)poly; art_svp_free(svp); diff --git a/lib/gfxpoly/Makefile b/lib/gfxpoly/Makefile index 2065984..7a8b9cc 100644 --- a/lib/gfxpoly/Makefile +++ b/lib/gfxpoly/Makefile @@ -37,13 +37,12 @@ stroke.o: stroke.c poly.h convert.h wind.h $(CC) -c stroke.c -o stroke.o GFX=../gfxfont.o ../gfxtools.o ../devices/ops.o ../devices/polyops.o ../devices/text.o ../devices/bbox.o ../devices/render.o ../devices/rescale.o ../devices/record.o - stroke: test_stroke.c $(OBJS) ../libgfxswf.a ../librfxswf.a ../libbase.a - $(CC) test_stroke.c $(OBJS) ../librfxswf.a ../libgfxswf.a $(GFX) ../libbase.a -o stroke $(LIBS) + $(CC) test_stroke.c $(OBJS) ../libgfxswf.a ../librfxswf.a $(GFX) ../libbase.a -o stroke $(LIBS) SWF = ../librfxswf.a ../libpdf.a -lstdc++ test: ../libbase.a test.c $(OBJS) poly.h convert.h $(GFX) - $(CC) test.c $(OBJS) $(SWF) ../libbase.a $(GFX) -o test $(LIBS) + $(CC) test.c $(OBJS) $(SWF) $(GFX) ../libbase.a -o test $(LIBS) clean: rm -f *.o test stroke diff --git a/lib/gfxpoly/test_stroke.c b/lib/gfxpoly/test_stroke.c index d468cb8..0e292cd 100644 --- a/lib/gfxpoly/test_stroke.c +++ b/lib/gfxpoly/test_stroke.c @@ -1,5 +1,6 @@ #include #include "../gfxtools.h" +#include "convert.h" #include "stroke.h" #include "convert.h" diff --git a/lib/modules/swfbits.c b/lib/modules/swfbits.c index 4fa38f5..4643551 100644 --- a/lib/modules/swfbits.c +++ b/lib/modules/swfbits.c @@ -1182,9 +1182,15 @@ TAG* swf_AddImage(TAG*tag, int bitid, RGBA*mem, int width, int height, int quali int has_alpha = swf_ImageHasAlpha(mem,width,height); /* try lossless image */ + +#ifdef NO_LOSSLESS + tag1 = swf_InsertTag(0, /*ST_DEFINEBITSLOSSLESS1/2*/0); + tag1->len = 0x7fffffff; +#else tag1 = swf_InsertTag(0, /*ST_DEFINEBITSLOSSLESS1/2*/0); swf_SetU16(tag1, bitid); swf_SetLosslessImage(tag1, mem, width, height); +#endif #if defined(HAVE_JPEGLIB) /* try jpeg image */ diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index da9ec41..2596d25 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -1442,10 +1442,13 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, gfxmatrix_t m = this->current_font_matrix; this->transformXY(state, x-originX, y-originY, &m.tx, &m.ty); //m.tx += originX; m.ty += originY; - - msg(" drawChar(%f,%f,c='%c' (%d), u=%d <%d>) CID=%d render=%d glyphid=%d font=%08x",m.tx,m.ty,(charid&127)>=32?charid:'?', charid, u, uLen, font->isCIDFont(), render, glyphid, current_gfxfont); - if((render == RENDER_FILL && !config_drawonlyshapes) || render == RENDER_INVISIBLE) { + msg(" drawChar(%f,%f,c='%c' (%d), u=%d <%d>) CID=%d render=%d glyphid=%d font=%08x",m.tx,m.ty,(charid&127)>=32?charid:'?', charid, u, uLen, font->isCIDFont(), render, glyphid, current_gfxfont); + + if((render == RENDER_FILL && !config_drawonlyshapes) || + (render == RENDER_FILLSTROKE && state->getTransformedLineWidth()<1.0) || + (render == RENDER_INVISIBLE)) { + int space = this->current_fontinfo->space_char; if(config_extrafontdata && space>=0 && m.m00 && !m.m01) { /* space char detection */ @@ -1478,6 +1481,7 @@ void GFXOutputDev::drawChar(GfxState *state, double x, double y, msg(" Some texts will be rendered as shape"); gfxglobals->textmodeinfo = 1; } + gfxline_t*glyph = current_gfxfont->glyphs[glyphid].line; gfxline_t*tglyph = gfxline_clone(glyph); gfxline_transform(tglyph, &m); @@ -1561,10 +1565,11 @@ GBool GFXOutputDev::beginType3Char(GfxState *state, double x, double y, double d gfxmatrix_t m = this->current_font_matrix; this->transformXY(state, 0, 0, &m.tx, &m.ty); - m.m00*=INTERNAL_FONT_SIZE; + + /*m.m00*=INTERNAL_FONT_SIZE; m.m01*=INTERNAL_FONT_SIZE; m.m10*=INTERNAL_FONT_SIZE; - m.m11*=INTERNAL_FONT_SIZE; + m.m11*=INTERNAL_FONT_SIZE;*/ if(!current_fontinfo || (unsigned)charid >= current_fontinfo->num_glyphs || !current_fontinfo->glyphs[charid]) { msg(" Invalid charid %d for font", charid); @@ -2039,6 +2044,8 @@ void GFXOutputDev::updateFont(GfxState *state) current_gfxfont = this->current_fontinfo->getGfxFont(); device->addfont(device, current_gfxfont); free(id); + + device->addfont(device, current_gfxfont); updateFontMatrix(state); } diff --git a/lib/pdf/InfoOutputDev.h b/lib/pdf/InfoOutputDev.h index 04e98f7..ead6a44 100644 --- a/lib/pdf/InfoOutputDev.h +++ b/lib/pdf/InfoOutputDev.h @@ -105,7 +105,6 @@ class InfoOutputDev: public OutputDev int num_polygons; int num_textfields; - void finish(); void dumpfonts(gfxdevice_t*dev); InfoOutputDev(XRef*xref); diff --git a/lib/rfxswf.c b/lib/rfxswf.c index f6353a3..18b2c56 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -177,7 +177,9 @@ int swf_SetU16(TAG * t,U16 v) void swf_SetS16(TAG * t,int v) { if(v>32767 || v<-32768) { + #ifdef DEBUG_RFXSWF fprintf(stderr, "Warning: S16 overflow: %d\n", v); + #endif } swf_SetU16(t, (S16)v); } @@ -657,7 +659,9 @@ int swf_SetRect(TAG * t,SRECT * r) nbits = swf_CountBits(r->ymin,nbits); nbits = swf_CountBits(r->ymax,nbits); if(nbits>=32) { + #ifdef DEBUG_RFXSWF fprintf(stderr, "rfxswf: Warning: num_bits overflow in swf_SetRect\n"); + #endif nbits=31; } @@ -823,7 +827,9 @@ int swf_SetMatrix(TAG * t,MATRIX * m) nbits = swf_CountBits(m->sy,nbits); if(nbits>=32) { /* TODO: happens on AMD64 systems for normal values? */ + #ifdef DEBUG_RFXSWF fprintf(stderr,"rfxswf: Error: matrix values too large\n"); + #endif nbits = 31; } swf_SetBits(t,nbits,5); @@ -837,7 +843,9 @@ int swf_SetMatrix(TAG * t,MATRIX * m) nbits = swf_CountBits(m->r0,0); nbits = swf_CountBits(m->r1,nbits); if(nbits>=32) { + #ifdef DEBUG_RFXSWF fprintf(stderr,"rfxswf: Error: matrix values too large\n"); + #endif nbits = 31; } swf_SetBits(t,nbits,5); @@ -848,7 +856,9 @@ int swf_SetMatrix(TAG * t,MATRIX * m) nbits = swf_CountBits(m->tx,0); nbits = swf_CountBits(m->ty,nbits); if(nbits>=32) { + #ifdef DEBUG_RFXSWF fprintf(stderr,"rfxswf: Error: matrix values too large\n"); + #endif nbits = 31; } swf_SetBits(t,nbits,5); @@ -1132,7 +1142,9 @@ TAG * swf_ReadTag(reader_t*reader, TAG * prev) { t->data = (U8*)rfx_alloc(t->len); t->memsize = t->len; if (reader->read(reader, t->data, t->len) != t->len) { + #ifdef DEBUG_RFXSWF fprintf(stderr, "rfxswf: Warning: Short read (tagid %d). File truncated?\n", t->id); + #endif free(t->data);t->data=0; free(t); return NULL; @@ -1311,7 +1323,9 @@ void swf_FoldSprite(TAG * t) if(t->id!=ST_DEFINESPRITE) return; if(!t->len) { + #ifdef DEBUG_RFXSWF fprintf(stderr, "Error: Sprite has no ID!"); + #endif return; } if(t->len>4) { diff --git a/spec/edit_spec.py b/spec/edit_spec.py index 670e1bf..9584b05 100755 --- a/spec/edit_spec.py +++ b/spec/edit_spec.py @@ -39,7 +39,12 @@ class TwoPixelCheck(Check): return "pixel at (%d,%d)" % (self.x2,self.y2) class PixelBrighterThan(TwoPixelCheck): - pass + def verifies(self, model): + p1 = model.getPixel(self.x,self.y) + p2 = model.getPixel(self.x2,self.y2) + val1 = p1[0] + p1[1] + p1[2] + val2 = p2[0] + p2[1] + p2[2] + return val1 > val2 class PixelDarkerThan(TwoPixelCheck): pass diff --git a/src/pdf2swf.c b/src/pdf2swf.c index 4344187..c50a3de 100644 --- a/src/pdf2swf.c +++ b/src/pdf2swf.c @@ -748,6 +748,8 @@ int main(int argn, char *argv[]) pagenum = 0; gfxdevice_t*out = create_output_device();; + pdf->prepare(pdf, out); + for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) { if(is_in_range(pagenr, pagerange)) { diff --git a/src/swfcombine.c b/src/swfcombine.c index 48847c2..378bf06 100644 --- a/src/swfcombine.c +++ b/src/swfcombine.c @@ -1385,6 +1385,7 @@ int main(int argn, char *argv[]) swf_WriteSWF(fi, &newswf); } close(fi); - return 0; + + return 0; //ok }