--- /dev/null
+From 61186c7ef083046b7e0c908952e8a773e2787d82 Mon Sep 17 00:00:00 2001
+From: Jean Ghali <jghali@libertysurf.fr>
+Date: Fri, 8 Sep 2017 16:52:10 +0000
+Subject: [PATCH] #14979: poppler-0.58 breaks build
+
+git-svn-id: svn://scribus.net/trunk/Scribus@22154 11d20701-8431-0410-a711-e3c959e3b870
+---
+ scribus/plugins/import/pdf/importpdf.cpp | 95 +++++++++++++++--
+ scribus/plugins/import/pdf/slaoutput.cpp | 174 ++++++++++++++++++++++++++++++-
+ 2 files changed, 258 insertions(+), 11 deletions(-)
+
+diff --git a/scribus/plugins/import/pdf/importpdf.cpp b/scribus/plugins/import/pdf/importpdf.cpp
+index 4c462beadd..1c0bd8a888 100644
+--- a/scribus/plugins/import/pdf/importpdf.cpp
++++ b/scribus/plugins/import/pdf/importpdf.cpp
+@@ -22,6 +22,7 @@ for which a new license (GPL+exception) is in place.
+ #include <poppler/PageTransition.h>\r
+ #include <poppler/ViewerPreferences.h>\r
+ #include <poppler/poppler-config.h>\r
++#include <poppler/cpp/poppler-version.h>\r
+ #include <poppler/SplashOutputDev.h>\r
+ #include <poppler/splash/SplashBitmap.h>\r
+ \r
+@@ -59,6 +60,12 @@ for which a new license (GPL+exception) is in place.
+ #include "ui/multiprogressdialog.h"\r
+ #include "ui/propertiespalette.h"\r
+ \r
++#define POPPLER_VERSION_ENCODE(major, minor, micro) ( \
++ ((major) * 10000) \
++ + ((minor) * 100) \
++ + ((micro) * 1))\r
++#define POPPLER_ENCODED_VERSION POPPLER_VERSION_ENCODE(POPPLER_VERSION_MAJOR, POPPLER_VERSION_MINOR, POPPLER_VERSION_MICRO)\r
++\r
+ PdfPlug::PdfPlug(ScribusDoc* doc, int flags)\r
+ {\r
+ tmpSele = new Selection(this, false);\r
+@@ -507,12 +514,20 @@ bool PdfPlug::convert(const QString& fn)
+ {\r
+ for (int i = 0; i < order->getLength (); ++i)\r
+ {\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object orderItem = order->get(i);\r
++#else\r
+ Object orderItem;\r
+ order->get(i, &orderItem);\r
++#endif\r
+ if (orderItem.isDict())\r
+ {\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object ref = order->getNF(i); \r
++#else\r
+ Object ref;\r
+ order->getNF(i, &ref);\r
++#endif\r
+ if (ref.isRef())\r
+ {\r
+ OptionalContentGroup *oc = ocg->findOcgByRef(ref.getRef());\r
+@@ -523,7 +538,9 @@ bool PdfPlug::convert(const QString& fn)
+ ocgNames.append(ocgName);\r
+ }\r
+ }\r
++#if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 58, 0)\r
+ ref.free();\r
++#endif\r
+ }\r
+ else\r
+ {\r
+@@ -597,39 +614,71 @@ bool PdfPlug::convert(const QString& fn)
+ dev->layersSetByOCG = true;\r
+ }\r
+ #endif\r
++\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object info = pdfDoc->getDocInfo();\r
++ if (info.isDict())\r
++ {\r
++ Object obj;\r
++ Dict *infoDict = info.getDict();\r
++ obj = infoDict->lookup((char*) "Title");\r
++ if (obj.isString())\r
++ {\r
++ m_Doc->documentInfo().setTitle(UnicodeParsedString(obj.getString()));\r
++ }\r
++ obj = infoDict->lookup((char*) "Author");\r
++ if (obj.isString())\r
++ {\r
++ m_Doc->documentInfo().setAuthor(UnicodeParsedString(obj.getString()));\r
++ }\r
++ obj = infoDict->lookup((char*) "Subject");\r
++ if (obj.isString())\r
++ {\r
++ m_Doc->documentInfo().setSubject(UnicodeParsedString(obj.getString()));\r
++ }\r
++ obj = infoDict->lookup((char*) "Keywords");\r
++ if (obj.isString())\r
++ {\r
++ // s1 = obj.getString();\r
++ m_Doc->documentInfo().setKeywords(UnicodeParsedString(obj.getString()));\r
++ }\r
++ }\r
++ info = Object();\r
++#else\r
+ Object info;\r
+ pdfDoc->getDocInfo(&info);\r
+ if (info.isDict())\r
+ {\r
+ Object obj;\r
+- // GooString *s1;\r
++ // GooString *s1;\r
+ Dict *infoDict = info.getDict();\r
+- if (infoDict->lookup((char*)"Title", &obj )->isString())\r
++ if (infoDict->lookup((char*)"Title", &obj)->isString())\r
+ {\r
+- // s1 = obj.getString();\r
++ // s1 = obj.getString();\r
+ m_Doc->documentInfo().setTitle(UnicodeParsedString(obj.getString()));\r
+ obj.free();\r
+ }\r
+- if (infoDict->lookup((char*)"Author", &obj )->isString())\r
++ if (infoDict->lookup((char*)"Author", &obj)->isString())\r
+ {\r
+- // s1 = obj.getString();\r
++ // s1 = obj.getString();\r
+ m_Doc->documentInfo().setAuthor(UnicodeParsedString(obj.getString()));\r
+ obj.free();\r
+ }\r
+- if (infoDict->lookup((char*)"Subject", &obj )->isString())\r
++ if (infoDict->lookup((char*)"Subject", &obj)->isString())\r
+ {\r
+- // s1 = obj.getString();\r
++ // s1 = obj.getString();\r
+ m_Doc->documentInfo().setSubject(UnicodeParsedString(obj.getString()));\r
+ obj.free();\r
+ }\r
+- if (infoDict->lookup((char*)"Keywords", &obj )->isString())\r
++ if (infoDict->lookup((char*)"Keywords", &obj)->isString())\r
+ {\r
+- // s1 = obj.getString();\r
++ // s1 = obj.getString();\r
+ m_Doc->documentInfo().setKeywords(UnicodeParsedString(obj.getString()));\r
+ obj.free();\r
+ }\r
+ }\r
+ info.free();\r
++#endif\r
+ if (cropped)\r
+ {\r
+ QRectF crBox = getCBox(contentRect, pageNs[0]);\r
+@@ -746,8 +795,13 @@ bool PdfPlug::convert(const QString& fn)
+ pdfDoc->displayPage(dev, pp, hDPI, vDPI, rotate, useMediaBox, crop, printing, NULL, NULL, dev->annotations_callback, dev);\r
+ }\r
+ PDFPresentationData ef;\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object trans = pdfDoc->getPage(pp)->getTrans();\r
++ Object *transi = &trans;\r
++#else\r
+ Object trans;\r
+ Object *transi = pdfDoc->getPage(pp)->getTrans(&trans);\r
++#endif\r
+ if (transi->isDict())\r
+ {\r
+ m_Doc->pdfOptions().PresentMode = true;\r
+@@ -793,32 +847,51 @@ bool PdfPlug::convert(const QString& fn)
+ delete pgTrans;\r
+ }\r
+ m_Doc->currentPage()->PresentVals = ef;\r
++#if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 58, 0)\r
+ trans.free();\r
+ transi->free();\r
++#endif\r
+ }\r
+ int numjs = pdfDoc->getCatalog()->numJS();\r
+ if (numjs > 0)\r
+ {\r
+ NameTree *jsNameTreeP = new NameTree();\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object catDict = pdfDoc->getXRef()->getCatalog();\r
++#else\r
+ Object catDict;\r
+ pdfDoc->getXRef()->getCatalog(&catDict);\r
++#endif\r
+ if (catDict.isDict())\r
+ {\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object names = catDict.dictLookup("Names");\r
++#else\r
+ Object names;\r
+ catDict.dictLookup("Names", &names);\r
++#endif\r
+ if (names.isDict())\r
+ {\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object obj = names.dictLookup("JavaScript");\r
++ jsNameTreeP->init(pdfDoc->getXRef(), &obj);\r
++#else\r
+ Object obj;\r
+ names.dictLookup("JavaScript", &obj);\r
+ jsNameTreeP->init(pdfDoc->getXRef(), &obj);\r
+ obj.free();\r
++#endif\r
+ }\r
+ for (int a = 0; a < numjs; a++)\r
+ {\r
+ m_Doc->JavaScripts.insert(UnicodeParsedString(jsNameTreeP->getName(a)), UnicodeParsedString(pdfDoc->getCatalog()->getJS(a)));\r
+ }\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ names = catDict.dictLookup("OpenAction");\r
++#else\r
+ names.free();\r
+ catDict.dictLookup("OpenAction", &names);\r
++#endif\r
+ if (names.isDict())\r
+ {\r
+ LinkAction *linkAction = NULL;\r
+@@ -839,9 +912,13 @@ bool PdfPlug::convert(const QString& fn)
+ }\r
+ }\r
+ }\r
++#if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 58, 0)\r
+ names.free();\r
++#endif\r
+ }\r
++#if POPPLER_ENCODED_VERSION < POPPLER_VERSION_ENCODE(0, 58, 0)\r
+ catDict.free();\r
++#endif\r
+ delete jsNameTreeP;\r
+ }\r
+ m_Doc->pdfOptions().Version = (PDFOptions::PDFVersion)qMin(15, qMax(13, pdfDoc->getPDFMajorVersion() * 10 + pdfDoc->getPDFMinorVersion()));\r
+diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp
+index 32cfed1012..ffa417a3b6 100644
+--- a/scribus/plugins/import/pdf/slaoutput.cpp
++++ b/scribus/plugins/import/pdf/slaoutput.cpp
+@@ -6,6 +6,7 @@ for which a new license (GPL+exception) is in place.
+ */\r
+ \r
+ #include "slaoutput.h"\r
++#include <poppler/cpp/poppler-version.h>\r
+ #include <poppler/GlobalParams.h>\r
+ #include <poppler/poppler-config.h>\r
+ #include <poppler/FileSpec.h>\r
+@@ -19,11 +20,49 @@ for which a new license (GPL+exception) is in place.
+ #include "util_math.h"\r
+ #include <tiffio.h>\r
+ \r
++#define POPPLER_VERSION_ENCODE(major, minor, micro) ( \
++ ((major) * 10000) \
++ + ((minor) * 100) \
++ + ((micro) * 1))\r
++#define POPPLER_ENCODED_VERSION POPPLER_VERSION_ENCODE(POPPLER_VERSION_MAJOR, POPPLER_VERSION_MINOR, POPPLER_VERSION_MICRO)\r
++\r
+ LinkSubmitForm::LinkSubmitForm(Object *actionObj)\r
+ {\r
+ Object obj1, obj2, obj3;\r
+ fileName = NULL;\r
+ m_flags = 0;\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ if (actionObj->isDict())\r
++ {\r
++ obj1 = actionObj->dictLookup("F");\r
++ if (!obj1.isNull())\r
++ {\r
++ if (obj1.isDict())\r
++ {\r
++ obj3 = obj1.dictLookup("FS");\r
++ if (!obj3.isNull())\r
++ {\r
++ if (obj3.isName())\r
++ {\r
++ char *name = obj3.getName();\r
++ if (!strcmp(name, "URL"))\r
++ {\r
++ obj2 = obj1.dictLookup("F");\r
++ if (!obj2.isNull())\r
++ fileName = obj2.getString()->copy();\r
++ }\r
++ }\r
++ }\r
++ }\r
++ }\r
++ obj1 = actionObj->dictLookup("Flags");\r
++ if (!obj1.isNull())\r
++ {\r
++ if (obj1.isNum())\r
++ m_flags = obj1.getInt();\r
++ }\r
++ }\r
++#else\r
+ if (actionObj->isDict())\r
+ {\r
+ if (!actionObj->dictLookup("F", &obj1)->isNull())\r
+@@ -54,6 +93,7 @@ LinkSubmitForm::LinkSubmitForm(Object *actionObj)
+ }\r
+ obj1.free();\r
+ }\r
++#endif\r
+ }\r
+ \r
+ LinkSubmitForm::~LinkSubmitForm()\r
+@@ -66,11 +106,25 @@ LinkImportData::LinkImportData(Object *actionObj)
+ {\r
+ Object obj1, obj3;\r
+ fileName = NULL;\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ if (actionObj->isDict())\r
++ {\r
++ obj1 = actionObj->dictLookup("F");\r
++ if (!obj1.isNull())\r
++ {\r
++ obj3 = getFileSpecNameForPlatform(&obj1);\r
++ if (!obj3.isNull())\r
++ {\r
++ fileName = obj3.getString()->copy();\r
++ }\r
++ }\r
++ }\r
++#else\r
+ if (actionObj->isDict())\r
+ {\r
+ if (!actionObj->dictLookup("F", &obj1)->isNull())\r
+ {\r
+- if (getFileSpecNameForPlatform (&obj1, &obj3))\r
++ if (getFileSpecNameForPlatform(&obj1, &obj3))\r
+ {\r
+ fileName = obj3.getString()->copy();\r
+ obj3.free();\r
+@@ -78,6 +132,7 @@ LinkImportData::LinkImportData(Object *actionObj)
+ }\r
+ obj1.free();\r
+ }\r
++#endif\r
+ }\r
+ \r
+ LinkImportData::~LinkImportData()\r
+@@ -256,6 +311,27 @@ LinkAction* SlaOutputDev::SC_getAction(AnnotWidget *ano)
+ Object obj;\r
+ Ref refa = ano->getRef();\r
+ Object additionalActions;\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ obj = xref->fetch(refa.num, refa.gen);\r
++ if (obj.isDict())\r
++ {\r
++ Dict* adic = obj.getDict();\r
++ additionalActions = adic->lookupNF("A");\r
++ Object additionalActionsObject = additionalActions.fetch(pdfDoc->getXRef());\r
++ if (additionalActionsObject.isDict())\r
++ {\r
++ Object actionObject = additionalActionsObject.dictLookup("S");\r
++ if (actionObject.isName("ImportData"))\r
++ {\r
++ linkAction = new LinkImportData(&additionalActionsObject);\r
++ }\r
++ else if (actionObject.isName("SubmitForm"))\r
++ {\r
++ linkAction = new LinkSubmitForm(&additionalActionsObject);\r
++ }\r
++ }\r
++ }\r
++#else\r
+ Object *act = xref->fetch(refa.num, refa.gen, &obj);\r
+ if (act)\r
+ {\r
+@@ -283,6 +359,7 @@ LinkAction* SlaOutputDev::SC_getAction(AnnotWidget *ano)
+ }\r
+ }\r
+ obj.free();\r
++#endif\r
+ return linkAction;\r
+ }\r
+ \r
+@@ -293,6 +370,22 @@ LinkAction* SlaOutputDev::SC_getAdditionalAction(const char *key, AnnotWidget *a
+ Object obj;\r
+ Ref refa = ano->getRef();\r
+ Object additionalActions;\r
++\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ obj = xref->fetch(refa.num, refa.gen);\r
++ if (obj.isDict())\r
++ {\r
++ Dict* adic = obj.getDict();\r
++ additionalActions = adic->lookupNF("AA");\r
++ Object additionalActionsObject = additionalActions.fetch(pdfDoc->getXRef());\r
++ if (additionalActionsObject.isDict())\r
++ {\r
++ Object actionObject = additionalActionsObject.dictLookup(key);\r
++ if (actionObject.isDict())\r
++ linkAction = LinkAction::parseAction(&actionObject, pdfDoc->getCatalog()->getBaseURI());\r
++ }\r
++ }\r
++#else\r
+ Object *act = xref->fetch(refa.num, refa.gen, &obj);\r
+ if (act)\r
+ {\r
+@@ -313,6 +406,7 @@ LinkAction* SlaOutputDev::SC_getAdditionalAction(const char *key, AnnotWidget *a
+ }\r
+ }\r
+ obj.free();\r
++#endif\r
+ return linkAction;\r
+ }\r
+ \r
+@@ -838,6 +932,33 @@ bool SlaOutputDev::handleWidgetAnnot(Annot* annota, double xCoor, double yCoor,
+ {\r
+ Object obj1;\r
+ Ref refa = annota->getRef();\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ obj1 = xref->fetch(refa.num, refa.gen);\r
++ if (obj1.isDict())\r
++ {\r
++ Dict* dict = obj1.getDict();\r
++ Object obj2 = dict->lookup("Kids");\r
++ //childs\r
++ if (obj2.isArray())\r
++ {\r
++ // Load children\r
++ QList<int> radList;\r
++ for (int i = 0; i < obj2.arrayGetLength(); i++)\r
++ {\r
++ Object childRef = obj2.arrayGetNF(i);\r
++ if (!childRef.isRef())\r
++ continue;\r
++ Object childObj = obj2.arrayGet(i);\r
++ if (!childObj.isDict())\r
++ continue;\r
++ const Ref ref = childRef.getRef();\r
++ radList.append(ref.num);\r
++ }\r
++ QString tmTxt = UnicodeParsedString(annota->getName());\r
++ m_radioMap.insert(tmTxt, radList);\r
++ }\r
++ }\r
++#else\r
+ Object *act = xref->fetch(refa.num, refa.gen, &obj1);\r
+ if (act && act->isDict())\r
+ {\r
+@@ -873,6 +994,7 @@ bool SlaOutputDev::handleWidgetAnnot(Annot* annota, double xCoor, double yCoor,
+ obj2.free();\r
+ }\r
+ obj1.free();\r
++#endif\r
+ }\r
+ return retVal;\r
+ }\r
+@@ -3007,6 +3129,23 @@ void SlaOutputDev::beginMarkedContent(char *name, Object *dictRef)
+ }\r
+ else\r
+ {\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ dictObj = dictRef->fetch(xref);\r
++ if (!dictObj.isDict())\r
++ return;\r
++ dict = dictObj.getDict();\r
++ dictType = dict->lookup("Type");\r
++ if (dictType.isName("OCG"))\r
++ {\r
++ oc = contentConfig->findOcgByRef(dictRef->getRef());\r
++ if (oc)\r
++ {\r
++ // qDebug() << "Begin OCG Content with Name " << UnicodeParsedString(oc->getName());\r
++ m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));\r
++ mSte.ocgName = UnicodeParsedString(oc->getName());\r
++ }\r
++ }\r
++#else\r
+ dictRef->fetch(xref, &dictObj);\r
+ if (!dictObj.isDict())\r
+ {\r
+@@ -3027,6 +3166,7 @@ void SlaOutputDev::beginMarkedContent(char *name, Object *dictRef)
+ }\r
+ dictType.free();\r
+ dictObj.free();\r
++#endif\r
+ }\r
+ }\r
+ m_mcStack.push(mSte);\r
+@@ -3046,14 +3186,20 @@ void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
+ {\r
+ if (layersSetByOCG)\r
+ return;\r
+- Object obj;\r
+ QString lName = QString("Layer_%1").arg(layerNum + 1);\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ Object obj = properties->lookup((char*) "Title");\r
++ if (obj.isString())\r
++ lName = QString(obj.getString()->getCString());\r
++#else\r
++ Object obj;\r
+ if (properties->lookup((char*)"Title", &obj))\r
+ {\r
+ if (obj.isString())\r
+ lName = QString(obj.getString()->getCString());\r
+ obj.free();\r
+ }\r
++#endif\r
+ for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)\r
+ {\r
+ if (it->Name == lName)\r
+@@ -3066,6 +3212,29 @@ void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
+ if (!firstLayer)\r
+ currentLayer = m_doc->addLayer(lName, true);\r
+ firstLayer = false;\r
++#if POPPLER_ENCODED_VERSION >= POPPLER_VERSION_ENCODE(0, 58, 0)\r
++ obj = properties->lookup((char*) "Visible");\r
++ if (obj.isBool())\r
++ m_doc->setLayerVisible(currentLayer, obj.getBool());\r
++ obj = properties->lookup((char*) "Editable");\r
++ if (obj.isBool())\r
++ m_doc->setLayerLocked(currentLayer, !obj.getBool());\r
++ obj = properties->lookup((char*) "Printed");\r
++ if (obj.isBool())\r
++ m_doc->setLayerPrintable(currentLayer, obj.getBool());\r
++ obj = properties->lookup((char*)"Color");\r
++ if (obj.isArray())\r
++ {\r
++ Object obj1;\r
++ obj1 = obj.arrayGet(0);\r
++ int r = obj1.getNum() / 256;\r
++ obj1 = obj.arrayGet(1);\r
++ int g = obj1.getNum() / 256;\r
++ obj1 = obj.arrayGet(2);\r
++ int b = obj1.getNum() / 256;\r
++ m_doc->setLayerMarker(currentLayer, QColor(r, g, b));\r
++ }\r
++#else\r
+ if (properties->lookup((char*)"Visible", &obj))\r
+ {\r
+ if (obj.isBool())\r
+@@ -3102,6 +3271,7 @@ void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
+ }\r
+ obj.free();\r
+ }\r
++#endif\r
+ }\r
+ }\r
+ }\r