+static SWF swf;
+static int fontnum = 0;
+static SWFFONT**fonts = 0;
+
+void fontcallback1(void*self, U16 id,U8 * name)
+{ fontnum++;
+}
+
+void fontcallback2(void*self, U16 id,U8 * name)
+{
+ swf_FontExtract(&swf,id,&fonts[fontnum]);
+ fontnum++;
+}
+
+
+void textcallback(void*self, int*glyphs, int*advance, int nr, int fontid, int fontsize, int startx, int starty, RGBA*color)
+{
+ SWFFONT*font = 0;
+ int t;
+ for(t=0;t<fontnum;t++)
+ {
+ if(fonts[t]->id == fontid) {
+ font = fonts[t];
+ break;
+ }
+ }
+
+ if(showfonts) {
+ if(font)
+ printf("#<font %d \"%s\"%s%s>\n", fontid, font->name, swf_FontIsBold(font)?" bold":"",swf_FontIsItalic(font)?" italic":"");
+ printf("#<color #%02x%02x%02x%02x>\n", color->r, color->g, color->b, color->a);
+ printf("#<size %d>\n", fontsize);
+ }
+
+ for(t=0;t<nr;t++)
+ {
+ int xx = startx + advance[t];
+ int yy = starty;
+ MATRIX*m = (MATRIX*)self;
+
+ SPOINT p = {xx,yy};
+ p = swf_TurnPoint(p, m);
+ xx = p.x / 20;
+ yy = p.y / 20;
+
+ if(x|y|w|h) {
+ if(xx < x || yy < y || xx > x+w || yy > y+h) {
+ /* outside of bounding box */
+ ///printf("(%d+%d,%d) -> (%d,%d)\n", startx, advance[t]/20, starty, xx, yy);
+ if(t==nr-1) return;
+ else continue;
+ }
+ }
+
+ unsigned char a;
+ int advance = 0;
+ if(font>=0) {
+ if(glyphs[t]<0 || glyphs[t] >= font->numchars /*glyph is not in range*/
+ || !font->glyph2ascii /* font has ascii<->glyph mapping */
+ ) a = glyphs[t];
+ else {
+ if(font->glyph2ascii[glyphs[t]])
+ a = font->glyph2ascii[glyphs[t]];
+ else
+ a = glyphs[t];
+ }
+ } else {
+ a = glyphs[t];
+ }
+
+ if(a>=32) {
+ char* utf8 = getUTF8(a);
+ printf("%s", utf8);
+ } else {
+ printf("\\x%x", (int)a);
+ }
+ }
+ printf("\n");
+}
+