+static gfximage_t* findimage(render_t*r, U16 id)
+{
+ character_t*c = (character_t*)map16_get_id(r->id2char, id);
+ assert(c && c->type == TYPE_BITMAP);
+ gfximage_t*img = (gfximage_t*)c->data;
+
+ /*char filename[80];
+ sprintf(filename, "bitmap%d.png", id);
+ writePNG(filename, (unsigned char*)img->data, img->width, img->height);
+ printf("saving bitmap %d to %s\n", id, filename);*/
+
+ return c->data;
+}
+//---- shape handling ----
+
+static void renderFilled(render_t*r, gfxline_t*line, FILLSTYLE*f, CXFORM*cx, MATRIX*po_m)
+{
+ if(f->type == FILL_SOLID) {
+ gfxcolor_t c = *(gfxcolor_t*)&f->color;
+ r->device->fill(r->device, line, &c);
+ } else if(f->type == FILL_TILED || f->type == FILL_CLIPPED) {
+ gfximage_t* img = findimage(r, f->id_bitmap);
+ gfxmatrix_t m;
+ gfxcxform_t gfxcx;
+ convertCXForm(cx, &gfxcx);
+ MATRIX m2;
+ swf_MatrixJoin(&m2, po_m, &f->m);
+ convertMatrix(&m2, &m);
+ m.m00/=20.0; m.m10/=20.0;
+ m.m01/=20.0; m.m11/=20.0;
+ /* TODO: handle clipped */
+ r->device->fillbitmap(r->device, line, img, &m, &gfxcx);
+ } else if(f->type == FILL_LINEAR || f->type == FILL_RADIAL) {
+ gfxmatrix_t m;
+ gfxgradient_t* g;
+ MATRIX* m2 = &f->m;
+ //swf_MatrixJoin(&m2, po_m, &f->m);
+
+ double z = f->type==FILL_RADIAL?4:4;
+ m.m00 = m2->sx/z/20.0; m.m10 = m2->r1/z/20.0;
+ m.m01 = m2->r0/z/20.0; m.m11 = m2->sy/z/20.0;
+ m.tx = m2->tx/20.0;
+ m.ty = m2->ty/20.0;
+
+ g = convertGradient(&f->gradient);
+ r->device->fillgradient(r->device, line, g, f->type == FILL_LINEAR ? gfxgradient_linear : gfxgradient_radial, &m);
+ free(g);
+ }
+}
+
+//---- font handling ----
+
+typedef struct
+{
+ int numchars;
+ gfxline_t**glyphs;
+} font_t;
+
+typedef struct textcallbackblock
+{
+ render_t*r;
+ MATRIX m;
+} textcallbackblock_t;
+
+static void textcallback(void*self, int*chars, int*xpos, int nr, int fontid, int fontsize,
+ int xstart, int ystart, RGBA* color)