Skip to content

Commit

Permalink
Build: fix build against Poppler 25.02.00
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 6, 2025
1 parent 8d8fb57 commit 1b6d32d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion autotest/gdrivers/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


###############################################################################
Expand Down
41 changes: 36 additions & 5 deletions frmts/pdf/pdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 ||
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions frmts/pdf/pdfio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() */
Expand Down
6 changes: 6 additions & 0 deletions frmts/pdf/pdfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions frmts/pdf/pdfobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,13 @@ class GDALPDFDictionaryPoppler : public GDALPDFDictionary
class GDALPDFArrayPoppler : public GDALPDFArray
{
private:
Array *m_poArray;
const Array *m_poArray;
std::vector<std::unique_ptr<GDALPDFObject>> m_v{};

CPL_DISALLOW_COPY_ASSIGN(GDALPDFArrayPoppler)

public:
GDALPDFArrayPoppler(Array *poArray) : m_poArray(poArray)
GDALPDFArrayPoppler(const Array *poArray) : m_poArray(poArray)
{
}

Expand Down Expand Up @@ -1334,7 +1334,7 @@ std::map<CPLString, GDALPDFObject *> &GDALPDFDictionaryPoppler::GetValues()
/* GDALPDFCreateArray() */
/************************************************************************/

GDALPDFArray *GDALPDFCreateArray(Array *array)
GDALPDFArray *GDALPDFCreateArray(const Array *array)
{
return new GDALPDFArrayPoppler(array);
}
Expand Down
2 changes: 1 addition & 1 deletion frmts/pdf/pdfobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class GDALPDFObjectPoppler : public GDALPDFObject
virtual int GetRefGen() override;
};

GDALPDFArray *GDALPDFCreateArray(Array *array);
GDALPDFArray *GDALPDFCreateArray(const Array *array);

#endif // HAVE_POPPLER

Expand Down
9 changes: 7 additions & 2 deletions frmts/pdf/pdfsdk_headers_poppler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@

#include <Dict.h>

#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 <Catalog.h>
#else
/* Ugly! Catalog::optContent is private but we need it for ancient Poppler versions. */
#define private public
#include <Catalog.h>
#undef private
#endif

#define private public /* Ugly! PDFDoc::str is private but we need it... */
#include <PDFDoc.h>
Expand Down

0 comments on commit 1b6d32d

Please sign in to comment.