+int swf_FontExtract_DefineFont2(int id,SWFFONT * font,TAG * tag,SHAPE * * * shapes)
+{
+ int t, glyphcount;
+ U8 flags1,flags2,namelen;
+ font->version=2;
+ font->id = swf_GetU16(tag);
+ flags1 = swf_GetU8(tag);
+ flags2 = swf_GetU8(tag); //reserved flags
+ namelen = swf_GetU8(tag);
+ font->flags = flags1;
+ font->name = (U8*)malloc(namelen+1);
+ font->name[namelen]=0;
+ swf_GetBlock(tag, font->name, namelen);
+ font->version = 2;
+ glyphcount = swf_GetU16(tag);
+ font->numchars = glyphcount;
+ (*shapes) = (SHAPE**)malloc(sizeof(SHAPE*)*glyphcount);
+ memset((*shapes), 0, sizeof(SHAPE*)*glyphcount);
+ if(flags1&8) { // wide offsets
+ for(t=0;t<glyphcount;t++)
+ swf_GetU32(tag); //offset[t]
+ swf_GetU32(tag); // fontcodeoffset
+ } else {
+ for(t=0;t<glyphcount;t++)
+ swf_GetU16(tag); //offset[t]
+ swf_GetU16(tag); // fontcodeoffset
+ }
+ for(t=0;t<glyphcount;t++)
+ swf_GetSimpleShape(tag,&((*shapes)[t]));
+
+ font->glyph = (SWFGLYPH*)malloc(sizeof(SWFGLYPH)*glyphcount);
+ memset(font->glyph, 0, sizeof(SWFGLYPH)*glyphcount);
+ font->codes = (U16*)malloc(sizeof(U16)*glyphcount);
+ memset(font->codes, 0, sizeof(U16)*glyphcount);
+ for(t=0;t<glyphcount;t++) {
+ U16 code;
+ if(flags1&4) // wide codes
+ code = swf_GetU16(tag);
+ else
+ code = swf_GetU8(tag);
+
+ font->glyph[code].shape = (*shapes)[t];
+ font->glyph[code].gid = t;
+ if (t<MAX_CHAR_PER_FONT)
+ font->codes[t] = code;
+ }
+ if(flags1&128) { // has layout
+ U16 kerningcount;
+ font->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
+ font->layout->ascent=swf_GetU16(tag);
+ font->layout->descent=swf_GetU16(tag);
+ font->layout->leading=swf_GetU16(tag);
+ for(t=0;t<glyphcount;t++) {
+ S16 advance = swf_GetS16(tag);
+ font->glyph[t].advance = advance;
+ }
+ font->layout->bounds = malloc(glyphcount*sizeof(SRECT));
+ for(t=0;t<glyphcount;t++) {
+ swf_ResetReadBits(tag);
+ swf_GetRect(tag, font->layout->bounds);
+ }
+ kerningcount = swf_GetU16(tag);
+ font->layout->kerningcount = kerningcount;
+ font->layout->kerning = (SWFKERNING*)malloc(sizeof(SWFKERNING)*kerningcount);
+ if(kerningcount) {
+ font->layout->kerning =
+ malloc(sizeof(*font->layout->kerning)* kerningcount);
+ for(t=0;t<kerningcount;t++)
+ {
+ if(flags1&4) { // wide codes
+ font->layout->kerning[t].char1 = swf_GetU16(tag);
+ font->layout->kerning[t].char2 = swf_GetU16(tag);
+ } else {
+ font->layout->kerning[t].char1 = swf_GetU16(tag);
+ font->layout->kerning[t].char2 = swf_GetU16(tag);
+ }
+ font->layout->kerning[t].adjustment = swf_GetS16(tag);
+ }
+ }
+ }
+ return font->id;
+}
+
+