Brought up to date
[swftools.git] / lib / modules / swffont.c
index f8f7707..e24d880 100644 (file)
@@ -130,9 +130,9 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
        font->glyphnames = malloc(face->num_glyphs*sizeof(char*));
     }
 
-    font->layout->ascent = face->ascender; //face->bbox.xMin;
-    font->layout->descent = face->descender; //face->bbox.xMax;
-    font->layout->leading = -face->bbox.xMin;
+    font->layout->ascent = face->ascender*20/FT_SUBPIXELS; //face->bbox.xMin;
+    font->layout->descent = abs(face->descender)*20/FT_SUBPIXELS; //face->bbox.xMax;
+    font->layout->leading = -face->bbox.xMin*20/FT_SUBPIXELS;
     font->layout->kerningcount = 0;
     
     name = FT_Get_Postscript_Name(face);
@@ -224,7 +224,7 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
            font->glyph[t].advance = ((bbox.xMax - bbox.xMin)*FT_SCALE)/FT_SUBPIXELS;
        }
 #else
-       font->glyph[t].advance = glyph->advance.x/65536;
+       font->glyph[t].advance = glyph->advance.x*20/65536;
 #endif
        
        font->glyph[t].shape = swf_ShapeDrawerToShape(&draw);
@@ -300,7 +300,10 @@ SWFFONT* swf_LoadT1Font(char*filename)
     memset(font, 0, sizeof(SWFFONT));
 
     font->version = 2;
-    font->name = (U8*)strdup(fontname);
+    if(fontname) 
+       font->name = (U8*)strdup(fontname);
+    else 
+       font->name = 0;
     font->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
     memset(font->layout, 0, sizeof(SWFLAYOUT));
 
@@ -389,7 +392,7 @@ SWFFONT* swf_LoadT1Font(char*filename)
        draw.dealloc(&draw);
            
        font->layout->bounds[c] = bbox;
-       font->glyph[c].advance = bbox.xmax/20;
+       font->glyph[c].advance = bbox.xmax;
        if(!font->glyph[c].advance) {
            font->glyph[c].advance = firstx;
        }
@@ -414,7 +417,7 @@ static int isSWF(const char*filename)
     char a[8];
     if(!fi) {
        perror(filename);
-       return 0;
+       return -1;
     }
     memset(a, 0, sizeof(a));
     fread(a, 4, 1, fi);
@@ -428,7 +431,10 @@ static int isSWF(const char*filename)
 
 SWFFONT* swf_LoadFont(char*filename)
 {
-    if(isSWF(filename)) {
+    int is_swf = isSWF(filename);
+    if(is_swf<0)
+       return 0;
+    if(is_swf) {
        return swf_ReadFont(filename);
     }
 #if defined(HAVE_FREETYPE)
@@ -436,7 +442,7 @@ SWFFONT* swf_LoadFont(char*filename)
 #elif defined(HAVE_T1LIB)
     return swf_LoadT1Font(filename);
 #else
-    fprintf(stderr, "Error: Neither T1lib nor FreeType support compiled in. Could not load %s\n", infile);
+    fprintf(stderr, "Error: Neither T1lib nor FreeType support compiled in. Could not load %s\n", filename);
     return 0;
 #endif
 }