From 45cca81d842779203d21a5ddf390c272b7056d42 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 6 Sep 2017 16:37:16 +0200 Subject: [PATCH] adapt to poppler 0.58 --- Applications/Cxx/CMakeLists.txt | 6 ++++++ Applications/Cxx/gdcminfo.cxx | 22 ++++++++++++++++++++++ Applications/Cxx/gdcmpdf.cxx | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/Applications/Cxx/CMakeLists.txt b/Applications/Cxx/CMakeLists.txt index 9b42682..2843fd5 100644 --- a/Applications/Cxx/CMakeLists.txt +++ b/Applications/Cxx/CMakeLists.txt @@ -84,6 +84,12 @@ if(GDCM_USE_SYSTEM_POPPLER) if(LIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT) list(APPEND libpoppler_flags -DLIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT) endif() + CHECK_CXX_SOURCE_COMPILES( + "\#include \nint main() { Object o(42); }" + LIBPOPPLER_NEW_OBJECT_API) +if(LIBPOPPLER_NEW_OBJECT_API) + list(APPEND libpoppler_flags -DLIBPOPPLER_NEW_OBJECT_API) + endif() if(libpoppler_flags) string(REPLACE ";" " " libpoppler_flags_string "${libpoppler_flags}") set_source_files_properties( diff --git a/Applications/Cxx/gdcminfo.cxx b/Applications/Cxx/gdcminfo.cxx index 6e2b50d..8d2a137 100644 --- a/Applications/Cxx/gdcminfo.cxx +++ b/Applications/Cxx/gdcminfo.cxx @@ -193,7 +193,11 @@ static std::string getInfoDate(Dict *infoDict, const char *key) //char buf[256]; std::string out; +#ifdef LIBPOPPLER_NEW_OBJECT_API + if ((obj = infoDict->lookup((char*)key)).isString()) +#else if (infoDict->lookup((char*)key, &obj)->isString()) +#endif { s = obj.getString()->getCString(); if (s[0] == 'D' && s[1] == ':') @@ -241,7 +245,9 @@ static std::string getInfoDate(Dict *infoDict, const char *key) out = date; } } +#ifndef LIBPOPPLER_NEW_OBJECT_API obj.free(); +#endif return out; } @@ -255,7 +261,11 @@ static std::string getInfoString(Dict *infoDict, const char *key, UnicodeMap *uM int i, n; std::string out; +#ifdef LIBPOPPLER_NEW_OBJECT_API + if ((obj = infoDict->lookup((char*)key)).isString()) +#else if (infoDict->lookup((char*)key, &obj)->isString()) +#endif { s1 = obj.getString(); if ((s1->getChar(0) & 0xff) == 0xfe && @@ -287,7 +297,9 @@ static std::string getInfoString(Dict *infoDict, const char *key, UnicodeMap *uM out.append( std::string(buf, n) ); } } +#ifndef LIBPOPPLER_NEW_OBJECT_API obj.free(); +#endif return out; } #endif @@ -434,7 +446,11 @@ static int ProcessOneFile( std::string const & filename, gdcm::Defs const & defs MemStream *appearStream; appearStream = new MemStream((char*)bv->GetPointer(), 0, +#ifdef LIBPOPPLER_NEW_OBJECT_API + bv->GetLength(), std::move(appearDict)); +#else bv->GetLength(), &appearDict); +#endif GooString *ownerPW, *userPW; ownerPW = NULL; userPW = NULL; @@ -462,7 +478,11 @@ static int ProcessOneFile( std::string const & filename, gdcm::Defs const & defs Object info; if (doc->isOk()) { +#ifdef LIBPOPPLER_NEW_OBJECT_API + info = doc->getDocInfo(); +#else doc->getDocInfo(&info); +#endif if (info.isDict()) { title = getInfoString(info.getDict(), "Title", uMap); @@ -473,7 +493,9 @@ static int ProcessOneFile( std::string const & filename, gdcm::Defs const & defs producer = getInfoString(info.getDict(), "Producer", uMap); creationdate = getInfoDate( info.getDict(), "CreationDate" ); moddate = getInfoDate( info.getDict(), "ModDate" ); +#ifndef LIBPOPPLER_NEW_OBJECT_API info.free(); +#endif } #ifdef LIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT const char *tagged = doc->getStructTreeRoot() ? "yes" : "no"; diff --git a/Applications/Cxx/gdcmpdf.cxx b/Applications/Cxx/gdcmpdf.cxx index 4c7a7bb..92caad7 100644 --- a/Applications/Cxx/gdcmpdf.cxx +++ b/Applications/Cxx/gdcmpdf.cxx @@ -43,7 +43,11 @@ static std::string getInfoDate(Dict *infoDict, const char *key) //char buf[256]; std::string out; +#ifdef LIBPOPPLER_NEW_OBJECT_API + if ((obj = infoDict->lookup((char*)key)).isString()) +#else if (infoDict->lookup((char*)key, &obj)->isString()) +#endif { s = obj.getString()->getCString(); if (s[0] == 'D' && s[1] == ':') @@ -91,7 +95,9 @@ static std::string getInfoDate(Dict *infoDict, const char *key) out = date; } } +#ifndef LIBPOPPLER_NEW_OBJECT_API obj.free(); +#endif return out; } @@ -105,7 +111,11 @@ static std::string getInfoString(Dict *infoDict, const char *key, UnicodeMap *uM int i, n; std::string out; +#ifdef LIBPOPPLER_NEW_OBJECT_API + if ((obj = infoDict->lookup((char*)key)).isString()) +#else if (infoDict->lookup((char*)key, &obj)->isString()) +#endif { s1 = obj.getString(); if ((s1->getChar(0) & 0xff) == 0xfe && @@ -137,7 +147,9 @@ static std::string getInfoString(Dict *infoDict, const char *key, UnicodeMap *uM out.append( std::string(buf, n) ); } } +#ifndef LIBPOPPLER_NEW_OBJECT_API obj.free(); +#endif unicode = unicode || isUnicode; return out; } @@ -340,7 +352,9 @@ int main (int argc, char *argv[]) //ownerPW = new GooString( "toto" ); Object obj; +#ifndef LIBPOPPLER_NEW_OBJECT_API obj.initNull(); +#endif doc = new PDFDoc(fileName, ownerPW, userPW); if (doc->isEncrypted()) @@ -386,7 +400,11 @@ http://msdn.microsoft.com/en-us/library/078sfkak(VS.80).aspx GBool isUnicode = gFalse; if (doc->isOk()) { +#ifdef LIBPOPPLER_NEW_OBJECT_API + info = doc->getDocInfo(); +#else doc->getDocInfo(&info); +#endif if (info.isDict()) { title = getInfoString(info.getDict(), "Title", uMap, isUnicode); @@ -397,7 +415,9 @@ http://msdn.microsoft.com/en-us/library/078sfkak(VS.80).aspx producer = getInfoString(info.getDict(), "Producer", uMap, isUnicode); creationdate = getInfoDate( info.getDict(), "CreationDate" ); moddate = getInfoDate( info.getDict(), "ModDate" ); +#ifndef LIBPOPPLER_NEW_OBJECT_API info.free(); +#endif } } -- 2.13.5