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

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