added opengl check
[swftools.git] / src / swfc.c
index 0601ed1..f2224a1 100644 (file)
@@ -816,7 +816,8 @@ TAG* removeFromTo(TAG*from, TAG*to)
     TAG*save = from->prev;
     while(from!=to) {
        TAG*next = from->next;
-       swf_DeleteTag(from);
+       if(swf_isAllowedSpriteTag(from))
+           swf_DeleteTag(from);
        from = next;
     }
     save->next = 0;
@@ -953,9 +954,6 @@ static void s_endSprite()
 {
     SRECT r = currentrect;
 
-    if(stack[stackpos].cut)
-       tag = removeFromTo(stack[stackpos].cut, tag);
-
     stackpos--;
     instance_t *i;
     stringarray_t* index =dictionary_index(&instances);
@@ -969,6 +967,12 @@ static void s_endSprite()
             writeInstance(i);
        }
     }
+
+    if(stack[stackpos].cut)
+       tag = removeFromTo(stack[stackpos].cut, tag);
+
+    // the writeInstance loop above may have inserted tags after what used yo be the current tag,
+    // so let's make sure 'tag' point to the current tag again.
     while (tag->next)
        tag = tag->next;
 
@@ -1028,6 +1032,11 @@ static void s_endSWF()
     swf = stack[stackpos].swf;
     filename = stack[stackpos].filename;
 
+    // the writeInstance loop above may have inserted tags after what used yo be the current tag,
+    // so let's make sure 'tag' point to the current tag again.
+    while (tag->next)
+       tag = tag->next;
+
     //if(tag->prev && tag->prev->id != ST_SHOWFRAME)
     //    tag = swf_InsertTag(tag, ST_SHOWFRAME);
     tag = swf_InsertTag(tag, ST_SHOWFRAME);
@@ -1546,13 +1555,15 @@ void s_font(char*name, char*filename)
        swf_FontCreateLayout(font);
     }
     font->id = id;
-       swf_FontReduce_swfc(font);
+    swf_FontReduce_swfc(font);
     tag = swf_InsertTag(tag, ST_DEFINEFONT2);
     swf_FontSetDefine2(tag, font);
-    tag = swf_InsertTag(tag, ST_EXPORTASSETS);
-    swf_SetU16(tag, 1);
-    swf_SetU16(tag, id);
-    swf_SetString(tag, name);
+    if(do_exports) {
+       tag = swf_InsertTag(tag, ST_EXPORTASSETS);
+       swf_SetU16(tag, 1);
+       swf_SetU16(tag, id);
+       swf_SetString(tag, name);
+    }
 
     incrementid();
 }
@@ -1634,13 +1645,15 @@ void s_sound(char*name, char*filename)
     else
         swf_SetSoundDefine(tag, samples, numsamples);
 
-    tag = swf_InsertTag(tag, ST_NAMECHARACTER);
-    swf_SetU16(tag, id);
-    swf_SetString(tag, name);
-    tag = swf_InsertTag(tag, ST_EXPORTASSETS);
-    swf_SetU16(tag, 1);
-    swf_SetU16(tag, id);
-    swf_SetString(tag, name);
+    if(do_exports) {
+       tag = swf_InsertTag(tag, ST_NAMECHARACTER);
+       swf_SetU16(tag, id);
+       swf_SetString(tag, name);
+       tag = swf_InsertTag(tag, ST_EXPORTASSETS);
+       swf_SetU16(tag, 1);
+       swf_SetU16(tag, id);
+       swf_SetString(tag, name);
+    }
 
     sound = (sound_t*)malloc(sizeof(sound_t)); /* mem leak */
     sound->tag = tag;
@@ -2123,7 +2136,7 @@ void s_endClip()
     swf_SetTagPos(stack[stackpos].tag, 0);
     swf_GetPlaceObject(stack[stackpos].tag, &p);
     p.clipdepth = currentdepth;
-    p.name = 0;
+    //p.name = 0;
     swf_ClearTag(stack[stackpos].tag);
     swf_SetPlaceObject(stack[stackpos].tag, &p);
     currentdepth++;
@@ -2404,17 +2417,15 @@ int parseTwip(char*str)
     /* TODO: make this a proper expression parser */
     char*p = str;
     int val = 0;
-    int add = 1;
-    char*lastpos = str;
+    char ex = 0;
+    char*lastpos = 0;
     while(*p) {
-       if(*p == '+') 
-           add = 1;
-       else if(*p == '-')
-           add = -1;
+       if(*p == '+' || *p == '-' || *p == '/' || *p == '*')
+           ex = *p;
        else if(!lastpos)
            lastpos = p;
        p++;
-       if((*p == '+' || *p == '-' || *p == 0) && lastpos) {
+       if((*p == '+' || *p == '-' || *p == '/' || *p == '*' || *p == 0) && lastpos) {
            char save = *p;
            *p = 0;
 
@@ -2429,11 +2440,22 @@ int parseTwip(char*str)
                v = parseRawTwip(lastpos);
            }
            *p = save;
-           val += v*add;
+            printf("%f %c= %f\n", val/20.0, ex, v/20.0);
+           if(ex == '+') 
+               val += v;
+           else if(ex == '-')
+               val -= v;
+           else if(ex == '/')
+               val = (val*20) / v;
+           else if(ex == '*')
+               val = (val*v) / 20;
+           else
+               val += v;
+           ex = 0;
            lastpos = 0;
-           add = 1;
        }
     }
+    printf("%s -> %.2f\n", str, val/20.0);
     return val;
 }
 
@@ -4282,6 +4304,7 @@ static void analyseArgumentsForCommand(char*command)
     map_t args;
     char* fontfile;
     int nr = -1;
+    U8* glyphs_to_include;
     msg("<verbose> analyse Command: %s (line %d)", command, line);
 
     for(t=0;t<sizeof(arguments)/sizeof(arguments[0]);t++)
@@ -4311,8 +4334,26 @@ static void analyseArgumentsForCommand(char*command)
            font = (SWFFONT*)malloc(sizeof(SWFFONT));
            memset(font, 0, sizeof(SWFFONT));
        }
-       swf_FontUseUTF8(font, lu(&args, "glyphs"));
-       swf_FontPrepareForEditText(font);
+       else
+       {
+           swf_FontPrepareForEditText(font);
+           glyphs_to_include = lu(&args, "glyphs");
+           if (!strcmp(glyphs_to_include, "all"))
+           {
+               swf_FontUseAll(font);
+               font->use->glyphs_specified = 1;
+           }
+           else
+           {
+               if (strcmp (glyphs_to_include, ""))
+               {
+                   swf_FontUseUTF8(font, glyphs_to_include);
+                   font->use->glyphs_specified = 1;
+               }
+               else
+                   swf_FontInitUsage(font);
+           }
+       }
        dictionary_put2(&fonts, name, font);
     }
     else
@@ -4321,10 +4362,16 @@ static void analyseArgumentsForCommand(char*command)
         if (!font)
             syntaxerror("font %s is not known in line %d", lu(&args, "font"), line);
         else
-            if (!strcmp(command, "edittext"))
-               swf_FontUseAll(font);
-            else
-               swf_FontUseUTF8(font, lu(&args, "text"));
+            if (font->use && !font->use->glyphs_specified)
+            {
+               if (!strcmp(command, "edittext"))
+               {
+                   swf_FontUseAll(font);
+                   font->use->glyphs_specified = 1;
+               }
+               else
+                   swf_FontUseUTF8(font, lu(&args, "text"));
+            }
     }
     map_clear(&args);
     return;