PrintLayout: disable the QPainter scaling

This is wrong because we don't really need to scale. We already
have the estimated page dimentions in pixels, so taking the
quotient of the printer DPI and screen DPI and then scaling
(probably up) our rendered widgets via the QPainter introduces
blur (due to the oversampling), and a performance penalty.

By rendering at the exact dimensions we ensure that the widgets
are crisp at a 100% printout.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2014-07-25 03:50:40 +03:00 committed by Dirk Hohndel
parent 5e8f4c8560
commit feda96cec5
2 changed files with 9 additions and 15 deletions

View file

@ -89,12 +89,9 @@ void PrintLayout::setup()
printerDpi = printer->resolution(); printerDpi = printer->resolution();
pageRect = printer->pageRect(); pageRect = printer->pageRect();
scaleX = (qreal)printerDpi / (qreal)screenDpiX; // a printer page in pixels
scaleY = (qreal)printerDpi / (qreal)screenDpiY; pageW = pageRect.width();
pageH = pageRect.height();
// a printer page scalled to screen DPI
scaledPageW = pageRect.width() / scaleX;
scaledPageH = pageRect.height() / scaleY;
} }
// go trought the dive table and find how many dives we are a going to print // go trought the dive table and find how many dives we are a going to print
@ -139,7 +136,6 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
painter.begin(printer); painter.begin(printer);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.scale(scaleX, scaleY);
QPicture pic; QPicture pic;
QPainter picPainter; QPainter picPainter;
@ -163,8 +159,8 @@ void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
const int padW = (divesPerColumn < 2) ? 0 : padDef; const int padW = (divesPerColumn < 2) ? 0 : padDef;
const int padH = (divesPerRow < 2) ? 0 : padDef; const int padH = (divesPerRow < 2) ? 0 : padDef;
// estimate dimensions for a single dive // estimate dimensions for a single dive
const int scaledW = ESTIMATE_DIVE_DIM(scaledPageW, divesPerColumn, padW); const int scaledW = ESTIMATE_DIVE_DIM(pageW, divesPerColumn, padW);
const int scaledH = ESTIMATE_DIVE_DIM(scaledPageH, divesPerRow, padH); const int scaledH = ESTIMATE_DIVE_DIM(pageH, divesPerRow, padH);
// padding in pixels between profile and table // padding in pixels between profile and table
const int padPT = 5; const int padPT = 5;
// create a model and table // create a model and table
@ -328,7 +324,7 @@ void PrintLayout::printTable()
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// fit table to one page initially // fit table to one page initially
table.resize(scaledPageW, scaledPageH); table.resize(pageW, pageH);
// don't show border // don't show border
table.setStyleSheet( table.setStyleSheet(
@ -388,7 +384,7 @@ void PrintLayout::printTable()
headings += rowH; headings += rowH;
isHeading = false; isHeading = false;
} }
if (accH > scaledPageH) { if (accH > pageH) {
lastAccIndex = i; lastAccIndex = i;
pageIndexes.append(pageIndexes.last() + (accH - rowH)); pageIndexes.append(pageIndexes.last() + (accH - rowH));
addTablePrintHeadingRow(&model, i); addTablePrintHeadingRow(&model, i);
@ -404,13 +400,12 @@ void PrintLayout::printTable()
} }
done = 90; done = 90;
pageIndexes.append(pageIndexes.last() + accH + headings); pageIndexes.append(pageIndexes.last() + accH + headings);
table.resize(scaledPageW, tableHeight); table.resize(pageW, tableHeight);
// attach a painter and render pages by using pageIndexes // attach a painter and render pages by using pageIndexes
QPainter painter(printer); QPainter painter(printer);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.scale(scaleX, scaleY);
total = pageIndexes.size() - 1; total = pageIndexes.size() - 1;
progress = 0; progress = 0;
for (i = 0; i < total; i++) { for (i = 0; i < total; i++) {

View file

@ -25,8 +25,7 @@ private:
QPrinter *printer; QPrinter *printer;
struct options *printOptions; struct options *printOptions;
int screenDpiX, screenDpiY, printerDpi, scaledPageW, scaledPageH; int screenDpiX, screenDpiY, printerDpi, pageW, pageH;
qreal scaleX, scaleY;
QRect pageRect; QRect pageRect;
QVector<QString> tablePrintColumnNames; QVector<QString> tablePrintColumnNames;