added ?pt fontsize support.
[swftools.git] / src / swfc.c
index c2de7de..15b2425 100644 (file)
@@ -967,13 +967,16 @@ void s_quicktime(char*name, char*url)
 
 void s_edittext(char*name, char*fontname, int size, int width, int height, char*text, RGBA*color, int maxlength, char*variable, int flags)
 {
-    SWFFONT*font;
+    SWFFONT*font = 0;
     EditTextLayout layout;
     SRECT r;
 
-    font = dictionary_lookup(&fonts, fontname);
-    if(!font)
-       syntaxerror("font \"%s\" not known!", fontname);
+    if(fontname && *fontname) {
+       flags |= ET_USEOUTLINES;
+       font = dictionary_lookup(&fonts, fontname);
+       if(!font)
+           syntaxerror("font \"%s\" not known!", fontname);
+    }
     tag = swf_InsertTag(tag, ST_DEFINEEDITTEXT);
     swf_SetU16(tag, id);
     layout.align = 0;
@@ -985,7 +988,8 @@ void s_edittext(char*name, char*fontname, int size, int width, int height, char*
     r.ymin = 0;
     r.xmax = width;
     r.ymax = height;
-    swf_SetEditText(tag, flags|ET_USEOUTLINES, r, text, color, maxlength, font->id, size, &layout, variable);
+    
+    swf_SetEditText(tag, flags, r, text, color, maxlength, font?font->id:0, size, &layout, variable);
 
     s_addcharacter(name, id, tag, r);
     incrementid();
@@ -1102,6 +1106,7 @@ void s_sound(char*name, char*filename)
     sound_t* sound;
     U16*samples;
     int numsamples;
+    int t;
 
     if(!readWAV(filename, &wav)) {
        warning("Couldn't read wav file \"%s\"", filename);
@@ -1268,10 +1273,10 @@ void s_outline(char*name, char*format, char*source)
 int s_playsound(char*name, int loops, int nomultiple, int stop)
 {
     sound_t* sound;
+    SOUNDINFO info;
     if(!name)
        return 0;
     sound = dictionary_lookup(&sounds, name);
-    SOUNDINFO info;
     if(!sound)
        return 0;
 
@@ -1316,7 +1321,7 @@ void s_includeswf(char*name, char*filename)
     
     s = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
     swf_SetU16(tag, id);
-    swf_SetU16(tag, 0);
+    swf_SetU16(tag, swf.frameCount);
 
     swf_Relocate(&swf, idmap);
 
@@ -1781,6 +1786,19 @@ MULADD mergeMulAdd(MULADD m1, MULADD m2)
     return r;
 }
 
+float parsePxOrPercent(char*fontname, char*str)
+{
+    int l = strlen(str);
+    if(strchr(str, '%'))
+       return parsePercent(str);
+    if(l>2 && str[l-2]=='p' && str[l-1]=='t') {
+       float p = atof(str);
+       return p/64.0; /*64 = FT_SUBPIXELS- see ../lib/modules/swffont.c */
+    }
+    syntaxerror("Expression '%s' is neither a point size (?pt) nor a percentage (?%)", str);
+    return 0;
+}
+
 float parsePercent(char*str)
 {
     int l = strlen(str);
@@ -2302,7 +2320,7 @@ static int c_textshape(map_t*args)
     char*name = lu(args, "name");
     char*text = lu(args, "text");
     char*font = lu(args, "font");
-    float size = parsePercent(lu(args, "size"));
+    float size = parsePxOrPercent(font, lu(args, "size"));
 
     s_textshape(name, font, size, text);
     return 0;
@@ -2340,7 +2358,7 @@ static int c_text(map_t*args)
     char*name = lu(args, "name");
     char*text = lu(args, "text");
     char*font = lu(args, "font");
-    float size = parsePercent(lu(args, "size"));
+    float size = parsePxOrPercent(font, lu(args, "size"));
     RGBA color = parseColor(lu(args, "color"));
     s_text(name, font, text, (int)(size*100), color);
     return 0;
@@ -2521,7 +2539,7 @@ static int c_edittext(map_t*args)
  //"name font size width height text="" color=black maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0"},
     char*name = lu(args, "name");
     char*font = lu(args, "font");
-    int size = (int)(1024*parsePercent(lu(args, "size")));
+    int size = (int)(1024*parsePxOrPercent(font, lu(args, "size")));
     int width = parseTwip(lu(args, "width"));
     int height = parseTwip(lu(args, "height"));
     char*text  = lu(args, "text");
@@ -2565,10 +2583,10 @@ static int c_action(map_t*args)
        s_action(text);
     } else {
        FILE*fi = fopen(filename, "rb");
-       if(!fi) 
-           syntaxerror("Couldn't find file %s: %s", filename, strerror(errno));
        int l;
        char*text;
+       if(!fi) 
+           syntaxerror("Couldn't find file %s: %s", filename, strerror(errno));
        fseek(fi, 0, SEEK_END);
        l = ftell(fi);
        fseek(fi, 0, SEEK_SET);
@@ -2615,7 +2633,7 @@ static struct {
 
  {"egon", c_egon, "name vertices color=white line=1 @fill=none"},
  {"text", c_text, "name text font size=100% color=white"},
- {"edittext", c_edittext, "name font size=100% width height text="" color=white maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0 @border=0"},
+ {"edittext", c_edittext, "name font= size=100% width height text="" color=white maxlength=0 variable="" @password=0 @wordwrap=0 @multiline=0 @html=0 @noselect=0 @readonly=0 @border=0"},
  {"morphshape", c_morphshape, "name start end"},
  {"button", c_button, "name"},
     {"show", c_show,             "name x=0 y=0 red=+0 green=+0 blue=+0 alpha=+0 luminance= scale= scalex= scaley= pivot= pin= shear= rotate= ratio= above= below= as="},