+ for(pass = 0; pass < 2; pass++)
+ {
+ charstorepos = 0;
+ lastfontid = -1;
+ lastx = CHARMIDX;
+ lasty = CHARMIDY;
+ lastsize = -1;
+
+ if(pass==1)
+ {
+ advancebits++; // add sign bit
+ SetU8(tag, glyphbits);
+ SetU8(tag, advancebits);
+ }
+
+ for(t=0;t<=chardatapos;t++)
+ {
+ if(lastfontid != chardata[t].fontid ||
+ lastx!=chardata[t].x ||
+ lasty!=chardata[t].y ||
+ !colorcompare(&color, &chardata[t].color) ||
+ charstorepos==127 ||
+ lastsize != chardata[t].size ||
+ t == chardatapos)
+ {
+ if(charstorepos && pass==0)
+ {
+ int s;
+ for(s=0;s<charstorepos;s++)
+ {
+ while(charids[s]>=(1<<glyphbits))
+ glyphbits++;
+ while(charadvance[s]>=(1<<advancebits))
+ advancebits++;
+ }
+ }
+ if(charstorepos && pass==1)
+ {
+ tag->bitcount = 0;
+ SetBits(tag, 0, 1); // GLYPH Record
+ SetBits(tag, charstorepos, 7); // number of glyphs
+ int s;
+ for(s=0;s<charstorepos;s++)
+ {
+ SetBits(tag, charids[s], glyphbits);
+ SetBits(tag, charadvance[s], advancebits);
+ }
+ }
+ charstorepos = 0;
+
+ if(pass == 1 && t<chardatapos)
+ {
+ RGBA*newcolor=0;
+ SWFFONT*newfont=0;
+ int newx = 0;
+ int newy = 0;
+ if(lastx != chardata[t].x ||
+ lasty != chardata[t].y)
+ {
+ newx=chardata[t].x;
+ newy=chardata[t].y;
+ }
+ if(!colorcompare(&color, &chardata[t].color))
+ {
+ color = chardata[t].color;
+ newcolor = &color;
+ }
+ font.id = chardata[t].fontid;
+ if(lastfontid != chardata[t].fontid || lastsize != chardata[t].size)
+ newfont = &font;
+
+ tag->bitcount = 0;
+ TextSetInfoRecord(tag, newfont, chardata[t].size, newcolor, newx,newy);
+ }
+
+ lastfontid = chardata[t].fontid;
+ lastx = chardata[t].x;
+ lasty = chardata[t].y;
+ lastsize = chardata[t].size;
+ }
+
+ if(t==chardatapos)
+ break;
+
+ int advance;
+ int nextt = t==chardatapos-1?t:t+1;
+ int rel = chardata[nextt].x-chardata[t].x;
+ if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
+ advance = rel;
+ lastx=chardata[nextt].x;
+ }
+ else {
+ advance = 0;
+ lastx=chardata[t].x;
+ }
+ charids[charstorepos] = chardata[t].charid;
+ charadvance[charstorepos] = advance;
+ charstorepos ++;
+ }
+ }
+ chardatapos = 0;
+}
+
+void putcharacter(struct swfoutput*obj, int fontid, int charid,
+ int x,int y, int size)
+{
+ if(chardatapos == CHARDATAMAX)
+ {
+ endtext();
+ starttext(obj);
+ }
+ chardata[chardatapos].fontid = fontid;
+ chardata[chardatapos].charid = charid;
+ chardata[chardatapos].x = x;
+ chardata[chardatapos].y = y;
+ chardata[chardatapos].color = obj->fillrgb;
+ chardata[chardatapos].size = size;
+ chardatapos++;
+}
+
+
+/* process a character. */
+void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m)
+{
+ int usefonts=1;
+ if(m->m12!=0 || m->m21!=0)
+ usefonts=0;
+ if(m->m11 != m->m22)
+ usefonts=0;
+
+ if(usefonts && ! drawonlyshapes)
+ {
+ int charid = font->getSWFCharID(character);
+ if(shapeid>=0)
+ endshape();
+ if(textid<0)
+ starttext(obj);
+ putcharacter(obj, font->swfid, charid,(int)(m->m13*20),(int)(m->m23*20),
+ (int)(m->m11*20/2+0.5)); //where does the /2 come from?
+ }
+ else
+ {
+ T1_OUTLINE*outline = font->getOutline(character);
+ char* charname = character;