Implement rasterized printing with QPrinter with hidden annotations

Previously, rasterized printing would use the QPrinter backend whenever
annotations were to be printed, and fall back to the convert-to-ps
toolchain otherwise.  Effectively, this meant that printing on
windows without showing the annotations was not possible (because
on windows only the QPrinter can be used for printing).

Starting with poppler 0.60, there is a way to disable annotation
rendering for the renderToImage and renderToPainter methods that
are used by QPrinter.  This patch makes use of this new option,
making printing on windows without annotations possible.

Differential Revision: https://phabricator.kde.org/D7688
remotes/origin/Applications/17.12
Oliver Sander 9 years ago
parent a53a2402ca
commit 5a716e067a
  1. 9
      generators/poppler/CMakeLists.txt
  2. 3
      generators/poppler/config-okular-poppler.h.cmake
  3. 13
      generators/poppler/generator_pdf.cpp

@ -41,6 +41,15 @@ int main()
}
" HAVE_POPPLER_0_53)
check_cxx_source_compiles("
#include <poppler-qt5.h>
int main()
{
Poppler::Document::RenderHint hint = Poppler::Document::HideAnnotations;
return 0;
}
" HAVE_POPPLER_0_60)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h

@ -15,3 +15,6 @@
/* Defined if we have the 0.53 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_53 1
/* Defined if we have the 0.60 version of the Poppler library */
#cmakedefine HAVE_POPPLER_0_60 1

@ -85,7 +85,7 @@ class PDFOptionsPage : public QWidget
layout->addWidget(m_forceRaster);
layout->addStretch(1);
#if defined(Q_OS_WIN)
#if defined(Q_OS_WIN) && !defined HAVE_POPPLER_0_60
m_printAnnots->setVisible( false );
#endif
setPrintAnnots( true ); // Default value
@ -1076,15 +1076,24 @@ bool PDFGenerator::print( QPrinter& printer )
}
#ifdef Q_OS_WIN
// Windows can only print by rasterization and with annotations, because that is
// Windows can only print by rasterization, because that is
// currently the only way Okular implements printing without using UNIX-specific
// tools like 'lpr'.
forceRasterize = true;
#ifndef HAVE_POPPLER_0_60
// The Document::HideAnnotations flags was introduced in poppler 0.60
printAnnots = true;
#endif
#endif
#ifdef HAVE_POPPLER_0_60
if ( forceRasterize )
{
pdfdoc->setRenderHint(Poppler::Document::HideAnnotations, !printAnnots);
#else
if ( forceRasterize && printAnnots)
{
#endif
QPainter painter;
painter.begin(&printer);

Loading…
Cancel
Save