Print via QPrinter when rasterizing and printing annotations

When the user chooses to print with rasterization and annotations,
it is easy to print directly to a QPrinter, rather than converting
to PostScript and then using CUPS tools.  The code for it was
already there, but it was hidden behind an #ifdef Q_OS_WIN.
This patch enables it for all plattforms.  If nothing else,
it will make an interesting debugging tool, because it allows
to bypass the postscript & CUPS toolchain from the GUI.
This may allow to track down some of the numerous my-printer-settings-
are-getting-ignored bugs.

The previously windows-only rasterization code used printer.physicalDpiX()
as the rasterization resolution.  At least on my machine this resulted
in a dpi value of 1200, which means quite a lot of memory is used.
I left the windows code untouched, but on Unix I lowered that value
to 300dpi, which is what the postscript rasterizer uses.

Incidentally, this patch does fix at least one bug for me:
Without it, my printer will happily ignore the 'print in grayscale'
button.  With the patch, that button is suddenly honoured.

REVIEW: 130218
remotes/origin/Applications/17.12
Oliver Sander 9 years ago
parent 024d25cdec
commit 0c4c2ddbbc
  1. 34
      generators/poppler/generator_pdf.cpp

@ -1066,7 +1066,25 @@ void PDFGenerator::requestFontData(const Okular::FontInfo &font, QByteArray *dat
#define DUMMY_QPRINTER_COPY
bool PDFGenerator::print( QPrinter& printer )
{
bool printAnnots = true;
bool forceRasterize = false;
if ( pdfOptionsPage )
{
printAnnots = pdfOptionsPage->printAnnots();
forceRasterize = pdfOptionsPage->printForceRaster();
}
#ifdef Q_OS_WIN
// Windows can only print by rasterization and with annotations, because that is
// currently the only way Okular implements printing without using UNIX-specific
// tools like 'lpr'.
forceRasterize = true;
printAnnots = true;
#endif
if ( forceRasterize && printAnnots)
{
QPainter painter;
painter.begin(&printer);
@ -1083,7 +1101,12 @@ bool PDFGenerator::print( QPrinter& printer )
Poppler::Page *pp = pdfdoc->page( page );
if (pp)
{
#ifdef Q_OS_WIN
QImage img = pp->renderToImage( printer.physicalDpiX(), printer.physicalDpiY() );
#else
// UNIX: Same resolution as the postscript rasterizer; see discussion at https://git.reviewboard.kde.org/r/130218/
QImage img = pp->renderToImage( 300, 300 );
#endif
painter.drawImage( painter.window(), img, QRectF(0, 0, img.width(), img.height()) );
delete pp;
}
@ -1091,8 +1114,8 @@ bool PDFGenerator::print( QPrinter& printer )
}
painter.end();
return true;
}
#else
#ifdef DUMMY_QPRINTER_COPY
// Get the real page size to pass to the ps generator
QPrinter dummy( QPrinter::PrinterResolution );
@ -1137,14 +1160,6 @@ bool PDFGenerator::print( QPrinter& printer )
pstitle = document()->currentDocument().fileName();
}
bool printAnnots = true;
bool forceRasterize = false;
if ( pdfOptionsPage )
{
printAnnots = pdfOptionsPage->printAnnots();
forceRasterize = pdfOptionsPage->printForceRaster();
}
Poppler::PSConverter *psConverter = pdfdoc->psConverter();
psConverter->setOutputDevice(&tf);
@ -1189,7 +1204,6 @@ bool PDFGenerator::print( QPrinter& printer )
tf.close();
return false;
#endif
}
QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) const

Loading…
Cancel
Save