From: kramm <kramm>
Date: Sun, 6 Mar 2005 20:17:51 +0000 (+0000)
Subject: fixed a bug where a non-loadable character shifts all other characters
X-Git-Tag: release-0-7-0~175
X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=338fe5380bbfab8828826ae7b81b7bbbcc29cf50;p=swftools.git

fixed a bug where a non-loadable character shifts all other characters
to incorrect encoding positions.
---

diff --git a/lib/modules/swffont.c b/lib/modules/swffont.c
index 63ccc4f..876c139 100644
--- a/lib/modules/swffont.c
+++ b/lib/modules/swffont.c
@@ -256,15 +256,24 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
 	error = FT_Load_Glyph(face, t, FT_LOAD_NO_BITMAP);
 	if(error) {
 	    fprintf(stderr, "Couldn't load glyph %d, error:%d\n", t, error);
-	    continue;
-	}
-	error = FT_Get_Glyph(face->glyph, &glyph);
-	if(error) {
-	    fprintf(stderr, "Couldn't get glyph %d, error:%d\n", t, error);
-	    continue;
+	    glyph=0;
+	    if(skip_unused) 
+		continue;
+	} else {
+	    error = FT_Get_Glyph(face->glyph, &glyph);
+	    if(error) {
+		fprintf(stderr, "Couldn't get glyph %d, error:%d\n", t, error);
+		glyph=0;
+		if(skip_unused) 
+		    continue;
+	    }
 	}
 
-	FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_unscaled, &bbox);
+	if(glyph)
+	    FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_unscaled, &bbox);
+	else
+	    memset(&bbox, 0, sizeof(bbox));
+
 	bbox.yMin = -bbox.yMin;
 	bbox.yMax = -bbox.yMax;
 	if(bbox.xMax < bbox.xMin) {
@@ -283,7 +292,10 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
 	swf_Shape01DrawerInit(&draw, 0);
 
 	//error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &draw);
-	error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &draw);
+	if(glyph)
+	    error = FT_Outline_Decompose(&face->glyph->outline, &outline_functions, &draw);
+	else
+	    error = 0;
 	draw.finish(&draw);
 	
 	if(error) {
@@ -299,7 +311,10 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
 	    font->glyph[font->numchars].advance = ((bbox.xMax - bbox.xMin)*20*FT_SCALE)/FT_SUBPIXELS;
 	}
 #else
-	font->glyph[font->numchars].advance = glyph->advance.x*20/65536;
+	if(glyph)
+	    font->glyph[font->numchars].advance = glyph->advance.x*20/65536;
+	else
+	    font->glyph[font->numchars].advance = 0;
 #endif
 	
 	font->glyph[font->numchars].shape = swf_ShapeDrawerToShape(&draw);
@@ -311,7 +326,8 @@ SWFFONT* swf_LoadTrueTypeFont(char*filename)
 
 	draw.dealloc(&draw);
 
-	FT_Done_Glyph(glyph);
+	if(glyph)
+	    FT_Done_Glyph(glyph);
 	font->glyph2ascii[font->numchars] = font->glyph2ascii[t];
 	glyph2glyph[t] = font->numchars;
 	font->numchars++;