const char* compiler fixes
[swftools.git] / lib / pdf / pdf.cc
index b51cc9a..3f74b60 100644 (file)
@@ -19,9 +19,6 @@ static int ppm_dpi = 0;
 static int multiply = 1;
 static char* global_page_range = 0;
 
-static parameter_t* device_config = 0;
-static parameter_t* device_config_next = 0;
-
 static int globalparams_count=0;
 
 typedef struct _pdf_page_info
@@ -45,6 +42,7 @@ typedef struct _pdf_doc_internal
     pdf_page_info_t*pages;
     gfxdevice_t* middev;
     char*filename;
+    gfxsource_t*parent;
 } pdf_doc_internal_t;
 
 typedef struct _pdf_page_internal
@@ -56,8 +54,25 @@ typedef struct _dev_output_internal
     CommonOutputDev*outputDev;
 } dev_output_internal_t;
 
+typedef struct _parameter
+{
+    struct _parameter *next;
+    const char*name;
+    const char*value;
+} parameter_t;
+
+typedef struct _gfxsource_internal
+{
+    int config_bitmap_optimizing;
+    int config_full_bitmap_optimizing;
+
+    parameter_t* device_config;
+    parameter_t* device_config_next;
+
+} gfxsource_internal_t;
+
 
-static char* dirseparator()
+static const char* dirseparator()
 {
 #ifdef WIN32
     return "\\";
@@ -101,7 +116,7 @@ void render2(gfxpage_t*page, gfxdevice_t*dev)
     }
     
     /* pass global parameters to output device */
-    parameter_t*p = device_config;
+    parameter_t*p = ((gfxsource_internal_t*)pi->parent->internal)->device_config;
     while(p) {
        dev->setparameter(dev, p->name, p->value);
        p = p->next;
@@ -213,13 +228,13 @@ gfxpage_t* pdf_doc_getpage(gfxdocument_t*doc, int page)
     return pdf_page;
 }
 
-static char*getInfoString(Dict *infoDict, char *key)
+static char*getInfoString(Dict *infoDict, const char *key)
 {
     Object obj;
     GString *s1, *s2;
     int i;
 
-    if (infoDict && infoDict->lookup(key, &obj)->isString()) {
+    if (infoDict && infoDict->lookup((char*)key, &obj)->isString()) {
        s1 = obj.getString();
        if ((s1->getChar(0) & 0xff) == 0xfe &&
            (s1->getChar(1) & 0xff) == 0xff) {
@@ -246,12 +261,12 @@ static char*getInfoString(Dict *infoDict, char *key)
     return strdup("");
 }
 
-static char*getInfoDate(Dict *infoDict, char *key) 
+static char*getInfoDate(Dict *infoDict, const char *key) 
 {
     Object obj;
     char *s;
 
-    if (infoDict && infoDict->lookup(key, &obj)->isString()) {
+    if (infoDict && infoDict->lookup((char*)key, &obj)->isString()) {
        s = obj.getString()->getCString();
        if (s[0] == 'D' && s[1] == ':') {
          s += 2;
@@ -290,13 +305,13 @@ char* pdf_doc_getinfo(gfxdocument_t*doc, const char*name)
 }
 
 
-static void storeDeviceParameter(const char*name, const char*value)
+static void storeDeviceParameter(gfxsource_internal_t*i, const char*name, const char*value)
 {
-    parameter_t*o = device_config;
+    parameter_t*o = i->device_config;
     while(o) {
         if(!strcmp(name, o->name)) {
             /* overwrite old value */
-            free(o->value);
+            free((void*)o->value);
             o->value = strdup(value);
             return;
         }
@@ -307,21 +322,15 @@ static void storeDeviceParameter(const char*name, const char*value)
     p->value = strdup(value);
     p->next = 0;
 
-    if(device_config_next) {
-       device_config_next->next = p;
-       device_config_next = p;
+    if(i->device_config_next) {
+       i->device_config_next->next = p;
+       i->device_config_next = p;
     } else {
-       device_config = p;
-       device_config_next = p;
+       i->device_config = p;
+       i->device_config_next = p;
     }
 }
 
-typedef struct _gfxsource_internal
-{
-    int config_bitmap_optimizing;
-    int config_full_bitmap_optimizing;
-} gfxsource_internal_t;
-
 static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value)
 {
     gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal;
@@ -338,19 +347,19 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value
        char buf[80];
        zoom = atof(value);
        sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom);
-       storeDeviceParameter("jpegsubpixels", buf);
+       storeDeviceParameter(i, "jpegsubpixels", buf);
        sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
-       storeDeviceParameter("ppmsubpixels", buf);
+       storeDeviceParameter(i, "ppmsubpixels", buf);
     } else if(!strcmp(name, "jpegdpi")) {
        char buf[80];
        jpeg_dpi = atoi(value);
        sprintf(buf, "%f", (double)jpeg_dpi/(double)zoom);
-       storeDeviceParameter("jpegsubpixels", buf);
+       storeDeviceParameter(i, "jpegsubpixels", buf);
     } else if(!strcmp(name, "ppmdpi")) {
        char buf[80];
        ppm_dpi = atoi(value);
        sprintf(buf, "%f", (double)ppm_dpi/(double)zoom);
-       storeDeviceParameter("ppmsubpixels", buf);
+       storeDeviceParameter(i, "ppmsubpixels", buf);
     } else if(!strcmp(name, "poly2bitmap")) {
         i->config_bitmap_optimizing = atoi(value);
     } else if(!strcmp(name, "bitmapfonts") || !strcmp(name, "bitmap")) {
@@ -368,7 +377,6 @@ static void pdf_set_parameter(gfxsource_t*src, const char*name, const char*value
        printf("poly2bitmap       Convert graphics to bitmaps\n");
        printf("bitmap            Convert everything to bitmaps\n");
     }  
-    storeDeviceParameter(name,value);
 }
 
 static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
@@ -378,6 +386,7 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
     memset(pdf_doc, 0, sizeof(gfxdocument_t));
     pdf_doc_internal_t*i= (pdf_doc_internal_t*)malloc(sizeof(pdf_doc_internal_t));
     memset(i, 0, sizeof(pdf_doc_internal_t));
+    i->parent = src;
     pdf_doc->internal = i;
     char*userPassword=0;
     
@@ -453,7 +462,7 @@ static gfxdocument_t*pdf_open(gfxsource_t*src, const char*filename)
     }
 
     /* pass global parameters to PDF driver*/
-    parameter_t*p = device_config;
+    parameter_t*p = isrc->device_config;
     while(p) {
        i->outputDev->setParameter(p->name, p->value);
        p = p->next;
@@ -481,16 +490,19 @@ void pdf_destroy(gfxsource_t*src)
     if(!src->internal)
        return;
     gfxsource_internal_t*i = (gfxsource_internal_t*)src->internal;
-    free(src->internal);src->internal=0;
     
-    parameter_t*p = device_config;
+    parameter_t*p = i->device_config;
     while(p) {
        parameter_t*next = p->next;
-       if(p->name) free(p->name);p->name = 0;
-       if(p->value) free(p->value);p->value =0;
+       if(p->name) free((void*)p->name);p->name = 0;
+       if(p->value) free((void*)p->value);p->value =0;
        p->next = 0;delete p;
        p = next;
     }
+    i->device_config=i->device_config_next=0;
+    
+    free(src->internal);src->internal=0;
+
     delete globalParams;globalParams = 0;
     free(src);
 }