+int swf_FontSetDefine2(TAG *tag, SWFFONT * f)
+{
+ U8 flags = 0;
+ int t;
+ int pos;
+ int pos2;
+ swf_SetU16(tag, f->id);
+ if(f->layout)
+ flags |= 128; // haslayout
+ if(f->numchars>256)
+ flags |= 4; // widecodes
+ if(f->style & FONT_STYLE_BOLD)
+ flags |= 1; // bold
+ if(f->style & FONT_STYLE_ITALIC)
+ flags |= 2; // italic
+ /* wideoffs 8 */
+ if(f->encoding & FONT_ENCODING_ANSI)
+ flags |= 16; // ansi
+ if(f->encoding & FONT_ENCODING_UNICODE)
+ flags |= 32; // unicode
+ if(f->encoding & FONT_ENCODING_SHIFTJIS)
+ flags |= 64; // shiftjis
+
+ swf_SetU8(tag, flags);
+ swf_SetU8(tag, 0); //reserved flags
+ if(f->name) {
+ /* font name */
+ swf_SetU8(tag, strlen(f->name));
+ swf_SetBlock(tag, f->name, strlen(f->name));
+ } else {
+ /* font name (="") */
+ swf_SetU8(tag, 0); /*placeholder*/
+ }
+ /* number of glyphs */
+ swf_SetU16(tag, f->numchars);
+ /* font offset table */
+ pos = tag->len;
+ for(t=0;t<f->numchars;t++)
+ {
+ swf_SetU16(tag, /* fontoffset */ 0); /*placeholder*/
+ }
+ pos2 = tag->len;
+ swf_SetU16(tag, 0); //fontcode-fontoffset
+ for(t=0;t<f->numchars;t++) {
+ tag->data[pos + t*2] = (tag->len-pos);
+ tag->data[pos + t*2 + 1] = (tag->len-pos) >> 8;
+ swf_SetSimpleShape(tag, f->glyph[t].shape);
+ }
+
+ tag->data[pos2] = tag->len - pos;
+ tag->data[pos2 + 1] = (tag->len - pos) >> 8;
+
+ /* font code table */
+ if(flags & 4) /* wide codes */ {
+ for(t=0;t<f->numchars;t++)
+ swf_SetU16(tag,f->glyph2ascii[t]);
+ } else {
+ for(t=0;t<f->numchars;t++)
+ swf_SetU8(tag,f->glyph2ascii[t]);
+ }
+ if(f->layout)
+ {
+ swf_SetU16(tag,f->layout->ascent);
+ swf_SetU16(tag,f->layout->descent);
+ swf_SetU16(tag,f->layout->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);
+ swf_SetRect(tag,&f->layout->bounds[t]);
+ }
+ swf_SetU16(tag, f->layout->kerningcount);
+ for(t=0;t<f->layout->kerningcount;t++) {
+ if(flags & 4) /* wide codes */ {
+ swf_SetU8(tag,f->layout->kerning[t].char1);
+ swf_SetU8(tag,f->layout->kerning[t].char2);
+ } else {
+ swf_SetU16(tag,f->layout->kerning[t].char1);
+ swf_SetU16(tag,f->layout->kerning[t].char2);
+ }
+ swf_SetU16(tag,f->layout->kerning[t].adjustment);
+ }
+ }
+ return 0;
+}
+
+void swf_FontAddLayout(SWFFONT * f, int ascent, int descent, int leading)
+{
+ f->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
+ f->layout->ascent = ascent;
+ f->layout->descent = descent;
+ f->layout->leading = leading;
+ f->layout->kerningcount = 0;
+ f->layout->kerning = 0;
+ f->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*f->numchars);
+ memset(f->layout->bounds, 0, sizeof(SRECT)*f->numchars);
+}
+