applied MSVC compatibility patch from Dwight Kelly
[swftools.git] / lib / pdf / GFXOutputDev.cc
index a1ddba9..2c41499 100644 (file)
@@ -22,7 +22,9 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include "../../config.h"
 #include "../os.h"
 #ifdef HAVE_DIRENT_H
@@ -31,9 +33,6 @@
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#ifdef HAVE_FONTCONFIG
-#include <fontconfig.h>
-#endif
 //xpdf header files
 #include "config.h"
 #include "gfile.h"
@@ -60,7 +59,7 @@
 #include "GHash.h"
 #include "GFXOutputDev.h"
 
-//swftools header files
+//  swftools header files
 #include "../log.h"
 #include "../gfxdevice.h"
 #include "../gfxtools.h"
@@ -71,7 +70,7 @@
 #include "../devices/render.h"
 
 #include "../art/libart.h"
-#include "../devices/artsutils.c"
+#include "../devices/artsutils.h"
 
 #include "../png.h"
 #include "fonts.h"
@@ -338,8 +337,12 @@ DisplayFontParam *GFXGlobalParams::getDisplayFont(GString *fontName)
     return GlobalParams::getDisplayFont(fontName);
 }
 
-GFXOutputDev::GFXOutputDev(parameter_t*p)
+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;
@@ -363,52 +366,45 @@ GFXOutputDev::GFXOutputDev(parameter_t*p)
     this->pages = 0;
     this->pagebuflen = 0;
     this->pagepos = 0;
-    this->config_use_fontconfig=1;
     this->config_break_on_warning=0;
     this->config_remapunicode=0;
     this->config_transparent=0;
     this->config_extrafontdata = 0;
+    this->config_fontquality = 10;
 
-    this->parameters = p;
-    
     this->gfxfontlist = gfxfontlist_create();
   
     memset(states, 0, sizeof(states));
-
-    /* configure device */
-    while(p) {
-        setParameter(p->name, p->value);
-       p = p->next;
-    }
 };
 
 void GFXOutputDev::setParameter(const char*key, const char*value)
 {
     if(!strcmp(key,"breakonwarning")) {
        this->config_break_on_warning = atoi(value);
-    } else if(!strcmp(key,"fontconfig")) {
-        this->config_use_fontconfig = atoi(value);
     } else if(!strcmp(key,"remapunicode")) {
         this->config_remapunicode = atoi(value);
     } else if(!strcmp(key,"transparent")) {
         this->config_transparent = atoi(value);
     } else if(!strcmp(key,"extrafontdata")) {
         this->config_extrafontdata = atoi(value);
+    } else if(!strcmp(key,"fontquality")) {
+        this->config_fontquality = atof(value);
+       if(this->config_fontquality<=1)
+           this->config_fontquality=1;
+    } else if(!strcmp(key,"help")) {
+       printf("\nPDF layer options:\n");
+       printf("breakonwarning=0/1  Abort conversion if graphic objects are found which\n");
+       printf("                    are not 100%% supported\n");
+       printf("transparent=0/1     Make PDF transparent (alpha background)\n");
+       printf("extrafontdata=0/1   Store Type3 characters and capture characters\n");
+       printf("fontquality=1..100  Curve approximation quality of the fonts\n");
     }
+    
 }
   
 void GFXOutputDev::setDevice(gfxdevice_t*dev)
 {
-    parameter_t*p = this->parameters;
-
-    /* pass parameters to output device */
     this->device = dev;
-    if(this->device) {
-       while(p) {
-           this->device->setparameter(this->device, p->name, p->value);
-           p = p->next;
-       }
-    }
 }
   
 void GFXOutputDev::setMove(int x,int y)
@@ -657,6 +653,10 @@ GBool GFXOutputDev::needNonText()
 void GFXOutputDev::endPage() 
 {
     msg("<verbose> endPage");
+    if(outer_clip_box) {
+       device->endclip(device);
+       outer_clip_box = 0;
+    }
 }
 
 #define STROKE_FILL 1
@@ -703,7 +703,7 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags)
        msg("<trace> %d dashes", dashnum);
        msg("<trace> |  phase: %f", dashphase);
        for(t=0;t<dashnum;t++) {
-           dash[t] = ldash[t];
+           dash[t] = (float)ldash[t];
            msg("<trace> |  d%-3d: %f", t, ldash[t]);
        }
        dash[dashnum] = -1;
