- for(t=0;t<=i->chardatapos;t++)
- {
- if(lastfontid != i->chardata[t].fontid ||
- lastx!=i->chardata[t].x ||
- lasty!=i->chardata[t].y ||
- !colorcompare(dev,&color, &i->chardata[t].color) ||
- charstorepos==127 ||
- lastsize != i->chardata[t].size ||
- t == i->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->writeBit = 0; // Q&D
- swf_SetBits(tag, 0, 1); // GLYPH Record
- swf_SetBits(tag, charstorepos, 7); // number of glyphs
- int s;
- for(s=0;s<charstorepos;s++)
- {
- swf_SetBits(tag, charids[s], glyphbits);
- swf_SetBits(tag, charadvance[s], advancebits);
- }
- }
- charstorepos = 0;
-
- if(pass == 1 && t<i->chardatapos)
- {
- RGBA*newcolor=0;
- SWFFONT*newfont=0;
- int newx = 0;
- int newy = 0;
- if(lastx != i->chardata[t].x ||
- lasty != i->chardata[t].y)
- {
- newx = i->chardata[t].x;
- newy = i->chardata[t].y;
- if(newx == 0)
- newx = SET_TO_ZERO;
- if(newy == 0)
- newy = SET_TO_ZERO;
- }
- if(!colorcompare(dev,&color, &i->chardata[t].color))
- {
- color = i->chardata[t].color;
- newcolor = &color;
- }
- font.id = i->chardata[t].fontid;
- if(lastfontid != i->chardata[t].fontid || lastsize != i->chardata[t].size)
- newfont = &font;
-
- tag->writeBit = 0; // Q&D
- swf_TextSetInfoRecord(tag, newfont, i->chardata[t].size, newcolor, newx,newy);
- }
-
- lastfontid = i->chardata[t].fontid;
- lastx = i->chardata[t].x;
- lasty = i->chardata[t].y;
- lastsize = i->chardata[t].size;
- }
-
- if(t==i->chardatapos)
- break;
-
- int advance;
- int nextt = t==i->chardatapos-1?t:t+1;
- int rel = i->chardata[nextt].x-i->chardata[t].x;
- if(rel>=0 && (rel<(1<<(advancebits-1)) || pass==0)) {
- advance = rel;
- lastx=i->chardata[nextt].x;
- }
- else {
- advance = 0;
- lastx=i->chardata[t].x;
- }
- charids[charstorepos] = i->chardata[t].charid;
- charadvance[charstorepos] = advance;
- charstorepos ++;
- }
+ chararray_t*chardata = _chardata;
+
+ while(chardata) {
+ int t;
+
+ assert(!chardata->next || chardata->pos == CHARDATAMAX);
+ assert(chardata->pos);
+
+ int to = chardata->next?chardata->pos-1:chardata->pos;
+
+ for(t=0;t<=to;t++)
+ {
+ char islast = t==chardata->pos;
+
+ charatposition_t*chr = &chardata->chr[t];
+
+ if(lastfont != chr->font ||
+ lastx!=chr->x ||
+ lasty!=chr->y ||
+ !colorcompare(&color, &chardata->chr[t].color) ||
+ charstorepos==127 ||
+ lastsize != chardata->chr[t].size ||
+ islast)
+ {
+ 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->writeBit = 0; // Q&D
+ swf_SetBits(tag, 0, 1); // GLYPH Record
+ swf_SetBits(tag, charstorepos, 7); // number of glyphs
+ int s;
+ for(s=0;s<charstorepos;s++)
+ {
+ swf_SetBits(tag, charids[s], glyphbits);
+ swf_SetBits(tag, charadvance[s], advancebits);
+ }
+ }
+ charstorepos = 0;
+
+ if(pass == 1 && !islast)
+ {
+ RGBA*newcolor=0;
+ SWFFONT*newfont=0;
+ int newx = 0;
+ int newy = 0;
+ if(lastx != chr->x ||
+ lasty != chr->y)
+ {
+ newx = chr->x;
+ newy = chr->y;
+ if(newx == 0)
+ newx = SET_TO_ZERO;
+ if(newy == 0)
+ newy = SET_TO_ZERO;
+ }
+ if(!colorcompare(&color, &chr->color))
+ {
+ color = chr->color;
+ newcolor = &color;
+ }
+ font.id = chr->font->id;
+ if(lastfont != chr->font || lastsize != chr->size)
+ newfont = &font;
+
+ tag->writeBit = 0; // Q&D
+ swf_TextSetInfoRecord(tag, newfont, chr->size, newcolor, newx, newy);
+ }
+
+ lastfont = chr->font;
+ lastx = chr->x;
+ lasty = chr->y;
+ lastsize = chr->size;
+ }
+
+ if(islast)
+ break;
+
+ int nextx = chr->x;
+ if(t<chardata->pos-1) nextx = chardata->chr[t+1].x;
+ if(t==chardata->pos-1 && chardata->next) nextx = chardata->next->chr[0].x;
+ int dx = nextx-chr->x;
+
+ int advance;
+ if(dx>=0 && (dx<(1<<(advancebits-1)) || pass==0)) {
+ advance = dx;
+ lastx=nextx;
+ } else {
+ advance = 0;
+ lastx=chr->x;
+ }
+
+ charids[charstorepos] = chr->charid;
+ charadvance[charstorepos] = advance;
+ lastchar = chr->charid;
+ charstorepos ++;
+ }
+ chardata = chardata->next;
+ }