Blame texlive-20210325-new-poppler.patch

1007fe9
diff -up texlive-base-20210325/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler texlive-base-20210325/source/texk/web2c/pdftexdir/pdftoepdf.cc
1007fe9
--- texlive-base-20210325/source/texk/web2c/pdftexdir/pdftoepdf.cc.newpoppler	2020-05-14 17:45:48.000000000 -0400
1007fe9
+++ texlive-base-20210325/source/texk/web2c/pdftexdir/pdftoepdf.cc	2021-05-06 17:39:49.308416042 -0400
1007fe9
@@ -1,5 +1,5 @@
1007fe9
 /*
1007fe9
-Copyright 1996-2016 Han The Thanh, <thanh@pdftex.org>
1007fe9
+Copyright 1996-2017 Han The Thanh, <thanh@pdftex.org>
1007fe9
 
1007fe9
 This file is part of pdfTeX.
1007fe9
 
1007fe9
@@ -17,6 +17,15 @@ You should have received a copy of the G
1007fe9
 with this program.  If not, see <http://www.gnu.org/licenses/>.
1007fe9
 */
1007fe9
 
1007fe9
+/*
1007fe9
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
1007fe9
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
1007fe9
+by Arch Linux. A little modifications are made to avoid a crash for
1007fe9
+some kind of pdf images, such as figure_missing.pdf in gnuplot.
1007fe9
+The poppler should be 0.59.0 or newer versions.
1007fe9
+POPPLER_VERSION should be defined.
1007fe9
+*/
1007fe9
+
1007fe9
 /* Do this early in order to avoid a conflict between
1007fe9
    MINGW32 <rpcndr.h> defining 'boolean' as 'unsigned char' and
1007fe9
    <kpathsea/types.h> defining Pascal's boolean as 'int'.
1007fe9
@@ -75,31 +84,6 @@ extern integer zround(double);
1007fe9
 #define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
1007fe9
 #define MASK_SUPPRESS_PTEX_INFODICT   0x08
1007fe9
 
1007fe9
-// PdfObject encapsulates the xpdf Object type,
1007fe9
-// and properly frees its resources on destruction.
1007fe9
-// Use obj-> to access members of the Object,
1007fe9
-// and &obj to get a pointer to the object.
1007fe9
-// It is no longer necessary to call Object::free explicitely.
1007fe9
-
1007fe9
-class PdfObject {
1007fe9
-  public:
1007fe9
-    PdfObject() {               // nothing
1007fe9
-    } ~PdfObject() {
1007fe9
-        iObject.free();
1007fe9
-    }
1007fe9
-    Object *operator->() {
1007fe9
-        return &iObject;
1007fe9
-    }
1007fe9
-    Object *operator&() {
1007fe9
-        return &iObject;
1007fe9
-    }
1007fe9
-  private:                     // no copying or assigning
1007fe9
-    PdfObject(const PdfObject &);
1007fe9
-    void operator=(const PdfObject &);
1007fe9
-  public:
1007fe9
-    Object iObject;
1007fe9
-};
1007fe9
-
1007fe9
 // When copying the Resources of the selected page, all objects are copied
1007fe9
 // recusively top-down. Indirect objects however are not fetched during
1007fe9
 // copying, but get a new object number from pdfTeX and then will be
1007fe9
@@ -203,18 +187,6 @@ static void delete_document(PdfDocument
1007fe9
     delete pdf_doc;
1007fe9
 }
1007fe9
 
1007fe9
-// Replacement for
1007fe9
-//      Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
1007fe9
-
1007fe9
-static void initDictFromDict(PdfObject & obj, Dict * dict)
1007fe9
-{
1007fe9
-    obj->initDict(xref);
1007fe9
-    for (int i = 0, l = dict->getLength(); i < l; i++) {
1007fe9
-        Object obj1;
1007fe9
-        obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
1007fe9
-    }
1007fe9
-}
1007fe9
-
1007fe9
 // --------------------------------------------------------------------
1007fe9
 
1007fe9
 static int addEncoding(GfxFont * gfont)
1007fe9
@@ -311,10 +283,10 @@ static void copyName(char *s)
1007fe9
 
1007fe9
 static void copyDictEntry(Object * obj, int i)
1007fe9
 {
1007fe9
-    PdfObject obj1;
1007fe9
+    Object obj1;
1007fe9
     copyName(obj->dictGetKey(i));
1007fe9
     pdf_puts(" ");
1007fe9
-    obj->dictGetValNF(i, &obj1);
1007fe9
+    obj1 = obj->dictGetValNF(i);
1007fe9
     copyObject(&obj1);
1007fe9
     pdf_puts("\n");
1007fe9
 }
1007fe9
@@ -367,17 +339,17 @@ static void copyStream(Stream * str)
1007fe9
 static void copyProcSet(Object * obj)
1007fe9
 {
1007fe9
     int i, l;
1007fe9
-    PdfObject procset;
1007fe9
+    Object procset;
1007fe9
     if (!obj->isArray())
1007fe9
         pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
1007fe9
                     obj->getTypeName());
1007fe9
     pdf_puts("/ProcSet [ ");
1007fe9
     for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
1007fe9
-        obj->arrayGetNF(i, &procset);
1007fe9
-        if (!procset->isName())
1007fe9
+        procset = obj->arrayGetNF(i);
1007fe9
+        if (!procset.isName())
1007fe9
             pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
1007fe9
-                        procset->getTypeName());
1007fe9
-        copyName(procset->getName());
1007fe9
+                        procset.getTypeName());
1007fe9
+        copyName(procset.getName());
1007fe9
         pdf_puts(" ");
1007fe9
     }
1007fe9
     pdf_puts("]\n");
1007fe9
@@ -385,10 +357,29 @@ static void copyProcSet(Object * obj)
1007fe9
 
1007fe9
 #define REPLACE_TYPE1C true
1007fe9
 
1007fe9
+static bool embeddableFont(Object * fontdesc)
1007fe9
+{
1007fe9
+    Object fontfile, ffsubtype;
1007fe9
+
1007fe9
+    if (!fontdesc->isDict())
1007fe9
+        return false;
1007fe9
+    fontfile = fontdesc->dictLookup("FontFile");
1007fe9
+    if (fontfile.isStream())
1007fe9
+        return true;
1007fe9
+    if (REPLACE_TYPE1C) {
1007fe9
+        fontfile = fontdesc->dictLookup("FontFile3");
1007fe9
+        if (!fontfile.isStream())
1007fe9
+            return false;
1007fe9
+        ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
1007fe9
+        return ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C");
1007fe9
+    }
1007fe9
+    return false;
1007fe9
+}
1007fe9
+
1007fe9
 static void copyFont(char *tag, Object * fontRef)
1007fe9
 {
1007fe9
-    PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
1007fe9
-        fontfile, ffsubtype, stemV;
1007fe9
+    Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
1007fe9
+        stemV;
1007fe9
     GfxFont *gfont;
1007fe9
     fd_entry *fd;
1007fe9
     fm_entry *fontmap;
1007fe9
@@ -404,33 +395,39 @@ static void copyFont(char *tag, Object *
1007fe9
     }
1007fe9
     // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
1007fe9
     // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
1007fe9
-    if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
1007fe9
-        && fontdict->dictLookup("Subtype", &subtype)->isName()
1007fe9
-        && !strcmp(subtype->getName(), "Type1")
1007fe9
-        && fontdict->dictLookup("BaseFont", &basefont)->isName()
1007fe9
-        && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
1007fe9
-        && fontdescRef->fetch(xref, &fontdesc)->isDict()
1007fe9
-        && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
1007fe9
-            || (REPLACE_TYPE1C
1007fe9
-                && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
1007fe9
-                && fontfile->streamGetDict()->lookup("Subtype",
1007fe9
-                                                     &ffsubtype)->isName()
1007fe9
-                && !strcmp(ffsubtype->getName(), "Type1C")))
1007fe9
-        && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
1007fe9
+    fontdict = fontRef->fetch(xref);
1007fe9
+    fontdesc = Object(objNull);
1007fe9
+    if (fontdict.isDict()) {
1007fe9
+        subtype = fontdict.dictLookup("Subtype");
1007fe9
+        basefont = fontdict.dictLookup("BaseFont");
1007fe9
+        fontdescRef = fontdict.dictLookupNF("FontDescriptor");
1007fe9
+        if (fontdescRef.isRef()) {
1007fe9
+            fontdesc = fontdescRef.fetch(xref);
1007fe9
+        }
1007fe9
+    }
1007fe9
+    if (!fixedinclusioncopyfont && fontdict.isDict()
1007fe9
+        && subtype.isName()
1007fe9
+        && !strcmp(subtype.getName(), "Type1")
1007fe9
+        && basefont.isName()
1007fe9
+        && fontdescRef.isRef()
1007fe9
+        && fontdesc.isDict()
1007fe9
+        && embeddableFont(&fontdesc)
1007fe9
+        && (fontmap = lookup_fontmap(basefont.getName())) != NULL) {
1007fe9
         // round /StemV value, since the PDF input is a float
1007fe9
         // (see Font Descriptors in PDF reference), but we only store an
1007fe9
         // integer, since we don't want to change the struct.
1007fe9
-        fontdesc->dictLookup("StemV", &stemV);
1007fe9
-        fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
1007fe9
-        if (fontdesc->dictLookup("CharSet", &charset) &&
1007fe9
-            charset->isString() && is_subsetable(fontmap))
1007fe9
-            epdf_mark_glyphs(fd, charset->getString()->getCString());
1007fe9
+        stemV = fontdesc.dictLookup("StemV");
1007fe9
+        fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
1007fe9
+        charset = fontdesc.dictLookup("CharSet");
1007fe9
+        if (!charset.isNull() &&
1007fe9
+            charset.isString() && is_subsetable(fontmap))
1007fe9
+            epdf_mark_glyphs(fd, charset.getString()->getCString());
1007fe9
         else
1007fe9
             embed_whole_font(fd);
1007fe9
-        addFontDesc(fontdescRef->getRef(), fd);
1007fe9
+        addFontDesc(fontdescRef.getRef(), fd);
1007fe9
         copyName(tag);
1007fe9
         gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
1007fe9
-                                  fontdict->getDict());
1007fe9
+                                  fontdict.getDict());
1007fe9
         pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
1007fe9
                                        addEncoding(gfont)));
1007fe9
     } else {
1007fe9
@@ -442,24 +439,24 @@ static void copyFont(char *tag, Object *
1007fe9
 
1007fe9
 static void copyFontResources(Object * obj)
1007fe9
 {
1007fe9
-    PdfObject fontRef;
1007fe9
+    Object fontRef;
1007fe9
     int i, l;
1007fe9
     if (!obj->isDict())
1007fe9
         pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
1007fe9
                     obj->getTypeName());
1007fe9
     pdf_puts("/Font << ");
1007fe9
     for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
1007fe9
-        obj->dictGetValNF(i, &fontRef);
1007fe9
-        if (fontRef->isRef())
1007fe9
+        fontRef = obj->dictGetValNF(i);
1007fe9
+        if (fontRef.isRef())
1007fe9
             copyFont(obj->dictGetKey(i), &fontRef);
1007fe9
-        else if (fontRef->isDict()) {   // some programs generate pdf with embedded font object
1007fe9
+        else if (fontRef.isDict()) {   // some programs generate pdf with embedded font object
1007fe9
             copyName(obj->dictGetKey(i));
1007fe9
             pdf_puts(" ");
1007fe9
             copyObject(&fontRef);
1007fe9
         }
1007fe9
         else
1007fe9
             pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
1007fe9
-                        fontRef->getTypeName());
1007fe9
+                        fontRef.getTypeName());
1007fe9
     }
1007fe9
     pdf_puts(">>\n");
1007fe9
 }
1007fe9
@@ -548,7 +545,7 @@ static char *convertNumToPDF(double n)
1007fe9
 
1007fe9
 static void copyObject(Object * obj)
1007fe9
 {
1007fe9
-    PdfObject obj1;
1007fe9
+    Object obj1;
1007fe9
     int i, l, c;
1007fe9
     Ref ref;
1007fe9
     char *p;
1007fe9
@@ -592,8 +589,8 @@ static void copyObject(Object * obj)
1007fe9
     } else if (obj->isArray()) {
1007fe9
         pdf_puts("[");
1007fe9
         for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
1007fe9
-            obj->arrayGetNF(i, &obj1);
1007fe9
-            if (!obj1->isName())
1007fe9
+            obj1 = obj->arrayGetNF(i);
1007fe9
+            if (!obj1.isName())
1007fe9
                 pdf_puts(" ");
1007fe9
             copyObject(&obj1);
1007fe9
         }
1007fe9
@@ -603,9 +600,8 @@ static void copyObject(Object * obj)
1007fe9
         copyDict(obj);
1007fe9
         pdf_puts(">>");
1007fe9
     } else if (obj->isStream()) {
1007fe9
-        initDictFromDict(obj1, obj->streamGetDict());
1007fe9
         pdf_puts("<<\n");
1007fe9
-        copyDict(&obj1);
1007fe9
+        copyDict(obj->getStream()->getDictObject());
1007fe9
         pdf_puts(">>\n");
1007fe9
         pdf_puts("stream\n");
1007fe9
         copyStream(obj->getStream()->getUndecodedStream());
1007fe9
@@ -629,9 +625,8 @@ static void writeRefs()
1007fe9
     InObj *r;
1007fe9
     for (r = inObjList; r != 0; r = r->next) {
1007fe9
         if (!r->written) {
1007fe9
-            Object obj1;
1007fe9
             r->written = 1;
1007fe9
-            xref->fetch(r->ref.num, r->ref.gen, &obj1);
1007fe9
+            Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
1007fe9
             if (r->type == objFont) {
1007fe9
                 assert(!obj1.isStream());
1007fe9
                 pdfbeginobj(r->num, 2);         // \pdfobjcompresslevel = 2 is for this
1007fe9
@@ -647,7 +642,6 @@ static void writeRefs()
1007fe9
                 pdf_puts("\n");
1007fe9
                 pdfendobj();
1007fe9
             }
1007fe9
-            obj1.free();
1007fe9
         }
1007fe9
     }
1007fe9
 }
1007fe9
@@ -805,8 +799,8 @@ void write_epdf(void)
1007fe9
     Page *page;
1007fe9
     Ref *pageRef;
1007fe9
     Dict *pageDict;
1007fe9
-    PdfObject contents, obj1, obj2, pageObj, dictObj;
1007fe9
-    PdfObject groupDict;
1007fe9
+    Object contents, obj1, obj2, pageObj, dictObj;
1007fe9
+    Object groupDict;
1007fe9
     bool writeSepGroup = false;
1007fe9
     Object info;
1007fe9
     char *key;
1007fe9
@@ -833,8 +827,8 @@ void write_epdf(void)
1007fe9
     encodingList = 0;
1007fe9
     page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
1007fe9
     pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
1007fe9
-    xref->fetch(pageRef->num, pageRef->gen, &pageObj);
1007fe9
-    pageDict = pageObj->getDict();
1007fe9
+    pageObj = xref->fetch(pageRef->num, pageRef->gen);
1007fe9
+    pageDict = pageObj.getDict();
1007fe9
     rotate = page->getRotate();
1007fe9
     PDFRectangle *pagebox;
1007fe9
     // write the Page header
1007fe9
@@ -852,7 +846,7 @@ void write_epdf(void)
1007fe9
         pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
1007fe9
     }
1007fe9
     if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
1007fe9
-        pdf_doc->doc->getDocInfoNF(&info;;
1007fe9
+        info = pdf_doc->doc->getDocInfoNF();
1007fe9
         if (info.isRef()) {
1007fe9
             // the info dict must be indirect (PDF Ref p. 61)
1007fe9
             pdf_printf("/%s.InfoDict ", pdfkeyprefix);
1007fe9
@@ -908,14 +902,14 @@ void write_epdf(void)
1007fe9
     pdf_puts(stripzeros(s));
1007fe9
 
1007fe9
     // Metadata validity check (as a stream it must be indirect)
1007fe9
-    pageDict->lookupNF("Metadata", &dictObj);
1007fe9
-    if (!dictObj->isNull() && !dictObj->isRef())
1007fe9
+    dictObj = pageDict->lookupNF("Metadata");
1007fe9
+    if (!dictObj.isNull() && !dictObj.isRef())
1007fe9
         pdftex_warn("PDF inclusion: /Metadata must be indirect object");
1007fe9
 
1007fe9
     // copy selected items in Page dictionary except Resources & Group
1007fe9
     for (i = 0; pageDictKeys[i] != NULL; i++) {
1007fe9
-        pageDict->lookupNF(pageDictKeys[i], &dictObj);
1007fe9
-        if (!dictObj->isNull()) {
1007fe9
+        dictObj = pageDict->lookupNF(pageDictKeys[i]);
1007fe9
+        if (!dictObj.isNull()) {
1007fe9
             pdf_newline();
1007fe9
             pdf_printf("/%s ", pageDictKeys[i]);
1007fe9
             copyObject(&dictObj); // preserves indirection
1007fe9
@@ -923,8 +917,8 @@ void write_epdf(void)
1007fe9
     } 
1007fe9
 
1007fe9
     // handle page group
1007fe9
-    pageDict->lookupNF("Group", &dictObj);
1007fe9
-    if (!dictObj->isNull()) {
1007fe9
+    dictObj = pageDict->lookupNF("Group");
1007fe9
+    if (!dictObj.isNull()) {
1007fe9
         if (pdfpagegroupval == 0) { 
1007fe9
             // another pdf with page group was included earlier on the
1007fe9
             // same page; copy the Group entry as is.  See manual for
1007fe9
@@ -938,11 +932,36 @@ void write_epdf(void)
1007fe9
             copyObject(&dictObj);
1007fe9
         } else {
1007fe9
             // write Group dict as a separate object, since the Page dict also refers to it
1007fe9
-            pageDict->lookup("Group", &dictObj);
1007fe9
-            if (!dictObj->isDict())
1007fe9
+            dictObj = pageDict->lookup("Group");
1007fe9
+            if (!dictObj.isDict())
1007fe9
                 pdftex_fail("PDF inclusion: /Group dict missing");
1007fe9
             writeSepGroup = true;
1007fe9
-            initDictFromDict(groupDict, page->getGroup());
1007fe9
+/*
1007fe9
+This part is only a single line
1007fe9
+            groupDict = Object(page->getGroup());
1007fe9
+in the original patch. In this case, however, pdftex crashes at
1007fe9
+"delete pdf_doc->doc" in "delete_document()" for inclusion of some
1007fe9
+kind of pdf images, for example, figure_missing.pdf in gnuplot.
1007fe9
+A change
1007fe9
+            groupDict = Object(page->getGroup()).copy();
1007fe9
+does not improve the situation.
1007fe9
+The changes below seem to work fine. 
1007fe9
+*/
1007fe9
+// begin modification
1007fe9
+            groupDict = pageDict->lookup("Group");
1007fe9
+            const Dict& dic1 = page->getGroup();
1007fe9
+            const Dict& dic2 = groupDict.getDict();
1007fe9
+            // replace dic2 in groupDict with dic1
1007fe9
+            l = dic2.getLength();
1007fe9
+            for (i = 0; i < l; i++) {
1007fe9
+                groupDict.dictRemove(dic2.getKey(i));
1007fe9
+            }
1007fe9
+            l = dic1.getLength();
1007fe9
+            for (i = 0; i < l; i++) {
1007fe9
+                groupDict.dictAdd(copyString(dic1.getKey(i)),
1007fe9
+                                  dic1.getValNF(i));
1007fe9
+            }
1007fe9
+// end modification
1007fe9
             pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
