X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftext.c;h=2b2bf91a3f92d600afb23672d1bac6d3afe165d6;hb=faca00b8c7eeee769980e19057a15ea82f52da7a;hp=683f494319f96ff707c4e4287e204ef10af0dc1b;hpb=2cb5e2da8a910e8afeabba2eadf259260052ae3b;p=swftools.git diff --git a/lib/modules/swftext.c b/lib/modules/swftext.c index 683f494..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 @@ -1265,6 +1280,10 @@ void swf_DrawText(drawer_t*draw, SWFFONT*font, int size, 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) {