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 <simon.hausmann@qt.io>
bb10
Eskil Abrahamsen Blomfeldt 2017-04-11 09:35:52 +02:00
parent da1be671cf
commit 17fc188aec
2 changed files with 11 additions and 2 deletions

View File

@ -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<quint16>(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)

View File

@ -143,6 +143,7 @@ private:
QFixed m_descent;
QFixed m_xHeight;
QFixed m_lineGap;
QFixed m_maxAdvanceWidth;
FaceId m_faceId;
QString m_uniqueFamilyName;
};