Skip to content

Commit bf1fce4

Browse files
lasconicashkulz
authored andcommitted
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 <[email protected]> Change-Id: I38ca46d50e490e3b704a89d08b1a8697bca5f079 (cherry picked from qtbase/4aba2d07d2fe67beaf544a4b38c5b9aa8b8ec39b) Reviewed-by: Oswald Buddenhagen <[email protected]> Reviewed-by: Konstantin Ritt <[email protected]> Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
1 parent 61379d4 commit bf1fce4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/gui/text/qfontengine_win.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,34 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
864864
mat.eM11.fract = mat.eM22.fract = 0;
865865
mat.eM21.value = mat.eM12.value = 0;
866866
mat.eM21.fract = mat.eM12.fract = 0;
867+
868+
GLYPHMETRICS gMetric;
869+
memset(&gMetric, 0, sizeof(GLYPHMETRICS));
870+
871+
#ifndef Q_OS_WINCE
872+
if (metric) {
873+
// If metrics requested, retrieve first using GGO_METRICS, because the returned
874+
// values are incorrect for OpenType PS fonts if obtained at the same time as the
875+
// glyph paths themselves (ie. with GGO_NATIVE as the format).
876+
uint format = GGO_METRICS;
877+
if (ttf)
878+
format |= GGO_GLYPH_INDEX;
879+
int res = GetGlyphOutline(hdc, glyph, format, &gMetric, 0, 0, &mat);
880+
if (res == GDI_ERROR) {
881+
return false;
882+
}
883+
// #### obey scale
884+
*metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y,
885+
(int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY,
886+
gMetric.gmCellIncX, gMetric.gmCellIncY);
887+
}
888+
#endif
889+
867890
uint glyphFormat = GGO_NATIVE;
868891

869892
if (ttf)
870893
glyphFormat |= GGO_GLYPH_INDEX;
871894

872-
GLYPHMETRICS gMetric;
873-
memset(&gMetric, 0, sizeof(GLYPHMETRICS));
874895
int bufferSize = GDI_ERROR;
875896
#if !defined(Q_WS_WINCE)
876897
bufferSize = GetGlyphOutline(hdc, glyph, glyphFormat, &gMetric, 0, 0, &mat);
@@ -889,12 +910,14 @@ static bool addGlyphToPath(glyph_t glyph, const QFixedPoint &position, HDC hdc,
889910
return false;
890911
}
891912

892-
if(metric) {
913+
#ifdef Q_OS_WINCE
914+
if (metric) {
893915
// #### obey scale
894916
*metric = glyph_metrics_t(gMetric.gmptGlyphOrigin.x, -gMetric.gmptGlyphOrigin.y,
895917
(int)gMetric.gmBlackBoxX, (int)gMetric.gmBlackBoxY,
896918
gMetric.gmCellIncX, gMetric.gmCellIncY);
897919
}
920+
#endif
898921

899922
int offset = 0;
900923
int headerOffset = 0;

0 commit comments

Comments
 (0)