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]
212 if(glyphcount) /* this _if_ is not in the specs */
213 swf_GetU32(tag); // fontcodeoffset
215 for(t=0;t<glyphcount;t++)
216 swf_GetU16(tag); //offset[t]
218 if(glyphcount) /* this _if_ is not in the specs */
219 swf_GetU16(tag); // fontcodeoffset
221 for(t=0;t<glyphcount;t++)
222 swf_GetSimpleShape(tag,&(font->glyph[t].shape));
225 for(t=0;t<glyphcount;t++) {
227 if(flags1&4) // wide codes
228 code = swf_GetU16(tag);
230 code = swf_GetU8(tag);
231 font->glyph2ascii[t] = code;
238 font->maxascii = maxcode;
239 font->ascii2glyph = (int*)malloc(sizeof(int)*maxcode);
240 memset(font->ascii2glyph, -1, sizeof(int)*maxcode);
241 for(t=0;t<glyphcount;t++)
243 font->ascii2glyph[font->glyph2ascii[t]] = t;
246 if(flags1&128) { // has layout
248 font->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
249 font->layout->ascent=swf_GetU16(tag);
250 font->layout->descent=swf_GetU16(tag);
251 font->layout->leading=swf_GetU16(tag);
252 for(t=0;t<glyphcount;t++) {
253 S16 advance = swf_GetS16(tag);
254 font->glyph[t].advance = advance;
256 font->layout->bounds = malloc(glyphcount*sizeof(SRECT));
257 for(t=0;t<glyphcount;t++) {
258 swf_ResetReadBits(tag);
259 swf_GetRect(tag, font->layout->bounds);
262 kerningcount = swf_GetU16(tag);
263 font->layout->kerningcount = kerningcount;
265 font->layout->kerning = (SWFKERNING*)malloc(sizeof(SWFKERNING)*kerningcount);
267 font->layout->kerning =
268 malloc(sizeof(*font->layout->kerning)* kerningcount);
269 for(t=0;t<kerningcount;t++)
271 if(flags1&4) { // wide codes
272 font->layout->kerning[t].char1 = swf_GetU16(tag);
273 font->layout->kerning[t].char2 = swf_GetU16(tag);
275 font->layout->kerning[t].char1 = swf_GetU8(tag);
276 font->layout->kerning[t].char2 = swf_GetU8(tag);
278 font->layout->kerning[t].adjustment = swf_GetS16(tag);
282 swf_RestoreTagPos(t);
287 #define FEDTJ_PRINT 0x01
288 #define FEDTJ_MODIFY 0x02
289 #define FEDTJ_CALLBACK 0x04
291 int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs,
292 void(*callback)(int*chars, int nr, int fontid))
296 U8 gbits, abits, flags;
307 gbits = swf_GetU8(t);
308 abits = swf_GetU8(t);
310 flags = swf_GetU8(t);
313 { if (flags&TF_TEXTCONTROL)
314 { if (flags&TF_HASFONT) fid = swf_GetU16(t);
315 if (flags&TF_HASCOLOR)
316 { swf_GetU8(t); // rgb
319 if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_GetU8(t);
321 if (flags&TF_HASXOFFSET) swf_GetS16(t);
322 if (flags&TF_HASYOFFSET) swf_GetS16(t);
323 if (flags&TF_HASFONT) swf_GetU16(t);
328 for (i=0;i<flags;i++)
331 glyph = swf_GetBits(t,gbits);
332 adv = swf_GetBits(t,abits);
333 if (id==fid) // mitlesen ?
334 if (jobs&FEDTJ_PRINT) {
335 { int code = f->glyph2ascii[glyph];
338 if (jobs&FEDTJ_MODIFY)
339 /*if (!f->glyph[code].advance)*/ f->glyph[glyph].advance = adv;
343 if ((id==fid)&&(jobs&FEDTJ_PRINT)) printf("\n");
344 if (jobs&FEDTJ_CALLBACK)
345 callback(buf, flags, fid);
347 flags = swf_GetU8(t);
350 swf_RestoreTagPos(t);
354 int swf_FontExtract_DefineText(int id,SWFFONT * f,TAG * t,int jobs)
356 return swf_FontExtract_DefineTextCallback(id,f,t,jobs,0);
359 int swf_FontExtract(SWF * swf,int id,SWFFONT * * font)
363 if ((!swf)||(!font)) return -1;
365 f = (SWFFONT *)malloc(sizeof(SWFFONT)); font[0] = f;
368 memset(f,0x00,sizeof(SWFFONT));
374 switch (swf_GetTagID(t))
375 { case ST_DEFINEFONT:
376 nid = swf_FontExtract_DefineFont(id,f,t);
380 nid = swf_FontExtract_DefineFont2(id,f,t);
383 case ST_DEFINEFONTINFO:
384 nid = swf_FontExtract_DefineFontInfo(id,f,t);
389 nid = swf_FontExtract_DefineText(id,f,t,f->layout?0:FEDTJ_MODIFY);
398 int swf_FontSetID(SWFFONT * f,U16 id) { if (!f) return -1; f->id = id; return 0; }
400 int swf_FontReduce(SWFFONT * f,FONTUSAGE * use)
402 if ((!f)||(!use)) return -1;
405 for (i=0;i<f->numchars;i++)
406 if (f->glyph[i].shape)
407 { if (f->glyph2ascii[i]<MAX_CHAR_PER_FONT &&
408 use->code[f->glyph2ascii[i]])
409 { f->ascii2glyph[f->glyph2ascii[i]] = j;
410 f->glyph2ascii[j] = f->glyph2ascii[i];
411 f->glyph[j] = f->glyph[i];
415 { swf_ShapeFree(f->glyph[i].shape);
416 f->ascii2glyph[f->glyph2ascii[i]] = -1;
417 f->glyph2ascii[i] = 0;
418 f->glyph[i].shape = NULL;
419 f->glyph[i].advance = 0;
421 } else f->ascii2glyph[f->glyph2ascii[i]] = -1;
428 int swf_FontInitUsage(FONTUSAGE * use)
429 { if (!use) return -1;
430 memset(use->code,0,sizeof(use->code[0])*MAX_CHAR_PER_FONT);
434 int swf_FontUse(FONTUSAGE * use,U8 * s)
435 { if ((!use)||(!s)) return -1;
437 { use->code[s[0]] = 1;
443 int swf_FontSetDefine(TAG * t,SWFFONT * f)
444 { U16*ofs = (U16*)malloc(f->numchars*2);
447 if ((!t)||(!f)) return -1;
448 swf_ResetWriteBits(t);
452 for (i=0;i<f->numchars;i++)
453 if (f->glyph[i].shape)
455 p+=swf_SetSimpleShape(NULL,f->glyph[i].shape);
458 for (i=0;i<j;i++) swf_SetU16(t,ofs[i]+j*2);
460 for (i=0;i<f->numchars;i++)
461 if (f->glyph[i].shape)
462 swf_SetSimpleShape(t,f->glyph[i].shape);
464 swf_ResetWriteBits(t);
469 int swf_FontSetDefine2(TAG *tag, SWFFONT * f)
475 swf_SetU16(tag, f->id);
477 flags |= 128; // haslayout
479 flags |= 4; // widecodes
480 if(f->style & FONT_STYLE_BOLD)
482 if(f->style & FONT_STYLE_ITALIC)
483 flags |= 2; // italic
485 if(f->encoding & FONT_ENCODING_ANSI)
487 if(f->encoding & FONT_ENCODING_UNICODE)
488 flags |= 32; // unicode
489 if(f->encoding & FONT_ENCODING_SHIFTJIS)
490 flags |= 64; // shiftjis
492 swf_SetU8(tag, flags);
493 swf_SetU8(tag, 0); //reserved flags
496 swf_SetU8(tag, strlen(f->name));
497 swf_SetBlock(tag, f->name, strlen(f->name));
499 /* font name (="") */
500 swf_SetU8(tag, 0); /*placeholder*/
502 /* number of glyphs */
503 swf_SetU16(tag, f->numchars);
504 /* font offset table */
506 for(t=0;t<f->numchars;t++)
508 swf_SetU16(tag, /* fontoffset */ 0); /*placeholder*/
511 swf_SetU16(tag, 0); //fontcode-fontoffset
512 for(t=0;t<f->numchars;t++) {
513 tag->data[pos + t*2] = (tag->len-pos);
514 tag->data[pos + t*2 + 1] = (tag->len-pos) >> 8;
515 swf_SetSimpleShape(tag, f->glyph[t].shape);
518 tag->data[pos2] = tag->len - pos;
519 tag->data[pos2 + 1] = (tag->len - pos) >> 8;
521 /* font code table */
522 if(flags & 4) /* wide codes */ {
523 for(t=0;t<f->numchars;t++)
524 swf_SetU16(tag,f->glyph2ascii[t]);
526 for(t=0;t<f->numchars;t++)
527 swf_SetU8(tag,f->glyph2ascii[t]);
531 swf_SetU16(tag,f->layout->ascent);
532 swf_SetU16(tag,f->layout->descent);
533 swf_SetU16(tag,f->layout->leading);
534 for(t=0;t<f->numchars;t++)
535 swf_SetU16(tag,f->glyph[t].advance);
536 for(t=0;t<f->numchars;t++) {
537 swf_ResetWriteBits(tag);
538 swf_SetRect(tag,&f->layout->bounds[t]);
540 swf_SetU16(tag, f->layout->kerningcount);
541 for(t=0;t<f->layout->kerningcount;t++) {
542 if(flags & 4) /* wide codes */ {
543 swf_SetU8(tag,f->layout->kerning[t].char1);
544 swf_SetU8(tag,f->layout->kerning[t].char2);
546 swf_SetU16(tag,f->layout->kerning[t].char1);
547 swf_SetU16(tag,f->layout->kerning[t].char2);
549 swf_SetU16(tag,f->layout->kerning[t].adjustment);
555 void swf_FontAddLayout(SWFFONT * f, int ascent, int descent, int leading)
557 f->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
558 f->layout->ascent = ascent;
559 f->layout->descent = descent;
560 f->layout->leading = leading;
561 f->layout->kerningcount = 0;
562 f->layout->kerning = 0;
563 f->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*f->numchars);
564 memset(f->layout->bounds, 0, sizeof(SRECT)*f->numchars);
567 int swf_FontSetInfo(TAG * t,SWFFONT * f)
571 if ((!t)||(!f)) return -1;
572 swf_ResetWriteBits(t);
574 l = strlen(f->name); if (l>255) l = 255;
576 swf_SetBlock(t,f->name,l);
580 if(f->style & FONT_STYLE_BOLD)
582 if(f->style & FONT_STYLE_ITALIC)
584 if(f->style & FONT_ENCODING_ANSI)
586 if(f->style & FONT_ENCODING_SHIFTJIS)
588 if(f->style & FONT_ENCODING_UNICODE)
591 swf_SetU8(t,(flags&0xfe)|wide);
593 for (i=0;i<f->numchars;i++) {
594 if (f->glyph[i].shape)
595 wide?swf_SetU16(t,f->glyph2ascii[i]):
596 swf_SetU8(t,f->glyph2ascii[i]);
602 int swf_FontExport(int handle,SWFFONT * f)
609 if (write(handle,f,sizeof(SWFFONT))!=sizeof(SWFFONT)) return -1;
612 { U16 ln = strlen(f->name);
615 { if (write(handle,&ln,2)!=2) return -1;
616 if (write(handle,f->name,ln)!=ln) return -1;
621 { l+=sizeof(SWFLAYOUT);
623 if (write(handle,f->layout,sizeof(SWFLAYOUT))!=sizeof(SWFLAYOUT)) return -1;
624 /* new kerning struct. hope commenting this out doesn't break things
625 if (f->layout->kerning.data)
626 { l+=f->layout->kerning.count*4;
628 if (write(handle,f->layout->kerning.data,f->layout->kerning.count*4)!=f->layout->kerning.count*4) return -1;
632 for (i=0;i<f->numchars;i++)
633 { if (f->glyph[i].shape)
634 { int ll = swf_ShapeExport(handle,f->glyph[i].shape);
643 int swf_FontImport(int handle,SWFFONT * * font)
648 if ((!font)||(handle<0)) return -1;
650 f = (SWFFONT *)malloc(sizeof(SWFFONT)); font[0] = f;
653 memset(f,0x00,sizeof(SWFFONT));
655 if (read(handle,f,sizeof(SWFFONT))!=sizeof(SWFFONT)) goto fehler;
657 layout = (f->layout)?1:0; // avoid illegal free()
663 if (read(handle,&ln,2)!=2) goto fehler;
664 f->name = (U8*)malloc(ln+1);
665 if (!f->name) goto fehler;
666 if (read(handle,f->name,ln)!=ln) goto fehler;
671 { f->layout = (SWFLAYOUT *)malloc(sizeof(SWFLAYOUT));
672 if (!f->layout) goto fehler;
673 if (read(handle,f->layout,sizeof(SWFLAYOUT))!=sizeof(SWFLAYOUT)) goto fehler;
674 /* new kerning struct. hope commenting this out doesn't break things
675 if (f->layout->kerning.data)
676 { int l = f->layout->kerning.count*4;
677 f->layout->kerning.data = (U8*)malloc(l);
678 if (!f->layout->kerning.data) goto fehler;
679 if (read(handle,f->layout->kerning.data,l)!=l) goto fehler;
683 for (i=0;i<f->numchars;i++)
684 { if (f->glyph[i].shape)
685 { if (swf_ShapeImport(handle,&f->glyph[i].shape)<0) goto fehler;
694 if (f) for (;i<MAX_CHAR_PER_FONT;i++) f->glyph[i].shape = NULL;
700 int swf_TextPrintDefineText(TAG * t,SWFFONT * f)
701 { int id = swf_GetTagID(t);
702 if ((id==ST_DEFINETEXT)||(id==ST_DEFINETEXT2)) swf_FontExtract_DefineText(f->id,f,t,FEDTJ_PRINT);
707 void swf_LayoutFree(SWFLAYOUT * l)
709 { if (l->kerning) free(l->kerning);
711 if (l->bounds) free(l->bounds);
717 void swf_FontFree(SWFFONT * f)
721 if (f->name) free(f->name);
722 if (f->layout) swf_LayoutFree(f->layout);
728 for (i=0;i<f->numchars;i++)
729 if (f->glyph[i].shape)
730 { swf_ShapeFree(f->glyph[i].shape);
731 f->glyph[i].shape = NULL;
737 free(f->ascii2glyph);
738 f->ascii2glyph = NULL;
741 free(f->glyph2ascii);
742 f->glyph2ascii = NULL;
748 int swf_TextSetInfoRecord(TAG * t,SWFFONT * font,U16 size,RGBA * color,S16 dx,S16 dy)
752 flags = TF_TEXTCONTROL|(font?TF_HASFONT:0)|(color?TF_HASCOLOR:0)|(dx?TF_HASXOFFSET:0)|(dy?TF_HASYOFFSET:0);
755 if (font) swf_SetU16(t,font->id);
757 { if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_SetRGBA(t,color);
758 else swf_SetRGB(t,color);
760 if (dx) swf_SetS16(t,dx);
761 if (dy) swf_SetS16(t,dy);
762 if (font) swf_SetU16(t,size);
767 int swf_TextCountBits(SWFFONT * font,U8 * s,int scale,U8 * gbits,U8 * abits)
769 if ((!s)||(!font)||((!gbits)&&(!abits))||(!font->ascii2glyph)) return -1;
774 int glyph = font->ascii2glyph[s[0]];
776 g = swf_CountBits(glyph,g);
777 a = swf_CountBits((((U32)font->glyph[glyph].advance)*scale)/100,a);
782 if (gbits) gbits[0] = (U8)g;
783 if (abits) abits[0] = (U8)a;
788 int swf_TextSetCharRecord(TAG * t,SWFFONT * font,U8 * s,int scale,U8 gbits,U8 abits)
791 if ((!t)||(!font)||(!s)||(!font->ascii2glyph)) return -1;
794 if (l>0x7f) l = 0x7f;
799 int g = font->ascii2glyph[s[i]];
801 swf_SetBits(t,g,gbits);
802 swf_SetBits(t,(((U32)font->glyph[g].advance)*scale)/100,abits);
806 swf_ResetWriteBits(t);
810 U32 swf_TextGetWidth(SWFFONT * font,U8 * s,int scale)
816 int g = font->ascii2glyph[*s];
818 res += font->glyph[g].advance;
821 if (scale) res = (res*scale)/100;
826 SWFFONT* swf_ReadFont(char* filename)
832 f = open(filename,O_RDONLY);
834 if (f<0 || swf_ReadSWF(f,&swf)<0)
835 { fprintf(stderr,"%s is not a valid SWF font file or contains errors.\n",filename);
842 if(swf_FontExtract(&swf, WRITEFONTID, &font) < 0)
849 void swf_WriteFont(SWFFONT*font, char* filename)
855 int useDefineFont2 = 0;
858 useDefineFont2 = 1; /* the only thing new in definefont2
859 is layout information. */
861 font->id = WRITEFONTID; //"FN"
863 memset(&swf,0x00,sizeof(SWF));
866 swf.frameRate = 0x4000;
868 /* if we use DefineFont1 to store the characters,
869 we have to build a textfield to store the
870 advance values. While at it, we can also
871 make the whole .swf viewable */
873 /* we now always create viewable swfs, even if we
874 did use definefont2 -mk*/
875 t = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
881 if(!useDefineFont2) {
882 t = swf_InsertTag(t,ST_DEFINEFONT);
883 swf_FontSetDefine(t,font);
884 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
885 swf_FontSetInfo(t,font);
887 t = swf_InsertTag(t,ST_DEFINEFONT2);
888 swf_FontSetDefine2(t,font);
891 if(1) //useDefineFont2
892 { int textscale = 400;
895 int ymax = textscale * 2 * (font->maxascii/16+1);
897 char text[MAX_CHAR_PER_FONT+1];
899 text[MAX_CHAR_PER_FONT]=0;
900 for(s=0;s<font->maxascii;s++)
902 int g = font->ascii2glyph[s];
905 if(font->glyph[g].advance*textscale/200 > xmax)
906 xmax = font->glyph[g].advance*textscale/200;
909 swf.movieSize.xmax = xmax*20;
910 swf.movieSize.ymax = ymax;
912 t = swf_InsertTag(t,ST_DEFINETEXT);
914 swf_SetU16(t,font->id+1); // ID
918 r.xmax = swf.movieSize.xmax*20;
919 r.ymax = swf.movieSize.ymax;
923 swf_SetMatrix(t,NULL);
925 abits = swf_CountBits(xmax*16, 0);
934 for(y=0;y<=((font->maxascii-1)/16);y++)
939 int g = (y*16+x<font->maxascii)?font->ascii2glyph[y*16+x]:-1;
940 if(g>=0 && font->glyph[g].shape) {
947 swf_TextSetInfoRecord(t,font,textscale,&rgb,lastx+1,textscale*y*2);
950 int g = (y*16+x<font->maxascii)?font->ascii2glyph[y*16+x]:-1;
951 if(g>=0 && font->glyph[g].shape) {
952 if(lastx != x*xmax) {
953 swf_TextSetInfoRecord(t,0,0,0,x*xmax+1,0);
956 swf_SetBits(t, g, gbits);
957 swf_SetBits(t, font->glyph[g].advance, abits);
958 lastx = x*xmax+font->glyph[g].advance;
959 swf_ResetWriteBits(t);
967 t = swf_InsertTag(t,ST_PLACEOBJECT2);
969 swf_ObjectPlace(t,font->id+1,1,NULL,NULL,NULL);
971 t = swf_InsertTag(t,ST_SHOWFRAME);
974 t = swf_InsertTag(t,ST_END);
976 f = open(filename, O_RDWR|O_CREAT|O_TRUNC,0644);
977 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed in writeFont().\n");
984 void swf_SetEditText(TAG*tag, U16 flags, SRECT r, char*text, RGBA*color,
985 int maxlength, U16 font, U16 height, EditTextLayout*layout, char*variable)
988 swf_ResetWriteBits(tag);
990 flags &= ~(ET_HASTEXT|ET_HASTEXTCOLOR|ET_HASMAXLENGTH|ET_HASFONT|ET_HASLAYOUT);
991 if(text) flags |= ET_HASTEXT;
992 if(color) flags |= ET_HASTEXTCOLOR;
993 if(maxlength) flags |= ET_HASMAXLENGTH;
994 if(font) flags |= ET_HASFONT;
995 if(layout) flags |= ET_HASLAYOUT;
997 swf_SetBits(tag, flags, 16);
999 if(flags & ET_HASFONT) {
1000 swf_SetU16(tag, font); //font
1001 swf_SetU16(tag, height); //fontheight
1003 if(flags & ET_HASTEXTCOLOR) {
1004 swf_SetRGBA(tag, color);
1006 if(flags & ET_HASMAXLENGTH) {
1007 swf_SetU16(tag, maxlength); //maxlength
1009 if(flags & ET_HASLAYOUT) {
1010 swf_SetU8(tag,layout->align); //align
1011 swf_SetU16(tag,layout->leftmargin); //left margin
1012 swf_SetU16(tag,layout->rightmargin); //right margin
1013 swf_SetU16(tag,layout->indent); //indent
1014 swf_SetU16(tag,layout->leading); //leading
1016 swf_SetString(tag, variable);
1017 if(flags & ET_HASTEXT)
1018 swf_SetString(tag,text);