Blame texlive-20180414-new-poppler.patch

802fd2d
diff -up texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc
802fd2d
--- texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler	2016-11-25 13:24:37.000000000 -0500
802fd2d
+++ texlive-base-20180414/source/texk/web2c/pdftexdir/pdftoepdf.cc	2018-04-30 13:26:10.442342831 -0400
802fd2d
@@ -1,5 +1,5 @@
802fd2d
 /*
802fd2d
-Copyright 1996-2016 Han The Thanh, <thanh@pdftex.org>
802fd2d
+Copyright 1996-2017 Han The Thanh, <thanh@pdftex.org>
802fd2d
 
802fd2d
 This file is part of pdfTeX.
802fd2d
 
802fd2d
@@ -17,6 +17,15 @@ You should have received a copy of the G
802fd2d
 with this program.  If not, see <http://www.gnu.org/licenses/>.
802fd2d
 */
802fd2d
 
802fd2d
+/*
802fd2d
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
802fd2d
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
802fd2d
+by Arch Linux. A little modifications are made to avoid a crash for
802fd2d
+some kind of pdf images, such as figure_missing.pdf in gnuplot.
802fd2d
+The poppler should be 0.59.0 or newer versions.
802fd2d
+POPPLER_VERSION should be defined.
802fd2d
+*/
802fd2d
+
802fd2d
 /* Do this early in order to avoid a conflict between
802fd2d
    MINGW32 <rpcndr.h> defining 'boolean' as 'unsigned char' and
802fd2d
    <kpathsea/types.h> defining Pascal's boolean as 'int'.
802fd2d
@@ -39,10 +48,7 @@ with this program.  If not, see 
802fd2d
 #include <goo/gfile.h>
802fd2d
 #define GString GooString
802fd2d
 #else
802fd2d
-#include <aconf.h>
802fd2d
-#include <GString.h>
802fd2d
-#include <gmem.h>
802fd2d
-#include <gfile.h>
802fd2d
+#error POPPLER_VERSION should be defined.
802fd2d
 #endif
802fd2d
 #include <assert.h>
802fd2d
 
802fd2d
@@ -84,31 +90,6 @@ extern integer zround(double);
802fd2d
 #define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
802fd2d
 #define MASK_SUPPRESS_PTEX_INFODICT   0x08
802fd2d
 
802fd2d
-// PdfObject encapsulates the xpdf Object type,
802fd2d
-// and properly frees its resources on destruction.
802fd2d
-// Use obj-> to access members of the Object,
802fd2d
-// and &obj to get a pointer to the object.
802fd2d
-// It is no longer necessary to call Object::free explicitely.
802fd2d
-
802fd2d
-class PdfObject {
802fd2d
-  public:
802fd2d
-    PdfObject() {               // nothing
802fd2d
-    } ~PdfObject() {
802fd2d
-        iObject.free();
802fd2d
-    }
802fd2d
-    Object *operator->() {
802fd2d
-        return &iObject;
802fd2d
-    }
802fd2d
-    Object *operator&() {
802fd2d
-        return &iObject;
802fd2d
-    }
802fd2d
-  private:                     // no copying or assigning
802fd2d
-    PdfObject(const PdfObject &);
802fd2d
-    void operator=(const PdfObject &);
802fd2d
-  public:
802fd2d
-    Object iObject;
802fd2d
-};
802fd2d
-
802fd2d
 // When copying the Resources of the selected page, all objects are copied
802fd2d
 // recusively top-down. Indirect objects however are not fetched during
802fd2d
 // copying, but get a new object number from pdfTeX and then will be
802fd2d
@@ -212,18 +193,6 @@ static void delete_document(PdfDocument
802fd2d
     delete pdf_doc;
802fd2d
 }
802fd2d
 
802fd2d
-// Replacement for
802fd2d
-//      Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
802fd2d
-
802fd2d
-static void initDictFromDict(PdfObject & obj, Dict * dict)
802fd2d
-{
802fd2d
-    obj->initDict(xref);
802fd2d
-    for (int i = 0, l = dict->getLength(); i < l; i++) {
802fd2d
-        Object obj1;
802fd2d
-        obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
802fd2d
-    }
802fd2d
-}
802fd2d
-
802fd2d
 // --------------------------------------------------------------------
802fd2d
 
802fd2d
 static int addEncoding(GfxFont * gfont)
802fd2d
@@ -320,10 +289,10 @@ static void copyName(char *s)
802fd2d
 
802fd2d
 static void copyDictEntry(Object * obj, int i)
802fd2d
 {
802fd2d
-    PdfObject obj1;
802fd2d
+    Object obj1;
802fd2d
     copyName(obj->dictGetKey(i));
802fd2d
     pdf_puts(" ");
802fd2d
-    obj->dictGetValNF(i, &obj1);
802fd2d
+    obj1 = obj->dictGetValNF(i);
802fd2d
     copyObject(&obj1);
802fd2d
     pdf_puts("\n");
802fd2d
 }
802fd2d
@@ -376,17 +345,17 @@ static void copyStream(Stream * str)
802fd2d
 static void copyProcSet(Object * obj)
802fd2d
 {
802fd2d
     int i, l;
802fd2d
-    PdfObject procset;
802fd2d
+    Object procset;
802fd2d
     if (!obj->isArray())
802fd2d
         pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
802fd2d
                     obj->getTypeName());
802fd2d
     pdf_puts("/ProcSet [ ");
802fd2d
     for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
802fd2d
-        obj->arrayGetNF(i, &procset);
802fd2d
-        if (!procset->isName())
802fd2d
+        procset = obj->arrayGetNF(i);
802fd2d
+        if (!procset.isName())
802fd2d
             pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
802fd2d
-                        procset->getTypeName());
802fd2d
-        copyName(procset->getName());
802fd2d
+                        procset.getTypeName());
802fd2d
+        copyName(procset.getName());
802fd2d
         pdf_puts(" ");
802fd2d
     }
802fd2d
     pdf_puts("]\n");
802fd2d
@@ -394,10 +363,29 @@ static void copyProcSet(Object * obj)
802fd2d
 
802fd2d
 #define REPLACE_TYPE1C true
802fd2d
 
802fd2d
+static bool embeddableFont(Object * fontdesc)
802fd2d
+{
802fd2d
+    Object fontfile, ffsubtype;
802fd2d
+
802fd2d
+    if (!fontdesc->isDict())
802fd2d
+        return false;
802fd2d
+    fontfile = fontdesc->dictLookup("FontFile");
802fd2d
+    if (fontfile.isStream())
802fd2d
+        return true;
802fd2d
+    if (REPLACE_TYPE1C) {
802fd2d
+        fontfile = fontdesc->dictLookup("FontFile3");
802fd2d
+        if (!fontfile.isStream())
802fd2d
+            return false;
802fd2d
+        ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
802fd2d
+        return ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C");
802fd2d
+    }
802fd2d
+    return false;
802fd2d
+}
802fd2d
+
802fd2d
 static void copyFont(char *tag, Object * fontRef)
802fd2d
 {
802fd2d
-    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
802fd2d
-        fontfile, ffsubtype, stemV;
802fd2d
+    Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
802fd2d
+        stemV;
802fd2d
     GfxFont *gfont;
802fd2d
     fd_entry *fd;
802fd2d
     fm_entry *fontmap;
802fd2d
@@ -413,33 +401,39 @@ static void copyFont(char *tag, Object *
802fd2d
     }
802fd2d
     // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
802fd2d
     // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
802fd2d
-    if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
802fd2d
-        && fontdict->dictLookup("Subtype", &subtype)->isName()
802fd2d
-        && !strcmp(subtype->getName(), "Type1")
802fd2d
-        && fontdict->dictLookup("BaseFont", &basefont)->isName()
802fd2d
-        && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
802fd2d
-        && fontdescRef->fetch(xref, &fontdesc)->isDict()
802fd2d
-        && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
802fd2d
-            || (REPLACE_TYPE1C
802fd2d
-                && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
802fd2d
-                && fontfile->streamGetDict()->lookup("Subtype",
802fd2d
-                                                     &ffsubtype)->isName()
802fd2d
-                && !strcmp(ffsubtype->getName(), "Type1C")))
802fd2d
-        && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
802fd2d
+    fontdict = fontRef->fetch(xref);
802fd2d
+    fontdesc = Object(objNull);
802fd2d
+    if (fontdict.isDict()) {
802fd2d
+        subtype = fontdict.dictLookup("Subtype");
802fd2d
+        basefont = fontdict.dictLookup("BaseFont");
802fd2d
+        fontdescRef = fontdict.dictLookupNF("FontDescriptor");
802fd2d
+        if (fontdescRef.isRef()) {
802fd2d
+            fontdesc = fontdescRef.fetch(xref);
802fd2d
+        }
802fd2d
+    }
802fd2d
+    if (!fixedinclusioncopyfont && fontdict.isDict()
802fd2d
+        && subtype.isName()
802fd2d
+        && !strcmp(subtype.getName(), "Type1")
802fd2d
+        && basefont.isName()
802fd2d
+        && fontdescRef.isRef()
802fd2d
+        && fontdesc.isDict()
802fd2d
+        && embeddableFont(&fontdesc)
802fd2d
+        && (fontmap = lookup_fontmap(basefont.getName())) != NULL) {
802fd2d
         // round /StemV value, since the PDF input is a float
802fd2d
         // (see Font Descriptors in PDF reference), but we only store an
802fd2d
         // integer, since we don't want to change the struct.
802fd2d
-        fontdesc->dictLookup("StemV", &stemV);
802fd2d
-        fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
802fd2d
-        if (fontdesc->dictLookup("CharSet", &charset) &&
802fd2d
-            charset->isString() && is_subsetable(fontmap))
802fd2d
-            epdf_mark_glyphs(fd, charset->getString()->getCString());
802fd2d
+        stemV = fontdesc.dictLookup("StemV");
802fd2d
+        fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
802fd2d
+        charset = fontdesc.dictLookup("CharSet");
802fd2d
+        if (!charset.isNull() &&
802fd2d
+            charset.isString() && is_subsetable(fontmap))
802fd2d
+            epdf_mark_glyphs(fd, charset.getString()->getCString());
802fd2d
         else
802fd2d
             embed_whole_font(fd);
802fd2d
-        addFontDesc(fontdescRef->getRef(), fd);
802fd2d
+        addFontDesc(fontdescRef.getRef(), fd);
802fd2d
         copyName(tag);
802fd2d
         gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
802fd2d
-                                  fontdict->getDict());
802fd2d
+                                  fontdict.getDict());
802fd2d
         pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
802fd2d
                                        addEncoding(gfont)));
802fd2d
     } else {
802fd2d
@@ -451,24 +445,24 @@ static void copyFont(char *tag, Object *
802fd2d
 
802fd2d
 static void copyFontResources(Object * obj)
802fd2d
 {
802fd2d
-    PdfObject fontRef;
802fd2d
+    Object fontRef;
802fd2d
     int i, l;
802fd2d
     if (!obj->isDict())
802fd2d
         pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
802fd2d
                     obj->getTypeName());
802fd2d
     pdf_puts("/Font << ");
802fd2d
     for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
802fd2d
-        obj->dictGetValNF(i, &fontRef);
802fd2d
-        if (fontRef->isRef())
802fd2d
+        fontRef = obj->dictGetValNF(i);
802fd2d
+        if (fontRef.isRef())
802fd2d
             copyFont(obj->dictGetKey(i), &fontRef);
802fd2d
-        else if (fontRef->isDict()) {   // some programs generate pdf with embedded font object
802fd2d
+        else if (fontRef.isDict()) {   // some programs generate pdf with embedded font object
802fd2d
             copyName(obj->dictGetKey(i));
802fd2d
             pdf_puts(" ");
802fd2d
             copyObject(&fontRef);
802fd2d
         }
802fd2d
         else
802fd2d
             pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
802fd2d
-                        fontRef->getTypeName());
802fd2d
+                        fontRef.getTypeName());
802fd2d
     }
802fd2d
     pdf_puts(">>\n");
802fd2d
 }
802fd2d
@@ -557,7 +551,7 @@ static char *convertNumToPDF(double n)
802fd2d
 
802fd2d
 static void copyObject(Object * obj)
802fd2d
 {
802fd2d
-    PdfObject obj1;
802fd2d
+    Object obj1;
802fd2d
     int i, l, c;
802fd2d
     Ref ref;
802fd2d
     char *p;
802fd2d
@@ -601,8 +595,8 @@ static void copyObject(Object * obj)
802fd2d
     } else if (obj->isArray()) {
802fd2d
         pdf_puts("[");
802fd2d
         for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
802fd2d
-            obj->arrayGetNF(i, &obj1);
802fd2d
-            if (!obj1->isName())
802fd2d
+            obj1 = obj->arrayGetNF(i);
802fd2d
+            if (!obj1.isName())
802fd2d
                 pdf_puts(" ");
802fd2d
             copyObject(&obj1);
802fd2d
         }
802fd2d
@@ -612,9 +606,8 @@ static void copyObject(Object * obj)
802fd2d
         copyDict(obj);
802fd2d
         pdf_puts(">>");
802fd2d
     } else if (obj->isStream()) {
802fd2d
-        initDictFromDict(obj1, obj->streamGetDict());
802fd2d
         pdf_puts("<<\n");
802fd2d
-        copyDict(&obj1);
802fd2d
+        copyDict(obj->getStream()->getDictObject());
802fd2d
         pdf_puts(">>\n");
802fd2d
         pdf_puts("stream\n");
802fd2d
         copyStream(obj->getStream()->getUndecodedStream());
802fd2d
@@ -638,9 +631,8 @@ static void writeRefs()
802fd2d
     InObj *r;
802fd2d
     for (r = inObjList; r != 0; r = r->next) {
802fd2d
         if (!r->written) {
802fd2d
-            Object obj1;
802fd2d
             r->written = 1;
802fd2d
-            xref->fetch(r->ref.num, r->ref.gen, &obj1);
802fd2d
+            Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
802fd2d
             if (r->type == objFont) {
802fd2d
                 assert(!obj1.isStream());
802fd2d
                 pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
802fd2d
@@ -656,7 +648,6 @@ static void writeRefs()
802fd2d
                 pdf_puts("\n");
802fd2d
                 pdfendobj();
802fd2d
             }
802fd2d
-            obj1.free();
802fd2d
         }
802fd2d
     }
802fd2d
 }
802fd2d
@@ -685,7 +676,7 @@ static void writeEncodings()
802fd2d
 #ifdef POPPLER_VERSION
802fd2d
         r->font->decRefCnt();
802fd2d
 #else
802fd2d
-        delete r->font;
802fd2d
+#error POPPLER_VERSION should be defined.
802fd2d
 #endif
802fd2d
         delete r;
802fd2d
     }
802fd2d
@@ -728,7 +719,7 @@ read_pdf_info(char *image_name, char *pa
802fd2d
 #ifdef POPPLER_VERSION
802fd2d
     int pdf_major_version_found, pdf_minor_version_found;
802fd2d
 #else
802fd2d
-    float pdf_version_found, pdf_version_wanted;
802fd2d
+#error POPPLER_VERSION should be defined.
802fd2d
 #endif
802fd2d
     // initialize
802fd2d
     if (!isInit) {
802fd2d
@@ -760,19 +751,7 @@ read_pdf_info(char *image_name, char *pa
802fd2d
         }
802fd2d
     }
802fd2d
 #else
802fd2d
-    pdf_version_found = pdf_doc->doc->getPDFVersion();
802fd2d
-    pdf_version_wanted = 1 + (minor_pdf_version_wanted * 0.1);
802fd2d
-    if (pdf_version_found > pdf_version_wanted + 0.01) {
802fd2d
-        char msg[] =
802fd2d
-            "PDF inclusion: found PDF version <%.1f>, but at most version <%.1f> allowed";
802fd2d
-        if (pdf_inclusion_errorlevel > 0) {
802fd2d
-            pdftex_fail(msg, pdf_version_found, pdf_version_wanted);
802fd2d
-        } else if (pdf_inclusion_errorlevel < 0) {
802fd2d
-            ; /* do nothing */
802fd2d
-        } else { /* = 0, give warning */
802fd2d
-            pdftex_warn(msg, pdf_version_found, pdf_version_wanted);
802fd2d
-        }
802fd2d
-    }
802fd2d
+#error POPPLER_VERSION should be defined.
802fd2d
 #endif
