From d426cd980952c5f54bb32eef94b7875f7dc94a17 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 | 29 +++++++++++++++++++++++++++-- qt5/src/poppler-qt5.h | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc index 0d2dd5a8..c751f38c 100644 --- a/qt5/src/poppler-page.cc +++ b/qt5/src/poppler-page.cc @@ -365,9 +365,19 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h, splash_output.startDoc(m_page->parentDoc->doc); + bool showAnnotations = !(m_page->parentDoc->m_hints & Document::HideAnnotations); + + // Callback that for each annotation says whether it should be drawn or not + auto annotDisplayDecideCbk = [](Annot *annot, void *user_data) -> GBool + { + return (annot->getType() == Annot::typeWidget) + ? gTrue // Never hide forms + : *(GBool*)user_data; + }; + 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, annotDisplayDecideCbk, &showAnnotations, gTrue); SplashBitmap *bitmap = splash_output.getBitmap(); @@ -450,6 +460,17 @@ 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()); + + bool showAnnotations = !(m_page->parentDoc->m_hints & Document::HideAnnotations); + + // Callback that for each annotation says whether it should be drawn or not + auto annotDisplayDecideCbk = [](Annot *annot, void *user_data) -> GBool + { + return (annot->getType() == Annot::typeWidget) + ? gTrue // Never hide forms + : *(GBool*)user_data; + }; + m_page->parentDoc->doc->displayPageSlice(&arthur_output, m_page->index + 1, xres, @@ -461,7 +482,11 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i x, y, w, - h); + h, + nullptr, + nullptr, + annotDisplayDecideCbk, + &showAnnotations); if (savePainter) painter->restore(); return true; diff --git a/qt5/src/poppler-qt5.h b/qt5/src/poppler-qt5.h index e44e22d4..b1f20052 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.59 }; Q_DECLARE_FLAGS( RenderHints, RenderHint ) -- 2.14.1