298 lines
10 KiB
Diff
298 lines
10 KiB
Diff
From 97ffea9503c57fc8aa222ca9f2f428d47467771e Mon Sep 17 00:00:00 2001
|
|
From: David Tardon <dtardon@redhat.com>
|
|
Date: Fri, 8 Sep 2017 09:23:29 +0200
|
|
Subject: [PATCH] adapt to poppler 0.58
|
|
|
|
---
|
|
configure.in | 17 +++++++++++++++++
|
|
frmts/pdf/GNUmakefile | 4 ++++
|
|
frmts/pdf/pdfdataset.cpp | 16 ++++++++++++++++
|
|
frmts/pdf/pdfio.cpp | 18 ++++++++++++++++--
|
|
frmts/pdf/pdfio.h | 13 ++++++++++++-
|
|
frmts/pdf/pdfobject.cpp | 26 ++++++++++++++++++++++++--
|
|
6 files changed, 89 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/configure.in b/configure.in
|
|
index 3fb74b0..84194be 100644
|
|
--- a/configure.in
|
|
+++ b/configure.in
|
|
@@ -3921,6 +3921,7 @@ HAVE_POPPLER=no
|
|
POPPLER_HAS_OPTCONTENT=no
|
|
POPPLER_BASE_STREAM_HAS_TWO_ARGS=no
|
|
POPPLER_0_20_OR_LATER=no
|
|
+POPPLER_NEW_OBJECT_API=no
|
|
|
|
AC_MSG_CHECKING([for poppler])
|
|
|
|
@@ -4023,6 +4024,21 @@ if test "$with_poppler" != "no" -a "$with_poppler" != ""; then
|
|
else
|
|
AC_MSG_RESULT([no])
|
|
fi
|
|
+
|
|
+ # And now we check if we have Poppler >= 0.58.0
|
|
+ AC_MSG_CHECKING([if Object does have new API (>= 0.58.0)])
|
|
+ rm -f testpoppler.*
|
|
+ echo '#include <poppler/Object.h>' > testpoppler.cpp
|
|
+ echo 'int main(int argc, char** argv) { Object o(objNull); return 0; }' >> testpoppler.cpp
|
|
+ if test -z "`${CXX} testpoppler.cpp -c ${POPPLER_INC} 2>&1`" ; then
|
|
+ POPPLER_NEW_OBJECT_API=yes
|
|
+ POPPLER_0_23_OR_LATER=yes
|
|
+ POPPLER_0_20_OR_LATER=yes
|
|
+ POPPLER_BASE_STREAM_HAS_TWO_ARGS=yes
|
|
+ AC_MSG_RESULT([yes])
|
|
+ else
|
|
+ AC_MSG_RESULT([no])
|
|
+ fi
|
|
else
|
|
AC_MSG_RESULT([no])
|
|
fi
|
|
@@ -4037,6 +4053,7 @@ AC_SUBST(POPPLER_HAS_OPTCONTENT, $POPPLER_HAS_OPTCONTENT)
|
|
AC_SUBST(POPPLER_BASE_STREAM_HAS_TWO_ARGS, $POPPLER_BASE_STREAM_HAS_TWO_ARGS)
|
|
AC_SUBST(POPPLER_0_20_OR_LATER, $POPPLER_0_20_OR_LATER)
|
|
AC_SUBST(POPPLER_0_23_OR_LATER, $POPPLER_0_23_OR_LATER)
|
|
+AC_SUBST(POPPLER_NEW_OBJECT_API, $POPPLER_NEW_OBJECT_API)
|
|
AC_SUBST(POPPLER_INC, $POPPLER_INC)
|
|
AC_SUBST(POPPLER_PLUGIN_LIB, $POPPLER_PLUGIN_LIB)
|
|
|
|
diff --git a/frmts/pdf/GNUmakefile b/frmts/pdf/GNUmakefile
|
|
index f5b7f41..eb7dc1b 100644
|
|
--- a/frmts/pdf/GNUmakefile
|
|
+++ b/frmts/pdf/GNUmakefile
|
|
@@ -31,6 +31,10 @@ ifeq ($(POPPLER_0_23_OR_LATER),yes)
|
|
CPPFLAGS += -DPOPPLER_0_23_OR_LATER
|
|
endif
|
|
|
|
+ifeq ($(POPPLER_NEW_OBJECT_API),yes)
|
|
+CPPFLAGS += -DPOPPLER_NEW_OBJECT_API
|
|
+endif
|
|
+
|
|
ifeq ($(HAVE_PODOFO),yes)
|
|
CPPFLAGS += -DHAVE_PODOFO
|
|
endif
|
|
diff --git a/frmts/pdf/pdfdataset.cpp b/frmts/pdf/pdfdataset.cpp
|
|
index 4bee2d8..5b00d3d 100644
|
|
--- a/frmts/pdf/pdfdataset.cpp
|
|
+++ b/frmts/pdf/pdfdataset.cpp
|
|
@@ -128,7 +128,9 @@ class ObjectAutoFree : public Object
|
|
|
|
public:
|
|
ObjectAutoFree() {}
|
|
+#if !defined(POPPLER_NEW_OBJECT_API)
|
|
~ObjectAutoFree() { obj.free(); }
|
|
+#endif
|
|
|
|
Object* getObj() { return &obj; }
|
|
};
|
|
@@ -2283,7 +2285,11 @@ GDALPDFObject* PDFDataset::GetCatalog()
|
|
if (bUseLib.test(PDFLIB_POPPLER))
|
|
{
|
|
poCatalogObjectPoppler = new ObjectAutoFree;
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ *poCatalogObjectPoppler->getObj() = poDocPoppler->getXRef()->getCatalog();
|
|
+#else
|
|
poDocPoppler->getXRef()->getCatalog(poCatalogObjectPoppler->getObj());
|
|
+#endif
|
|
if (!poCatalogObjectPoppler->getObj()->isNull())
|
|
poCatalogObject = new GDALPDFObjectPoppler(poCatalogObjectPoppler->getObj(), FALSE);
|
|
}
|
|
@@ -4074,7 +4080,11 @@ GDALDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
|
|
if (pszUserPwd)
|
|
poUserPwd = new GooString(pszUserPwd);
|
|
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ *oObj.getObj() = Object(objNull);
|
|
+#else
|
|
oObj.getObj()->initNull();
|
|
+#endif
|
|
poDocPoppler = new PDFDoc(new VSIPDFFileStream(fp, pszFilename, oObj.getObj()), NULL, poUserPwd);
|
|
delete poUserPwd;
|
|
|
|
@@ -4764,10 +4774,16 @@ GDALDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
|
|
if( poDocPoppler->getXRef()->isOk() )
|
|
{
|
|
Object oInfo;
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ oInfo = poDocPoppler->getDocInfo();
|
|
+#else
|
|
poDocPoppler->getDocInfo(&oInfo);
|
|
+#endif
|
|
GDALPDFObjectPoppler oInfoObjPoppler(&oInfo, FALSE);
|
|
poDS->ParseInfo(&oInfoObjPoppler);
|
|
+#if !defined(POPPLER_NEW_OBJECT_API)
|
|
oInfo.free();
|
|
+#endif
|
|
}
|
|
|
|
/* Find layers */
|
|
diff --git a/frmts/pdf/pdfio.cpp b/frmts/pdf/pdfio.cpp
|
|
index 3baeac0..8d3060b 100644
|
|
--- a/frmts/pdf/pdfio.cpp
|
|
+++ b/frmts/pdf/pdfio.cpp
|
|
@@ -54,11 +54,15 @@ static vsi_l_offset VSIPDFFileStreamGetSize(VSILFILE* f)
|
|
/************************************************************************/
|
|
|
|
VSIPDFFileStream::VSIPDFFileStream(VSILFILE* fIn, const char* pszFilename, Object *dictA):
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ BaseStream(dictA->copy(), (setPos_offset_type)VSIPDFFileStreamGetSize(fIn))
|
|
+#else
|
|
#ifdef POPPLER_BASE_STREAM_HAS_TWO_ARGS
|
|
BaseStream(dictA, (setPos_offset_type)VSIPDFFileStreamGetSize(fIn))
|
|
#else
|
|
BaseStream(dictA)
|
|
#endif
|
|
+#endif
|
|
{
|
|
poParent = NULL;
|
|
poFilename = new GooString(pszFilename);
|
|
@@ -79,11 +83,15 @@ VSIPDFFileStream::VSIPDFFileStream(VSILFILE* fIn, const char* pszFilename, Objec
|
|
VSIPDFFileStream::VSIPDFFileStream(VSIPDFFileStream* poParentIn,
|
|
vsi_l_offset startA, GBool limitedA,
|
|
vsi_l_offset lengthA, Object *dictA):
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ BaseStream(dictA->copy(), (makeSubStream_offset_type)lengthA)
|
|
+#else
|
|
#ifdef POPPLER_BASE_STREAM_HAS_TWO_ARGS
|
|
BaseStream(dictA, (makeSubStream_offset_type)lengthA)
|
|
#else
|
|
BaseStream(dictA)
|
|
#endif
|
|
+#endif
|
|
{
|
|
this->poParent = poParentIn;
|
|
poFilename = poParent->poFilename;
|
|
@@ -129,11 +137,17 @@ BaseStream* VSIPDFFileStream::copy()
|
|
/************************************************************************/
|
|
|
|
Stream *VSIPDFFileStream::makeSubStream(makeSubStream_offset_type startA, GBool limitedA,
|
|
- makeSubStream_offset_type lengthA, Object *dictA)
|
|
+ makeSubStream_offset_type lengthA, makeSubStream_object_type dictA)
|
|
{
|
|
return new VSIPDFFileStream(this,
|
|
startA, limitedA,
|
|
- lengthA, dictA);
|
|
+ lengthA,
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ &dictA
|
|
+#else
|
|
+ dictA
|
|
+#endif
|
|
+ );
|
|
}
|
|
|
|
/************************************************************************/
|
|
diff --git a/frmts/pdf/pdfio.h b/frmts/pdf/pdfio.h
|
|
index 13b36a0..81345db 100644
|
|
--- a/frmts/pdf/pdfio.h
|
|
+++ b/frmts/pdf/pdfio.h
|
|
@@ -39,19 +39,30 @@
|
|
#define BUFFER_SIZE 1024
|
|
|
|
|
|
+#ifdef POPPLER_NEW_OBJECT_API
|
|
+#define getPos_ret_type Goffset
|
|
+#define getStart_ret_type Goffset
|
|
+#define makeSubStream_offset_type Goffset
|
|
+#define makeSubStream_object_type Object &&
|
|
+#define setPos_offset_type Goffset
|
|
+#define moveStart_delta_type Goffset
|
|
+#else
|
|
#ifdef POPPLER_0_23_OR_LATER
|
|
#define getPos_ret_type Goffset
|
|
#define getStart_ret_type Goffset
|
|
#define makeSubStream_offset_type Goffset
|
|
+#define makeSubStream_object_type Object *
|
|
#define setPos_offset_type Goffset
|
|
#define moveStart_delta_type Goffset
|
|
#else
|
|
#define getPos_ret_type int
|
|
#define getStart_ret_type Guint
|
|
#define makeSubStream_offset_type Guint
|
|
+#define makeSubStream_object_type Object *
|
|
#define setPos_offset_type Guint
|
|
#define moveStart_delta_type int
|
|
#endif
|
|
+#endif
|
|
|
|
|
|
class VSIPDFFileStream: public BaseStream
|
|
@@ -68,7 +79,7 @@ class VSIPDFFileStream: public BaseStream
|
|
#endif
|
|
|
|
virtual Stream * makeSubStream(makeSubStream_offset_type startA, GBool limitedA,
|
|
- makeSubStream_offset_type lengthA, Object *dictA);
|
|
+ makeSubStream_offset_type lengthA, makeSubStream_object_type dictA);
|
|
virtual getPos_ret_type getPos();
|
|
virtual getStart_ret_type getStart();
|
|
|
|
diff --git a/frmts/pdf/pdfobject.cpp b/frmts/pdf/pdfobject.cpp
|
|
index e1f11a9..9b1ab9a 100644
|
|
--- a/frmts/pdf/pdfobject.cpp
|
|
+++ b/frmts/pdf/pdfobject.cpp
|
|
@@ -975,7 +975,9 @@ class GDALPDFStreamPoppler : public GDALPDFStream
|
|
|
|
GDALPDFObjectPoppler::~GDALPDFObjectPoppler()
|
|
{
|
|
+#if !defined(POPPLER_NEW_OBJECT_API)
|
|
m_po->free();
|
|
+#endif
|
|
if (m_bDestroy)
|
|
delete m_po;
|
|
delete m_poDict;
|
|
@@ -1187,7 +1189,11 @@ GDALPDFObject* GDALPDFDictionaryPoppler::Get(const char* pszKey)
|
|
return oIter->second;
|
|
|
|
Object* po = new Object;
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ if (!(*po = m_poDict->lookupNF((char*)pszKey)).isNull())
|
|
+#else
|
|
if (m_poDict->lookupNF((char*)pszKey, po) && !po->isNull())
|
|
+#endif
|
|
{
|
|
int nRefNum = 0, nRefGen = 0;
|
|
if( po->isRef())
|
|
@@ -1195,7 +1201,13 @@ GDALPDFObject* GDALPDFDictionaryPoppler::Get(const char* pszKey)
|
|
nRefNum = po->getRefNum();
|
|
nRefGen = po->getRefGen();
|
|
}
|
|
- if( !po->isRef() || (m_poDict->lookup((char*)pszKey, po) && !po->isNull()) )
|
|
+ if( !po->isRef()
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ || (!(*po = m_poDict->lookupNF((char*)pszKey)).isNull())
|
|
+#else
|
|
+ || (m_poDict->lookup((char*)pszKey, po) && !po->isNull())
|
|
+#endif
|
|
+ )
|
|
{
|
|
GDALPDFObjectPoppler* poObj = new GDALPDFObjectPoppler(po, TRUE);
|
|
poObj->SetRefNumAndGen(nRefNum, nRefGen);
|
|
@@ -1290,7 +1302,11 @@ GDALPDFObject* GDALPDFArrayPoppler::Get(int nIndex)
|
|
return m_v[nIndex];
|
|
|
|
Object* po = new Object;
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ if (!(*po = m_poArray->getNF(nIndex)).isNull())
|
|
+#else
|
|
if (m_poArray->getNF(nIndex, po))
|
|
+#endif
|
|
{
|
|
int nRefNum = 0, nRefGen = 0;
|
|
if( po->isRef())
|
|
@@ -1298,7 +1314,13 @@ GDALPDFObject* GDALPDFArrayPoppler::Get(int nIndex)
|
|
nRefNum = po->getRefNum();
|
|
nRefGen = po->getRefGen();
|
|
}
|
|
- if( !po->isRef() || (m_poArray->get(nIndex, po)) )
|
|
+ if( !po->isRef()
|
|
+#if defined(POPPLER_NEW_OBJECT_API)
|
|
+ || !((*po = m_poArray->get(nIndex)).isNull())
|
|
+#else
|
|
+ || (m_poArray->get(nIndex, po))
|
|
+#endif
|
|
+ )
|
|
{
|
|
GDALPDFObjectPoppler* poObj = new GDALPDFObjectPoppler(po, TRUE);
|
|
poObj->SetRefNumAndGen(nRefNum, nRefGen);
|
|
--
|
|
2.13.5
|
|
|