added support for get(..,"width"), get(..,"height")
[swftools.git] / pdf2swf / swfoutput.cc
index 4fda3bf..569aef0 100644 (file)
@@ -77,6 +77,7 @@ typedef struct _swfoutput_internal
     int config_drawonlyshapes;
     int config_jpegquality;
     int config_storeallcharacters;
+    int config_generate_fake_tags;
     int config_enablezlib;
     int config_insertstoptag;
     int config_flashversion;
@@ -214,6 +215,7 @@ static swfoutput_internal* init_internal_struct()
     i->config_jpegquality=85;
     i->config_storeallcharacters=0;
     i->config_enablezlib=0;
+    i->config_generate_fake_tags=0;
     i->config_insertstoptag=0;
     i->config_flashversion=6;
     i->config_splinemaxerror=1;
@@ -661,9 +663,9 @@ static int drawchar(gfxdevice_t*dev, SWFFONT *swffont, int charid, swfmatrix*m,
        return 0;
     }
     /*if(swffont->glyph[charid].shape->bitlen <= 16) {
-       msg("<warning> Character '%s' (c=%d,u=%d), glyph %d in current charset (%s, %d characters) is empty", 
-               FIXNULL(character),charnr, u, charid, FIXNULL((char*)swffont->name), swffont->numchars);
-       return 0;
+       msg("<warning> Glyph %d in current charset (%s, %d characters) is empty", 
+               charid, FIXNULL((char*)swffont->name), swffont->numchars);
+       return 1;
     }*/
 
     if(i->shapeid>=0)
@@ -1146,8 +1148,10 @@ void swfoutput_finalize(gfxdevice_t*dev)
        TAG*mtag = i->swf->firstTag;
        if(iterator->swffont) {
            mtag = swf_InsertTag(mtag, ST_DEFINEFONT2);
-           if(!i->config_storeallcharacters)
+           if(!i->config_storeallcharacters) {
+               msg("<debug> Reducing font %s", iterator->swffont->name);
                swf_FontReduce(iterator->swffont);
+           }
            swf_FontSetDefine2(mtag, iterator->swffont);
        }
 
@@ -1211,6 +1215,10 @@ void* swfresult_get(gfxresult_t*gfx, char*name)
        return (void*)(swf->movieSize.xmax/20);
     } else if(!strcmp(name, "ymax")) {
        return (void*)(swf->movieSize.ymax/20);
+    } else if(!strcmp(name, "width")) {
+       return (void*)((swf->movieSize.xmax - swf->movieSize.xmin)/20);
+    } else if(!strcmp(name, "height")) {
+       return (void*)((swf->movieSize.ymax - swf->movieSize.ymin)/20);
     }
     return 0;
 }
@@ -1304,12 +1312,11 @@ static void swfoutput_setstrokecolor(gfxdevice_t* dev, U8 r, U8 g, U8 b, U8 a)
 static void swfoutput_setlinewidth(gfxdevice_t*dev, double _linewidth)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
-    if(i->linewidth == (U16)(_linewidth*20))
+    if(i->linewidth == (U16)(_linewidth*20+19))
         return;
-
     if(i->shapeid>=0)
        endshape(dev);
-    i->linewidth = (U16)(_linewidth*20);
+    i->linewidth = (U16)(_linewidth*20+19);
 }
 
 
@@ -1650,10 +1657,18 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
        i->config_bboxvars = atoi(value);
     } else if(!strcmp(name, "insertstop")) {
        i->config_insertstoptag = atoi(value);
-    } else if(!strcmp(name, "protected")) {
+    } else if(!strcmp(name, "protect")) {
        i->config_protect = atoi(value);
+       if(i->config_protect && i->tag) {
+           i->tag = swf_InsertTag(i->tag, ST_PROTECT);
+       }
+    } else if(!strcmp(name, "faketags")) {
+       i->config_generate_fake_tags = atoi(value);
     } else if(!strcmp(name, "flashversion")) {
        i->config_flashversion = atoi(value);
+       if(i->swf) {
+           i->swf->fileVersion = i->config_flashversion;
+       }
     } else if(!strcmp(name, "minlinewidth")) {
        i->config_minlinewidth = atof(value);
     } else if(!strcmp(name, "caplinewidth")) {
@@ -2158,7 +2173,7 @@ gfxline_t* gfxline_move(gfxline_t*line, double x, double y)
     return line;
 }
 
-#define NORMALIZE_POLYGON_POSITIONS
+//#define NORMALIZE_POLYGON_POSITIONS
 
 static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
 {
@@ -2399,5 +2414,16 @@ static void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*col
     m.m22 = i->fontm22;
     m.m31 = matrix->tx;
     m.m32 = matrix->ty;
+  
+/*    printf("%f %f\n", m.m31,  m.m32);
+    {
+    static int xpos = 40;
+    static int ypos = 200;
+    m.m31 = xpos;
+    m.m32 = ypos;
+    xpos += 10;
+    }*/
+
+
     drawchar(dev, i->swffont, glyph, &m, color);
 }