802fd2d
     epdf_num_pages = pdf_doc->doc->getCatalog()->getNumPages();
802fd2d
     if (page_name) {
802fd2d
@@ -839,8 +818,8 @@ void write_epdf(void)
802fd2d
     Page *page;
802fd2d
     Ref *pageRef;
802fd2d
     Dict *pageDict;
802fd2d
-    PdfObject contents, obj1, obj2, pageObj, dictObj;
802fd2d
-    PdfObject groupDict;
802fd2d
+    Object contents, obj1, obj2, pageObj, dictObj;
802fd2d
+    Object groupDict;
802fd2d
     bool writeSepGroup = false;
802fd2d
     Object info;
802fd2d
     char *key;
802fd2d
@@ -867,8 +846,8 @@ void write_epdf(void)
802fd2d
     encodingList = 0;
802fd2d
     page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
802fd2d
     pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
802fd2d
-    xref->fetch(pageRef->num, pageRef->gen, &pageObj);
802fd2d
-    pageDict = pageObj->getDict();
802fd2d
+    pageObj = xref->fetch(pageRef->num, pageRef->gen);
802fd2d
+    pageDict = pageObj.getDict();
802fd2d
     rotate = page->getRotate();
802fd2d
     PDFRectangle *pagebox;
802fd2d
     // write the Page header
802fd2d
@@ -886,7 +865,7 @@ void write_epdf(void)
802fd2d
         pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
802fd2d
     }
