From 0febe5ae240fb31f9b9f10f9062266f3ed5a5b64 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 29 May 2003 02:19:12 +0000 Subject: [PATCH] take the glyphs x values into account for spacing --- glft/font.c | 26 +++++++++++++++----------- glft/font.h | 2 ++ glft/render.c | 13 +++++++------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/glft/font.c b/glft/font.c index f93da67c..27e9f092 100644 --- a/glft/font.c +++ b/glft/font.c @@ -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; } diff --git a/glft/font.h b/glft/font.h index f96b2e1a..7f6ef746 100644 --- a/glft/font.h +++ b/glft/font.h @@ -48,6 +48,8 @@ struct GlftGlyph { /* The FT_Face glyph */ FT_UInt glyph; + int x; + int y; int width; int height; }; diff --git a/glft/render.c b/glft/render.c index 69716183..91bd9ba7 100644 --- a/glft/render.c +++ b/glft/render.c @@ -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); } } -- 2.34.1