+
+static int fontnum = -1;
+static SWFFONT**fonts;
+static SWF*c_swf;
+static void fontcallback1(U16 id,U8 * name)
+{ fontnum++;
+}
+static void fontcallback2(U16 id,U8 * name)
+{
+ fonts[fontnum] = 0;
+ swf_FontExtract(c_swf,id,&fonts[fontnum]);
+ if(verbose) {
+ if(fonts[fontnum]) printf("Extracting font %d (%s)\n", id, name);
+ else printf("Extracting font %d (%s) failed\n", id, name);
+ fflush(stdout);
+ }
+ fontnum++;
+}
+typedef struct _textbounds
+{
+ SRECT r;
+ MATRIX m; // character transform matrix
+} textbounds_t;
+
+static void textcallback(void*self, int*chars, int*xpos, int nr, int fontid, int fontsize,
+ int xstart, int ystart, RGBA* color)
+{
+ textbounds_t * bounds = (textbounds_t*)self;
+ SWFFONT*font = 0;
+ int t;
+ for(t=0;t<fontnum;t++) {
+ if(fonts[t]->id == fontid) {
+ font = fonts[t];
+ break;
+ }
+ }
+ if(!font) {
+ fprintf(stderr, "Font %d unknown\n", fontid);
+ exit(1);
+ }
+ if(!font->layout) {
+ /* This is an expensive operation- but what should we do, we
+ need the glyph's bounding boxes */
+ swf_FontCreateLayout(font);
+ }
+
+ if(verbose)
+ printf("%d chars, font %d, size %d, at (%d,%d)\n", nr, fontid, fontsize, xstart, ystart);
+
+ for(t=0;t<nr;t++) {
+ /* not tested yet- the matrix/fontsize calculation is probably all wrong */
+ int x = xstart + xpos[t];
+ int y = ystart;
+ int ch;
+ SRECT newglyphbbox, glyphbbox = font->layout->bounds[chars[t]];
+ MATRIX m = bounds->m;
+
+ if(ch < font->numchars && font->glyph2ascii) {
+ ch = font->glyph2ascii[ch];
+ }
+
+ m.sx = (m.sx * fontsize) / 1024;
+ m.sy = (m.sy * fontsize) / 1024;
+ m.r0 = (m.r0 * fontsize) / 1024;
+ m.r1 = (m.r1 * fontsize) / 1024;
+
+ m.tx += x;
+ m.ty += y;
+ newglyphbbox = swf_TurnRect(glyphbbox, &m);
+
+ if(ch<32) ch='?';
+
+ swf_ExpandRect2(&(bounds->r), &newglyphbbox);
+ if(verbose >= 2) {
+ printf("%5d %c, %d %d %d %d (%d %d %d %d) -> %d %d %d %d\n",
+ xpos[t], ch,
+ glyphbbox.xmin, glyphbbox.ymin, glyphbbox.xmax, glyphbbox.ymax,
+ newglyphbbox.xmin, newglyphbbox.ymin, newglyphbbox.xmax, newglyphbbox.ymax,
+ bounds->r.xmin, bounds->r.ymin, bounds->r.xmax, bounds->r.ymax);
+ }
+
+ }
+}
+