fixed drawonlyshapes implementation
[swftools.git] / lib / devices / swf.c
index 7740ca1..1f34c1b 100644 (file)
@@ -76,6 +76,7 @@ typedef struct _swfoutput_internal
     double config_dumpfonts;
     double config_ppmsubpixels;
     double config_jpegsubpixels;
+    char hasbuttons;
     int config_simpleviewer;
     int config_opennewwindow;
     int config_ignoredraworder;
@@ -259,7 +260,7 @@ static swfoutput_internal* init_internal_struct()
     i->config_internallinkfunction=0;
     i->config_externallinkfunction=0;
     i->config_reordertags=1;
-    i->config_linknameurl=1;
+    i->config_linknameurl=0;
 
     i->config_linkcolor.r = i->config_linkcolor.g = i->config_linkcolor.b = 255;
     i->config_linkcolor.a = 0x40;
@@ -1402,9 +1403,11 @@ void swfoutput_finalize(gfxdevice_t*dev)
        i->swf->compressed = 1;
     }
 
-    /* Initialize AVM2 if it is a Flash9 file */
-    if(i->config_flashversion>=9 && i->config_insertstoptag) {
-       AVM2_InsertStops(i->swf);
+    /* Add AVM2 actionscript */
+    if(i->config_flashversion>=9 && 
+            (i->config_insertstoptag || i->hasbuttons)) {
+        swf_AddButtonLinks(i->swf, i->config_insertstoptag, 
+                i->config_internallinkfunction||i->config_externallinkfunction);
     }
 //    if(i->config_reordertags)
 //     swf_Optimize(i->swf);
@@ -1586,8 +1589,10 @@ void swfoutput_linktourl(gfxdevice_t*dev, const char*url, gfxline_t*points)
        endshape(dev);
     if(i->textid>=0)
        endtext(dev);
+
+    /* TODO: escape special characters in url */
     
-    if(i->config_externallinkfunction) {
+    if(i->config_externallinkfunction && i->config_flashversion<=8) {
        actions = action_PushString(actions, url); //parameter
        actions = action_PushInt(actions, 1); //number of parameters (1)
        actions = action_PushString(actions, i->config_externallinkfunction); //function name
@@ -1614,7 +1619,7 @@ void swfoutput_linktopage(gfxdevice_t*dev, int page, gfxline_t*points)
     if(i->textid>=0)
        endtext(dev);
   
-    if(!i->config_internallinkfunction) {
+    if(!i->config_internallinkfunction || i->config_flashversion>=9) {
        actions = action_GotoFrame(actions, page-1);
        actions = action_End(actions);
     } else {
@@ -1738,6 +1743,8 @@ static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gf
     double posy = 0;
     int buttonid = getNewID(dev);
     gfxbbox_t bbox = gfxline_getbbox(points);
+    
+    i->hasbuttons = 1;
 
     /* shape */
     myshapeid = getNewID(dev);
@@ -1818,9 +1825,13 @@ static void drawlink(gfxdevice_t*dev, ActionTAG*actions1, ActionTAG*actions2, gf
             swf_ButtonPostProcess(i->tag, 1);
        }
     }
+    char buf[80];
     const char* name = 0;
     if(i->config_linknameurl) {
        name = url;
+    } else {
+        name = buf;
+        sprintf(buf, "button%d", buttonid);
     }
     
     msg("<trace> Placing link ID %d", buttonid);
@@ -2831,6 +2842,16 @@ static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*
        msg("<error> swf_drawchar called (glyph %d) without font", glyph);
        return;
     }
+
+    if(i->config_drawonlyshapes) {
+        gfxglyph_t*g = &font->glyphs[glyph];
+        gfxline_t*line2 = gfxline_clone(g->line);
+        gfxline_transform(line2, matrix);
+       dev->fill(dev, line2, color);
+        gfxline_free(line2);
+        return;
+    }
+
     if(!i->swffont || !i->swffont->name || strcmp((char*)i->swffont->name,font->id)) // not equal to current font
     {
        /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope