X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmodules%2Fswftext.c;h=2b2bf91a3f92d600afb23672d1bac6d3afe165d6;hb=dc0a59712d4452403bca5b80affef03535c6ce05;hp=b0b4cc239416450df26afad59ddc1bb0796e572e;hpb=6052834ef4944e94adc5b120564339beec203710;p=swftools.git diff --git a/lib/modules/swftext.c b/lib/modules/swftext.c index b0b4cc2..2b2bf91 100644 --- a/lib/modules/swftext.c +++ b/lib/modules/swftext.c @@ -625,7 +625,7 @@ int swf_FontSetDefine2(TAG *tag, SWFFONT * f) flags |= 4; //wide codecs if(fontSize(f)>65535) flags |= 8; //wide offsets - flags |= 8; //FIXME: the above check doesn't work + flags |= 8|4; //FIXME: the above check doesn't work if(f->encoding & FONT_ENCODING_ANSI) flags |= 16; // ansi @@ -805,7 +805,8 @@ void swf_FontFree(SWFFONT * f) if(f->glyphnames) { int t; for(t=0;tnumchars;t++) { - free(f->glyphnames[t]); + if(f->glyphnames[t]) + free(f->glyphnames[t]); } free(f->glyphnames); } @@ -930,6 +931,31 @@ U32 swf_TextGetWidth(SWFFONT * font,U8 * s,int scale) return res; } +SRECT swf_TextCalculateBBoxUTF8(SWFFONT * font,U8 * s,int scale) +{ + int pos=0; + SRECT r; + swf_GetRect(0, &r); + while(*s) { + int c = readUTF8char(&s); + if(c < font->maxascii) { + int g = font->ascii2glyph[c]; + if(g>=0) { + SRECT rn = font->layout->bounds[g]; + rn.xmin = (rn.xmin * scale)/20/100 + pos; + rn.xmax = (rn.xmax * scale)/20/100 + pos; + rn.ymin = (rn.ymin * scale)/20/100; + rn.ymax = (rn.ymax * scale)/20/100; + swf_ExpandRect2(&r, &rn); + pos += (font->glyph[g].advance*scale)/20/100; + } + } + c++; + } + return r; +} + + SWFFONT* swf_ReadFont(char* filename) { int f; @@ -1003,7 +1029,10 @@ void swf_WriteFont(SWFFONT*font, char* filename) swf_SetU16(t, WRITEFONTID); swf_SetU16(t, font->numchars); for(c=0;cnumchars;c++) { - swf_SetString(t, font->glyphnames[c]); + if(font->glyphnames[c]) + swf_SetString(t, font->glyphnames[c]); + else + swf_SetString(t, ""); } } @@ -1161,24 +1190,10 @@ SRECT swf_SetDefineText(TAG*tag, SWFFONT*font, RGBA*rgb, char*text, int scale) U8 gbits, abits; U8*c = (U8*)text; int pos = 0; - swf_GetRect(0, &r); if(font->layout) { - while(*c) { - if(*c < font->maxascii) { - int g = font->ascii2glyph[*c]; - if(g>=0) { - SRECT rn = font->layout->bounds[g]; - rn.xmin = (rn.xmin * scale)/100 + pos; - rn.xmax = (rn.xmax * scale)/100 + pos; - rn.ymin = (rn.ymin * scale)/100; - rn.ymax = (rn.ymax * scale)/100; - swf_ExpandRect2(&r, &rn); - pos += (font->glyph[g].advance*scale)/100; - } - } - c++; - } + r = swf_TextCalculateBBoxUTF8(font,text,scale*20); } else { + fprintf(stderr, "No layout information- can't compute text bbox accurately"); /* Hm, without layout information, we can't compute a bounding box. We could call swf_FontCreateLayout to create a layout, but the caller probably doesn't want us to mess up his font @@ -1254,7 +1269,7 @@ void swf_FontCreateLayout(SWFFONT*f) } } -void swf_DrawText(drawer_t*draw, SWFFONT*font, char*text) +void swf_DrawText(drawer_t*draw, SWFFONT*font, int size, char*text) { U8*s = (U8*)text; int advance = 0; @@ -1265,31 +1280,35 @@ void swf_DrawText(drawer_t*draw, SWFFONT*font, char*text) U32 c = readUTF8char(&s); int g = font->ascii2glyph[c]; shape = font->glyph[g].shape; + if(((int)g)<0) { + fprintf(stderr, "No char %d in font %s\n", c, font->name?(char*)font->name:"?"); + continue; + } shape2 = swf_ShapeToShape2(shape); l = shape2->lines; while(l) { if(l->type == moveTo) { FPOINT to; - to.x = l->x/20.0+advance; - to.y = l->y/20.0; + to.x = l->x*size/100.0/20.0+advance; + to.y = l->y*size/100.0/20.0; draw->moveTo(draw, &to); } else if(l->type == lineTo) { FPOINT to; - to.x = l->x/20.0+advance; - to.y = l->y/20.0; + to.x = l->x*size/100.0/20.0+advance; + to.y = l->y*size/100.0/20.0; draw->lineTo(draw, &to); } else if(l->type == splineTo) { FPOINT mid,to; - mid.x = l->sx/20.0+advance; - mid.y = l->sy/20.0; - to.x = l->x/20.0+advance; - to.y = l->y/20.0; + mid.x = l->sx*size/100.0/20.0+advance; + mid.y = l->sy*size/100.0/20.0; + to.x = l->x*size/100.0/20.0+advance; + to.y = l->y*size/100.0/20.0; draw->splineTo(draw, &mid, &to); } l = l->next; } swf_Shape2Free(shape2); - advance += font->glyph[g].advance/20.0; + advance += font->glyph[g].advance*size/100.0/20.0; } }