5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
10 This file is distributed under the GPL, see file COPYING for details
14 #define TF_TEXTCONTROL 0x80
15 #define TF_HASFONT 0x08
16 #define TF_HASCOLOR 0x04
17 #define TF_HASYOFFSET 0x02
18 #define TF_HASXOFFSET 0x01
20 #define FF_WIDECODES 0x01
22 #define FF_ITALIC 0x04
24 #define FF_SHIFTJIS 0x10
25 #define FF_UNICODE 0x20
28 #define FF2_ITALIC 0x02
29 #define FF2_WIDECODES 0x04
30 #define FF2_WIDEOFFSETS 0x08
32 #define FF2_UNICODE 0x20
33 #define FF2_SHIFTJIS 0x40
34 #define FF2_LAYOUT 0x80
36 int swf_FontIsItalic(SWFFONT * f) { return f->style&FONT_STYLE_ITALIC;}
37 int swf_FontIsBold(SWFFONT * f) { return f->style&FONT_STYLE_BOLD;}
39 static const int WRITEFONTID = 0x4e46; // font id for WriteFont and ReadFont
41 int swf_FontEnumerate(SWF * swf,void (*FontCallback) (U16,U8*))
49 { if (swf_GetTagID(t)==ST_DEFINEFONTINFO ||
50 swf_GetTagID(t)==ST_DEFINEFONT2)
60 if(swf_GetTagID(t) == ST_DEFINEFONT2)
76 int swf_FontExtract_DefineFont(int id,SWFFONT * f,TAG * t)
93 f->glyph = malloc(sizeof(SWFGLYPH)*n);
94 memset(f->glyph, 0, sizeof(SWFGLYPH)*n);
96 for (i=1;i<n;i++) swf_GetU16(t);
97 for (i=0;i<n;i++) swf_GetSimpleShape(t,&f->glyph[i].shape);
100 swf_RestoreTagPos(t);
104 int swf_FontExtract_DefineFontInfo(int id,SWFFONT * f,TAG * t)
113 { U8 l = swf_GetU8(t);
117 // DefineFont2 doesn't have FontInfo fields
118 fprintf(stderr, "fixme: FontInfo field for DefineFont2 encountered\n");
123 { if (f->name) free(f->name);
124 f->name = (U8*)malloc(l+1);
126 { swf_GetBlock(t,f->name,l);
130 { swf_RestoreTagPos(t);
134 flags = swf_GetU8(t);
136 f->style |= FONT_STYLE_BOLD;
138 f->style |= FONT_STYLE_ITALIC;
140 f->encoding |= FONT_ENCODING_ANSI;
142 f->encoding |= FONT_ENCODING_SHIFTJIS;
144 f->encoding |= FONT_ENCODING_UNICODE;
146 f->glyph2ascii = (U16*)malloc(sizeof(U16)*f->numchars);
148 for(i=0; i < f->numchars; i++) {
149 f->glyph2ascii[i] = ((flags&FF_WIDECODES)?swf_GetU16(t):swf_GetU8(t));
150 if(f->glyph2ascii[i] > maxcode)
151 maxcode = f->glyph2ascii[i];
156 f->maxascii = maxcode;
157 f->ascii2glyph = (int*)malloc(sizeof(int)*maxcode);
158 memset(f->ascii2glyph, -1, sizeof(int)*maxcode);
160 for(i = 0; i < f->numchars; i++)
161 f->ascii2glyph[f->glyph2ascii[i]] = i;
164 swf_RestoreTagPos(t);
168 int swf_FontExtract_DefineFont2(int id,SWFFONT * font,TAG * tag)
173 U8 flags1,flags2,namelen;
175 swf_SetTagPos(tag,0);
177 fid = swf_GetU16(tag);
181 flags1 = swf_GetU8(tag);
182 flags2 = swf_GetU8(tag); //reserved flags
185 font->style |= FONT_STYLE_BOLD;
187 font->style |= FONT_STYLE_ITALIC;
189 font->encoding |= FONT_ENCODING_ANSI;
191 font->encoding |= FONT_ENCODING_UNICODE;
193 font->encoding |= FONT_ENCODING_SHIFTJIS;
195 namelen = swf_GetU8(tag);
196 font->name = (U8*)malloc(namelen+1);
197 font->name[namelen]=0;
198 swf_GetBlock(tag, font->name, namelen);
200 glyphcount = swf_GetU16(tag);
201 font->numchars = glyphcount;
203 font->glyph = (SWFGLYPH*)malloc(sizeof(SWFGLYPH)*glyphcount);
204 memset(font->glyph, 0, sizeof(SWFGLYPH)*glyphcount);
205 font->glyph2ascii = (U16*)malloc(sizeof(U16)*glyphcount);
206 memset(font->glyph2ascii, 0, sizeof(U16)*glyphcount);
208 if(flags1&8) { // wide offsets
209 for(t=0;t<glyphcount;t++)
210 swf_GetU32(tag); //offset[t]
211 swf_GetU32(tag); // fontcodeoffset
213 for(t=0;t<glyphcount;t++)
214 swf_GetU16(tag); //offset[t]
215 swf_GetU16(tag); // fontcodeoffset
217 for(t=0;t<glyphcount;t++)
218 swf_GetSimpleShape(tag,&(font->glyph[t].shape));
221 for(t=0;t<glyphcount;t++) {
223 if(flags1&4) // wide codes
224 code = swf_GetU16(tag);
226 code = swf_GetU8(tag);
227 font->glyph2ascii[t] = code;
234 font->maxascii = maxcode;
235 font->ascii2glyph = (int*)malloc(sizeof(int)*maxcode);
236 memset(font->ascii2glyph, -1, sizeof(int)*maxcode);
237 for(t=0;t<glyphcount;t++)
239 font->ascii2glyph[font->glyph2ascii[t]] = t;
242 if(flags1&128) { // has layout
244 font->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
245 font->layout->ascent=swf_GetU16(tag);
246 font->layout->descent=swf_GetU16(tag);
247 font->layout->leading=swf_GetU16(tag);
248 for(t=0;t<glyphcount;t++) {
249 S16 advance = swf_GetS16(tag);
250 font->glyph[t].advance = advance;
252 font->layout->bounds = malloc(glyphcount*sizeof(SRECT));
253 for(t=0;t<glyphcount;t++) {
254 swf_ResetReadBits(tag);
255 swf_GetRect(tag, font->layout->bounds);
257 kerningcount = swf_GetU16(tag);
258 font->layout->kerningcount = kerningcount;
259 font->layout->kerning = (SWFKERNING*)malloc(sizeof(SWFKERNING)*kerningcount);
261 font->layout->kerning =
262 malloc(sizeof(*font->layout->kerning)* kerningcount);
263 for(t=0;t<kerningcount;t++)
265 if(flags1&4) { // wide codes
266 font->layout->kerning[t].char1 = swf_GetU16(tag);
267 font->layout->kerning[t].char2 = swf_GetU16(tag);
269 font->layout->kerning[t].char1 = swf_GetU8(tag);
270 font->layout->kerning[t].char2 = swf_GetU8(tag);
272 font->layout->kerning[t].adjustment = swf_GetS16(tag);
276 swf_RestoreTagPos(t);
281 #define FEDTJ_PRINT 0x01
282 #define FEDTJ_MODIFY 0x02
283 #define FEDTJ_CALLBACK 0x04
285 int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs,
286 void(*callback)(int*chars, int nr, int fontid))
290 U8 gbits, abits, flags;
301 gbits = swf_GetU8(t);
302 abits = swf_GetU8(t);
304 flags = swf_GetU8(t);
307 { if (flags&TF_TEXTCONTROL)
308 { if (flags&TF_HASFONT) fid = swf_GetU16(t);
309 if (flags&TF_HASCOLOR)
310 { swf_GetU8(t); // rgb
313 if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_GetU8(t);
315 if (flags&TF_HASXOFFSET) swf_GetS16(t);
316 if (flags&TF_HASYOFFSET) swf_GetS16(t);
317 if (flags&TF_HASFONT) swf_GetU16(t);
322 for (i=0;i<flags;i++)
325 glyph = swf_GetBits(t,gbits);
326 adv = swf_GetBits(t,abits);
327 if (id==fid) // mitlesen ?
328 if (jobs&FEDTJ_PRINT) {
329 { int code = f->glyph2ascii[glyph];
332 if (jobs&FEDTJ_MODIFY)
333 /*if (!f->glyph[code].advance)*/ f->glyph[glyph].advance = adv;
337 if ((id==fid)&&(jobs&FEDTJ_PRINT)) printf("\n");
338 if (jobs&FEDTJ_CALLBACK)
339 callback(buf, flags, fid);
341 flags = swf_GetU8(t);
344 swf_RestoreTagPos(t);
348 int swf_FontExtract_DefineText(int id,SWFFONT * f,TAG * t,int jobs)
350 return swf_FontExtract_DefineTextCallback(id,f,t,jobs,0);
353 int swf_FontExtract(SWF * swf,int id,SWFFONT * * font)
357 if ((!swf)||(!font)) return -1;
359 f = (SWFFONT *)malloc(sizeof(SWFFONT)); font[0] = f;
362 memset(f,0x00,sizeof(SWFFONT));
368 switch (swf_GetTagID(t))
369 { case ST_DEFINEFONT:
370 nid = swf_FontExtract_DefineFont(id,f,t);
374 nid = swf_FontExtract_DefineFont2(id,f,t);
377 case ST_DEFINEFONTINFO:
378 nid = swf_FontExtract_DefineFontInfo(id,f,t);
383 nid = swf_FontExtract_DefineText(id,f,t,f->layout?0:FEDTJ_MODIFY);
392 int swf_FontSetID(SWFFONT * f,U16 id) { if (!f) return -1; f->id = id; return 0; }
394 int swf_FontReduce(SWFFONT * f,FONTUSAGE * use)
396 if ((!f)||(!use)) return -1;
399 for (i=0;i<f->numchars;i++)
400 if (f->glyph[i].shape)
401 { if (f->glyph2ascii[i]<MAX_CHAR_PER_FONT &&
402 use->code[f->glyph2ascii[i]])
403 { f->ascii2glyph[f->glyph2ascii[i]] = j;
404 f->glyph2ascii[j] = f->glyph2ascii[i];
405 f->glyph[j] = f->glyph[i];
409 { swf_ShapeFree(f->glyph[i].shape);
410 f->ascii2glyph[f->glyph2ascii[i]] = -1;
411 f->glyph2ascii[i] = 0;
412 f->glyph[i].shape = NULL;
413 f->glyph[i].advance = 0;
415 } else f->ascii2glyph[f->glyph2ascii[i]] = -1;
422 int swf_FontInitUsage(FONTUSAGE * use)
423 { if (!use) return -1;
424 memset(use->code,0,sizeof(use->code[0])*MAX_CHAR_PER_FONT);
428 int swf_FontUse(FONTUSAGE * use,U8 * s)
429 { if ((!use)||(!s)) return -1;
431 { use->code[s[0]] = 1;
437 int swf_FontSetDefine(TAG * t,SWFFONT * f)
438 { U16*ofs = (U16*)malloc(f->numchars*2);
441 if ((!t)||(!f)) return -1;
442 swf_ResetWriteBits(t);
446 for (i=0;i<f->numchars;i++)
447 if (f->glyph[i].shape)
449 p+=swf_SetSimpleShape(NULL,f->glyph[i].shape);
452 for (i=0;i<j;i++) swf_SetU16(t,ofs[i]+j*2);
454 for (i=0;i<f->numchars;i++)
455 if (f->glyph[i].shape)
456 swf_SetSimpleShape(t,f->glyph[i].shape);
458 swf_ResetWriteBits(t);
463 int swf_FontSetDefine2(TAG *tag, SWFFONT * f)
469 swf_SetU16(tag, f->id);
471 flags |= 128; // haslayout
473 flags |= 4; // widecodes
474 if(f->style & FONT_STYLE_BOLD)
476 if(f->style & FONT_STYLE_ITALIC)
477 flags |= 2; // italic
479 if(f->encoding & FONT_ENCODING_ANSI)
481 if(f->encoding & FONT_ENCODING_UNICODE)
482 flags |= 32; // unicode
483 if(f->encoding & FONT_ENCODING_SHIFTJIS)
484 flags |= 64; // shiftjis
486 swf_SetU8(tag, flags);
487 swf_SetU8(tag, 0); //reserved flags
490 swf_SetU8(tag, strlen(f->name));
491 swf_SetBlock(tag, f->name, strlen(f->name));
493 /* font name (="") */
494 swf_SetU8(tag, 0); /*placeholder*/
496 /* number of glyphs */
497 swf_SetU16(tag, f->numchars);
498 /* font offset table */
500 for(t=0;t<f->numchars;t++)
502 swf_SetU16(tag, /* fontoffset */ 0); /*placeholder*/
505 swf_SetU16(tag, 0); //fontcode-fontoffset
506 for(t=0;t<f->numchars;t++) {
507 tag->data[pos + t*2] = (tag->len-pos);
508 tag->data[pos + t*2 + 1] = (tag->len-pos) >> 8;
509 swf_SetSimpleShape(tag, f->glyph[t].shape);
512 tag->data[pos2] = tag->len - pos;
513 tag->data[pos2 + 1] = (tag->len - pos) >> 8;
515 /* font code table */
516 if(flags & 4) /* wide codes */ {
517 for(t=0;t<f->numchars;t++)
518 swf_SetU16(tag,f->glyph2ascii[t]);
520 for(t=0;t<f->numchars;t++)
521 swf_SetU8(tag,f->glyph2ascii[t]);
525 swf_SetU16(tag,f->layout->ascent);
526 swf_SetU16(tag,f->layout->descent);
527 swf_SetU16(tag,f->layout->leading);
528 for(t=0;t<f->numchars;t++)
529 swf_SetU16(tag,f->glyph[t].advance);
530 for(t=0;t<f->numchars;t++) {
531 swf_ResetWriteBits(tag);
532 swf_SetRect(tag,&f->layout->bounds[t]);
534 swf_SetU16(tag, f->layout->kerningcount);
535 for(t=0;t<f->layout->kerningcount;t++) {
536 if(flags & 4) /* wide codes */ {
537 swf_SetU8(tag,f->layout->kerning[t].char1);
538 swf_SetU8(tag,f->layout->kerning[t].char2);
540 swf_SetU16(tag,f->layout->kerning[t].char1);
541 swf_SetU16(tag,f->layout->kerning[t].char2);
543 swf_SetU16(tag,f->layout->kerning[t].adjustment);
549 void swf_FontAddLayout(SWFFONT * f, int ascent, int descent, int leading)
551 f->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
552 f->layout->ascent = ascent;
553 f->layout->descent = descent;
554 f->layout->leading = leading;
555 f->layout->kerningcount = 0;
556 f->layout->kerning = 0;
557 f->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*f->numchars);
558 memset(f->layout->bounds, 0, sizeof(SRECT)*f->numchars);
561 int swf_FontSetInfo(TAG * t,SWFFONT * f)
565 if ((!t)||(!f)) return -1;
566 swf_ResetWriteBits(t);
568 l = strlen(f->name); if (l>255) l = 255;
570 swf_SetBlock(t,f->name,l);
574 if(f->style & FONT_STYLE_BOLD)
576 if(f->style & FONT_STYLE_ITALIC)
578 if(f->style & FONT_ENCODING_ANSI)
580 if(f->style & FONT_ENCODING_SHIFTJIS)
582 if(f->style & FONT_ENCODING_UNICODE)
585 swf_SetU8(t,(flags&0xfe)|wide);
587 for (i=0;i<f->numchars;i++) {
588 if (f->glyph[i].shape)
589 wide?swf_SetU16(t,f->glyph2ascii[i]):
590 swf_SetU8(t,f->glyph2ascii[i]);
596 int swf_FontExport(int handle,SWFFONT * f)
603 if (write(handle,f,sizeof(SWFFONT))!=sizeof(SWFFONT)) return -1;
606 { U16 ln = strlen(f->name);
609 { if (write(handle,&ln,2)!=2) return -1;
610 if (write(handle,f->name,ln)!=ln) return -1;
615 { l+=sizeof(SWFLAYOUT);
617 if (write(handle,f->layout,sizeof(SWFLAYOUT))!=sizeof(SWFLAYOUT)) return -1;
618 /* new kerning struct. hope commenting this out doesn't break things
619 if (f->layout->kerning.data)
620 { l+=f->layout->kerning.count*4;
622 if (write(handle,f->layout->kerning.data,f->layout->kerning.count*4)!=f->layout->kerning.count*4) return -1;
626 for (i=0;i<f->numchars;i++)
627 { if (f->glyph[i].shape)
628 { int ll = swf_ShapeExport(handle,f->glyph[i].shape);
637 int swf_FontImport(int handle,SWFFONT * * font)
642 if ((!font)||(handle<0)) return -1;
644 f = (SWFFONT *)malloc(sizeof(SWFFONT)); font[0] = f;
647 memset(f,0x00,sizeof(SWFFONT));
649 if (read(handle,f,sizeof(SWFFONT))!=sizeof(SWFFONT)) goto fehler;
651 layout = (f->layout)?1:0; // avoid illegal free()
657 if (read(handle,&ln,2)!=2) goto fehler;
658 f->name = (U8*)malloc(ln+1);
659 if (!f->name) goto fehler;
660 if (read(handle,f->name,ln)!=ln) goto fehler;
665 { f->layout = (SWFLAYOUT *)malloc(sizeof(SWFLAYOUT));
666 if (!f->layout) goto fehler;
667 if (read(handle,f->layout,sizeof(SWFLAYOUT))!=sizeof(SWFLAYOUT)) goto fehler;
668 /* new kerning struct. hope commenting this out doesn't break things
669 if (f->layout->kerning.data)
670 { int l = f->layout->kerning.count*4;
671 f->layout->kerning.data = (U8*)malloc(l);
672 if (!f->layout->kerning.data) goto fehler;
673 if (read(handle,f->layout->kerning.data,l)!=l) goto fehler;
677 for (i=0;i<f->numchars;i++)
678 { if (f->glyph[i].shape)
679 { if (swf_ShapeImport(handle,&f->glyph[i].shape)<0) goto fehler;
688 if (f) for (;i<MAX_CHAR_PER_FONT;i++) f->glyph[i].shape = NULL;
694 int swf_TextPrintDefineText(TAG * t,SWFFONT * f)
695 { int id = swf_GetTagID(t);
696 if ((id==ST_DEFINETEXT)||(id==ST_DEFINETEXT2)) swf_FontExtract_DefineText(f->id,f,t,FEDTJ_PRINT);
701 void swf_LayoutFree(SWFLAYOUT * l)
703 { if (l->kerning) free(l->kerning);
705 if (l->bounds) free(l->bounds);
711 void swf_FontFree(SWFFONT * f)
715 if (f->name) free(f->name);
716 if (f->layout) swf_LayoutFree(f->layout);
722 for (i=0;i<f->numchars;i++)
723 if (f->glyph[i].shape)
724 { swf_ShapeFree(f->glyph[i].shape);
725 f->glyph[i].shape = NULL;
731 free(f->ascii2glyph);
732 f->ascii2glyph = NULL;
735 free(f->glyph2ascii);
736 f->glyph2ascii = NULL;
742 int swf_TextSetInfoRecord(TAG * t,SWFFONT * font,U16 size,RGBA * color,S16 dx,S16 dy)
746 flags = TF_TEXTCONTROL|(font?TF_HASFONT:0)|(color?TF_HASCOLOR:0)|(dx?TF_HASXOFFSET:0)|(dy?TF_HASYOFFSET:0);
749 if (font) swf_SetU16(t,font->id);
751 { if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_SetRGBA(t,color);
752 else swf_SetRGB(t,color);
754 if (dx) swf_SetS16(t,dx);
755 if (dy) swf_SetS16(t,dy);
756 if (font) swf_SetU16(t,size);
761 int swf_TextCountBits(SWFFONT * font,U8 * s,int scale,U8 * gbits,U8 * abits)
763 if ((!s)||(!font)||((!gbits)&&(!abits))||(!font->ascii2glyph)) return -1;
768 int glyph = font->ascii2glyph[s[0]];
770 g = swf_CountBits(glyph,g);
771 a = swf_CountBits((((U32)font->glyph[glyph].advance)*scale)/100,a);
776 if (gbits) gbits[0] = (U8)g;
777 if (abits) abits[0] = (U8)a;
782 int swf_TextSetCharRecord(TAG * t,SWFFONT * font,U8 * s,int scale,U8 gbits,U8 abits)
785 if ((!t)||(!font)||(!s)||(!font->ascii2glyph)) return -1;
788 if (l>0x7f) l = 0x7f;
793 int g = font->ascii2glyph[s[i]];
795 swf_SetBits(t,g,gbits);
796 swf_SetBits(t,(((U32)font->glyph[g].advance)*scale)/100,abits);
800 swf_ResetWriteBits(t);
804 U32 swf_TextGetWidth(SWFFONT * font,U8 * s,int scale)
810 int g = font->ascii2glyph[*s];
812 res += font->glyph[g].advance;
815 if (scale) res = (res*scale)/100;
820 SWFFONT* swf_ReadFont(char* filename)
826 f = open(filename,O_RDONLY);
828 if (f<0 || swf_ReadSWF(f,&swf)<0)
829 { fprintf(stderr,"%s is not a valid SWF font file or contains errors.\n",filename);
836 if(swf_FontExtract(&swf, WRITEFONTID, &font) < 0)
843 void swf_WriteFont(SWFFONT*font, char* filename)
849 int useDefineFont2 = 0;
852 useDefineFont2 = 1; /* the only thing new in definefont2
853 is layout information. */
855 font->id = WRITEFONTID; //"FN"
857 memset(&swf,0x00,sizeof(SWF));
860 swf.frameRate = 0x4000;
862 /* if we use DefineFont1 to store the characters,
863 we have to build a textfield to store the
864 advance values. While at it, we can also
865 make the whole .swf viewable */
867 /* we now always create viewable swfs, even if we
868 did use definefont2 -mk*/
869 t = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
875 if(!useDefineFont2) {
876 t = swf_InsertTag(t,ST_DEFINEFONT);
877 swf_FontSetDefine(t,font);
878 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
879 swf_FontSetInfo(t,font);
881 t = swf_InsertTag(t,ST_DEFINEFONT2);
882 swf_FontSetDefine2(t,font);
885 if(1) //useDefineFont2
886 { int textscale = 400;
889 int ymax = textscale * 2 * (font->maxascii/16+1);
891 char text[MAX_CHAR_PER_FONT+1];
893 text[MAX_CHAR_PER_FONT]=0;
894 for(s=0;s<font->maxascii;s++)
896 int g = font->ascii2glyph[s];
899 if(font->glyph[g].advance*textscale/200 > xmax)
900 xmax = font->glyph[g].advance*textscale/200;
903 swf.movieSize.xmax = xmax*20;
904 swf.movieSize.ymax = ymax;
906 t = swf_InsertTag(t,ST_DEFINETEXT);
908 swf_SetU16(t,font->id+1); // ID
912 r.xmax = swf.movieSize.xmax*20;
913 r.ymax = swf.movieSize.ymax;
917 swf_SetMatrix(t,NULL);
919 abits = swf_CountBits(xmax*16, 0);
928 for(y=0;y<=((font->maxascii-1)/16);y++)
930 int c=0,lastx=-1, firstx=0;
932 int g = (y*16+x<font->maxascii)?font->ascii2glyph[y*16+x]:-1;
933 if(g>=0 && font->glyph[g].shape) {
940 swf_TextSetInfoRecord(t,font,textscale,&rgb,lastx+1,textscale*y*2);
943 int g = (y*16+x<font->maxascii)?font->ascii2glyph[y*16+x]:-1;
944 if(g>=0 && font->glyph[g].shape) {
945 if(lastx != x*xmax) {
946 swf_TextSetInfoRecord(t,0,0,0,x*xmax+1,0);
949 swf_SetBits(t, g, gbits);
950 swf_SetBits(t, font->glyph[g].advance, abits);
951 lastx = x*xmax+font->glyph[g].advance;
952 swf_ResetWriteBits(t);
960 t = swf_InsertTag(t,ST_PLACEOBJECT2);
962 swf_ObjectPlace(t,font->id+1,1,NULL,NULL,NULL);
964 t = swf_InsertTag(t,ST_SHOWFRAME);
967 t = swf_InsertTag(t,ST_END);
969 f = open(filename, O_RDWR|O_CREAT|O_TRUNC,0644);
970 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed in writeFont().\n");
977 void swf_SetEditText(TAG*tag, U16 flags, SRECT r, char*text, RGBA*color,
978 int maxlength, U16 font, U16 height, EditTextLayout*layout, char*variable)
981 swf_ResetWriteBits(tag);
983 flags &= ~(ET_HASTEXT|ET_HASTEXTCOLOR|ET_HASMAXLENGTH|ET_HASFONT|ET_HASLAYOUT);
984 if(text) flags |= ET_HASTEXT;
985 if(color) flags |= ET_HASTEXTCOLOR;
986 if(maxlength) flags |= ET_HASMAXLENGTH;
987 if(font) flags |= ET_HASFONT;
988 if(layout) flags |= ET_HASLAYOUT;
990 swf_SetBits(tag, flags, 16);
992 if(flags & ET_HASFONT) {
993 swf_SetU16(tag, font); //font
994 swf_SetU16(tag, height); //fontheight
996 if(flags & ET_HASTEXTCOLOR) {
997 swf_SetRGBA(tag, color);
999 if(flags & ET_HASMAXLENGTH) {
1000 swf_SetU16(tag, maxlength); //maxlength
1002 if(flags & ET_HASLAYOUT) {
1003 swf_SetU8(tag,layout->align); //align
1004 swf_SetU16(tag,layout->leftmargin); //left margin
1005 swf_SetU16(tag,layout->rightmargin); //right margin
1006 swf_SetU16(tag,layout->indent); //indent
1007 swf_SetU16(tag,layout->leading); //leading
1009 swf_SetString(tag, variable);
1010 if(flags & ET_HASTEXT)
1011 swf_SetString(tag,text);