@@ -711,7 +711,7 @@ void GFXOutputDev::strokeGfxline(GfxState *state, gfxline_t*line, int flags)
            dump_outline(line);
        }
 
-       line2 = gfxtool_dash_line(line, dash, dashphase);
+       line2 = gfxtool_dash_line(line, dash, (float)dashphase);
        line = line2;
        free(dash);
        msg("<trace> After dashing:");
@@ -826,14 +826,6 @@ void GFXOutputDev::clipToStrokePath(GfxState *state)
     gfxline_free(line);
 }
 
-void GFXOutputDev::endframe()
-{
-    if(outer_clip_box) {
-       device->endclip(device);
-       outer_clip_box = 0;
-    }
-}
-
 void GFXOutputDev::finish()
 {
     if(outer_clip_box) {
@@ -852,7 +844,7 @@ GFXOutputDev::~GFXOutputDev()
        free(this->pages); this->pages = 0;
     }
 
-    gfxfontlist_free(this->gfxfontlist, 1);
+    gfxfontlist_free(this->gfxfontlist, 1);this->gfxfontlist = 0;
 };
 GBool GFXOutputDev::upsideDown() 
 {
@@ -866,12 +858,6 @@ GBool GFXOutputDev::useDrawChar()
 const char*renderModeDesc[]= {"fill", "stroke", "fill+stroke", "invisible",
                       "clip+fill", "stroke+clip", "fill+stroke+clip", "clip"};
 
-#define RENDER_FILL 0
-#define RENDER_STROKE 1
-#define RENDER_FILLSTROKE 2
-#define RENDER_INVISIBLE 3
-#define RENDER_CLIP 4
-
 static char tmp_printstr[4096];
 char* makeStringPrintable(char*str)
 {
@@ -1108,29 +1094,16 @@ void GFXOutputDev::endType3Char(GfxState *state)
     msg("<debug> endType3Char");
 }
 
-void GFXOutputDev::startFrame(int width, int height) 
-{
-    if(outer_clip_box) {
-       device->endclip(device);
-       outer_clip_box = 0;
-    }
-
-    device->startpage(device, width, height);
-    this->width = width;
-    this->height = height;
-}
-
 void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) 
 {
     this->currentpage = pageNum;
     double x1,y1,x2,y2;
     int rot = doc->getPageRotate(1);
-    gfxcolor_t white;
+    gfxcolor_t white = {255,255,255,255};
+    gfxcolor_t black = {255,0,0,0};
     laststate = state;
     gfxline_t clippath[5];
 
-    white.r = white.g = white.b = white.a = 255;
-
     /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
     state->transform(state->getX2(),state->getY2(),&x2,&y2);
     Use CropBox, not MediaBox, as page size
@@ -1178,7 +1151,7 @@ void GFXOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl
 
 void GFXOutputDev::processLink(Link *link, Catalog *catalog)
 {
-    double x1, y1, x2, y2, w;
+    double x1, y1, x2, y2;
     gfxline_t points[5];
     int x, y;
     
@@ -1452,13 +1425,8 @@ void GFXOutputDev::updateStrokeColor(GfxState *state)
     state->getStrokeRGB(&rgb);
 }
 
-void GFXOutputDev::setXRef(PDFDoc*doc, XRef *xref) 
-{
-    this->doc = doc;
-    this->xref = xref;
-}
 
-gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src)
+gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src, double config_fontquality)
 {
     gfxfont_t*font = (gfxfont_t*)malloc(sizeof(gfxfont_t));
     memset(font, 0, sizeof(gfxfont_t));
@@ -1467,7 +1435,8 @@ gfxfont_t* createGfxFont(GfxFont*xpdffont, FontInfo*src)
     memset(font->glyphs, 0, sizeof(gfxglyph_t)*src->num_glyphs);
     font->id = strdup(getFontID(xpdffont));
     int t;
-    double quality = (INTERNAL_FONT_SIZE * 0.05) / src->max_size;
+    
+    double quality = (INTERNAL_FONT_SIZE * 200 / config_fontquality) / src->max_size;
     double scale = 1;
     //printf("%d glyphs\n", font->num_glyphs);
     font->num_glyphs = 0;
@@ -1551,6 +1520,7 @@ void GFXOutputDev::updateFont(GfxState *state)
     this->current_fontinfo = this->info->getFont(id);
     if(!this->current_fontinfo) {
        msg("<error> Internal Error: no fontinfo for font %s\n", id);
+    return;
     }
     if(!this->current_fontinfo->seen) {
        dumpFontInfo("<verbose>", gfxFont);
@@ -1558,7 +1528,7 @@ void GFXOutputDev::updateFont(GfxState *state)
     
     gfxfont_t*font = gfxfontlist_findfont(this->gfxfontlist,id);
     if(!font) {
-       font = createGfxFont(gfxFont, current_fontinfo);
+       font = createGfxFont(gfxFont, current_fontinfo, this->config_fontquality);
         font->id = strdup(id);
        this->gfxfontlist = gfxfontlist_addfont(this->gfxfontlist, font);
        device->addfont(device, font);
@@ -1579,7 +1549,6 @@ unsigned char* antialize(unsigned char*data, int width, int height, int newwidth
     unsigned char*newdata;
     int x,y;
     newdata= (unsigned char*)malloc(newwidth*newheight);
-    int t;
     double fx = (double)(width)/newwidth;
     double fy = (double)(height)/newheight;
     double px = 0;
@@ -1652,9 +1621,6 @@ static void drawimage(gfxdevice_t*dev, gfxcolor_t* data, int sizex,int sizey,
      p5.y = (int)(p5.y*20)/20.0;
     }
     
-    float m00,m10,tx;
-    float m01,m11,ty;
-    
     gfxmatrix_t m;
     m.m00 = (p4.x-p1.x)/sizex; m.m10 = (p2.x-p1.x)/sizey;
     m.m01 = (p4.y-p1.y)/sizex; m.m11 = (p2.y-p1.y)/sizey;
@@ -1779,7 +1745,6 @@ void GFXOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
   }
 
   if(mask) {
-      int i,j;
       unsigned char buf[8];
       int x,y;
       unsigned char*pic = new unsigned char[width*height];
@@ -1808,7 +1773,7 @@ void GFXOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
       /* the size of the drawn image is added to the identifier
         as the same image may require different bitmaps if displayed
         at different sizes (due to antialiasing): */
-      int t,found = -1;
+      int found = -1;
       if(type3active) {
          unsigned char*pic2 = 0;
          numpalette = 16;
@@ -1828,7 +1793,7 @@ void GFXOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
          
          /* make a black/white palette */
 
-         float r = 255/(numpalette-1);
+         float r = 255./(float)(numpalette-1);
          int t;
          for(t=0;t<numpalette;t++) {
              pal[t].r = colToByte(rgb.r);
@@ -2054,7 +2019,6 @@ void addGlobalLanguageDir(const char*dir)
 {
     msg("<notice> Adding %s to language pack directories", dir);
 
-    int l;
     FILE*fi = 0;
     char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("add-to-xpdfrc") + 1);
     strcpy(config_file, dir);
@@ -2108,7 +2072,7 @@ void addGlobalFontDir(const char*dirname)
     }
     closedir(dir);
 #else
-    msg("<warning> No dirent.h- unable to add font dir %s", dir);
+    msg("<warning> No dirent.h- unable to add font dir %s", dirname);
 #endif
 }
 
@@ -2222,13 +2186,11 @@ void GFXOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
                                      GBool forSoftMask)
 {
     const char*colormodename = "";
-    BBox rect = mkBBox(state, bbox, this->width, this->height);
 
     if(blendingColorSpace) {
        colormodename = GfxColorSpace::getColorSpaceModeName(blendingColorSpace->getMode());
     }
     dbg("beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
-    dbg("using clipping rect %f/%f/%f/%f\n", rect.posx,rect.posy,rect.width,rect.height);
     msg("<verbose> beginTransparencyGroup %.1f/%.1f/%.1f/%.1f %s isolated=%d knockout=%d forsoftmask=%d", bbox[0],bbox[1],bbox[2],bbox[3], colormodename, isolated, knockout, forSoftMask);
     
     states[statepos].createsoftmask |= forSoftMask;