-/* process a character. */
-void drawchar(struct swfoutput*obj, int t1fontindex, char character, swfmatrix*m)
-{
-
- /* <T1 stuff> */
- T1_OUTLINE*outline;
- int width = T1_GetCharWidth(t1fontindex, character);
- BBox bbox = T1_GetCharBBox(t1fontindex, character);
- char*charname= T1_GetCharName(t1fontindex, character);
- logf("<debug> Font name is %s", T1_GetFontFileName(t1fontindex));
- logf("<debug> char 0x%02x is named %s\n",character,charname);
- logf("<debug> bbox: %d %d %d %d\n",bbox.llx,bbox.lly,bbox.urx,bbox.ury);
- if(!charname || charname[0] == '.')
+int colorcompare(RGBA*a,RGBA*b)
+{
+
+ if(a->r!=b->r ||
+ a->g!=b->g ||
+ a->b!=b->b ||
+ a->a!=b->a) {
+ return 0;
+ }
+ return 1;
+}
+
+static const int CHARDATAMAX = 1024;
+struct chardata {
+ int charid;
+ int fontid;
+ int x;
+ int y;
+ int size;
+ RGBA color;
+} chardata[CHARDATAMAX];
+int chardatapos = 0;
+
+int once=0;
+void putcharacters(TAG*tag)
+{
+ int t;
+ SWFFONT font;
+ RGBA color;
+ color.r = chardata[0].color.r^255;
+ color.g = 0;
+ color.b = 0;
+ color.a = 0;
+ int lastfontid;
+ int lastx;
+ int lasty;
+ int lastsize;
+ int charids[128];
+ int charadvance[128];
+ int charstorepos;
+ int pass;
+ int glyphbits=1; //TODO: can this be zero?
+ int advancebits=1;
+
+ if(tag->id != ST_DEFINETEXT &&
+ tag->id != ST_DEFINETEXT2) {
+ logf("<error> internal error: putcharacters needs an text tag, not %d\n",tag->id);
+ exit(1);
+ }
+
+ for(pass = 0; pass < 2; pass++)
+ {
+ charstorepos = 0;
+ lastfontid = -1;
+ lastx = CHARMIDX;
+ lasty = CHARMIDY;
+ lastsize = -1;
+
+ if(pass==1)
+ {
+ advancebits++;
+ 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); // one glyph
+ 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)