From 626edf3c2d1064aa5e5bb331d8e2f8ba98f9d58b Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 17 Feb 2017 08:13:50 +0100 Subject: Fix rounding errors in generation of '/W' and '/DW' entries Calculating the glyph widths for '/W' and '/DW' entries in PDF documents based on QFixed leads to rounding errors, which result in different glyph widths than the ones store into the font program. Use qreal-based calculation in both places, to have consistent glyph width information across the PDF document. Change-Id: I761809f4bc586005e35640929c4663c8b477e0e6 Reviewed-by: Lars Knoll --- src/gui/text/qfontsubset.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui/text/qfontsubset.cpp') diff --git a/src/gui/text/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp index 92eeaf7919..f5fc562e13 100644 --- a/src/gui/text/qfontsubset.cpp +++ b/src/gui/text/qfontsubset.cpp @@ -136,7 +136,7 @@ QByteArray QFontSubset::widthArray() const QByteArray width; QPdf::ByteStream s(&width); - QFixed scale = QFixed(1000)/emSquare; + const qreal scale = 1000.0/emSquare.toInt(); QFixed defWidth = widths[0]; //qDebug("defWidth=%d, scale=%f", defWidth.toInt(), scale.toReal()); @@ -145,7 +145,7 @@ QByteArray QFontSubset::widthArray() const defWidth = 0; } if (defWidth > 0) { - s << "/DW " << (defWidth*scale).toInt(); + s << "/DW " << qRound(defWidth.toInt() * scale); } else { s << "/W ["; for (int g = 0; g < nGlyphs();) { @@ -174,11 +174,11 @@ QByteArray QFontSubset::widthArray() const if (endnonlinear > start) { s << start << '['; for (int i = start; i < endnonlinear; ++i) - s << (widths[i]*scale).toInt(); + s << qRound(widths[i].toInt() * scale); s << "]\n"; } if (startLinear) - s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n'; + s << startLinear << g - 1 << qRound(widths[startLinear].toInt() * scale) << '\n'; } s << "]\n"; } -- cgit v1.2.3