802fd2d
     if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
802fd2d
-        pdf_doc->doc->getDocInfoNF(&info;;
802fd2d
+        info = pdf_doc->doc->getDocInfoNF();
802fd2d
         if (info.isRef()) {
802fd2d
             // the info dict must be indirect (PDF Ref p. 61)
802fd2d
             pdf_printf("/%s.InfoDict ", pdfkeyprefix);
802fd2d
@@ -942,14 +921,14 @@ void write_epdf(void)
802fd2d
     pdf_puts(stripzeros(s));
802fd2d
 
802fd2d
     // Metadata validity check (as a stream it must be indirect)
802fd2d
-    pageDict->lookupNF("Metadata", &dictObj);
802fd2d
-    if (!dictObj->isNull() && !dictObj->isRef())
802fd2d
+    dictObj = pageDict->lookupNF("Metadata");
802fd2d
+    if (!dictObj.isNull() && !dictObj.isRef())
802fd2d
         pdftex_warn("PDF inclusion: /Metadata must be indirect object");
802fd2d
 
802fd2d
     // copy selected items in Page dictionary except Resources & Group
802fd2d
     for (i = 0; pageDictKeys[i] != NULL; i++) {
802fd2d
-        pageDict->lookupNF(pageDictKeys[i], &dictObj);
802fd2d
-        if (!dictObj->isNull()) {
802fd2d
+        dictObj = pageDict->lookupNF(pageDictKeys[i]);
802fd2d
+        if (!dictObj.isNull()) {
802fd2d
             pdf_newline();
802fd2d
             pdf_printf("/%s ", pageDictKeys[i]);
802fd2d
             copyObject(&dictObj); // preserves indirection
802fd2d
@@ -957,8 +936,8 @@ void write_epdf(void)
802fd2d
     } 
802fd2d
 
802fd2d
     // handle page group
802fd2d
-    pageDict->lookupNF("Group", &dictObj);
802fd2d
-    if (!dictObj->isNull()) {
802fd2d
+    dictObj = pageDict->lookupNF("Group");
802fd2d
+    if (!dictObj.isNull()) {
802fd2d
         if (pdfpagegroupval == 0) { 
802fd2d
             // another pdf with page group was included earlier on the
802fd2d
             // same page; copy the Group entry as is.  See manual for
802fd2d
@@ -972,11 +951,36 @@ void write_epdf(void)
802fd2d
             copyObject(&dictObj);
802fd2d
         } else {
802fd2d
             // write Group dict as a separate object, since the Page dict also refers to it
802fd2d
-            pageDict->lookup("Group", &dictObj);
802fd2d
-            if (!dictObj->isDict())
802fd2d
+            dictObj = pageDict->lookup("Group");
802fd2d
+            if (!dictObj.isDict())
802fd2d
                 pdftex_fail("PDF inclusion: /Group dict missing");
802fd2d
             writeSepGroup = true;
802fd2d
-            initDictFromDict(groupDict, page->getGroup());
802fd2d
+/*
802fd2d
+This part is only a single line
802fd2d
+            groupDict = Object(page->getGroup());
802fd2d
+in the original patch. In this case, however, pdftex crashes at
802fd2d
+"delete pdf_doc->doc" in "delete_document()" for inclusion of some
802fd2d
+kind of pdf images, for example, figure_missing.pdf in gnuplot.
802fd2d
+A change
802fd2d
+            groupDict = Object(page->getGroup()).copy();
802fd2d
+does not improve the situation.
802fd2d
+The changes below seem to work fine. 
802fd2d
+*/
802fd2d
+// begin modification
802fd2d
+            groupDict = pageDict->lookup("Group");
802fd2d
+            const Dict& dic1 = page->getGroup();
802fd2d
+            const Dict& dic2 = groupDict.getDict();
802fd2d
+            // replace dic2 in groupDict with dic1
802fd2d
+            l = dic2.getLength();
802fd2d
+            for (i = 0; i < l; i++) {
802fd2d
+                groupDict.dictRemove(dic2.getKey(i));
802fd2d
+            }
802fd2d
+            l = dic1.getLength();
802fd2d
+            for (i = 0; i < l; i++) {
802fd2d
+                groupDict.dictAdd(copyString(dic1.getKey(i)),
802fd2d
+                                  dic1.getValNF(i));
802fd2d
+            }
802fd2d
+// end modification
802fd2d
             pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
802fd2d
         }
802fd2d
     }
802fd2d
@@ -989,14 +993,14 @@ void write_epdf(void)
802fd2d
         pdftex_warn
802fd2d
             ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
802fd2d
     } else {
802fd2d
-        initDictFromDict(obj1, page->getResourceDict());
802fd2d
+        Object *obj1 = page->getResourceDictObject();
802fd2d
         if (!obj1->isDict())
802fd2d
             pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
802fd2d
                         obj1->getTypeName());
802fd2d
         pdf_newline();
802fd2d
         pdf_puts("/Resources <<\n");
802fd2d
         for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
802fd2d
-            obj1->dictGetVal(i, &obj2);
802fd2d
+            obj2 = obj1->dictGetVal(i);
802fd2d
             key = obj1->dictGetKey(i);
802fd2d
             if (strcmp("Font", key) == 0)
802fd2d
                 copyFontResources(&obj2);
802fd2d
@@ -1009,8 +1013,8 @@ void write_epdf(void)
802fd2d
     }
802fd2d
 
802fd2d
     // write the page contents
802fd2d
-    page->getContents(&contents);
802fd2d
-    if (contents->isStream()) {
802fd2d
+    contents = page->getContents();
802fd2d
+    if (contents.isStream()) {
802fd2d
 
802fd2d
         // Variant A: get stream and recompress under control
802fd2d
         // of \pdfcompresslevel
802fd2d
@@ -1021,36 +1025,35 @@ void write_epdf(void)
802fd2d
 
802fd2d
         // Variant B: copy stream without recompressing
802fd2d
         //
802fd2d
-        contents->streamGetDict()->lookup("F", &obj1);
802fd2d
-        if (!obj1->isNull()) {
802fd2d
+        obj1 = contents.streamGetDict()->lookup("F");
802fd2d
+        if (!obj1.isNull()) {
802fd2d
             pdftex_fail("PDF inclusion: Unsupported external stream");
802fd2d
         }
802fd2d
-        contents->streamGetDict()->lookup("Length", &obj1);
802fd2d
-        assert(!obj1->isNull());
802fd2d
+        obj1 = contents.streamGetDict()->lookup("Length");
802fd2d
+        assert(!obj1.isNull());
802fd2d
         pdf_puts("/Length ");
802fd2d
         copyObject(&obj1);
802fd2d
         pdf_puts("\n");
802fd2d
-        contents->streamGetDict()->lookup("Filter", &obj1);
802fd2d
-        if (!obj1->isNull()) {
802fd2d
+        obj1 = contents.streamGetDict()->lookup("Filter");
802fd2d
+        if (!obj1.isNull()) {
802fd2d
             pdf_puts("/Filter ");
802fd2d
             copyObject(&obj1);
802fd2d
             pdf_puts("\n");
802fd2d
-            contents->streamGetDict()->lookup("DecodeParms", &obj1);
802fd2d
-            if (!obj1->isNull()) {
802fd2d
+            obj1 = contents.streamGetDict()->lookup("DecodeParms");
802fd2d
+            if (!obj1.isNull()) {
802fd2d
                 pdf_puts("/DecodeParms ");
802fd2d
                 copyObject(&obj1);
802fd2d
                 pdf_puts("\n");
802fd2d
             }
802fd2d
         }
802fd2d
         pdf_puts(">>\nstream\n");
802fd2d
-        copyStream(contents->getStream()->getUndecodedStream());
802fd2d
+        copyStream(contents.getStream()->getUndecodedStream());
802fd2d
         pdfendstream();
802fd2d
-    } else if (contents->isArray()) {
802fd2d
+    } else if (contents.isArray()) {
802fd2d
         pdfbeginstream();
802fd2d
-        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
802fd2d
-            Object contentsobj;
802fd2d
-            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
802fd2d
-            contentsobj.free();
802fd2d
+        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
802fd2d
+            Object contentsobj = contents.arrayGet(i);
802fd2d
+            copyStream(contentsobj.getStream());
802fd2d
             if (i < l - 1)
802fd2d
                 pdf_newline();  // add a newline after each stream except the last
802fd2d
         }
802fd2d
diff -up texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc
802fd2d
--- texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler	2018-04-30 13:32:27.005472583 -0400
802fd2d
+++ texlive-base-20180414/source/texk/web2c/pdftexdir/pdftosrc.cc	2018-04-30 13:38:12.805326988 -0400
802fd2d
@@ -16,6 +16,14 @@ GNU General Public License for more deta
802fd2d
 You should have received a copy of the GNU General Public License along
802fd2d
 with this program.  If not, see <http://www.gnu.org/licenses/>.
802fd2d
 */
802fd2d
+
802fd2d
+/*
802fd2d
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
802fd2d
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
802fd2d
+by Arch Linux. The poppler should be 0.59.0 or newer versions.
802fd2d
+POPPLER_VERSION should be defined.
802fd2d
+*/
802fd2d
+
802fd2d
 #include <w2c/config.h>
802fd2d
 
802fd2d
 #include <stdlib.h>
802fd2d
@@ -32,10 +40,7 @@ with this program.  If not, see 
802fd2d
 #include <goo/gmem.h>
802fd2d
 #include <goo/gfile.h>
802fd2d
 #else
802fd2d
-#include <aconf.h>
802fd2d
-#include <GString.h>
802fd2d
-#include <gmem.h>
802fd2d
-#include <gfile.h>
802fd2d
+#error POPPLER_VERSION should be defined.
802fd2d
 #endif
802fd2d
 #include <assert.h>
802fd2d
 
802fd2d
@@ -86,22 +91,20 @@ int main(int argc, char *argv[])
802fd2d
             objgen = atoi(argv[3]);
802fd2d
     }
802fd2d
     xref = doc->getXRef();
802fd2d
-    catalogDict.initNull();
802fd2d
-    xref->getCatalog(&catalogDict);
802fd2d
+    catalogDict = xref->getCatalog();
802fd2d
     if (!catalogDict.isDict("Catalog")) {
802fd2d
         fprintf(stderr, "No Catalog found\n");
802fd2d
         exit(1);
802fd2d
     }
802fd2d
-    srcStream.initNull();
802fd2d
+    srcStream = Object(objNull);
802fd2d
     if (objnum == 0) {
802fd2d
-        catalogDict.dictLookup("SourceObject", &srcStream);
802fd2d
+        srcStream = catalogDict.dictLookup("SourceObject");
802fd2d
         static char const_SourceFile[] = "SourceFile";
802fd2d
         if (!srcStream.isStream(const_SourceFile)) {
802fd2d
             fprintf(stderr, "No SourceObject found\n");
802fd2d
             exit(1);
802fd2d
         }
802fd2d
-        srcName.initNull();
802fd2d
-        srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
802fd2d
+        srcName = srcStream.getStream()->getDict()->lookup("SourceName");
802fd2d
         if (!srcName.isString()) {
802fd2d
             fprintf(stderr, "No SourceName found\n");
802fd2d
             exit(1);
802fd2d
@@ -110,7 +113,7 @@ int main(int argc, char *argv[])
802fd2d
         // We cannot free srcName, as objname shares its string.
802fd2d
         // srcName.free();
802fd2d
     } else if (objnum > 0) {
802fd2d
-        xref->fetch(objnum, objgen, &srcStream);
802fd2d
+        srcStream = xref->fetch(objnum, objgen);
802fd2d
         if (!srcStream.isStream()) {
802fd2d
             fprintf(stderr, "Not a Stream object\n");
802fd2d
             exit(1);
802fd2d
@@ -160,26 +163,24 @@ int main(int argc, char *argv[])
802fd2d
                 int localOffset = 0;
802fd2d
                 Guint firstOffset;
802fd2d
 
802fd2d
-                assert(xref->fetch(e->offset, 0, &objStr)->isStream());
802fd2d
-                nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
802fd2d
-                obj1.free();
802fd2d
-                first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
802fd2d
-                obj1.free();
802fd2d
+                objStr = xref->fetch(e->offset, 0);
802fd2d
+                assert(objStr.isStream());
802fd2d
+                obj1 = objStr.streamGetDict()->lookup("N");
802fd2d
+                nObjects = obj1.getInt();
802fd2d
+                obj1 = objStr.streamGetDict()->lookup("First");
802fd2d
+                first = obj1.getInt();
802fd2d
                 firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
802fd2d
 
802fd2d
                 // parse the header: object numbers and offsets
802fd2d
                 objStr.streamReset();
802fd2d
-                obj1.initNull();
802fd2d
-                str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
802fd2d
+                str = new EmbedStream(objStr.getStream(), Object(objNull), gTrue, first);
802fd2d
                 lexer = new Lexer(xref, str);
802fd2d
                 parser = new Parser(xref, lexer, gFalse);
802fd2d
                 for (n = 0; n < nObjects; ++n) {
802fd2d
-                    parser->getObj(&obj1);
802fd2d
-                    parser->getObj(&obj2);
802fd2d
+                    obj1 = parser->getObj();
802fd2d
+                    obj2 = parser->getObj();
802fd2d
                     if (n == e->gen)
802fd2d
                         localOffset = obj2.getInt();
802fd2d
-                    obj1.free();
802fd2d
-                    obj2.free();
802fd2d
                 }
802fd2d
 #if defined(POPPLER_VERSION) || defined(XPDF304)
802fd2d
                 while (str->getChar() != EOF) ;
802fd2d
@@ -187,7 +188,6 @@ int main(int argc, char *argv[])
802fd2d
                 lexer->skipToEOF();
802fd2d
 #endif
802fd2d
                 delete parser;
802fd2d
-                objStr.free();
802fd2d
 
802fd2d
                 fprintf(outfile, "%.10lu 00000 n\n",
802fd2d
                         (long unsigned)(firstOffset + localOffset));
802fd2d
@@ -198,7 +198,6 @@ int main(int argc, char *argv[])
802fd2d
         s->reset();
802fd2d
         while ((c = s->getChar()) != EOF)
802fd2d
             fputc(c, outfile);
802fd2d
-        srcStream.free();
802fd2d
     }
802fd2d
     if (objnum == 0)
802fd2d
         fprintf(stderr, "Source file extracted to %s\n", outname);
802fd2d
@@ -207,7 +206,6 @@ int main(int argc, char *argv[])
802fd2d
     else
802fd2d
         fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
802fd2d
     fclose(outfile);
802fd2d
-    catalogDict.free();
802fd2d
     delete doc;
802fd2d
     delete globalParams;
802fd2d
 }