diff options
author | Tobias Koenig <tobias.koenig@kdab.com> | 2017-02-17 08:13:50 +0100 |
---|---|---|
committer | Tobias Koenig <tobias.koenig@kdab.com> | 2017-02-17 08:14:19 +0000 |
commit | 626edf3c2d1064aa5e5bb331d8e2f8ba98f9d58b (patch) | |
tree | 0c60cd6424d0c31b4d17764fcc15e2fb819d1f39 /src/gui/text/qfontsubset.cpp | |
parent | 8d71fae08078afbf4aa2de7429302f46d46fb43f (diff) |
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text/qfontsubset.cpp')
-rw-r--r-- | src/gui/text/qfontsubset.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
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"; } |