From 87a42a61522beb8a279fe3e262af462185f6921d Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Fri, 1 Sep 2017 22:16:49 +0200 Subject: [PATCH 3/3] Control whether renderToImage shows annotations I'd like to control whether the renderToImage and renderToPainter methods show annotations or not. To this end, this patch introduces a new value 'HideAnnotations' to the Document::RenderHint enum. --- qt5/src/poppler-page.cc | 36 ++++++++++++++++++++++++++++++++++-- qt5/src/poppler-qt5.h | 3 ++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 0d2dd5a8..223d174f 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -365,9 +365,24 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, splash_output.startDoc(m_page->parentDoc->doc); + GBool hideAnnotations = m_page->parentDoc->m_hints & Document::HideAnnotations; + + // Callback that filters out everything but form fields + auto annotDisplayDecideCbk = [](Annot *annot, void *user_data) + { + // Hide everything but forms + return (annot->getType() == Annot::typeWidget); + }; + + // A nullptr, but with the type of a function pointer + // Needed to make the ternary operator below happy. + GBool (*nullCallBack)(Annot *annot, void *user_data) = nullptr; + m_page->parentDoc->doc->displayPageSlice(&splash_output, m_page->index + 1, xres, yres, rotation, false, true, false, x, y, w, h, - NULL, NULL, NULL, NULL, gTrue); + nullptr, nullptr, + (hideAnnotations) ? annotDisplayDecideCbk : nullCallBack, + nullptr, gTrue); SplashBitmap *bitmap = splash_output.getBitmap(); @@ -450,6 +465,20 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i painter->translate(x == -1 ? 0 : -x, y == -1 ? 0 : -y); ArthurOutputDev arthur_output(painter); arthur_output.startDoc(m_page->parentDoc->doc->getXRef()); + + GBool hideAnnotations = m_page->parentDoc->m_hints & Document::HideAnnotations; + + // Callback that filters out everything but form fields + auto annotDisplayDecideCbk = [](Annot *annot, void *user_data) + { + // Hide everything but forms + return (annot->getType() == Annot::typeWidget); + }; + + // A nullptr, but with the type of a function pointer + // Needed to make the ternary operator below happy. + GBool (*nullCallBack)(Annot *annot, void *user_data) = nullptr; + m_page->parentDoc->doc->displayPageSlice(&arthur_output, m_page->index + 1, xres, @@ -461,7 +490,10 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i x, y, w, - h); + h, + nullptr, + nullptr, + (hideAnnotations) ? annotDisplayDecideCbk : nullCallBack); if (savePainter) painter->restore(); return true; diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index e44e22d4..58a7925a 100644 --- a/qt5/src/poppler-qt5.h +++ b/qt5/src/poppler-qt5.h @@ -893,7 +893,8 @@ delete it; OverprintPreview = 0x00000010, ///< Overprint preview \since 0.22 ThinLineSolid = 0x00000020, ///< Enhance thin lines solid \since 0.24 ThinLineShape = 0x00000040, ///< Enhance thin lines shape. Wins over ThinLineSolid \since 0.24 - IgnorePaperColor = 0x00000080 ///< Do not compose with the paper color \since 0.35 + IgnorePaperColor = 0x00000080, ///< Do not compose with the paper color \since 0.35 + HideAnnotations = 0x00000100 ///< Do not render annotations \since 0.60 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) -- 2.14.1