made normalize_polygon_options a parameter
[swftools.git] / lib / devices / swf.c
index 67c6ac4..25eec62 100644 (file)
@@ -85,6 +85,7 @@ typedef struct _swfoutput_internal
     int config_protect;
     int config_bboxvars;
     int config_disable_polygon_conversion;
+    int config_normalize_polygon_positions;
     RGBA config_linkcolor;
     float config_minlinewidth;
     double config_caplinewidth;
@@ -92,6 +93,7 @@ typedef struct _swfoutput_internal
     char*config_internallinkfunction;
     char*config_externallinkfunction;
     char config_animate;
+    double config_framerate;
 
     SWF* swf;
 
@@ -227,6 +229,7 @@ static swfoutput_internal* init_internal_struct()
     i->config_generate_fake_tags=0;
     i->config_insertstoptag=0;
     i->config_flashversion=6;
+    i->config_framerate=0.25;
     i->config_splinemaxerror=1;
     i->config_fontsplinemaxerror=1;
     i->config_filloverlap=0;
@@ -933,7 +936,7 @@ void gfxdevice_swf_init(gfxdevice_t* dev)
    
     i->swf = (SWF*)rfx_calloc(sizeof(SWF));
     i->swf->fileVersion    = i->config_flashversion;
-    i->swf->frameRate      = 0x0040; // 1 frame per 4 seconds
+    i->swf->frameRate      = i->config_framerate*0x100;
     i->swf->movieSize.xmin = 0;
     i->swf->movieSize.ymin = 0;
     i->swf->movieSize.xmax = 0;
@@ -1778,8 +1781,13 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
        i->config_internallinkfunction = strdup(value);
     } else if(!strcmp(name, "externallinkfunction")) {
        i->config_externallinkfunction = strdup(value);
+    } else if(!strcmp(name, "linkfunction")) { //sets both internallinkfunction and externallinkfunction
+       i->config_internallinkfunction = strdup(value);
+       i->config_externallinkfunction = strdup(value);
     } else if(!strcmp(name, "disable_polygon_conversion")) {
        i->config_disable_polygon_conversion = atoi(value);
+    } else if(!strcmp(name, "normalize_polygon_positions")) {
+       i->config_normalize_polygon_positions = atoi(value);
     } else if(!strcmp(name, "insertstop")) {
        i->config_insertstoptag = atoi(value);
     } else if(!strcmp(name, "protect")) {
@@ -1794,6 +1802,11 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
        if(i->swf) {
            i->swf->fileVersion = i->config_flashversion;
        }
+    } else if(!strcmp(name, "framerate")) {
+       i->config_framerate = atoi(value);
+       if(i->swf) {
+           i->swf->frameRate = i->config_framerate*0x100;
+       }
     } else if(!strcmp(name, "minlinewidth")) {
        i->config_minlinewidth = atof(value);
     } else if(!strcmp(name, "caplinewidth")) {
@@ -1809,7 +1822,7 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
     } else if(!strcmp(name, "jpegquality")) {
        int val = atoi(value);
        if(val<0) val=0;
-       if(val>100) val=100;
+       if(val>101) val=101;
        i->config_jpegquality = val;
     } else if(!strcmp(name, "splinequality")) {
        int v = atoi(value);
@@ -2252,17 +2265,17 @@ static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcol
     msg("<trace> draw as stroke, type=%d dots=%d", type, has_dots);
     endtext(dev);
 
-#ifdef NORMALIZE_POLYGON_POSITIONS
-    endshape(dev);
-    double startx = 0, starty = 0;
-    if(line && line->type == gfx_moveTo) {
-       startx = line->x;
-       starty = line->y;
-    }
-    line = gfxline_move(line, -startx, -starty);
-    i->shapeposx = (int)(startx*20);
-    i->shapeposy = (int)(starty*20);
-#endif
+    if(i->config_normalize_polygon_positions) {
+       endshape(dev);
+       double startx = 0, starty = 0;
+       if(line && line->type == gfx_moveTo) {
+           startx = line->x;
+           starty = line->y;
+       }
+       line = gfxline_move(line, -startx, -starty);
+       i->shapeposx = (int)(startx*20);
+       i->shapeposy = (int)(starty*20);
+    }
 
     swfoutput_setstrokecolor(dev, color->r, color->g, color->b, color->a);
     swfoutput_setlinewidth(dev, width);
@@ -2270,9 +2283,9 @@ static void swf_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcol
     stopFill(dev);
     drawgfxline(dev, line);
 
-#ifdef NORMALIZE_POLYGON_POSITIONS
-    free(line); //account for _move
-#endif
+    if(i->config_normalize_polygon_positions) {
+       free(line); //account for _move
+    }
 
 }
 static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
@@ -2289,17 +2302,17 @@ static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
     if(!i->config_ignoredraworder)
        endshape(dev);
 
-#ifdef NORMALIZE_POLYGON_POSITIONS
-    endshape(dev);
-    double startx = 0, starty = 0;
-    if(line && line->type == gfx_moveTo) {
-       startx = line->x;
-       starty = line->y;
-    }
-    line = gfxline_move(line, -startx, -starty);
-    i->shapeposx = (int)(startx*20);
-    i->shapeposy = (int)(starty*20);
-#endif
+    if(i->config_normalize_polygon_positions) {
+       endshape(dev);
+       double startx = 0, starty = 0;
+       if(line && line->type == gfx_moveTo) {
+           startx = line->x;
+           starty = line->y;
+       }
+       line = gfxline_move(line, -startx, -starty);
+       i->shapeposx = (int)(startx*20);
+       i->shapeposy = (int)(starty*20);
+    }
 
     swfoutput_setfillcolor(dev, color->r, color->g, color->b, color->a);
     startshape(dev);
@@ -2308,9 +2321,9 @@ static void swf_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
     drawgfxline(dev, line);
     msg("<trace> end of swf_fill (shapeid=%d)", i->shapeid);
 
-#ifdef NORMALIZE_POLYGON_POSITIONS
-    free(line); //account for _move
-#endif
+    if(i->config_normalize_polygon_positions) {
+       free(line); //account for _move
+    }
 }
 static void swf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
 {
@@ -2482,6 +2495,8 @@ static void swf_switchfont(gfxdevice_t*dev, char*fontid)
 static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+    if(!font)
+       return;
        
     if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,font->id)) // not equal to current font
     {