+
+ return img;
+}
+
+typedef struct
+{
+ int numchars;
+ SHAPE2**glyphs;
+} font_t;
+
+typedef struct
+{
+ TAG*tag;
+ SRECT*bbox;
+ enum {none_type, shape_type, image_type, text_type, font_type} type;
+ union {
+ SHAPE2*shape;
+ font_t*font;
+ } obj;
+} character_t;
+
+int compare_placements(const void *v1, const void *v2)
+{
+ SWFPLACEOBJECT*p1 = (SWFPLACEOBJECT*)v1;
+ SWFPLACEOBJECT*p2 = (SWFPLACEOBJECT*)v2;
+ if(p1->depth != p2->depth)
+ return (int)p1->depth - (int)p2->depth;
+ else
+ if(p2->clipdepth)
+ return 1; // do the clip first
+ else
+ return -1;
+
+/* if(!p1->clipdepth) {
+ if(!p2->clipdepth) {
+ // !p1->clipdepth && !p2->clipdepth
+ return (int)p1->depth - (int)p2->depth;
+ } else {
+ // !p1->clipdepth && p2->clipdepth
+ if(p1->depth != p2->clipdepth)
+ return (int)p1->depth - (int)p2->clipdepth;
+ else
+ return 1; // do the clip first
+ }
+ } else {
+ if(!p2->clipdepth) {
+ // p1->clipdepth && !p2->clipdepth
+ if(p1->clipdepth != p2->depth)
+ return (int)p1->clipdepth - (int)p2->depth;
+ else
+ return -1;// do the clip first
+ } else {
+ if(p1->clipdepth != p2->clipdepth)
+ return (int)p1->clipdepth - (int)p2->clipdepth;
+ else
+ return (int)p1->depth - (int)p2->depth;
+ }
+ }*/
+}
+
+typedef struct textcallbackblock
+{
+ character_t*idtable;
+ U16 depth;
+ U16 clipdepth;
+ CXFORM* cxform;
+ MATRIX m;
+ RENDERBUF*buf;
+} textcallbackblock_t;
+
+static void textcallback(void*self, int*chars, int*xpos, int nr, int fontid, int fontsize,
+ int xstart, int ystart, RGBA* color)
+{
+ textcallbackblock_t * info = (textcallbackblock_t*)self;
+ font_t*font = 0;
+ int t;
+ if(!info->idtable[fontid].obj.font) {
+ fprintf(stderr, "Font %d unknown\n", fontid);
+ return;
+ } else {
+ font = info->idtable[fontid].obj.font;
+ }
+ for(t=0;t<nr;t++) {
+ int x = xstart + xpos[t];
+ int y = ystart;
+ MATRIX m = info->m;
+ SPOINT p;
+
+ p.x = x; p.y = y;
+ p = swf_TurnPoint(p, &m);
+
+ 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 += p.x;
+ m.ty += p.y;
+
+ if(chars[t]<0 || chars[t]>= font->numchars) {
+ fprintf(stderr, "Character out of range: %d\n", chars[t]);
+ } else {
+ SHAPE2*shape = font->glyphs[chars[t]];
+ shape->fillstyles[0].color = *color; //q&d
+ printf("Rendering char %d (size %d, x:%d, y:%d) color:%02x%02x%02x%02x\n", chars[t], fontsize, x, y,
+ color->a, color->r, color->g, color->b);
+ swf_DumpMatrix(stdout, &m);
+ swf_DumpShape(shape);
+ swf_RenderShape(info->buf, shape, &m, info->cxform, info->depth, info->clipdepth);
+ }
+ }
+}
+
+void swf_RenderSWF(RENDERBUF*buf, SWF*swf)
+{
+ TAG*tag;
+ int t;
+ int numplacements;
+ RGBA color;
+ SWFPLACEOBJECT* placements;