applied Huub Schaek's .edittext patch
[swftools.git] / src / swfc.c
index 0601ed1..14d5f9a 100644 (file)
@@ -1546,7 +1546,7 @@ 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);
@@ -2404,17 +2404,15 @@ int parseTwip(char*str)
     /* TODO: make this a proper expression parser */
     char*p = str;
     int val = 0;
-    int add = 1;
+    char ex = 0;
     char*lastpos = str;
     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,9 +2427,18 @@ int parseTwip(char*str)
                v = parseRawTwip(lastpos);
            }
            *p = save;
-           val += v*add;
+           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;
        }
     }
     return val;
@@ -4282,6 +4289,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 +4319,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 +4347,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;