-int swf_FontExtract_DefineTextCallback(int id,SWFFONT * f,TAG * t,int jobs,
- void(*callback)(int*chars, int nr, int fontid))
-{ U16 cid;
- SRECT r;
- MATRIX m;
- U8 gbits, abits, flags;
- int fid;
-
- fid = 0;
-
- swf_SaveTagPos(t);
- swf_SetTagPos(t,0);
-
- cid = swf_GetU16(t);
- swf_GetRect(t,&r);
- swf_GetMatrix(t,&m);
- gbits = swf_GetU8(t);
- abits = swf_GetU8(t);
-
- flags = swf_GetU8(t);
-
- while(flags)
- {
- // FIXME: according to open-swf@macromedia.com, this is wrong.
- // it should alternate textcontrol and text arrays, not
- // rely on the high bit. (and length can be 0-255).
- if (flags&TF_TEXTCONTROL)
- { if (flags&TF_HASFONT) fid = swf_GetU16(t);
- if (flags&TF_HASCOLOR)
- { swf_GetU8(t); // rgb
- swf_GetU8(t);
- swf_GetU8(t);
- if (swf_GetTagID(t)==ST_DEFINETEXT2) swf_GetU8(t);
- }
- if (flags&TF_HASXOFFSET) swf_GetS16(t);
- if (flags&TF_HASYOFFSET) swf_GetS16(t);
- if (flags&TF_HASFONT) swf_GetU16(t);
+static int
+swf_FontExtract_DefineTextCallback(int id, SWFFONT * f, TAG * t, int jobs,
+ void (*callback) (void *self,
+ int *chars, int *xpos, int nr, int fontid, int fontsize, int xstart, int ystart, RGBA * color), void *self)
+{
+ U16 cid;
+ SRECT r;
+ MATRIX m;
+ U8 gbits, abits;
+ int fid = 0;
+ RGBA color;
+ int x = 0, y = 0;
+ int fontsize = 0;
+
+ memset(&color, 0, sizeof(color));
+
+ swf_SaveTagPos(t);
+ swf_SetTagPos(t, 0);
+
+ cid = swf_GetU16(t);
+ swf_GetRect(t, &r);
+ swf_GetMatrix(t, &m);
+ gbits = swf_GetU8(t);
+ abits = swf_GetU8(t);
+
+ while (1) {
+ int flags, num;
+ flags = swf_GetU8(t);
+ if (!flags)
+ break;
+
+ if (flags & TF_TEXTCONTROL) {
+ if (flags & TF_HASFONT)
+ fid = swf_GetU16(t);
+ if (flags & TF_HASCOLOR) {
+ color.r = swf_GetU8(t); // rgb
+ color.g = swf_GetU8(t);
+ color.b = swf_GetU8(t);
+ if (swf_GetTagID(t) == ST_DEFINETEXT2)
+ color.a = swf_GetU8(t);
+ }
+ if (flags & TF_HASXOFFSET)
+ x = swf_GetS16(t);
+ if (flags & TF_HASYOFFSET)
+ y = swf_GetS16(t);
+ if (flags & TF_HASFONT)
+ fontsize = swf_GetU16(t);
+ }
+
+ num = swf_GetU8(t);
+ if (!num)
+ break;
+
+ {
+ int i;
+ int buf[256];
+ int advance[256];
+ int xpos = 0;
+ for (i = 0; i < num; i++) {
+ int glyph;
+ int adv = 0;
+ advance[i] = xpos;
+ glyph = swf_GetBits(t, gbits);
+ adv = swf_GetBits(t, abits);
+ xpos += adv;
+
+ // <deprecated>
+ if (id == fid) {
+ if (jobs & FEDTJ_PRINT) {
+ int code = f->glyph2ascii[glyph];
+ printf("%c", code);
+ }
+ if (jobs & FEDTJ_MODIFY)
+ f->glyph[glyph].advance = adv * 20; //?
+ } else {
+ if (jobs & FEDTJ_PRINT) {
+ printf("?");
+ }
+ }
+ // </deprecated>
+
+ buf[i] = glyph;
+ }
+ if ((id == fid) && (jobs & FEDTJ_PRINT))
+ printf("\n");
+ if (jobs & FEDTJ_CALLBACK)
+ callback(self, buf, advance, num, fid, fontsize, x, y, &color);
+ x += xpos;
+ }