OSX bearing fix
authorMatthias Kramm <kramm@quiss.org>
Sat, 17 Apr 2010 02:50:54 +0000 (19:50 -0700)
committerMatthias Kramm <kramm@quiss.org>
Sat, 17 Apr 2010 02:50:54 +0000 (19:50 -0700)
lib/gfxfont.c
lib/ttf.c

index 8650880..fa75059 100644 (file)
@@ -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;
 {
     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?
 
 
        //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)
 {
 
 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_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);
 }
     ttf_save_eot(ttf, filename);
     ttf_destroy(ttf);
 }
index fbbf200..0e442d1 100644 (file)
--- 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;
        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;
            if(ttf->glyphs[t].xmax < hea->minRightSideBearing)
                hea->minRightSideBearing = ttf->glyphs[t].xmax;
            int width = ttf->glyphs[t].xmax - ttf->glyphs[t].xmin;