take the glyphs x values into account for spacing
authorDana Jansens <danakj@orodu.net>
Thu, 29 May 2003 02:19:12 +0000 (02:19 +0000)
committerDana Jansens <danakj@orodu.net>
Thu, 29 May 2003 02:19:12 +0000 (02:19 +0000)
glft/font.c
glft/font.h
glft/render.c

index f93da67c87b2f97ab64e778f7b07b6965442e947..27e9f0929b74c3b1fd9b41ccbea296808d1e11d5 100644 (file)
@@ -257,11 +257,12 @@ struct GlftGlyph *GlftFontGlyph(struct GlftFont *font, const char *c)
         if (!(font->spacing == FC_PROPORTIONAL)) {
             g->width = font->max_advance_width;
         } else {
-            g->width = font->face->glyph->advance.x;
-            g->width = TRUNC(ROUND(font->face->glyph->metrics.width));/* >> 6;*/
+            g->width = font->face->glyph->advance.x >> 6;
         }
+        g->x = font->face->glyph->metrics.horiBearingX >> 6;
+        g->y = font->face->glyph->metrics.horiBearingY >> 6;
         g->height = TRUNC(ROUND(font->face->glyph->metrics.height));/* >> 6;*/
-        g_message("%c = Width: %d Height: %d", *c, g->width, g->height);
+        g_message("%c = X %d Y %d Width: %d Height: %d", *c, g->x, g->y, g->width, g->height);
 
         g_hash_table_insert(font->glyph_map, &g->w, g);
     }
@@ -274,16 +275,19 @@ int GlftFontAdvance(struct GlftFont *font,
                     struct GlftGlyph *right)
 {
     FT_Vector v;
-    int k = left->width;
+    int k = 0;
 
-/*    font->kerning = 0;*/
-    g_message("HAS KERNING: %d", font->kerning);
+    if (left) k+= left->width;
 
-    if (font->kerning && right) {
-        FT_Get_Kerning(font->face, left->glyph, right->glyph,
-                       FT_KERNING_UNFITTED, &v);
-/*x_scale  = pixel_size_x / EM_size*/
-        k += v.x >> 6;
+    g_message("HAS KERNING: %d", font->kerning);
+    if (right) {
+        k -= right->x;
+        if (font->kerning) {
+            FT_Get_Kerning(font->face, left->glyph, right->glyph,
+                           FT_KERNING_UNFITTED, &v);
+            k += v.x >> 6;
+        }
     }
+
     return k;
 }
index f96b2e1a951df7cf65ba79c04b09a12921b2d012..7f6ef746210b9e91944178b75138d3510fcc9612 100644 (file)
@@ -48,6 +48,8 @@ struct GlftGlyph {
     /* The FT_Face glyph */
     FT_UInt glyph;
 
+    int x;
+    int y;
     int width;
     int height;
 };
index 69716183a95e62511daf9e11db1cb2d16f607eb1..91bd9ba758e312031d6aac00917898ccdfa97453 100644 (file)
@@ -91,7 +91,7 @@ void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
                       int x, int y)
 {
     const char *c;
-    struct GlftGlyph *g;
+    struct GlftGlyph *g, *p = NULL;
 
     if (!g_utf8_validate(str, bytes, NULL)) {
         GlftDebug("Invalid UTF-8 in string\n");
@@ -104,10 +104,11 @@ void GlftRenderString(struct GlftFont *font, const char *str, int bytes,
     while (c - str < bytes) {
         g = GlftFontGlyph(font, c);
         if (g) {
+            glTranslatef(GlftFontAdvance(font, p, g), 0.0, 0.0);
             glCallList(g->dlist);
-            glTranslatef(g->width, 0.0, 0.0);
         } else
             glTranslatef(font->max_advance_width, 0.0, 0.0);
+        p = g;
         c = g_utf8_next_char(c);
     }
 
@@ -121,7 +122,7 @@ void GlftMeasureString(struct GlftFont *font,
                        int *h)
 {
     const char *c;
-    struct GlftGlyph *g;
+    struct GlftGlyph *g, *p = NULL;
 
     if (!g_utf8_validate(str, bytes, NULL)) {
         GlftDebug("Invalid UTF-8 in string\n");
@@ -135,11 +136,11 @@ void GlftMeasureString(struct GlftFont *font,
     while (c - str < bytes) {
         g = GlftFontGlyph(font, c);
         if (g) {
-            *w += g->width;
+            *w += GlftFontAdvance(font, p, g);
             *h = MAX(g->height, *h);
-        } else {
+        } else
             *w += font->max_advance_width;
-        }
+        p = g;
         c = g_utf8_next_char(c);
     }
 }