Blame SOURCES/texlive-20180414-new-poppler.patch

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