fixed vertical alignment bug
[swftools.git] / lib / pdf / GFXOutputDev.cc
index 698ae2c..940f5a0 100644 (file)
@@ -540,7 +540,7 @@ GFXOutputDev::GFXOutputDev(InfoOutputDev*info, PDFDoc*doc)
     this->info = info;
     this->doc = doc;
     this->xref = doc->getXRef();
-
+    
     this->jpeginfo = 0;
     this->textmodeinfo = 0;
     this->linkinfo = 0;
@@ -575,6 +575,7 @@ GFXOutputDev::GFXOutputDev(InfoOutputDev*info, PDFDoc*doc)
     this->config_multiply = 1;
 
     this->gfxfontlist = gfxfontlist_create();
+    this->dashPattern = 0;
   
     memset(states, 0, sizeof(states));
     this->featurewarnings = 0;
@@ -1004,6 +1005,8 @@ GBool GFXOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
     m.ty = (y0 + y1)/2 - 0.5;
 
     device->fillgradient(device, &p1, g, gfxgradient_linear, &m);
+
+    free(g);
     return gTrue;
 }
   
@@ -1088,6 +1091,8 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags)
        msg("<trace> |  phase: %f", this->dashStart);
        for(t=0;t<this->dashLength;t++) {
            dash[t] = (float)this->dashPattern[t] * f;
+            if(!dash[t])
+                dash[t] = 1e-37;
            msg("<trace> |  d%-3d: %f", t, this->dashPattern[t]);
        }
        dash[this->dashLength] = -1;
@@ -1228,6 +1233,9 @@ GFXOutputDev::~GFXOutputDev()
     if(this->pages) {
        free(this->pages); this->pages = 0;
     }
+    if(this->dashPattern) {
+        free(this->dashPattern);this->dashPattern = 0;
+    }
     
     feature_t*f = this->featurewarnings;
     while(f) {
@@ -1365,7 +1373,7 @@ 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;
+    //m.tx += originX; m.ty += originY;
 
     if(render == RENDER_FILL || render == RENDER_INVISIBLE) {
        device->drawchar(device, current_gfxfont, glyphid, &col, &m);
@@ -1786,10 +1794,18 @@ void GFXOutputDev::restoreState(GfxState *state) {
  
 void GFXOutputDev::updateLineDash(GfxState *state) 
 {
-    state->getLineDash(&this->dashPattern, &this->dashLength, &this->dashStart);
+    if(this->dashPattern) {
+        free(this->dashPattern);this->dashPattern = 0;
+    }
+    double *pattern = 0;
+    state->getLineDash(&pattern, &this->dashLength, &this->dashStart);
     msg("<debug> updateLineDash, %d dashes", this->dashLength);
     if(!this->dashLength) {
         this->dashPattern = 0;
+    } else {
+        double*p = (double*)malloc(this->dashLength*sizeof(this->dashPattern[0]));
+        memcpy(p, pattern, this->dashLength*sizeof(this->dashPattern[0]));
+        this->dashPattern = p;
     }
 }
 
@@ -2160,7 +2176,7 @@ void GFXOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
   imgStr = new ImageStream(str, width, ncomps,bits);
   imgStr->reset();
 
-  if(!width || !height || (height<=1 && width<=1 && maskWidth<=1 && maskHeight<=1))
+  if(!width || !height || ((height+width)<=1 && (maskWidth+maskHeight)<=1))
   {
       msg("<verbose> Ignoring %d by %d image", width, height);
       unsigned char buf[8];