Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdal: add build patch for poppler 25.02.0 #982

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 225 additions & 0 deletions gdal/gdal-3.10.1-poppler-25.02.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
From d8f86b3e7e5e5dd1d7ab6e12365d6b96e6da3c9b Mon Sep 17 00:00:00 2001
From: Rui Chen <[email protected]>
Date: Fri, 7 Feb 2025 00:08:19 -0500
Subject: [PATCH] gdal: build patch

Signed-off-by: Rui Chen <[email protected]>
---
frmts/pdf/pdfdataset.cpp | 41 ++++++++++++++++++++++++++----
frmts/pdf/pdfio.cpp | 9 +++++++
frmts/pdf/pdfio.h | 5 ++++
frmts/pdf/pdfobject.cpp | 6 ++---
frmts/pdf/pdfobject.h | 2 +-
frmts/pdf/pdfsdk_headers_poppler.h | 9 +++++--
6 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp
index cb57e2a..d6d0af9 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 bb5a5da..9ecf65e 100644
--- a/frmts/pdf/pdfio.cpp
+++ b/frmts/pdf/pdfio.cpp
@@ -237,13 +237,22 @@ 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
}

/************************************************************************/
diff --git a/frmts/pdf/pdfio.h b/frmts/pdf/pdfio.h
index d942b41..f45a7f2 100644
--- a/frmts/pdf/pdfio.h
+++ b/frmts/pdf/pdfio.h
@@ -48,7 +48,12 @@ 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;
+#else
virtual void reset() override;
+#endif
virtual void unfilteredReset() override;
virtual void close() override;

diff --git a/frmts/pdf/pdfobject.cpp b/frmts/pdf/pdfobject.cpp
index 9b04668..38690b7 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<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)
{
}

@@ -1334,7 +1334,7 @@ std::map<CPLString, GDALPDFObject *> &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 73c3a27..6f0ecf5 100644
--- a/frmts/pdf/pdfobject.h
+++ b/frmts/pdf/pdfobject.h
@@ -405,7 +405,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 d2a3a44..fcb56e3 100644
--- a/frmts/pdf/pdfsdk_headers_poppler.h
+++ b/frmts/pdf/pdfsdk_headers_poppler.h
@@ -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>
--
2.48.1