From 17fc188aec5806167d3c6165b0ad299a8d2a6bcf Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 11 Apr 2017 09:35:52 +0200 Subject: Implement maxCharWidth() for DirectWrite engine This is used to create the bounding box in QFontEngine::properties(), which in turn is used for the FontBBox when generating PDFs. The result was that the bounding width in the output was 0 and Adobe Reader complained that the PDF was malformed. We could implement the proper bounding rect in properties() at some point, instead of assuming an origin at x = 0 for instance. The metrics for that are in the head table. But for silencing the warning in Reader, just implementing the maxCharWidth() function is sufficient. [ChangeLog][Windows][PDF] Fixed a bug in PDF output when using high-dpi scaling which was causing the display of warnings when opening the file in Adobe Reader. Task-number: QTBUG-58954 Change-Id: I2540571863d4dd0f85af533b591f75dad3f0d75b Reviewed-by: Simon Hausmann --- .../fontdatabases/windows/qwindowsfontenginedirectwrite.cpp | 12 ++++++++++-- .../fontdatabases/windows/qwindowsfontenginedirectwrite_p.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index 683b7f65ad..6f2755a05a 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -355,6 +355,13 @@ void QWindowsFontEngineDirectWrite::collectMetrics() m_faceId.filename = QFile::encodeName(filenameFromFontFile(fontFile)); fontFile->Release(); } + + QByteArray table = getSfntTable(MAKE_TAG('h', 'h', 'e', 'a')); + const int advanceWidthMaxLocation = 10; + if (table.size() >= advanceWidthMaxLocation + sizeof(quint16)) { + quint16 advanceWidthMax = qFromBigEndian(table.constData() + advanceWidthMaxLocation); + m_maxAdvanceWidth = DESIGN_TO_LOGICAL(advanceWidthMax); + } } QFixed QWindowsFontEngineDirectWrite::underlinePosition() const @@ -607,8 +614,9 @@ QFixed QWindowsFontEngineDirectWrite::xHeight() const qreal QWindowsFontEngineDirectWrite::maxCharWidth() const { - // ### - return 0; + return fontDef.styleStrategy & QFont::ForceIntegerMetrics + ? m_maxAdvanceWidth.round().toReal() + : m_maxAdvanceWidth.toReal(); } QImage QWindowsFontEngineDirectWrite::alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h index 65b16b9ba7..db4e79e44f 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite_p.h @@ -143,6 +143,7 @@ private: QFixed m_descent; QFixed m_xHeight; QFixed m_lineGap; + QFixed m_maxAdvanceWidth; FaceId m_faceId; QString m_uniqueFamilyName; }; -- cgit v1.2.3