X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpdf%2FGFXOutputDev.cc;h=0fb2591ab49571a8a4feaac9ca1ef72d13887569;hb=8e4e0278a8fbde7e4f65402f3692724aad4e9698;hp=27042b8455be9b2d9de35847c01c098e1fbab04c;hpb=5b288559c452f70766c57386dd5c5a3c9ff306b6;p=swftools.git diff --git a/lib/pdf/GFXOutputDev.cc b/lib/pdf/GFXOutputDev.cc index 27042b8..0fb2591 100644 --- a/lib/pdf/GFXOutputDev.cc +++ b/lib/pdf/GFXOutputDev.cc @@ -80,6 +80,8 @@ #include +#define SQRT2 1.41421356237309504880 + typedef struct _fontfile { const char*filename; @@ -1026,10 +1028,13 @@ void GFXOutputDev::endPage() device->endclip(device); outer_clip_box = 0; } + this->dashPattern = 0; /* notice: we're not fully done yet with this page- there might still be a few calls to drawLink() yet to come */ } +static inline double sqr(double x) {return x*x;} + #define STROKE_FILL 1 #define STROKE_CLIP 2 void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags) @@ -1050,7 +1055,7 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags) col.g = colToByte(rgb.g); col.b = colToByte(rgb.b); col.a = (unsigned char)(opaq*255); - + gfx_capType capType = gfx_capRound; if(lineCap == 0) capType = gfx_capButt; else if(lineCap == 1) capType = gfx_capRound; @@ -1061,28 +1066,37 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags) else if(lineJoin == 1) joinType = gfx_joinRound; else if(lineJoin == 2) joinType = gfx_joinBevel; - int dashnum = 0; - double dashphase = 0; - double * ldash = 0; - state->getLineDash(&ldash, &dashnum, &dashphase); - gfxline_t*line2 = 0; - if(dashnum && ldash) { - float * dash = (float*)malloc(sizeof(float)*(dashnum+1)); + if(this->dashLength && this->dashPattern) { + float * dash = (float*)malloc(sizeof(float)*(this->dashLength+1)); int t; - msg(" %d dashes", dashnum); - msg(" | phase: %f", dashphase); - for(t=0;t | d%-3d: %f", t, ldash[t]); + + /* try to find out how much the transformation matrix would + stretch the dashes, and factor that into the dash lengths. + This is not the entirely correct approach- it would be + better to first convert the path to an unscaled version, + then apply dashing, and then transform the path using + the current transformation matrix. However there are few + PDFs which actually stretch a dashed path in a non-orthonormal + way */ + double tx1, ty1, tx2, ty2; + this->transformXY(state, 0, 0, &tx1, &ty1); + this->transformXY(state, 1, 1, &tx2, &ty2); + double f = sqrt(sqr(tx2-tx1)+sqr(ty2-ty1)) / SQRT2; + + msg(" %d dashes", this->dashLength); + msg(" | phase: %f", this->dashStart); + for(t=0;tdashLength;t++) { + dash[t] = (float)this->dashPattern[t] * f; + msg(" | d%-3d: %f", t, this->dashPattern[t]); } - dash[dashnum] = -1; + dash[this->dashLength] = -1; if(getLogLevel() >= LOGLEVEL_TRACE) { dump_outline(line); } - line2 = gfxtool_dash_line(line, dash, (float)dashphase); + line2 = gfxtool_dash_line(line, dash, (float)(this->dashStart*f)); line = line2; free(dash); msg(" After dashing:"); @@ -1093,7 +1107,7 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags) width, lineJoin==0?"miter": (lineJoin==1?"round":"bevel"), lineCap==0?"butt": (lineJoin==1?"round":"square"), - dashnum, + this->dashLength, col.r,col.g,col.b,col.a ); dump_outline(line); @@ -1529,6 +1543,10 @@ void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl states[statepos].clipbbox.ymin = x1; states[statepos].clipbbox.xmax = x2; states[statepos].clipbbox.ymax = y2; + + this->dashPattern = 0; + this->dashLength = 0; + this->dashStart = 0; } @@ -1755,11 +1773,19 @@ void GFXOutputDev::restoreState(GfxState *state) { } statepos--; } + +void GFXOutputDev::updateLineDash(GfxState *state) +{ + state->getLineDash(&this->dashPattern, &this->dashLength, &this->dashStart); + msg(" updateLineDash, %d dashes", this->dashLength); + if(!this->dashLength) { + this->dashPattern = 0; + } +} void GFXOutputDev::updateLineWidth(GfxState *state) { double width = state->getTransformedLineWidth(); - //swfoutput_setlinewidth(&device, width); } void GFXOutputDev::updateLineCap(GfxState *state)