X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswffont.c;h=986c07d72297039d67bc54e4ba9d14b71367b95b;hb=3d73649bf0e39778e715a07da902d0a858065a43;hp=75069e3d2c9b54d2774914fe9bfb5e6ff4d2aead;hpb=0784a8a882e7b98299fb6a90f0f9a7ebb322562b;p=swftools.git diff --git a/lib/modules/swffont.c b/lib/modules/swffont.c index 75069e3..986c07d 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; @@ -112,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, char flashtype) { FT_Face face; FT_Error error; @@ -137,17 +141,19 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) fprintf(stderr, "Couldn't load file %s- not a TTF file?\n", filename); return 0; } - - FT_Set_Pixel_Sizes (face, 16*loadfont_scale, 16*loadfont_scale); + + int scale = flashtype?20:1; + FT_Set_Pixel_Sizes (face, 16*loadfont_scale*scale, 16*loadfont_scale*scale); if(face->num_glyphs <= 0) { - fprintf(stderr, "File %s contains %d glyphs\n", face->num_glyphs); + fprintf(stderr, "File %s contains %d glyphs\n", filename, (int)face->num_glyphs); return 0; } font = (SWFFONT*)rfx_calloc(sizeof(SWFFONT)); font->id = -1; - font->version = 2; + font->version = flashtype?3:2; + font->layout = (SWFLAYOUT*)rfx_calloc(sizeof(SWFLAYOUT)); font->layout->bounds = (SRECT*)rfx_calloc(face->num_glyphs*sizeof(SRECT)); font->style = ((face->style_flags&FT_STYLE_FLAG_ITALIC)?FONT_STYLE_ITALIC:0) @@ -159,13 +165,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); @@ -235,6 +240,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; @@ -317,12 +324,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); @@ -332,6 +344,24 @@ 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; + + if(-fontbbox.ymin < 0) + font->layout->ascent = 0; + else + font->layout->ascent = -fontbbox.ymin; + + if(fontbbox.ymax < 0) + font->layout->descent = 0; + else + font->layout->descent = fontbbox.ymax; + + int leading = fontbbox.ymax - fontbbox.ymin; + font->layout->leading = leading>0x7fff?0x7fff:leading; + /* 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 */ @@ -350,7 +380,7 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename) } #else //HAVE_FREETYPE -SWFFONT* swf_LoadTrueTypeFont(char*filename) +SWFFONT* swf_LoadTrueTypeFont(const char*filename, char flashtype) { fprintf(stderr, "Warning: no freetype library- not able to load %s\n", filename); return 0; @@ -366,7 +396,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; @@ -516,7 +546,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; @@ -548,7 +578,7 @@ static int isSWF(const char*filename) return 0; } -SWFFONT* swf_LoadFont(char*filename) +SWFFONT* swf_LoadFont(const char*filename, char flashtype) { int is_swf; if(filename == 0) @@ -557,11 +587,14 @@ SWFFONT* swf_LoadFont(char*filename) if(is_swf<0) return 0; if(is_swf) { - return swf_ReadFont(filename); + SWFFONT*font = swf_ReadFont(filename); + if(flashtype && font->version==2) + fprintf(stderr, "Warning: Can't load font v2 file as flashtype (%s)\n", filename); + return font; } #if defined(HAVE_FREETYPE) - return swf_LoadTrueTypeFont(filename); + return swf_LoadTrueTypeFont(filename, flashtype); #elif defined(HAVE_T1LIB) return swf_LoadT1Font(filename); #else