added 'flashtype' option to .font in swfc
authorMatthias Kramm <kramm@quiss.org>
Sun, 29 Nov 2009 19:38:04 +0000 (11:38 -0800)
committerMatthias Kramm <kramm@quiss.org>
Sun, 29 Nov 2009 19:38:04 +0000 (11:38 -0800)
lib/devices/swf.c
lib/modules/swffont.c
lib/modules/swftext.c
lib/rfxswf.h
src/swfc.c

index 5f0fe70..182aa55 100644 (file)
@@ -2813,21 +2813,26 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
     swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
     swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
     swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
     swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
     swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
     swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
-    for(t=0;t<font->max_unicode;t++) {
-       swffont->ascii2glyph[t] = font->unicode2glyph[t];
-    }
+
     SRECT max = {0,0,0,0};
     for(t=0;t<font->num_glyphs;t++) {
        drawer_t draw;
        gfxline_t*line;
        double advance = 0;
     SRECT max = {0,0,0,0};
     for(t=0;t<font->num_glyphs;t++) {
        drawer_t draw;
        gfxline_t*line;
        double advance = 0;
-       swffont->glyph2ascii[t] = font->glyphs[t].unicode;
-       if(swffont->glyph2ascii[t] == 0xffff || swffont->glyph2ascii[t] == 0x0000) {
+       int u = font->glyphs[t].unicode;
+       int s;
+       char twice=0;
+       for(s=0;s<font->num_glyphs;s++) {
+           if(swffont->glyph2ascii[s]==u) 
+               twice=1;
+       }
+       if(u >= 0xe000 || u == 0x0000 || twice) {
            /* flash 8 flashtype requires unique unicode IDs for each character.
               We use the Unicode private user area to assign characters, hoping that
               the font doesn't contain more than 2048 glyphs */
            /* flash 8 flashtype requires unique unicode IDs for each character.
               We use the Unicode private user area to assign characters, hoping that
               the font doesn't contain more than 2048 glyphs */
-           swffont->glyph2ascii[t] = 0xe000 + (t&0x1fff);
+           u = 0xe000 + (t&0x1fff);
        }
        }
+       swffont->glyph2ascii[t] = u;
 
        if(font->glyphs[t].name) {
            swffont->glyphnames[t] = strdup(font->glyphs[t].name);
 
        if(font->glyphs[t].name) {
            swffont->glyphnames[t] = strdup(font->glyphs[t].name);
@@ -2845,6 +2850,11 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
            c.x = line->sx * scale; c.y = -line->sy * scale;
            //to.x = floor(line->x * scale); to.y = floor(-line->y * scale);
            to.x = line->x * scale; to.y = -line->y * scale;
            c.x = line->sx * scale; c.y = -line->sy * scale;
            //to.x = floor(line->x * scale); to.y = floor(-line->y * scale);
            to.x = line->x * scale; to.y = -line->y * scale;
+
+           /*if(strstr(swffont->name, "BIRNU") && t==90) {
+               to.x += 1;
+           }*/
+
            if(line->type == gfx_moveTo) {
                draw.moveTo(&draw, &to);
            } else if(line->type == gfx_lineTo) {
            if(line->type == gfx_moveTo) {
                draw.moveTo(&draw, &to);
            } else if(line->type == gfx_lineTo) {
@@ -2873,6 +2883,7 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
 
        swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
     }
 
        swf_ExpandRect2(&bounds, &swffont->layout->bounds[t]);
     }
+
     for(t=0;t<font->num_glyphs;t++) {
        SRECT bbox = swffont->layout->bounds[t];
 
     for(t=0;t<font->num_glyphs;t++) {
        SRECT bbox = swffont->layout->bounds[t];
 
@@ -2912,6 +2923,7 @@ static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, const char* id, int version)
     if(font->descent*20 > swffont->layout->descent)
        swffont->layout->descent = font->descent*20;
 
     if(font->descent*20 > swffont->layout->descent)
        swffont->layout->descent = font->descent*20;
 
+    swf_FontSort(swffont);
     return swffont;
 }
 
     return swffont;
 }
 
@@ -3066,6 +3078,7 @@ static void swf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*
        msg("<warning> No character %d in font %s (%d chars)", glyph, FIXNULL((char*)i->swffont->name), i->swffont->numchars);
        return;
     }
        msg("<warning> No character %d in font %s (%d chars)", glyph, FIXNULL((char*)i->swffont->name), i->swffont->numchars);
        return;
     }
+    glyph = i->swffont->glyph2glyph[glyph];
     
     setfontscale(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11, matrix->tx, matrix->ty, 0);
     
     
     setfontscale(dev, matrix->m00, matrix->m01, matrix->m10, matrix->m11, matrix->tx, matrix->ty, 0);
     
index aee2fae..c16cf05 100644 (file)
@@ -116,7 +116,7 @@ static FT_Outline_Funcs outline_functions =
 
 static FT_Library ftlibrary = 0;
 
 
 static FT_Library ftlibrary = 0;
 
-SWFFONT* swf_LoadTrueTypeFont(const char*filename)
+SWFFONT* swf_LoadTrueTypeFont(const char*filename, char flashtype)
 {
     FT_Face face;
     FT_Error error;
 {
     FT_Face face;
     FT_Error error;
@@ -141,8 +141,9 @@ SWFFONT* swf_LoadTrueTypeFont(const char*filename)
        fprintf(stderr, "Couldn't load file %s- not a TTF file?\n", filename);
        return 0;
     }
        fprintf(stderr, "Couldn't load file %s- not a TTF file?\n", filename);
        return 0;
     }
-    
-    FT_Set_Pixel_Sizes (face, 16*loadfont_scale, 16*loadfont_scale);
+   
+    int scale = flashtype?20:1;
+    FT_Set_Pixel_Sizes (face, 16*loadfont_scale*scale, 16*loadfont_scale*scale);
 
     if(face->num_glyphs <= 0) {
        fprintf(stderr, "File %s contains %d glyphs\n", face->num_glyphs);
 
     if(face->num_glyphs <= 0) {
        fprintf(stderr, "File %s contains %d glyphs\n", face->num_glyphs);
@@ -151,7 +152,8 @@ SWFFONT* swf_LoadTrueTypeFont(const char*filename)
 
     font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
     font->id = -1;
 
     font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
     font->id = -1;
-    font->version = 2;
+    font->version = flashtype?3:2;
+
     font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
     font->layout->bounds = (SRECT*)rfx_calloc(face->num_glyphs*sizeof(SRECT));
     font->style =  ((face->style_flags&FT_STYLE_FLAG_ITALIC)?FONT_STYLE_ITALIC:0)
     font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
     font->layout->bounds = (SRECT*)rfx_calloc(face->num_glyphs*sizeof(SRECT));
     font->style =  ((face->style_flags&FT_STYLE_FLAG_ITALIC)?FONT_STYLE_ITALIC:0)
@@ -352,12 +354,13 @@ SWFFONT* swf_LoadTrueTypeFont(const char*filename)
     else
        font->layout->ascent = -fontbbox.ymin;
 
     else
        font->layout->ascent = -fontbbox.ymin;
 
-    if(-fontbbox.ymax < 0)
+    if(fontbbox.ymax < 0)
         font->layout->descent = 0;
     else
         font->layout->descent = 0;
     else
-       font->layout->descent = -fontbbox.ymax;
+       font->layout->descent = fontbbox.ymax;
 
 
-    font->layout->leading = fontbbox.ymax - fontbbox.ymin;
+    int leading = fontbbox.ymax - fontbbox.ymin;
+    font->layout->leading = leading>0x7fff?0x7fff:leading;
 
     /* notice: if skip_unused is true, font->glyph2ascii, font->glyphnames and font->layout->bounds will 
               have more memory allocated than just font->numchars, but only the first font->numchars 
 
     /* notice: if skip_unused is true, font->glyph2ascii, font->glyphnames and font->layout->bounds will 
               have more memory allocated than just font->numchars, but only the first font->numchars 
@@ -377,7 +380,7 @@ SWFFONT* swf_LoadTrueTypeFont(const char*filename)
 }
 #else  //HAVE_FREETYPE
 
 }
 #else  //HAVE_FREETYPE
 
-SWFFONT* swf_LoadTrueTypeFont(const char*filename)
+SWFFONT* swf_LoadTrueTypeFont(const char*filename, char flashtype)
 {
     fprintf(stderr, "Warning: no freetype library- not able to load %s\n", filename);
     return 0;
 {
     fprintf(stderr, "Warning: no freetype library- not able to load %s\n", filename);
     return 0;
@@ -575,7 +578,7 @@ static int isSWF(const char*filename)
     return 0;
 }
 
     return 0;
 }
 
-SWFFONT* swf_LoadFont(const char*filename)
+SWFFONT* swf_LoadFont(const char*filename, char flashtype)
 {
     int is_swf;
     if(filename == 0)
 {
     int is_swf;
     if(filename == 0)
@@ -584,11 +587,14 @@ SWFFONT* swf_LoadFont(const char*filename)
     if(is_swf<0)
        return 0;
     if(is_swf) {
     if(is_swf<0)
        return 0;
     if(is_swf) {
-       return swf_ReadFont(filename);
+       SWFFONT*font = swf_ReadFont(filename);
+       if(flashtype && font->version==2)
+           fprintf(stderr, "Warning: Can't load font v2 file as flashtype (%s)\n", filename);
+       return font;
     }
 
 #if defined(HAVE_FREETYPE)
     }
 
 #if defined(HAVE_FREETYPE)
-    return swf_LoadTrueTypeFont(filename);
+    return swf_LoadTrueTypeFont(filename, flashtype);
 #elif defined(HAVE_T1LIB)
     return swf_LoadT1Font(filename);
 #else
 #elif defined(HAVE_T1LIB)
     return swf_LoadT1Font(filename);
 #else
index cb2624e..41207bf 100644 (file)
@@ -832,6 +832,12 @@ int swf_FontReduce(SWFFONT * f)
     return 0;
 }
 
     return 0;
 }
 
+static SWFFONT* font_to_sort;
+int cmp_chars(const void*a, const void*b)
+{
+    int x = *(const int*)a;
+    int y = *(const int*)b;
+}
 void swf_FontSort(SWFFONT * font)
 {
     int i, j;
 void swf_FontSort(SWFFONT * font)
 {
     int i, j;
@@ -845,6 +851,8 @@ void swf_FontSort(SWFFONT * font)
     for (i = 0; i < font->numchars; i++) {
        newplace[i] = i;
     }
     for (i = 0; i < font->numchars; i++) {
        newplace[i] = i;
     }
+    //qsort(newplace, sizeof(newplace[0]), font->numchars, cmp_chars);
+
     for (i = 0; i < font->numchars; i++)
        for (j = 0; j < i; j++) {
            if (font->glyph2ascii[i] < font->glyph2ascii[j]) {
     for (i = 0; i < font->numchars; i++)
        for (j = 0; j < i; j++) {
            if (font->glyph2ascii[i] < font->glyph2ascii[j]) {
@@ -887,8 +895,8 @@ void swf_FontSort(SWFFONT * font)
            font->ascii2glyph[i] = newpos[font->ascii2glyph[i]];
     }
 
            font->ascii2glyph[i] = newpos[font->ascii2glyph[i]];
     }
 
-    rfx_free(newpos);
     rfx_free(newplace);
     rfx_free(newplace);
+    font->glyph2glyph = newpos;
 }
 
 void swf_FontPrepareForEditText(SWFFONT * font)
 }
 
 void swf_FontPrepareForEditText(SWFFONT * font)
@@ -932,14 +940,14 @@ int swf_FontUse(SWFFONT * f, U8 * s)
     return 0;
 }
 
     return 0;
 }
 
-int swf_FontUseUTF8(SWFFONT * f, U8 * s, U16 size)
+int swf_FontUseUTF8(SWFFONT * f, const U8 * s, U16 size)
 {
     if( (!s))
        return -1;
     int ascii;
     while (*s)
     {
 {
     if( (!s))
        return -1;
     int ascii;
     while (*s)
     {
-       ascii = readUTF8char(&s);
+       ascii = readUTF8char((U8**)&s);
        if(ascii < f->maxascii && f->ascii2glyph[ascii]>=0)
            swf_FontUseGlyph(f, f->ascii2glyph[ascii], size);
     }
        if(ascii < f->maxascii && f->ascii2glyph[ascii]>=0)
            swf_FontUseGlyph(f, f->ascii2glyph[ascii], size);
     }
@@ -1188,12 +1196,15 @@ int swf_FontSetDefine2(TAG * tag, SWFFONT * f)
     if (f->layout) {
        swf_SetU16(tag, f->layout->ascent);
        swf_SetU16(tag, f->layout->descent);
     if (f->layout) {
        swf_SetU16(tag, f->layout->ascent);
        swf_SetU16(tag, f->layout->descent);
-       swf_SetU16(tag, f->layout->leading);
+       swf_SetU16(tag, 0); // flash ignores leading
+
        for (t = 0; t < f->numchars; t++)
            swf_SetU16(tag, f->glyph[t].advance);
        for (t = 0; t < f->numchars; t++) {
            swf_ResetWriteBits(tag);
        for (t = 0; t < f->numchars; t++)
            swf_SetU16(tag, f->glyph[t].advance);
        for (t = 0; t < f->numchars; t++) {
            swf_ResetWriteBits(tag);
-           swf_SetRect(tag, &f->layout->bounds[t]);
+           /* not used by flash, so leave this empty */
+           SRECT b = {0,0,0,0};
+           swf_SetRect(tag, &b);
        }
        swf_SetU16(tag, f->layout->kerningcount);
        for (t = 0; t < f->layout->kerningcount; t++) {
        }
        swf_SetU16(tag, f->layout->kerningcount);
        for (t = 0; t < f->layout->kerningcount; t++) {
@@ -1299,6 +1310,10 @@ void swf_FontFree(SWFFONT * f)
         rfx_free(f->glyph2ascii);
         f->glyph2ascii = NULL;
     }
         rfx_free(f->glyph2ascii);
         f->glyph2ascii = NULL;
     }
+    if (f->glyph2glyph) {
+       rfx_free(f->glyph2glyph);
+       f->glyph2glyph = NULL;
+    }
     font_freename(f);
     font_freelayout(f);
     font_freeglyphnames(f);
     font_freename(f);
     font_freelayout(f);
     font_freeglyphnames(f);
index 5bfeb5d..c2cf0e3 100644 (file)
@@ -520,7 +520,7 @@ typedef struct _KERNING
 typedef struct _SWFLAYOUT
 { U16          ascent;
   U16          descent;
 typedef struct _SWFLAYOUT
 { U16          ascent;
   U16          descent;
-  S16          leading;
+  U16          leading;
   SRECT      * bounds;
   U16         kerningcount;
   SWFKERNING * kerning;
   SRECT      * bounds;
   U16         kerningcount;
   SWFKERNING * kerning;
@@ -570,7 +570,7 @@ typedef struct _ALIGNZONE
 
 typedef struct _SWFFONT
 { int          id; // -1 = not set
 
 typedef struct _SWFFONT
 { int          id; // -1 = not set
-  U8           version; // 0 = not set, 1 = definefont, 2 = definefont2
+  U8           version; // 0 = not set, 1 = definefont, 2 = definefont2, 3 = definefont3
   U8 *          name;
   SWFLAYOUT *   layout;
   int           numchars;
   U8 *          name;
   SWFLAYOUT *   layout;
   int           numchars;
@@ -581,6 +581,7 @@ typedef struct _SWFFONT
 
   U16  *       glyph2ascii;
   int  *       ascii2glyph;
 
   U16  *       glyph2ascii;
   int  *       ascii2glyph;
+  int   *       glyph2glyph; // only if the font is resorted
   SWFGLYPH *   glyph;
   ALIGNZONE *  alignzones;
   U8            alignzone_flags;
   SWFGLYPH *   glyph;
   ALIGNZONE *  alignzones;
   U8            alignzone_flags;
@@ -648,8 +649,9 @@ int swf_FontUseGlyph(SWFFONT * f, int glyph, U16 size);
 void swf_FontUsePair(SWFFONT * f, int char1, int char2);
 int swf_FontUseGetPair(SWFFONT * f, int char1, int char2);
 int swf_FontUseAll(SWFFONT* f);
 void swf_FontUsePair(SWFFONT * f, int char1, int char2);
 int swf_FontUseGetPair(SWFFONT * f, int char1, int char2);
 int swf_FontUseAll(SWFFONT* f);
-int swf_FontUseUTF8(SWFFONT * f, U8 * s, U16 size);
+int swf_FontUseUTF8(SWFFONT * f, const U8 * s, U16 size);
 int swf_FontUse(SWFFONT* f,U8 * s);
 int swf_FontUse(SWFFONT* f,U8 * s);
+void swf_FontSort(SWFFONT * font);
 
 int swf_FontSetDefine(TAG * t,SWFFONT * f);
 int swf_FontSetDefine2(TAG * t,SWFFONT * f);
 
 int swf_FontSetDefine(TAG * t,SWFFONT * f);
 int swf_FontSetDefine2(TAG * t,SWFFONT * f);
@@ -690,9 +692,9 @@ void swf_DrawText(drawer_t*draw, SWFFONT*font, int size, const char*text);
 
 // swffont.c
 
 
 // swffont.c
 
-SWFFONT* swf_LoadTrueTypeFont(const char*filename);
+SWFFONT* swf_LoadTrueTypeFont(const char*filename, char flashtype);
 SWFFONT* swf_LoadT1Font(const char*filename);
 SWFFONT* swf_LoadT1Font(const char*filename);
-SWFFONT* swf_LoadFont(const char*filename);
+SWFFONT* swf_LoadFont(const char*filename, char flashtype);
 
 void swf_SetLoadFontParameters(int scale, int skip_unused, int full_unicode);
 
 
 void swf_SetLoadFontParameters(int scale, int skip_unused, int full_unicode);
 
index c8827c1..42db7f4 100644 (file)
@@ -877,7 +877,7 @@ static void free_filterlist(FILTERLIST* f_list)
     int i;
     for (i = 0; i < f_list->num; i++)
     {
     int i;
     for (i = 0; i < f_list->num; i++)
     {
-        if (f_list->filter[i]->type == FILTERTYPE_GRADIENTGLOW)
+        if(f_list->filter[i]->type == FILTERTYPE_GRADIENTGLOW)
             gradient_free(((FILTER_GRADIENTGLOW*)f_list->filter[i])->gradient);
         free(f_list->filter[i]);
     }
             gradient_free(((FILTER_GRADIENTGLOW*)f_list->filter[i])->gradient);
         free(f_list->filter[i]);
     }
@@ -924,7 +924,7 @@ void setPlacement(TAG*tag, U16 id, U16 depth, MATRIX m, const char*name, paramet
     if(p->blendmode) {
     po.blendmode = p->blendmode;
     }
     if(p->blendmode) {
     po.blendmode = p->blendmode;
     }
-    if (p->filters)
+    if(p->filters)
        po.filters = p->filters;
     swf_SetPlaceObject(tag, &po);
 }
        po.filters = p->filters;
     swf_SetPlaceObject(tag, &po);
 }
@@ -942,7 +942,7 @@ static void writeInstance(void* _i)
         frame++;
         while (tag && tag->id != ST_SHOWFRAME)
             tag = tag->next;
         frame++;
         while (tag && tag->id != ST_SHOWFRAME)
             tag = tag->next;
-        if (parametersChange(i->history, frame))
+        if(parametersChange(i->history, frame))
         {
             readParameters(i->history, &p, frame);
             m = s_instancepos(i->character->size, &p);
         {
             readParameters(i->history, &p, frame);
             m = s_instancepos(i->character->size, &p);
@@ -952,7 +952,7 @@ static void writeInstance(void* _i)
             else
                tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
             setPlacement(tag, 0, i->depth, m, 0, &p, 1);
             else
                tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
             setPlacement(tag, 0, i->depth, m, 0, &p, 1);
-            if (p.filters)
+            if(p.filters)
                free_filterlist(p.filters);
         } else if(tag) {
             tag = tag->next;
                free_filterlist(p.filters);
         } else if(tag) {
             tag = tag->next;
@@ -1057,9 +1057,9 @@ static void s_endSWF()
         tag = swf_InsertTag(tag, ST_DOABC);
         void*code = as3_getcode();
         swf_WriteABC(tag, code);
         tag = swf_InsertTag(tag, ST_DOABC);
         void*code = as3_getcode();
         swf_WriteABC(tag, code);
-        if (*mainclass)
+        if(*mainclass)
             mc = mainclass;
             mc = mainclass;
-        else if (as3_getglobalclass())
+        else if(as3_getglobalclass())
             mc = as3_getglobalclass();
         if(*mc) {
             tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
             mc = as3_getglobalclass();
         if(*mc) {
             tag = swf_InsertTag(tag, ST_SYMBOLCLASS);
@@ -1174,7 +1174,7 @@ int addFillStyle(SHAPE*s, SRECT*r, const char*name)
     if(name[0] == '#') {
        parseColor2(name, &color);
        return swf_ShapeAddSolidFillStyle(s, &color);
     if(name[0] == '#') {
        parseColor2(name, &color);
        return swf_ShapeAddSolidFillStyle(s, &color);
-    } else if ((texture = dict_lookup(&textures, name))) {
+    } else if((texture = dict_lookup(&textures, name))) {
        return swf_ShapeAddFillStyle2(s, &texture->fs);
     } else if((image = dict_lookup(&images, name))) {
        MATRIX m;
        return swf_ShapeAddFillStyle2(s, &texture->fs);
     } else if((image = dict_lookup(&images, name))) {
        MATRIX m;
@@ -1184,7 +1184,7 @@ int addFillStyle(SHAPE*s, SRECT*r, const char*name)
        m.tx = r->xmin;
        m.ty = r->ymin;
        return swf_ShapeAddBitmapFillStyle(s, &m, image->id, 0);
        m.tx = r->xmin;
        m.ty = r->ymin;
        return swf_ShapeAddBitmapFillStyle(s, &m, image->id, 0);
-    }  else if ((gradient = dict_lookup(&gradients, name))) {
+    }  else if((gradient = dict_lookup(&gradients, name))) {
        SRECT r2;
        MATRIX rot,m;
        double ccos,csin;
        SRECT r2;
        MATRIX rot,m;
        double ccos,csin;
@@ -1204,7 +1204,7 @@ int addFillStyle(SHAPE*s, SRECT*r, const char*name)
        m.tx = r->xmin + (r->xmax - r->xmin)/2;
        m.ty = r->ymin + (r->ymax - r->ymin)/2;
        return swf_ShapeAddGradientFillStyle(s, &m, &gradient->gradient, gradient->radial);
        m.tx = r->xmin + (r->xmax - r->xmin)/2;
        m.ty = r->ymin + (r->ymax - r->ymin)/2;
        return swf_ShapeAddGradientFillStyle(s, &m, &gradient->gradient, gradient->radial);
-    }  else if (parseColor2(name, &color)) {
+    }  else if(parseColor2(name, &color)) {
        return swf_ShapeAddSolidFillStyle(s, &color);
     } else {
        syntaxerror("not a color/fillstyle: %s", name);
        return swf_ShapeAddSolidFillStyle(s, &color);
     } else {
        syntaxerror("not a color/fillstyle: %s", name);
@@ -1589,24 +1589,49 @@ void s_texture(const char*name, const char*object, int x, int y, float scalex, f
     dict_put(&textures, name, texture);
 }
 
     dict_put(&textures, name, texture);
 }
 
+void s_createfont(const char*name, const char*filename, const char*glyphs, char flashtype)
+{
+    if(dict_lookup(&fonts, name))
+       syntaxerror("font %s defined twice", name);
+
+    SWFFONT* font = swf_LoadFont(filename, flashtype);
+    if(font == 0) {
+       warning("Couldn't open font file \"%s\"", filename);
+       font = (SWFFONT*)malloc(sizeof(SWFFONT));
+       memset(font, 0, sizeof(SWFFONT));
+       dict_put(&fonts, name, font);
+       return;
+    }
+    swf_FontPrepareForEditText(font);
+
+    if(!strcmp(glyphs, "all")) {
+       swf_FontUseAll(font);
+       font->use->glyphs_specified = 1;
+    } else {
+       if(!glyphs[0]) {
+           swf_FontInitUsage(font);
+       } else {
+           swf_FontUseUTF8(font, (const U8*)glyphs, 0xffff);
+           font->use->glyphs_specified = 1;
+       }
+    }
+    dict_put(&fonts, name, font);
+}
+
 void s_font(const char*name, const char*filename)
 {
     SWFFONT* font;
     font = dict_lookup(&fonts, name);
 void s_font(const char*name, const char*filename)
 {
     SWFFONT* font;
     font = dict_lookup(&fonts, name);
-    if(0)
-    {
-       /* fix the layout. Only needed for old fonts */
-       int t;
-       for(t=0;t<font->numchars;t++) {
-           font->glyph[t].advance = 0;
-       }
-       font->layout = 0;
-       swf_FontCreateLayout(font);
-    }
     font->id = id;
     swf_FontReduce_swfc(font);
     font->id = id;
     swf_FontReduce_swfc(font);
-    tag = swf_InsertTag(tag, ST_DEFINEFONT2);
+       
+    if(font->version>=3 && stack[0].swf->fileVersion < 8) {
+       warning("flashtype not supported for flash versions 8 and below");
+    }
+
+    tag = swf_InsertTag(tag, font->version==3?ST_DEFINEFONT3:ST_DEFINEFONT2);
     swf_FontSetDefine2(tag, font);
     swf_FontSetDefine2(tag, font);
+
     if(do_exports) {
        tag = swf_InsertTag(tag, ST_EXPORTASSETS);
        swf_SetU16(tag, 1);
     if(do_exports) {
        tag = swf_InsertTag(tag, ST_EXPORTASSETS);
        swf_SetU16(tag, 1);
@@ -1712,7 +1737,7 @@ void s_sound(const char*name, const char*filename)
 
     incrementid();
 
 
     incrementid();
 
-    if (samples)
+    if(samples)
         free(samples);
 }
 
         free(samples);
 }
 
@@ -1785,7 +1810,7 @@ GRADIENT parseGradient(const char*str)
 
 FILTERLIST* parseFilters(char* list)
 {
 
 FILTERLIST* parseFilters(char* list)
 {
-    if (!strcmp(list, "no_filters"))
+    if(!strcmp(list, "no_filters"))
        return 0;
     FILTER* f;
     FILTERLIST* f_list = (FILTERLIST*)malloc(sizeof(FILTERLIST));
        return 0;
     FILTER* f;
     FILTERLIST* f_list = (FILTERLIST*)malloc(sizeof(FILTERLIST));
@@ -1795,22 +1820,22 @@ FILTERLIST* parseFilters(char* list)
     while (f_start)
     {
        f_end = strchr(f_start, ',');
     while (f_start)
     {
        f_end = strchr(f_start, ',');
-       if (f_end)
+       if(f_end)
            *f_end = '\0';
        f = dict_lookup(&filters, f_start);
            *f_end = '\0';
        f = dict_lookup(&filters, f_start);
-       if (!f)
+       if(!f)
        {
            free(f_list);
            syntaxerror("unknown filter %s", f_start);
        }
        {
            free(f_list);
            syntaxerror("unknown filter %s", f_start);
        }
-       if (f_list->num == 8)
+       if(f_list->num == 8)
        {
            warning("too many filters in filterlist, no more than 8 please, rest ignored");
            break;
        }
        f_list->filter[f_list->num] = f;
        f_list->num++;
        {
            warning("too many filters in filterlist, no more than 8 please, rest ignored");
            break;
        }
        f_list->filter[f_list->num] = f;
        f_list->num++;
-       if (f_end)
+       if(f_end)
        {
            *f_end = ',';
            f_start = f_end + 1;
        {
            *f_end = ',';
            f_start = f_end + 1;
@@ -2043,12 +2068,12 @@ void s_includeswf(const char*name, const char*filename)
     int level = 0;
     U16 cutout[] = {ST_SETBACKGROUNDCOLOR, ST_PROTECT, ST_FREEALL, ST_REFLEX};
     f = open(filename,O_RDONLY|O_BINARY);
     int level = 0;
     U16 cutout[] = {ST_SETBACKGROUNDCOLOR, ST_PROTECT, ST_FREEALL, ST_REFLEX};
     f = open(filename,O_RDONLY|O_BINARY);
-    if (f<0) {
+    if(f<0) {
        warning("Couldn't open file \"%s\": %s", filename, strerror(errno));
        s_box(name, 0, 0, black, 20, 0);
        return;
     }
        warning("Couldn't open file \"%s\": %s", filename, strerror(errno));
        s_box(name, 0, 0, black, 20, 0);
        return;
     }
-    if (swf_ReadSWF(f,&swf)<0) {
+    if(swf_ReadSWF(f,&swf)<0) {
        warning("Only SWF files supported in .shape for now. File \"%s\" wasn't SWF.", filename);
        s_box(name, 0, 0, black, 20, 0);
        return;
        warning("Only SWF files supported in .shape for now. File \"%s\" wasn't SWF.", filename);
        s_box(name, 0, 0, black, 20, 0);
        return;
@@ -2125,7 +2150,7 @@ void s_getParameters(const char*name, parameters_t* p)
     instance_t * i = dict_lookup(&instances, name);
     if(!i)
        syntaxerror("instance '%s' unknown(10)", name);
     instance_t * i = dict_lookup(&instances, name);
     if(!i)
        syntaxerror("instance '%s' unknown(10)", name);
-    if (change_sets_all)
+    if(change_sets_all)
         readParameters(i->history, p, currentframe);
     else
        *p = i->parameters;
         readParameters(i->history, p, currentframe);
     else
        *p = i->parameters;
@@ -2224,51 +2249,51 @@ void s_put(const char*instance, const char*character, parameters_t p)
 
 void recordChanges(history_t* history, parameters_t p, int changeFunction, interpolation_t* inter)
 {
 
 void recordChanges(history_t* history, parameters_t p, int changeFunction, interpolation_t* inter)
 {
-    if (p.set & SF_X)
+    if(p.set & SF_X)
         history_remember(history, "x", currentframe, changeFunction, p.x, inter);
         history_remember(history, "x", currentframe, changeFunction, p.x, inter);
-    if (p.set & SF_Y)
+    if(p.set & SF_Y)
         history_remember(history, "y", currentframe, changeFunction, p.y, inter);
         history_remember(history, "y", currentframe, changeFunction, p.y, inter);
-    if (p.set & SF_SCALEX)
+    if(p.set & SF_SCALEX)
         history_remember(history, "scalex", currentframe, changeFunction, p.scalex, inter);
         history_remember(history, "scalex", currentframe, changeFunction, p.scalex, inter);
-    if (p.set & SF_SCALEY)
+    if(p.set & SF_SCALEY)
         history_remember(history, "scaley", currentframe, changeFunction, p.scaley, inter);
         history_remember(history, "scaley", currentframe, changeFunction, p.scaley, inter);
-    if (p.set & SF_CX_R)
+    if(p.set & SF_CX_R)
     {
         history_remember(history, "cxform.r0", currentframe, changeFunction, p.cxform.r0, inter);
         history_remember(history, "cxform.r1", currentframe, changeFunction, p.cxform.r1, inter);
     }
     {
         history_remember(history, "cxform.r0", currentframe, changeFunction, p.cxform.r0, inter);
         history_remember(history, "cxform.r1", currentframe, changeFunction, p.cxform.r1, inter);
     }
-    if (p.set & SF_CX_G)
+    if(p.set & SF_CX_G)
     {
         history_remember(history, "cxform.g0", currentframe, changeFunction, p.cxform.g0, inter);
         history_remember(history, "cxform.g1", currentframe, changeFunction, p.cxform.g1, inter);
     }
     {
         history_remember(history, "cxform.g0", currentframe, changeFunction, p.cxform.g0, inter);
         history_remember(history, "cxform.g1", currentframe, changeFunction, p.cxform.g1, inter);
     }
-    if (p.set & SF_CX_B)
+    if(p.set & SF_CX_B)
     {
         history_remember(history, "cxform.b0", currentframe, changeFunction, p.cxform.b0, inter);
         history_remember(history, "cxform.b1", currentframe, changeFunction, p.cxform.b1, inter);
     }
     {
         history_remember(history, "cxform.b0", currentframe, changeFunction, p.cxform.b0, inter);
         history_remember(history, "cxform.b1", currentframe, changeFunction, p.cxform.b1, inter);
     }
-    if (p.set & SF_CX_A)
+    if(p.set & SF_CX_A)
     {
         history_remember(history, "cxform.a0", currentframe, changeFunction, p.cxform.a0, inter);
         history_remember(history, "cxform.a1", currentframe, changeFunction, p.cxform.a1, inter);
     }
     {
         history_remember(history, "cxform.a0", currentframe, changeFunction, p.cxform.a0, inter);
         history_remember(history, "cxform.a1", currentframe, changeFunction, p.cxform.a1, inter);
     }
-    if (p.set & SF_ROTATE)
+    if(p.set & SF_ROTATE)
         history_remember(history, "rotate", currentframe, changeFunction, p.rotate, inter);
         history_remember(history, "rotate", currentframe, changeFunction, p.rotate, inter);
-    if (p.set & SF_SHEAR)
+    if(p.set & SF_SHEAR)
         history_remember(history, "shear", currentframe, changeFunction, p.shear, inter);
         history_remember(history, "shear", currentframe, changeFunction, p.shear, inter);
-    if (p.set & SF_PIVOT)
+    if(p.set & SF_PIVOT)
     {
         history_remember(history, "pivot.x", currentframe, changeFunction, p.pivot.x, inter);
         history_remember(history, "pivot.y", currentframe, changeFunction, p.pivot.y, inter);
     }
     {
         history_remember(history, "pivot.x", currentframe, changeFunction, p.pivot.x, inter);
         history_remember(history, "pivot.y", currentframe, changeFunction, p.pivot.y, inter);
     }
-    if (p.set & SF_PIN)
+    if(p.set & SF_PIN)
     {
         history_remember(history, "pin.x", currentframe, changeFunction, p.pin.x, inter);
         history_remember(history, "pin.y", currentframe, changeFunction, p.pin.y, inter);
     }
     {
         history_remember(history, "pin.x", currentframe, changeFunction, p.pin.x, inter);
         history_remember(history, "pin.y", currentframe, changeFunction, p.pin.y, inter);
     }
-    if (p.set & SF_BLEND)
+    if(p.set & SF_BLEND)
         history_remember(history, "blendmode", currentframe, changeFunction, p.blendmode, inter);
         history_remember(history, "blendmode", currentframe, changeFunction, p.blendmode, inter);
-    if (p.set & SF_FILTER)
+    if(p.set & SF_FILTER)
         history_rememberFilter(history, currentframe, changeFunction, p.filters, inter);
 }
 
         history_rememberFilter(history, currentframe, changeFunction, p.filters, inter);
 }
 
@@ -2299,7 +2324,7 @@ void s_sweep(const char* instance, parameters_t p, float radius, int clockwise,
 void s_toggle(const char* instance, U16 flagsOn, U16 flagsOff)
 {
     instance_t* i = dict_lookup(&instances, instance);
 void s_toggle(const char* instance, U16 flagsOn, U16 flagsOff)
 {
     instance_t* i = dict_lookup(&instances, instance);
-    if (!i)
+    if(!i)
         syntaxerror("instance %s not known", instance);
     U16 flags = (U16)history_value(i->history, currentframe, "flags");
     flags |= flagsOn;
         syntaxerror("instance %s not known", instance);
     U16 flags = (U16)history_value(i->history, currentframe, "flags");
     flags |= flagsOn;
@@ -2594,9 +2619,9 @@ int parseTwip(const char*str)
 
 int parseArc(const char* str)
 {
 
 int parseArc(const char* str)
 {
-    if (!strcmp(str, "short"))
+    if(!strcmp(str, "short"))
        return 1;
        return 1;
-    if (!strcmp(str, "long"))
+    if(!strcmp(str, "long"))
        return 0;
     syntaxerror("invalid value for the arc parameter: %s", str);
     return 1;
        return 0;
     syntaxerror("invalid value for the arc parameter: %s", str);
     return 1;
@@ -2604,9 +2629,9 @@ int parseArc(const char* str)
 
 int parseDir(const char* str)
 {
 
 int parseDir(const char* str)
 {
-    if (!strcmp(str, "clockwise"))
+    if(!strcmp(str, "clockwise"))
        return 1;
        return 1;
-    if (!strcmp(str, "counterclockwise"))
+    if(!strcmp(str, "counterclockwise"))
        return 0;
     syntaxerror("invalid value for the dir parameter: %s", str);
     return 1;
        return 0;
     syntaxerror("invalid value for the dir parameter: %s", str);
     return 1;
@@ -2869,19 +2894,19 @@ static int c_interpolation(map_t *args)
 {
     int i;
     const char* name = lu(args, "name");
 {
     int i;
     const char* name = lu(args, "name");
-    if (dict_lookup(&interpolations, name))
+    if(dict_lookup(&interpolations, name))
         syntaxerror("interpolation %s defined twice", name);
 
     interpolation_t* inter = (interpolation_t*)malloc(sizeof(interpolation_t));
     const char* functionstr = lu(args, "function");
     inter->function = 0;
     for (i = 0; i < sizeof(interpolationFunctions) / sizeof(interpolationFunctions[0]); i++)
         syntaxerror("interpolation %s defined twice", name);
 
     interpolation_t* inter = (interpolation_t*)malloc(sizeof(interpolation_t));
     const char* functionstr = lu(args, "function");
     inter->function = 0;
     for (i = 0; i < sizeof(interpolationFunctions) / sizeof(interpolationFunctions[0]); i++)
-        if (!strcmp(functionstr,interpolationFunctions[i]))
+        if(!strcmp(functionstr,interpolationFunctions[i]))
         {
             inter->function = i + 1;
             break;
         }
         {
             inter->function = i + 1;
             break;
         }
-    if (!inter->function)
+    if(!inter->function)
         syntaxerror("unkown interpolation function %s", functionstr);
     inter->speed = parseFloat(lu(args, "speed"));
     inter->amplitude = parseTwip(lu(args, "amplitude"));
         syntaxerror("unkown interpolation function %s", functionstr);
     inter->speed = parseFloat(lu(args, "speed"));
     inter->amplitude = parseTwip(lu(args, "amplitude"));
@@ -2903,49 +2928,49 @@ SPOINT getPoint(SRECT r, const char*name)
         p.y = (r.ymin + r.ymax)/2;
         return p;
     }
         p.y = (r.ymin + r.ymax)/2;
         return p;
     }
-    if (!strcmp(name, "bottom-center")) {
+    if(!strcmp(name, "bottom-center")) {
         SPOINT p;
         p.x = (r.xmin + r.xmax)/2;
         p.y = r.ymax;
         return p;
     }
         SPOINT p;
         p.x = (r.xmin + r.xmax)/2;
         p.y = r.ymax;
         return p;
     }
-    if (!strcmp(name, "top-center")) {
+    if(!strcmp(name, "top-center")) {
         SPOINT p;
         p.x = (r.xmin + r.xmax)/2;
         p.y = r.ymin;
         return p;
     }
         SPOINT p;
         p.x = (r.xmin + r.xmax)/2;
         p.y = r.ymin;
         return p;
     }
-    if (!strcmp(name, "top-left")) {
+    if(!strcmp(name, "top-left")) {
         SPOINT p;
         p.x = r.xmin;
         p.y = r.ymin;
         return p;
     }
         SPOINT p;
         p.x = r.xmin;
         p.y = r.ymin;
         return p;
     }
-    if (!strcmp(name, "top-right")) {
+    if(!strcmp(name, "top-right")) {
         SPOINT p;
         p.x = r.xmax;
         p.y = r.ymin;
         return p;
     }
         SPOINT p;
         p.x = r.xmax;
         p.y = r.ymin;
         return p;
     }
-    if (!strcmp(name, "bottom-right")) {
+    if(!strcmp(name, "bottom-right")) {
         SPOINT p;
         p.x = r.xmax;
         p.y = r.ymax;
         return p;
     }
         SPOINT p;
         p.x = r.xmax;
         p.y = r.ymax;
         return p;
     }
-    if (!strcmp(name, "bottom-left")) {
+    if(!strcmp(name, "bottom-left")) {
         SPOINT p;
         p.x = r.xmin;
         p.y = r.ymax;
         return p;
     }
         SPOINT p;
         p.x = r.xmin;
         p.y = r.ymax;
         return p;
     }
-    if (!strcmp(name, "left-center")) {
+    if(!strcmp(name, "left-center")) {
         SPOINT p;
         p.x = r.xmin;
         p.y = (r.ymin + r.ymax)/2;
         return p;
     }
         SPOINT p;
         p.x = r.xmin;
         p.y = (r.ymin + r.ymax)/2;
         return p;
     }
-    if (!strcmp(name, "right-center")) {
+    if(!strcmp(name, "right-center")) {
         SPOINT p;
         p.x = r.xmax;
         p.y = (r.ymin + r.ymax)/2;
         SPOINT p;
         p.x = r.xmax;
         p.y = (r.ymin + r.ymax)/2;
@@ -3058,7 +3083,7 @@ static int c_gradient(map_t*args)
 static const char* checkFiltername(map_t* args)
 {
     const char* name = lu(args, "name");
 static const char* checkFiltername(map_t* args)
 {
     const char* name = lu(args, "name");
-    if (strchr(name, ','))
+    if(strchr(name, ','))
        syntaxerror("the comma (,) is used to separate filters in filterlists. Please do not use in filternames.");
     return name;
 }
        syntaxerror("the comma (,) is used to separate filters in filterlists. Please do not use in filternames.");
     return name;
 }
@@ -3302,7 +3327,7 @@ static int c_movement(map_t*args, int type)
         set = set | SF_Y;
     }
 
         set = set | SF_Y;
     }
 
-    if (change_sets_all)
+    if(change_sets_all)
        set = SF_ALL;
     p.set = set;
 
        set = SF_ALL;
     p.set = set;
 
@@ -3312,7 +3337,7 @@ static int c_movement(map_t*args, int type)
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
-                if (!inter)
+                if(!inter)
                     syntaxerror("unkown interpolation %s", interstr);
                 s_change(instance, p, inter);
             }
                     syntaxerror("unkown interpolation %s", interstr);
                 s_change(instance, p, inter);
             }
@@ -3321,7 +3346,7 @@ static int c_movement(map_t*args, int type)
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
-                if (!inter)
+                if(!inter)
                     syntaxerror("unkown interpolation %s", interstr);
                s_schange(instance, p, inter);
             }
                     syntaxerror("unkown interpolation %s", interstr);
                s_schange(instance, p, inter);
             }
@@ -3330,7 +3355,7 @@ static int c_movement(map_t*args, int type)
             {
                const char* rstr = lu(args, "r");
                int radius = parseTwip(rstr);
             {
                const char* rstr = lu(args, "r");
                int radius = parseTwip(rstr);
-               if (radius <= 0)
+               if(radius <= 0)
                        syntaxerror("sweep not possible: radius must be greater than 0.");
                const char* dirstr = lu(args, "dir");
                int clockwise = parseDir(dirstr);
                        syntaxerror("sweep not possible: radius must be greater than 0.");
                const char* dirstr = lu(args, "dir");
                int clockwise = parseDir(dirstr);
@@ -3338,7 +3363,7 @@ static int c_movement(map_t*args, int type)
                int short_arc = parseArc(arcstr);
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
                int short_arc = parseArc(arcstr);
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
-                if (!inter)
+                if(!inter)
                     syntaxerror("unkown interpolation %s", interstr);
                s_sweep(instance, p, radius, clockwise, short_arc, inter);
             }
                     syntaxerror("unkown interpolation %s", interstr);
                s_sweep(instance, p, radius, clockwise, short_arc, inter);
             }
@@ -3409,7 +3434,7 @@ static int c_placement(map_t*args, int type)
        // put or startclip
        character = lu(args, "character");
        parameters_clear(&p);
        // put or startclip
        character = lu(args, "character");
        parameters_clear(&p);
-    } else if (type == PT_BUTTON) {
+    } else if(type == PT_BUTTON) {
        character = lu(args, "name");
        parameters_clear(&p);
        // button's show
        character = lu(args, "name");
        parameters_clear(&p);
        // button's show
@@ -3592,13 +3617,13 @@ static int c_placement(map_t*args, int type)
         set = set | SF_FILTER;
     }
 
         set = set | SF_FILTER;
     }
 
-    if (type == PT_CHANGE && set & (SF_X | SF_Y))
+    if(type == PT_CHANGE && set & (SF_X | SF_Y))
        warning("As of version 0.8.2 using the .change command to modify an \
 object's position on the stage is considered deprecated. Future \
 versions may consider x and y parameters for the .change command \
 to be illegal; please use the .move command.");
 
        warning("As of version 0.8.2 using the .change command to modify an \
 object's position on the stage is considered deprecated. Future \
 versions may consider x and y parameters for the .change command \
 to be illegal; please use the .move command.");
 
-    if (change_sets_all)
+    if(change_sets_all)
        set = SF_ALL;
     p.set = set;
 
        set = SF_ALL;
     p.set = set;
 
@@ -3611,7 +3636,7 @@ to be illegal; please use the .move command.");
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
-                if (!inter)
+                if(!inter)
                     syntaxerror("unkown interpolation %s", interstr);
                 s_change(instance, p, inter);
             }
                     syntaxerror("unkown interpolation %s", interstr);
                 s_change(instance, p, inter);
             }
@@ -3620,7 +3645,7 @@ to be illegal; please use the .move command.");
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
             {
                 const char* interstr = lu(args, "interpolation");
                 interpolation_t* inter = (interpolation_t*)dict_lookup(&interpolations, interstr);
-                if (!inter)
+                if(!inter)
                     syntaxerror("unkown interpolation %s", interstr);
                s_schange(instance, p, inter);
             }
                     syntaxerror("unkown interpolation %s", interstr);
                s_schange(instance, p, inter);
             }
@@ -3648,7 +3673,7 @@ static int c_put(map_t*args)
 }
 static int c_change(map_t*args)
 {
 }
 static int c_change(map_t*args)
 {
-    if (currentframe == 0)
+    if(currentframe == 0)
         warning("change commands in frame 1 will be ignored, please use the put command to set object parameters");
     c_placement(args, PT_CHANGE);
     return 0;
         warning("change commands in frame 1 will be ignored, please use the put command to set object parameters");
     c_placement(args, PT_CHANGE);
     return 0;
@@ -3698,10 +3723,10 @@ static int c_toggle(map_t* args)
     const char*instance = lu(args, "name");
     U16 flagsOn = 0x0000, flagsOff = 0xffff;
     const char* alignstr = lu(args, "fixed_alignment");
     const char*instance = lu(args, "name");
     U16 flagsOn = 0x0000, flagsOff = 0xffff;
     const char* alignstr = lu(args, "fixed_alignment");
-    if (!strcmp(alignstr, "on"))
+    if(!strcmp(alignstr, "on"))
        flagsOn += IF_FIXED_ALIGNMENT;
     else
        flagsOn += IF_FIXED_ALIGNMENT;
     else
-       if (!strcmp(alignstr, "off"))
+       if(!strcmp(alignstr, "off"))
            flagsOff -= IF_FIXED_ALIGNMENT;
        else
            syntaxerror("values for toggle must be \"on\" or \"off\". %s is not legal.", alignstr);
            flagsOff -= IF_FIXED_ALIGNMENT;
        else
            syntaxerror("values for toggle must be \"on\" or \"off\". %s is not legal.", alignstr);
@@ -3787,9 +3812,9 @@ static int c_primitive(map_t*args)
     if(type==0) {
        width = parseTwip(lu(args, "width"));
        height = parseTwip(lu(args, "height"));
     if(type==0) {
        width = parseTwip(lu(args, "width"));
        height = parseTwip(lu(args, "height"));
-    } else if (type==1) {
+    } else if(type==1) {
        r = parseTwip(lu(args, "r"));
        r = parseTwip(lu(args, "r"));
-    } else if (type==2) {
+    } else if(type==2) {
        outline = lu(args, "outline");
     }
 
        outline = lu(args, "outline");
     }
 
@@ -4144,7 +4169,7 @@ static struct {
  {"png", c_image, "name filename"},
  {"movie", c_movie, "name filename"},
  {"sound", c_sound, "name filename"},
  {"png", c_image, "name filename"},
  {"movie", c_movie, "name filename"},
  {"sound", c_sound, "name filename"},
- {"font", c_font, "name filename glyphs="},
+ {"font", c_font, "name filename glyphs= @flashtype="},
  {"soundtrack", c_soundtrack, "filename"},
  {"quicktime", c_quicktime, "url"},
  {"video", c_video, "name width= height="},
  {"soundtrack", c_soundtrack, "filename"},
  {"quicktime", c_quicktime, "url"},
  {"video", c_video, "name width= height="},
@@ -4440,7 +4465,6 @@ static void analyseArgumentsForCommand(char*command)
 {
     int t;
     map_t args;
 {
     int t;
     map_t args;
-    const char* fontfile;
     int nr = -1;
     U8* glyphs_to_include;
     msg("<verbose> analyse Command: %s (line %d)", command, line);
     int nr = -1;
     U8* glyphs_to_include;
     msg("<verbose> analyse Command: %s (line %d)", command, line);
@@ -4459,51 +4483,20 @@ static void analyseArgumentsForCommand(char*command)
     map_dump(&args, stdout, "\t");fflush(stdout);
 #endif
     const char* name = lu(&args, "name");
     map_dump(&args, stdout, "\t");fflush(stdout);
 #endif
     const char* name = lu(&args, "name");
-    if (!strcmp(command, "font"))
-    {
-       if(dict_lookup(&fonts, name))
-            syntaxerror("font %s defined twice", name);
-
-       SWFFONT* font;
-       fontfile = lu(&args, "filename");
-       font = swf_LoadFont(fontfile);
-       if(font == 0) {
-           warning("Couldn't open font file \"%s\"", fontfile);
-           font = (SWFFONT*)malloc(sizeof(SWFFONT));
-           memset(font, 0, sizeof(SWFFONT));
-       }
-       else
-       {
-           swf_FontPrepareForEditText(font);
-           glyphs_to_include = (U8*)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, /*FIXME*/0xffff);
-                   font->use->glyphs_specified = 1;
-               }
-               else
-                   swf_FontInitUsage(font);
-           }
-       }
-       dict_put(&fonts, name, font);
-    }
-    else
+    if(!strcmp(command, "font"))
     {
     {
+       const char* fontfile = lu(&args, "filename");
+       const char* glyphs = lu(&args, "glyphs");
+       const char* flashtype = lu(&args, "flashtype");
+       s_createfont(name, fontfile, glyphs, flashtype[0]);
+    } else {
         SWFFONT* font = dict_lookup(&fonts, lu(&args, "font"));
         SWFFONT* font = dict_lookup(&fonts, lu(&args, "font"));
-        if (!font) {
+        if(!font) {
            //that's ok... it might be an edittext with a system font
             //syntaxerror("font %s is not known in line %d", lu(&args, "font"), line);
        } else
            //that's ok... it might be an edittext with a system font
             //syntaxerror("font %s is not known in line %d", lu(&args, "font"), line);
        } else
-            if (font->use && !font->use->glyphs_specified)
-            {
-               if (!strcmp(command, "edittext"))
+            if(font->use && !font->use->glyphs_specified) {
+               if(!strcmp(command, "edittext"))
                {
                    swf_FontUseAll(font);
                    font->use->glyphs_specified = 1;
                {
                    swf_FontUseAll(font);
                    font->use->glyphs_specified = 1;
@@ -4532,7 +4525,7 @@ void findFontUsage()
         readToken();
         if(type != COMMAND)
             syntaxerror("command expected");
         readToken();
         if(type != COMMAND)
             syntaxerror("command expected");
-        if (strstr(fontRelated, text))
+        if(strstr(fontRelated, text))
             analyseArgumentsForCommand(text);
         else
             if(strcmp(text, "end"))
             analyseArgumentsForCommand(text);
         else
             if(strcmp(text, "end"))