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>
This commit is contained in:
parent
8d71fae080
commit
626edf3c2d
@ -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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user