X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswftext.c;h=62546db2a3ecfb9cb13062cd7cffc7b5c854bccf;hb=3d73649bf0e39778e715a07da902d0a858065a43;hp=1bb40d9db1fc1ddd6f19ba4fc9f64010f60ebb87;hpb=cde153b0547e260367cc82ea7563ff8689cb61d8;p=swftools.git diff --git a/lib/modules/swftext.c b/lib/modules/swftext.c index 1bb40d9..62546db 100644 --- a/lib/modules/swftext.c +++ b/lib/modules/swftext.c @@ -349,6 +349,13 @@ int swf_FontExtract_DefineFont2(int id, SWFFONT * font, TAG * tag) for (t = 0; t < glyphcount; t++) { swf_ResetReadBits(tag); swf_GetRect(tag, &font->layout->bounds[t]); + SRECT b = font->layout->bounds[t]; + if((b.xmin|b.xmax|b.ymin|b.ymax) == 0) { + // recalculate bounding box + SHAPE2 *shape2 = swf_ShapeToShape2(font->glyph[t].shape); + font->layout->bounds[t] = swf_GetShapeBoundingBox(shape2); + swf_Shape2Free(shape2);free(shape2); + } } kerningcount = swf_GetU16(tag); @@ -541,7 +548,6 @@ static void updateusage(void *self, int *chars, int *xpos, int nr, return; int t; - int firstpair=1; for(t=0;tlast!=c && !swf_ShapeIsEmpty(u->font->glyph[u->last].shape) && !swf_ShapeIsEmpty(u->font->glyph[c].shape)) { - /* ignore the first pair of every word (caps subset hack). */ - if(!firstpair) - swf_FontUsePair(u->font, u->last, c); - firstpair = 0; - } else { - firstpair = 1; + swf_FontUsePair(u->font, u->last, c); } u->lasty = y; /* FIXME: do we still need to divide advance by 20 for definefont3? */ @@ -838,6 +839,14 @@ int swf_FontReduce(SWFFONT * f) return 0; } +static SWFFONT* font_to_sort; +int cmp_chars(const void*a, const void*b) +{ + int x = *(const int*)a; + int y = *(const int*)b; + return 0; +} + void swf_FontSort(SWFFONT * font) { int i, j; @@ -851,6 +860,8 @@ void swf_FontSort(SWFFONT * font) for (i = 0; i < font->numchars; i++) { newplace[i] = i; } + //qsort(newplace, sizeof(newplace[0]), font->numchars, cmp_chars); + for (i = 0; i < font->numchars; i++) for (j = 0; j < i; j++) { if (font->glyph2ascii[i] < font->glyph2ascii[j]) { @@ -893,8 +904,8 @@ void swf_FontSort(SWFFONT * font) font->ascii2glyph[i] = newpos[font->ascii2glyph[i]]; } - rfx_free(newpos); rfx_free(newplace); + font->glyph2glyph = newpos; } void swf_FontPrepareForEditText(SWFFONT * font) @@ -938,14 +949,14 @@ int swf_FontUse(SWFFONT * f, U8 * s) return 0; } -int swf_FontUseUTF8(SWFFONT * f, U8 * s, U16 size) +int swf_FontUseUTF8(SWFFONT * f, const U8 * s, U16 size) { if( (!s)) return -1; int ascii; while (*s) { - ascii = readUTF8char(&s); + ascii = readUTF8char((U8**)&s); if(ascii < f->maxascii && f->ascii2glyph[ascii]>=0) swf_FontUseGlyph(f, f->ascii2glyph[ascii], size); } @@ -1194,12 +1205,15 @@ int swf_FontSetDefine2(TAG * tag, SWFFONT * f) if (f->layout) { swf_SetU16(tag, f->layout->ascent); swf_SetU16(tag, f->layout->descent); - swf_SetU16(tag, f->layout->leading); + swf_SetU16(tag, 0); // flash ignores leading + for (t = 0; t < f->numchars; t++) swf_SetU16(tag, f->glyph[t].advance); for (t = 0; t < f->numchars; t++) { swf_ResetWriteBits(tag); - swf_SetRect(tag, &f->layout->bounds[t]); + /* not used by flash, so leave this empty */ + SRECT b = {0,0,0,0}; + swf_SetRect(tag, &b); } swf_SetU16(tag, f->layout->kerningcount); for (t = 0; t < f->layout->kerningcount; t++) { @@ -1278,6 +1292,13 @@ int swf_TextPrintDefineText(TAG * t, SWFFONT * f) return 0; } +static void font_freealignzones(SWFFONT * f) +{ + if(f->alignzones) + free(f->alignzones); + f->alignzones = 0; +} + void swf_FontFree(SWFFONT * f) { int i; @@ -1305,10 +1326,15 @@ void swf_FontFree(SWFFONT * f) rfx_free(f->glyph2ascii); f->glyph2ascii = NULL; } + if (f->glyph2glyph) { + rfx_free(f->glyph2glyph); + f->glyph2glyph = NULL; + } font_freename(f); font_freelayout(f); font_freeglyphnames(f); font_freeusage(f); + font_freealignzones(f); rfx_free(f); }