From 41fa3e2c20c5f64470b41df18fd7a9cf5dd0c7c9 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Wed, 9 Jul 2008 07:38:55 +0000 Subject: [PATCH] (xfont_text_extents): Fix initial setting of metrics. --- src/xfont.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/xfont.c b/src/xfont.c index 6d529c9b54a..92370d4b15d 100644 --- a/src/xfont.c +++ b/src/xfont.c @@ -728,11 +728,11 @@ xfont_text_extents (font, code, nglyphs, metrics) { XFontStruct *xfont = ((struct xfont_info *) font)->xfont; int width = 0; - int i, x; + int i, first, x; if (metrics) bzero (metrics, sizeof (struct font_metrics)); - for (i = 0, x = 0; i < nglyphs; i++) + for (i = 0, x = 0, first = 1; i < nglyphs; i++) { XChar2b char2b; static XCharStruct *pcm; @@ -743,14 +743,31 @@ xfont_text_extents (font, code, nglyphs, metrics) pcm = xfont_get_pcm (xfont, &char2b); if (! pcm) continue; - if (metrics->lbearing > width + pcm->lbearing) - metrics->lbearing = width + pcm->lbearing; - if (metrics->rbearing < width + pcm->rbearing) - metrics->rbearing = width + pcm->rbearing; - if (metrics->ascent < pcm->ascent) - metrics->ascent = pcm->ascent; - if (metrics->descent < pcm->descent) - metrics->descent = pcm->descent; + if (first) + { + if (metrics) + { + metrics->lbearing = pcm->lbearing; + metrics->rbearing = pcm->rbearing; + metrics->ascent = pcm->ascent; + metrics->descent = pcm->descent; + } + first = 0; + } + else + { + if (metrics) + { + if (metrics->lbearing > width + pcm->lbearing) + metrics->lbearing = width + pcm->lbearing; + if (metrics->rbearing < width + pcm->rbearing) + metrics->rbearing = width + pcm->rbearing; + if (metrics->ascent < pcm->ascent) + metrics->ascent = pcm->ascent; + if (metrics->descent < pcm->descent) + metrics->descent = pcm->descent; + } + } width += pcm->width; } if (metrics) -- 2.39.2