1007fe9
         }
1007fe9
     }
1007fe9
@@ -955,14 +974,14 @@ void write_epdf(void)
1007fe9
         pdftex_warn
1007fe9
             ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
1007fe9
     } else {
1007fe9
-        initDictFromDict(obj1, page->getResourceDict());
1007fe9
+        Object *obj1 = page->getResourceDictObject();
1007fe9
         if (!obj1->isDict())
1007fe9
             pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
1007fe9
                         obj1->getTypeName());
1007fe9
         pdf_newline();
1007fe9
         pdf_puts("/Resources <<\n");
1007fe9
         for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
1007fe9
-            obj1->dictGetVal(i, &obj2);
1007fe9
+            obj2 = obj1->dictGetVal(i);
1007fe9
             key = obj1->dictGetKey(i);
1007fe9
             if (strcmp("Font", key) == 0)
1007fe9
                 copyFontResources(&obj2);
1007fe9
@@ -975,8 +994,8 @@ void write_epdf(void)
1007fe9
     }
1007fe9
 
1007fe9
     // write the page contents
1007fe9
-    page->getContents(&contents);
1007fe9
-    if (contents->isStream()) {
1007fe9
+    contents = page->getContents();
1007fe9
+    if (contents.isStream()) {
1007fe9
 
1007fe9
         // Variant A: get stream and recompress under control
1007fe9
         // of \pdfcompresslevel
1007fe9
@@ -987,36 +1006,35 @@ void write_epdf(void)
1007fe9
 
1007fe9
         // Variant B: copy stream without recompressing
1007fe9
         //
1007fe9
-        contents->streamGetDict()->lookup("F", &obj1);
1007fe9
-        if (!obj1->isNull()) {
1007fe9
+        obj1 = contents.streamGetDict()->lookup("F");
1007fe9
+        if (!obj1.isNull()) {
1007fe9
             pdftex_fail("PDF inclusion: Unsupported external stream");
1007fe9
         }
1007fe9
-        contents->streamGetDict()->lookup("Length", &obj1);
1007fe9
-        assert(!obj1->isNull());
1007fe9
+        obj1 = contents.streamGetDict()->lookup("Length");
1007fe9
+        assert(!obj1.isNull());
1007fe9
         pdf_puts("/Length ");
1007fe9
         copyObject(&obj1);
1007fe9
         pdf_puts("\n");
1007fe9
-        contents->streamGetDict()->lookup("Filter", &obj1);
1007fe9
-        if (!obj1->isNull()) {
1007fe9
+        obj1 = contents.streamGetDict()->lookup("Filter");
1007fe9
+        if (!obj1.isNull()) {
1007fe9
             pdf_puts("/Filter ");
1007fe9
             copyObject(&obj1);
1007fe9
             pdf_puts("\n");
1007fe9
-            contents->streamGetDict()->lookup("DecodeParms", &obj1);
1007fe9
-            if (!obj1->isNull()) {
1007fe9
+            obj1 = contents.streamGetDict()->lookup("DecodeParms");
1007fe9
+            if (!obj1.isNull()) {
1007fe9
                 pdf_puts("/DecodeParms ");
1007fe9
                 copyObject(&obj1);
1007fe9
                 pdf_puts("\n");
1007fe9
             }
1007fe9
         }
1007fe9
         pdf_puts(">>\nstream\n");
1007fe9
-        copyStream(contents->getStream()->getUndecodedStream());
1007fe9
+        copyStream(contents.getStream()->getUndecodedStream());
1007fe9
         pdfendstream();
1007fe9
-    } else if (contents->isArray()) {
1007fe9
+    } else if (contents.isArray()) {
1007fe9
         pdfbeginstream();
1007fe9
-        for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
1007fe9
-            Object contentsobj;
1007fe9
-            copyStream((contents->arrayGet(i, &contentsobj))->getStream());
1007fe9
-            contentsobj.free();
1007fe9
+        for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
1007fe9
+            Object contentsobj = contents.arrayGet(i);
1007fe9
+            copyStream(contentsobj.getStream());
1007fe9
             if (i < l - 1)
1007fe9
                 pdf_newline();  // add a newline after each stream except the last
1007fe9
         }
1007fe9
diff -up texlive-base-20210325/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler texlive-base-20210325/source/texk/web2c/pdftexdir/pdftosrc.cc
1007fe9
--- texlive-base-20210325/source/texk/web2c/pdftexdir/pdftosrc.cc.newpoppler	2020-05-14 17:45:48.000000000 -0400
1007fe9
+++ texlive-base-20210325/source/texk/web2c/pdftexdir/pdftosrc.cc	2021-05-06 17:50:38.863177570 -0400
1007fe9
@@ -16,6 +16,14 @@ GNU General Public License for more deta
1007fe9
 You should have received a copy of the GNU General Public License along
1007fe9
 with this program.  If not, see <http://www.gnu.org/licenses/>.
1007fe9
 */
1007fe9
+
1007fe9
+/*
1007fe9
+This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
1007fe9
+https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
1007fe9
+by Arch Linux. The poppler should be 0.59.0 or newer versions.
1007fe9
+POPPLER_VERSION should be defined.
1007fe9
+*/
1007fe9
+
1007fe9
 #include <w2c/config.h>
1007fe9
 
1007fe9
 #include <stdlib.h>
1007fe9
@@ -77,22 +85,20 @@ int main(int argc, char *argv[])
1007fe9
             objgen = atoi(argv[3]);
1007fe9
     }
1007fe9
     xref = doc->getXRef();
1007fe9
-    catalogDict.initNull();
1007fe9
-    xref->getCatalog(&catalogDict);
1007fe9
+    catalogDict = xref->getCatalog();
1007fe9
     if (!catalogDict.isDict("Catalog")) {
1007fe9
         fprintf(stderr, "No Catalog found\n");
1007fe9
         exit(1);
1007fe9
     }
1007fe9
-    srcStream.initNull();
1007fe9
+    srcStream = Object(objNull);
1007fe9
     if (objnum == 0) {
1007fe9
-        catalogDict.dictLookup("SourceObject", &srcStream);
1007fe9
+        srcStream = catalogDict.dictLookup("SourceObject");
1007fe9
         static char const_SourceFile[] = "SourceFile";
1007fe9
         if (!srcStream.isStream(const_SourceFile)) {
1007fe9
             fprintf(stderr, "No SourceObject found\n");
1007fe9
             exit(1);
1007fe9
         }
1007fe9
-        srcName.initNull();
1007fe9
-        srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
1007fe9
+        srcName = srcStream.getStream()->getDict()->lookup("SourceName");
1007fe9
         if (!srcName.isString()) {
1007fe9
             fprintf(stderr, "No SourceName found\n");
1007fe9
             exit(1);
1007fe9
@@ -101,7 +107,7 @@ int main(int argc, char *argv[])
1007fe9
         // We cannot free srcName, as objname shares its string.
1007fe9
         // srcName.free();
1007fe9
     } else if (objnum > 0) {
1007fe9
-        xref->fetch(objnum, objgen, &srcStream);
1007fe9
+        srcStream = xref->fetch(objnum, objgen);
1007fe9
         if (!srcStream.isStream()) {
1007fe9
             fprintf(stderr, "Not a Stream object\n");
1007fe9
             exit(1);
1007fe9
@@ -151,26 +157,24 @@ int main(int argc, char *argv[])
1007fe9
                 int localOffset = 0;
1007fe9
                 Guint firstOffset;
1007fe9
 
1007fe9
-                assert(xref->fetch(e->offset, 0, &objStr)->isStream());
1007fe9
-                nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
1007fe9
-                obj1.free();
1007fe9
-                first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
1007fe9
-                obj1.free();
1007fe9
+                objStr = xref->fetch(e->offset, 0);
1007fe9
+                assert(objStr.isStream());
1007fe9
+                obj1 = objStr.streamGetDict()->lookup("N");
1007fe9
+                nObjects = obj1.getInt();
1007fe9
+                obj1 = objStr.streamGetDict()->lookup("First");
1007fe9
+                first = obj1.getInt();
1007fe9
                 firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
1007fe9
 
1007fe9
                 // parse the header: object numbers and offsets
1007fe9
                 objStr.streamReset();
1007fe9
-                obj1.initNull();
1007fe9
-                str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
1007fe9
+                str = new EmbedStream(objStr.getStream(), Object(objNull), gTrue, first);
1007fe9
                 lexer = new Lexer(xref, str);
1007fe9
                 parser = new Parser(xref, lexer, gFalse);
1007fe9
                 for (n = 0; n < nObjects; ++n) {
1007fe9
-                    parser->getObj(&obj1);
1007fe9
-                    parser->getObj(&obj2);
1007fe9
+                    obj1 = parser->getObj();
1007fe9
+                    obj2 = parser->getObj();
1007fe9
                     if (n == e->gen)
1007fe9
                         localOffset = obj2.getInt();
1007fe9
-                    obj1.free();
1007fe9
-                    obj2.free();
1007fe9
                 }
1007fe9
 #if defined(XPDF304)
1007fe9
                 while (str->getChar() != EOF) ;
1007fe9
@@ -178,7 +182,6 @@ int main(int argc, char *argv[])
1007fe9
                 lexer->skipToEOF();
1007fe9
 #endif
1007fe9
                 delete parser;
1007fe9
-                objStr.free();
1007fe9
 
1007fe9
                 fprintf(outfile, "%.10lu 00000 n\n",
1007fe9
                         (long unsigned)(firstOffset + localOffset));
1007fe9
@@ -189,7 +192,6 @@ int main(int argc, char *argv[])
1007fe9
         s->reset();
1007fe9
         while ((c = s->getChar()) != EOF)
1007fe9
             fputc(c, outfile);
1007fe9
-        srcStream.free();
1007fe9
     }
1007fe9
     if (objnum == 0)
1007fe9
         fprintf(stderr, "Source file extracted to %s\n", outname);
1007fe9
@@ -198,7 +200,6 @@ int main(int argc, char *argv[])
1007fe9
     else
1007fe9
         fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
1007fe9
     fclose(outfile);
1007fe9
-    catalogDict.free();
1007fe9
     delete doc;
1007fe9
     delete globalParams;
1007fe9
 }