+
+static SWFFONT* gfxfont_to_swffont(gfxfont_t*font, char* id)
+{
+ SWFFONT*swffont = (SWFFONT*)rfx_calloc(sizeof(SWFFONT));
+ int t;
+ swffont->id = -1;
+ swffont->version = 2;
+ swffont->name = (U8*)strdup(id);
+ swffont->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT));
+ swffont->layout->ascent = 0; /* ? */
+ swffont->layout->descent = 0;
+ swffont->layout->leading = 0;
+ swffont->layout->bounds = (SRECT*)rfx_calloc(sizeof(SRECT)*font->num_glyphs);
+ swffont->encoding = FONT_ENCODING_UNICODE;
+ swffont->numchars = font->num_glyphs;
+ swffont->maxascii = font->max_unicode;
+ swffont->ascii2glyph = (int*)rfx_calloc(sizeof(int)*swffont->maxascii);
+ swffont->glyph2ascii = (U16*)rfx_calloc(sizeof(U16)*swffont->numchars);
+ swffont->glyph = (SWFGLYPH*)rfx_calloc(sizeof(SWFGLYPH)*swffont->numchars);
+ swffont->glyphnames = (char**)rfx_calloc(sizeof(char*)*swffont->numchars);
+ for(t=0;t<font->max_unicode;t++) {
+ swffont->ascii2glyph[t] = font->unicode2glyph[t];
+ }
+ for(t=0;t<font->num_glyphs;t++) {
+ drawer_t draw;
+ gfxline_t*line;
+ swffont->glyph2ascii[t] = font->glyphs[t].unicode;
+ if(font->glyphs[t].name) {
+ swffont->glyphnames[t] = strdup(font->glyphs[t].name);
+ } else {
+ swffont->glyphnames[t] = 0;
+ }
+ swffont->glyph[t].advance = (int)(font->glyphs[t].advance * 20);
+
+ swf_Shape01DrawerInit(&draw, 0);
+ line = font->glyphs[t].line;
+ while(line) {
+ FPOINT c,to;
+ c.x = line->sx; c.y = line->sy;
+ to.x = line->x; to.y = line->y;
+ if(line->type == gfx_moveTo) {
+ draw.moveTo(&draw, &to);
+ } else if(line->type == gfx_lineTo) {
+ draw.lineTo(&draw, &to);
+ } else if(line->type == gfx_splineTo) {
+ draw.splineTo(&draw, &c, &to);
+ }
+ line = line->next;
+ }
+ draw.finish(&draw);
+ swffont->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
+ draw.dealloc(&draw);
+ }
+ return swffont;
+}
+
+void swf_addfont(gfxdevice_t*dev, char*fontid, gfxfont_t*font)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+
+ if(i->obj->swffont && i->obj->swffont->name && !strcmp((char*)i->obj->swffont->name,fontid))
+ return; // the requested font is the current font
+
+ fontlist_t*last=0,*l = i->fontlist;
+ while(l) {
+ last = l;
+ if(!strcmp((char*)l->swffont->name, fontid)) {
+ return; // we already know this font
+ }
+ l = l->next;
+ }
+ l = (fontlist_t*)rfx_calloc(sizeof(fontlist_t));
+ l->swffont = gfxfont_to_swffont(font, fontid);
+ l->next = 0;
+ if(last) {
+ last->next = l;
+ } else {
+ i->fontlist = l;
+ }
+ swf_FontSetID(l->swffont, getNewID(i->obj));
+
+ if(getScreenLogLevel() >= LOGLEVEL_DEBUG) {
+ // print font information
+ msg("<debug> Font %s",fontid);
+ msg("<debug> | ID: %d", l->swffont->id);
+ msg("<debug> | Version: %d", l->swffont->version);
+ msg("<debug> | Name: %s", l->swffont->name);
+ msg("<debug> | Numchars: %d", l->swffont->numchars);
+ msg("<debug> | Maxascii: %d", l->swffont->maxascii);
+ msg("<debug> | Style: %d", l->swffont->style);
+ msg("<debug> | Encoding: %d", l->swffont->encoding);
+ for(int iii=0; iii<l->swffont->numchars;iii++) {
+ msg("<debug> | Glyph %d) name=%s, unicode=%d size=%d bbox=(%.2f,%.2f,%.2f,%.2f)\n", iii, l->swffont->glyphnames?l->swffont->glyphnames[iii]:"<nonames>", l->swffont->glyph2ascii[iii], l->swffont->glyph[iii].shape->bitlen,
+ l->swffont->layout->bounds[iii].xmin/20.0,
+ l->swffont->layout->bounds[iii].ymin/20.0,
+ l->swffont->layout->bounds[iii].xmax/20.0,
+ l->swffont->layout->bounds[iii].ymax/20.0
+ );
+ int t;
+ for(t=0;t<l->swffont->maxascii;t++) {
+ if(l->swffont->ascii2glyph[t] == iii)
+ msg("<debug> | - maps to %d",t);
+ }
+ }
+ }
+}
+
+static void swf_switchfont(gfxdevice_t*dev, char*fontid)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ if(obj->swffont && obj->swffont->name && !strcmp((char*)obj->swffont->name,fontid))
+ return; // the requested font is the current font
+
+ fontlist_t*l = i->fontlist;
+ while(l) {
+ if(!strcmp((char*)l->swffont->name, fontid)) {
+ obj->swffont = l->swffont;
+ return; //done!
+ }
+ l = l->next;
+ }
+ msg("<error> Unknown font id: %s", fontid);
+ return;
+}
+
+void swf_drawchar(gfxdevice_t*dev, char*fontid, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
+{
+ swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+ swfoutput*obj = i->obj;
+
+ if(!obj->swffont || !obj->swffont->name || strcmp((char*)obj->swffont->name,fontid)) // not equal to current font
+ {
+ /* TODO: remove the need for this (enhance getcharacterbbox so that it can cope
+ with multiple fonts */
+ endtext(obj);
+
+ swf_switchfont(dev, fontid); // set the current font
+ }
+ swfoutput_setfontmatrix(obj, matrix->m00, matrix->m01, matrix->m10, matrix->m11);
+
+ swfmatrix m;
+ m.m11 = obj->fontm11;
+ m.m12 = obj->fontm12;
+ m.m21 = obj->fontm21;
+ m.m22 = obj->fontm22;
+ m.m31 = matrix->tx;
+ m.m32 = matrix->ty;
+ drawchar(obj, obj->swffont, 0, glyph, -1, &m, color);
+}