diff --git a/autotest/gdrivers/pdf.py b/autotest/gdrivers/pdf.py index 2aa26339d5e2..a0b52465ff43 100755 --- a/autotest/gdrivers/pdf.py +++ b/autotest/gdrivers/pdf.py @@ -1272,7 +1272,7 @@ def test_pdf_extra_rasters(poppler_or_pdfium): "LAYER_01_NAME=subbyte", ], "did not get expected layers" if pdf_is_poppler(): - assert cs in (7926, 8177, 8174, 8165, 8172) + assert cs in (7926, 8177, 8174, 8165, 8172, 8193) ############################################################################### diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp index 9986deb178d7..db704117a9ac 100644 --- a/frmts/pdf/pdfdataset.cpp +++ b/frmts/pdf/pdfdataset.cpp @@ -1964,6 +1964,14 @@ CPLErr PDFDataset::ReadPixels(int nReqXOff, int nReqYOff, int nReqXSize, PDFDoc *poDoc = m_poDocPoppler; poSplashOut->startDoc(poDoc); + // Note: Poppler 25.2 is certainly not the lowest version where we can + // avoid the hack. +#if !(POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2)) +#define USE_OPTCONTENT_HACK +#endif + +#ifdef USE_OPTCONTENT_HACK /* EVIL: we modify a private member... */ /* poppler (at least 0.12 and 0.14 versions) don't render correctly */ /* some PDFs and display an error message 'Could not find a OCG with @@ -1978,6 +1986,7 @@ CPLErr PDFDataset::ReadPixels(int nReqXOff, int nReqYOff, int nReqXSize, OCGs *poOldOCGs = poCatalog->optContent; if (!m_bUseOCG) poCatalog->optContent = nullptr; +#endif try { poDoc->displayPageSlice(poSplashOut, m_iPage, m_dfDPI, m_dfDPI, 0, @@ -1988,14 +1997,19 @@ CPLErr PDFDataset::ReadPixels(int nReqXOff, int nReqYOff, int nReqXSize, { CPLError(CE_Failure, CPLE_AppDefined, "PDFDoc::displayPageSlice() failed with %s", e.what()); + +#ifdef USE_OPTCONTENT_HACK /* Restore back */ poCatalog->optContent = poOldOCGs; +#endif delete poSplashOut; return CE_Failure; } +#ifdef USE_OPTCONTENT_HACK /* Restore back */ poCatalog->optContent = poOldOCGs; +#endif SplashBitmap *poBitmap = poSplashOut->getBitmap(); if (poBitmap->getWidth() != nReqXSize || @@ -3734,9 +3748,14 @@ void PDFDataset::ExploreLayersPoppler(GDALPDFArray *poArray, } else osCurLayer = std::move(osName); - // CPLDebug("PDF", "Layer %s", osCurLayer.c_str()); + // CPLDebug("PDF", "Layer %s", osCurLayer.c_str()); - OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + const +#endif + OCGs *optContentConfig = + m_poDocPoppler->getOptContentConfig(); struct Ref r; r.num = poObj->GetRefNum().toInt(); r.gen = poObj->GetRefGen(); @@ -3772,11 +3791,19 @@ void PDFDataset::FindLayersPoppler(int iPageOfInterest) if (poPages) nPageCount = poPages->GetLength(); - OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + const +#endif + OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); if (optContentConfig == nullptr || !optContentConfig->isOk()) return; - Array *array = optContentConfig->getOrderArray(); +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + const +#endif + Array *array = optContentConfig->getOrderArray(); if (array) { GDALPDFArray *poArray = GDALPDFCreateArray(array); @@ -3812,7 +3839,11 @@ void PDFDataset::FindLayersPoppler(int iPageOfInterest) void PDFDataset::TurnLayersOnOffPoppler() { - OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + const +#endif + OCGs *optContentConfig = m_poDocPoppler->getOptContentConfig(); if (optContentConfig == nullptr || !optContentConfig->isOk()) return; diff --git a/frmts/pdf/pdfio.cpp b/frmts/pdf/pdfio.cpp index bb5a5da2c8d4..1ab77cd645b1 100644 --- a/frmts/pdf/pdfio.cpp +++ b/frmts/pdf/pdfio.cpp @@ -237,23 +237,40 @@ int VSIPDFFileStream::lookChar() /* reset() */ /************************************************************************/ +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) +bool VSIPDFFileStream::reset() +#else void VSIPDFFileStream::reset() +#endif { nSavedPos = VSIFTellL(f); bHasSavedPos = TRUE; VSIFSeekL(f, nCurrentPos = nStart, SEEK_SET); nPosInBuffer = -1; nBufferLength = -1; +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + return true; +#endif } /************************************************************************/ /* unfilteredReset() */ /************************************************************************/ +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) +bool VSIPDFFileStream::unfilteredReset() +{ + return reset(); +} +#else void VSIPDFFileStream::unfilteredReset() { reset(); } +#endif /************************************************************************/ /* close() */ diff --git a/frmts/pdf/pdfio.h b/frmts/pdf/pdfio.h index 10e0a5aaf5d9..bb6c2c2a7af0 100644 --- a/frmts/pdf/pdfio.h +++ b/frmts/pdf/pdfio.h @@ -47,8 +47,14 @@ class VSIPDFFileStream final : public BaseStream virtual int getUnfilteredChar() override; virtual int lookChar() override; +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) + virtual bool reset() override; + virtual bool unfilteredReset() override; +#else virtual void reset() override; virtual void unfilteredReset() override; +#endif virtual void close() override; bool FoundLinearizedHint() const diff --git a/frmts/pdf/pdfobject.cpp b/frmts/pdf/pdfobject.cpp index 9b04668946b9..38690b7c900f 100644 --- a/frmts/pdf/pdfobject.cpp +++ b/frmts/pdf/pdfobject.cpp @@ -979,13 +979,13 @@ class GDALPDFDictionaryPoppler : public GDALPDFDictionary class GDALPDFArrayPoppler : public GDALPDFArray { private: - Array *m_poArray; + const Array *m_poArray; std::vector> m_v{}; CPL_DISALLOW_COPY_ASSIGN(GDALPDFArrayPoppler) public: - GDALPDFArrayPoppler(Array *poArray) : m_poArray(poArray) + GDALPDFArrayPoppler(const Array *poArray) : m_poArray(poArray) { } @@ -1334,7 +1334,7 @@ std::map &GDALPDFDictionaryPoppler::GetValues() /* GDALPDFCreateArray() */ /************************************************************************/ -GDALPDFArray *GDALPDFCreateArray(Array *array) +GDALPDFArray *GDALPDFCreateArray(const Array *array) { return new GDALPDFArrayPoppler(array); } diff --git a/frmts/pdf/pdfobject.h b/frmts/pdf/pdfobject.h index 877ca76ff37e..1594efd0966a 100644 --- a/frmts/pdf/pdfobject.h +++ b/frmts/pdf/pdfobject.h @@ -404,7 +404,7 @@ class GDALPDFObjectPoppler : public GDALPDFObject virtual int GetRefGen() override; }; -GDALPDFArray *GDALPDFCreateArray(Array *array); +GDALPDFArray *GDALPDFCreateArray(const Array *array); #endif // HAVE_POPPLER diff --git a/frmts/pdf/pdfsdk_headers_poppler.h b/frmts/pdf/pdfsdk_headers_poppler.h index d2a3a449d124..fcb56e3343e3 100644 --- a/frmts/pdf/pdfsdk_headers_poppler.h +++ b/frmts/pdf/pdfsdk_headers_poppler.h @@ -51,10 +51,15 @@ #include -#define private \ - public /* Ugly! Catalog::optContent is private but we need it... */ +#if POPPLER_MAJOR_VERSION > 25 || \ + (POPPLER_MAJOR_VERSION == 25 && POPPLER_MINOR_VERSION >= 2) +#include +#else +/* Ugly! Catalog::optContent is private but we need it for ancient Poppler versions. */ +#define private public #include #undef private +#endif #define private public /* Ugly! PDFDoc::str is private but we need it... */ #include