From: Matthias Kramm <kramm@quiss.org>
Date: Sat, 17 Apr 2010 02:50:54 +0000 (-0700)
Subject: OSX bearing fix
X-Git-Tag: version-0-9-1~45
X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=c1c865b58f4fbc9c97f92110306e277665ad9c81;p=swftools.git

OSX bearing fix
---

diff --git a/lib/gfxfont.c b/lib/gfxfont.c
index 8650880..fa75059 100644
--- a/lib/gfxfont.c
+++ b/lib/gfxfont.c
@@ -593,7 +593,7 @@ void gfxfont_fix_unicode(gfxfont_t*font)
     }
 }
 
-ttf_t* gfxfont_to_ttf(gfxfont_t*font)
+ttf_t* gfxfont_to_ttf(gfxfont_t*font, char eot)
 {
     ttf_t*ttf = ttf_new();
     int num_glyphs = font->num_glyphs;
@@ -665,17 +665,23 @@ ttf_t* gfxfont_to_ttf(gfxfont_t*font)
 	    }
 	}
 
-	dest->bearing = dest->xmin;
-	/* make sure coordinates are always to the right of the origin */
-	int xshift=0;
-	if(dest->xmin < 0) {
-	    xshift = -dest->xmin;
-	    for(s=0;s<count;s++) {
-		dest->points[s].x += xshift;
+	if(eot) {
+	    dest->bearing = dest->xmin;
+	    /* for windows font rendering, make sure coordinates are always 
+	       to the right of the origin (and use bearing to shift them "back".)
+	       Don't do this for non-windows platforms though because e.g. OS X 
+	       ignores bearing. */
+	    int xshift=0;
+	    if(dest->xmin < 0) {
+		xshift = -dest->xmin;
+		for(s=0;s<count;s++) {
+		    dest->points[s].x += xshift;
+		}
+		dest->xmin += xshift;
+		dest->xmax += xshift;
 	    }
-	    dest->xmin += xshift;
-	    dest->xmax += xshift;
 	}
+	dest->advance = src->advance*scale;
 
 	//dest->xmin=0; //TODO: might be necessary for some font engines?
 
@@ -735,14 +741,14 @@ ttf_t* gfxfont_to_ttf(gfxfont_t*font)
 
 void gfxfont_save(gfxfont_t*font, const char*filename)
 {
-    ttf_t*ttf = gfxfont_to_ttf(font);
+    ttf_t*ttf = gfxfont_to_ttf(font, 0);
     ttf_save(ttf, filename);
     ttf_destroy(ttf);
 }
 
 void gfxfont_save_eot(gfxfont_t*font, const char*filename)
 {
-    ttf_t*ttf = gfxfont_to_ttf(font);
+    ttf_t*ttf = gfxfont_to_ttf(font, 1);
     ttf_save_eot(ttf, filename);
     ttf_destroy(ttf);
 }
diff --git a/lib/ttf.c b/lib/ttf.c
index fbbf200..0e442d1 100644
--- a/lib/ttf.c
+++ b/lib/ttf.c
@@ -726,8 +726,8 @@ static table_hea_t*hea_new(ttf_t*ttf)
 	for(t=0;t<ttf->num_glyphs;t++) {
 	    if(ttf->glyphs[t].advance > hea->advanceWidthMax)
 	        hea->advanceWidthMax = ttf->glyphs[t].advance;
-	    if(ttf->glyphs[t].xmin < hea->minLeftSideBearing)
-	        hea->minLeftSideBearing = ttf->glyphs[t].xmin;
+	    if(ttf->glyphs[t].bearing < hea->minLeftSideBearing)
+	        hea->minLeftSideBearing = ttf->glyphs[t].bearing;
 	    if(ttf->glyphs[t].xmax < hea->minRightSideBearing)
 	        hea->minRightSideBearing = ttf->glyphs[t].xmax;
 	    int width = ttf->glyphs[t].xmax - ttf->glyphs[t].xmin;