From bf1fce4fc18d09fd640f4c765522737173d4fee5 Mon Sep 17 00:00:00 2001 From: lasconic Date: Thu, 18 Sep 2014 13:14:03 +0530 Subject: Use metrics returned by GetGlyphOutline in GGO_METRICS mode GetGlyphOutline Windows API returns wrong values when used with an OpenType PS font and in GGO_NATIVE mode. It causes problem when exporting to PDF. The fix changes the GetGlyphOutline call to use GGO_METRICS instead. Task-number: QTBUG-12799 Reviewed-by: Eskil Abrahamsen Blomfeldt Change-Id: I38ca46d50e490e3b704a89d08b1a8697bca5f079 (cherry picked from qtbase/4aba2d07d2fe67beaf544a4b38c5b9aa8b8ec39b) Reviewed-by: Oswald Buddenhagen Reviewed-by: Konstantin Ritt Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontengine_win.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/text/qfontengine_win.cpp b/src/gui/text/qfontengine_win.cpp index 9852b89072..5d0c209a83 100644 --- a/src/gui/text/qfontengine_win.cpp +++ b/src/gui/text/qfontengine_win.cpp @@ -864,13 +864,34 @@ 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)); + +#ifndef Q_OS_WINCE + 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 (ttf) + format |= GGO_GLYPH_INDEX; + int res = GetGlyphOutline(hdc, glyph, format, &gMetric, 0, 0, &mat); + if (res == GDI_ERROR) { + return false; + } + // #### obey scale + *metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y, + (int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY, + gMetric.gmCellIncX, gMetric.gmCellIncY); + } +#endif + uint glyphFormat = GGO_NATIVE; if (ttf) 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); @@ -889,12 +910,14 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc, return false; } - if(metric) { +#ifdef Q_OS_WINCE + if (metric) { // #### obey scale *metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y, (int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY, gMetric.gmCellIncX, gMetric.gmCellIncY); } +#endif int offset = 0; int headerOffset = 0; -- cgit v1.2.3