X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswffont.c;h=cd553b820daa3aad769a060a644e1034bb9adfbf;hb=d85090d5a239735d923590480573573b1d856009;hp=df231e711b1c7f8aef89e52ee872ef8ea3caa60f;hpb=166f72fe8468fa00cc225cfa9bfa64d02fb7a87e;p=swftools.git diff --git a/lib/modules/swffont.c b/lib/modules/swffont.c index df231e7..cd553b8 100644 --- a/lib/modules/swffont.c +++ b/lib/modules/swffont.c @@ -116,7 +116,7 @@ static FT_Outline_Funcs outline_functions = static FT_Library ftlibrary = 0; -SWFFONT* swf_LoadTrueTypeFont(char*filename) +SWFFONT* swf_LoadTrueTypeFont(const char*filename) { FT_Face face; FT_Error error; @@ -163,10 +163,7 @@ 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 = face->family_name; @@ -241,6 +238,8 @@ 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; @@ -323,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); @@ -338,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 */ @@ -356,7 +373,7 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) } #else //HAVE_FREETYPE -SWFFONT* swf_LoadTrueTypeFont(char*filename) +SWFFONT* swf_LoadTrueTypeFont(const char*filename) { fprintf(stderr, "Warning: no freetype library- not able to load %s\n", filename); return 0; @@ -372,7 +389,7 @@ static int t1lib_initialized = 0; static int counter = 0; -SWFFONT* swf_LoadT1Font(char*filename) +SWFFONT* swf_LoadT1Font(const char*filename) { SWFFONT * font; int nr; @@ -522,7 +539,7 @@ SWFFONT* swf_LoadT1Font(char*filename) #else -SWFFONT* swf_LoadT1Font(char*filename) +SWFFONT* swf_LoadT1Font(const char*filename) { fprintf(stderr, "Warning: no t1lib- not able to load %s\n", filename); return 0; @@ -554,7 +571,7 @@ static int isSWF(const char*filename) return 0; } -SWFFONT* swf_LoadFont(char*filename) +SWFFONT* swf_LoadFont(const char*filename) { int is_swf; if(filename == 0)