From 5a716e067aa841733dca558c83efb3c83dd9e8e8 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 4 Sep 2017 16:37:26 +0200 Subject: [PATCH] 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 --- generators/poppler/CMakeLists.txt | 9 +++++++++ generators/poppler/config-okular-poppler.h.cmake | 3 +++ generators/poppler/generator_pdf.cpp | 13 +++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt index 783644566..d32f98725 100644 --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -41,6 +41,15 @@ int main() } " HAVE_POPPLER_0_53) +check_cxx_source_compiles(" +#include +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 diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake index 5d7f38900..24878d233 100644 --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -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 diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp index 2a73ca205..c29f96bf7 100644 --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -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);