From f2c8f4e5a346e52d36e30ffd0e5f95d9189a661b Mon Sep 17 00:00:00 2001 From: James Larcombe Date: Tue, 10 Aug 2010 15:55:09 +0100 Subject: [PATCH] Fixed glyph alignment problem with PDF export by working around an apparent bug in Win32 GetGlyphOutline API. --- src/gui/text/qfontengine_win.cpp | 31 ++++++++++++++++++++++--------- 1 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 0d21a35..c2fcba3 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -906,13 +906,33 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc, mat.eM11.fract = mat.eM22.fract = 0; mat.eM21.value = mat.eM12.value = 0; mat.eM21.fract = mat.eM12.fract = 0; + + GLYPHMETRICS gMetric; + memset(&gMetric, 0, sizeof(GLYPHMETRICS)); + if (metric) { + // If metrics requested, retrieve first using GGO_METRICS, because the returned + // values are incorrect for OpenType PS fonts if obtained at the same time as the + // glyph paths themselves (ie. with GGO_NATIVE as the format). + uint format = GGO_METRICS; + if (cmap) + format |= GGO_GLYPH_INDEX; + int res = GetGlyphOutline(hdc, glyph, format, &gMetric, 0, 0, &mat); + if (res == GDI_ERROR) { + return false; + } + if(metric) { + // #### obey scale + *metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y, + (int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY, + gMetric.gmCellIncX, gMetric.gmCellIncY); + } + } + uint glyphFormat = GGO_NATIVE; if (cmap) glyphFormat |= GGO_GLYPH_INDEX; - GLYPHMETRICS gMetric; - memset(&gMetric, 0, sizeof(GLYPHMETRICS)); int bufferSize = GDI_ERROR; #if !defined(Q_WS_WINCE) bufferSize = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat); @@ -931,13 +951,6 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc, return false; } - if(metric) { - // #### obey scale - *metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y, - (int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY, - gMetric.gmCellIncX, gMetric.gmCellIncY); - } - int offset = 0; int headerOffset = 0; TTPOLYGONHEADER *ttph = 0; -- 1.7.0.2.msysgit.0