X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswffont.c;h=ccb1a0f9c90f24ee5b4429d7f58457ee76d027e7;hb=1a8bf7cbf602bce86efc1dfe11d86e06373bcd44;hp=c8c3efa58b57d80fa4296e7a70a4b35178bdcf70;hpb=6c3ab5574d31504d24710c2756899d49275c1a37;p=swftools.git diff --git a/lib/modules/swffont.c b/lib/modules/swffont.c index c8c3efa..ccb1a0f 100644 --- a/lib/modules/swffont.c +++ b/lib/modules/swffont.c @@ -21,6 +21,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include +#include +#include "../rfxswf.h" + static int loadfont_scale = 4; static int skip_unused = 1; static int full_unicode = 0; @@ -122,7 +126,6 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) SWFFONT* font; int t; int*glyph2glyph; - FT_Size size; int max_unicode = 0; int charmap = -1; @@ -160,13 +163,12 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) if(FT_HAS_GLYPH_NAMES(face)) { font->glyphnames = (char**)rfx_calloc(face->num_glyphs*sizeof(char*)); } - - font->layout->ascent = abs(face->ascender)*FT_SCALE*loadfont_scale*20/FT_SUBPIXELS/2; //face->bbox.xMin; - font->layout->descent = abs(face->descender)*FT_SCALE*loadfont_scale*20/FT_SUBPIXELS/2; //face->bbox.xMax; - font->layout->leading = font->layout->ascent + font->layout->descent; + font->layout->kerningcount = 0; - name = FT_Get_Postscript_Name(face); + name = face->family_name; + if(!(name && *name)) + name = FT_Get_Postscript_Name(face); if(name && *name) font->name = (U8*)strdup(name); @@ -236,13 +238,13 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) glyph2glyph = (int*)rfx_calloc(face->num_glyphs*sizeof(int)); + SRECT fontbbox = {0,0,0,0}; + for(t=0; t < face->num_glyphs; t++) { FT_Glyph glyph; FT_BBox bbox; - FT_Matrix matrix; char name[128]; drawer_t draw; - int ret; char hasname = 0; name[0]=0; if(FT_HAS_GLYPH_NAMES(face)) { @@ -320,12 +322,17 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) font->glyph[font->numchars].advance = 0; #endif + SRECT b = swf_ShapeDrawerGetBBox(&draw); + + //font->layout->bounds[font->numchars].xmin = (bbox.xMin*FT_SCALE*20)/FT_SUBPIXELS; + //font->layout->bounds[font->numchars].ymin = (bbox.yMin*FT_SCALE*20)/FT_SUBPIXELS; + //font->layout->bounds[font->numchars].xmax = (bbox.xMax*FT_SCALE*20)/FT_SUBPIXELS; + //font->layout->bounds[font->numchars].ymax = (bbox.yMax*FT_SCALE*20)/FT_SUBPIXELS; + + font->layout->bounds[font->numchars] = b; font->glyph[font->numchars].shape = swf_ShapeDrawerToShape(&draw); - - font->layout->bounds[font->numchars].xmin = (bbox.xMin*FT_SCALE*20)/FT_SUBPIXELS; - font->layout->bounds[font->numchars].ymin = (bbox.yMin*FT_SCALE*20)/FT_SUBPIXELS; - font->layout->bounds[font->numchars].xmax = (bbox.xMax*FT_SCALE*20)/FT_SUBPIXELS; - font->layout->bounds[font->numchars].ymax = (bbox.yMax*FT_SCALE*20)/FT_SUBPIXELS; + + swf_ExpandRect2(&fontbbox, &font->layout->bounds[font->numchars]); draw.dealloc(&draw); @@ -335,6 +342,19 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) glyph2glyph[t] = font->numchars; font->numchars++; } + + //font->layout->ascent = abs(face->ascender)*FT_SCALE*loadfont_scale*20/FT_SUBPIXELS/2; //face->bbox.xMin; + //font->layout->descent = abs(face->descender)*FT_SCALE*loadfont_scale*20/FT_SUBPIXELS/2; //face->bbox.xMax; + //font->layout->leading = font->layout->ascent + font->layout->descent; + + font->layout->ascent = -fontbbox.ymin; + if(font->layout->ascent < 0) + font->layout->ascent = 0; + font->layout->descent = fontbbox.ymax; + if(font->layout->descent < 0) + font->layout->descent = 0; + font->layout->leading = fontbbox.ymax - fontbbox.ymin; + /* notice: if skip_unused is true, font->glyph2ascii, font->glyphnames and font->layout->bounds will have more memory allocated than just font->numchars, but only the first font->numchars are used/valid */