Gentoo Archives: gentoo-commits

From: Mikle Kolyada <zlogene@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/tex:master commit in: 2019/patches/
Date: Fri, 27 Dec 2019 10:28:21
Message-Id: 1577442461.b738509ade17c7df1a176c9bce9b5d7f66bc4e52.zlogene@gentoo
1 commit: b738509ade17c7df1a176c9bce9b5d7f66bc4e52
2 Author: Mikle Kolyada <zlogene <AT> gentoo <DOT> org>
3 AuthorDate: Fri Dec 27 10:27:41 2019 +0000
4 Commit: Mikle Kolyada <zlogene <AT> gentoo <DOT> org>
5 CommitDate: Fri Dec 27 10:27:41 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/tex.git/commit/?id=b738509a
7
8 Add poppler-0.83 compat patch
9
10 Signed-off-by: Mikle Kolyada <zlogene <AT> gentoo.org>
11
12 2019/patches/texlive-core-2019-poppler083.patch | 804 ++++++++++++++++++++++++
13 1 file changed, 804 insertions(+)
14
15 diff --git a/2019/patches/texlive-core-2019-poppler083.patch b/2019/patches/texlive-core-2019-poppler083.patch
16 new file mode 100644
17 index 0000000..42eee72
18 --- /dev/null
19 +++ b/2019/patches/texlive-core-2019-poppler083.patch
20 @@ -0,0 +1,804 @@
21 +From a2eb2d4c664c37d694a92f75ad5571d3f2e800bc Mon Sep 17 00:00:00 2001
22 +From: Mikle Kolyada <zlogene@g.o>
23 +Date: Fri, 27 Dec 2019 12:09:32 +0300
24 +Subject: [PATCH] poppler-0.83 compat
25 +
26 +Signed-off-by: Mikle Kolyada <zlogene@g.o>
27 +---
28 + pdftoepdf.cc | 306 ++++++++++++++++++++++++++-------------------------
29 + pdftosrc.cc | 76 ++++++-------
30 + 2 files changed, 191 insertions(+), 191 deletions(-)
31 +
32 +diff --git a/texk/web2c/pdftexdir/pdftoepdf.cc b/texk/web2c/pdftexdir/pdftoepdf.cc
33 +index 4db0c90..291c39e 100644
34 +--- a/texk/web2c/pdftexdir/pdftoepdf.cc
35 ++++ b/texk/web2c/pdftexdir/pdftoepdf.cc
36 +@@ -1,5 +1,5 @@
37 + /*
38 +-Copyright 1996-2016 Han The Thanh, <thanh@××××××.org>
39 ++Copyright 1996-2017 Han The Thanh, <thanh@××××××.org>
40 +
41 + This file is part of pdfTeX.
42 +
43 +@@ -17,6 +17,15 @@ You should have received a copy of the GNU General Public License along
44 + with this program. If not, see <http://www.gnu.org/licenses/>.
45 + */
46 +
47 ++/*
48 ++This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
49 ++https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
50 ++by Arch Linux. A little modifications are made to avoid a crash for
51 ++some kind of pdf images, such as figure_missing.pdf in gnuplot.
52 ++The poppler should be 0.75.0 or newer versions.
53 ++POPPLER_VERSION should be defined.
54 ++*/
55 ++
56 + /* Do this early in order to avoid a conflict between
57 + MINGW32 <rpcndr.h> defining 'boolean' as 'unsigned char' and
58 + <kpathsea/types.h> defining Pascal's boolean as 'int'.
59 +@@ -39,10 +48,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
60 + #include <goo/gfile.h>
61 + #define GString GooString
62 + #else
63 +-#include <aconf.h>
64 +-#include <GString.h>
65 +-#include <gmem.h>
66 +-#include <gfile.h>
67 ++#error POPPLER_VERSION should be defined.
68 + #endif
69 + #include <assert.h>
70 +
71 +@@ -84,31 +90,6 @@ extern integer zround(double);
72 + #define MASK_SUPPRESS_PTEX_PAGENUMBER 0x04
73 + #define MASK_SUPPRESS_PTEX_INFODICT 0x08
74 +
75 +-// PdfObject encapsulates the xpdf Object type,
76 +-// and properly frees its resources on destruction.
77 +-// Use obj-> to access members of the Object,
78 +-// and &obj to get a pointer to the object.
79 +-// It is no longer necessary to call Object::free explicitely.
80 +-
81 +-class PdfObject {
82 +- public:
83 +- PdfObject() { // nothing
84 +- } ~PdfObject() {
85 +- iObject.free();
86 +- }
87 +- Object *operator->() {
88 +- return &iObject;
89 +- }
90 +- Object *operator&() {
91 +- return &iObject;
92 +- }
93 +- private: // no copying or assigning
94 +- PdfObject(const PdfObject &);
95 +- void operator=(const PdfObject &);
96 +- public:
97 +- Object iObject;
98 +-};
99 +-
100 + // When copying the Resources of the selected page, all objects are copied
101 + // recusively top-down. Indirect objects however are not fetched during
102 + // copying, but get a new object number from pdfTeX and then will be
103 +@@ -139,7 +120,7 @@ struct UsedEncoding {
104 +
105 + static InObj *inObjList;
106 + static UsedEncoding *encodingList;
107 +-static GBool isInit = gFalse;
108 ++static bool isInit = false;
109 +
110 + // --------------------------------------------------------------------
111 + // Maintain list of open embedded PDF files
112 +@@ -212,18 +193,6 @@ static void delete_document(PdfDocument * pdf_doc)
113 + delete pdf_doc;
114 + }
115 +
116 +-// Replacement for
117 +-// Object *initDict(Dict *dict1){ initObj(objDict); dict = dict1; return this; }
118 +-
119 +-static void initDictFromDict(PdfObject & obj, Dict * dict)
120 +-{
121 +- obj->initDict(xref);
122 +- for (int i = 0, l = dict->getLength(); i < l; i++) {
123 +- Object obj1;
124 +- obj->dictAdd(copyString(dict->getKey(i)), dict->getValNF(i, &obj1));
125 +- }
126 +-}
127 +-
128 + // --------------------------------------------------------------------
129 +
130 + static int addEncoding(GfxFont * gfont)
131 +@@ -320,10 +289,10 @@ static void copyName(char *s)
132 +
133 + static void copyDictEntry(Object * obj, int i)
134 + {
135 +- PdfObject obj1;
136 +- copyName(obj->dictGetKey(i));
137 ++ Object obj1;
138 ++ copyName((char *)obj->dictGetKey(i));
139 + pdf_puts(" ");
140 +- obj->dictGetValNF(i, &obj1);
141 ++ obj1 = obj->dictGetValNF(i).copy();
142 + copyObject(&obj1);
143 + pdf_puts("\n");
144 + }
145 +@@ -348,7 +317,7 @@ static void copyFontDict(Object * obj, InObj * r)
146 + pdf_puts("<<\n");
147 + assert(r->type == objFont); // FontDescriptor is in fd_tree
148 + for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
149 +- key = obj->dictGetKey(i);
150 ++ key = (char *)obj->dictGetKey(i);
151 + if (strncmp("FontDescriptor", key, strlen("FontDescriptor")) == 0
152 + || strncmp("BaseFont", key, strlen("BaseFont")) == 0
153 + || strncmp("Encoding", key, strlen("Encoding")) == 0)
154 +@@ -376,17 +345,17 @@ static void copyStream(Stream * str)
155 + static void copyProcSet(Object * obj)
156 + {
157 + int i, l;
158 +- PdfObject procset;
159 ++ Object procset;
160 + if (!obj->isArray())
161 + pdftex_fail("PDF inclusion: invalid ProcSet array type <%s>",
162 + obj->getTypeName());
163 + pdf_puts("/ProcSet [ ");
164 + for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
165 +- obj->arrayGetNF(i, &procset);
166 +- if (!procset->isName())
167 ++ procset = obj->arrayGetNF(i).copy();
168 ++ if (!procset.isName())
169 + pdftex_fail("PDF inclusion: invalid ProcSet entry type <%s>",
170 +- procset->getTypeName());
171 +- copyName(procset->getName());
172 ++ procset.getTypeName());
173 ++ copyName((char *)procset.getName());
174 + pdf_puts(" ");
175 + }
176 + pdf_puts("]\n");
177 +@@ -394,10 +363,29 @@ static void copyProcSet(Object * obj)
178 +
179 + #define REPLACE_TYPE1C true
180 +
181 ++static bool embeddableFont(Object * fontdesc)
182 ++{
183 ++ Object fontfile, ffsubtype;
184 ++
185 ++ if (!fontdesc->isDict())
186 ++ return false;
187 ++ fontfile = fontdesc->dictLookup("FontFile");
188 ++ if (fontfile.isStream())
189 ++ return true;
190 ++ if (REPLACE_TYPE1C) {
191 ++ fontfile = fontdesc->dictLookup("FontFile3");
192 ++ if (!fontfile.isStream())
193 ++ return false;
194 ++ ffsubtype = fontfile.streamGetDict()->lookup("Subtype");
195 ++ return ffsubtype.isName() && !strcmp(ffsubtype.getName(), "Type1C");
196 ++ }
197 ++ return false;
198 ++}
199 ++
200 + static void copyFont(char *tag, Object * fontRef)
201 + {
202 +- PdfObject fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
203 +- fontfile, ffsubtype, stemV;
204 ++ Object fontdict, subtype, basefont, fontdescRef, fontdesc, charset,
205 ++ stemV;
206 + GfxFont *gfont;
207 + fd_entry *fd;
208 + fm_entry *fontmap;
209 +@@ -413,33 +401,39 @@ static void copyFont(char *tag, Object * fontRef)
210 + }
211 + // Only handle included Type1 (and Type1C) fonts; anything else will be copied.
212 + // Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
213 +- if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
214 +- && fontdict->dictLookup("Subtype", &subtype)->isName()
215 +- && !strcmp(subtype->getName(), "Type1")
216 +- && fontdict->dictLookup("BaseFont", &basefont)->isName()
217 +- && fontdict->dictLookupNF("FontDescriptor", &fontdescRef)->isRef()
218 +- && fontdescRef->fetch(xref, &fontdesc)->isDict()
219 +- && (fontdesc->dictLookup("FontFile", &fontfile)->isStream()
220 +- || (REPLACE_TYPE1C
221 +- && fontdesc->dictLookup("FontFile3", &fontfile)->isStream()
222 +- && fontfile->streamGetDict()->lookup("Subtype",
223 +- &ffsubtype)->isName()
224 +- && !strcmp(ffsubtype->getName(), "Type1C")))
225 +- && (fontmap = lookup_fontmap(basefont->getName())) != NULL) {
226 ++ fontdict = fontRef->fetch(xref);
227 ++ fontdesc = Object(objNull);
228 ++ if (fontdict.isDict()) {
229 ++ subtype = fontdict.dictLookup("Subtype");
230 ++ basefont = fontdict.dictLookup("BaseFont");
231 ++ fontdescRef = fontdict.dictLookupNF("FontDescriptor").copy();
232 ++ if (fontdescRef.isRef()) {
233 ++ fontdesc = fontdescRef.fetch(xref);
234 ++ }
235 ++ }
236 ++ if (!fixedinclusioncopyfont && fontdict.isDict()
237 ++ && subtype.isName()
238 ++ && !strcmp(subtype.getName(), "Type1")
239 ++ && basefont.isName()
240 ++ && fontdescRef.isRef()
241 ++ && fontdesc.isDict()
242 ++ && embeddableFont(&fontdesc)
243 ++ && (fontmap = lookup_fontmap((char *)basefont.getName())) != NULL) {
244 + // round /StemV value, since the PDF input is a float
245 + // (see Font Descriptors in PDF reference), but we only store an
246 + // integer, since we don't want to change the struct.
247 +- fontdesc->dictLookup("StemV", &stemV);
248 +- fd = epdf_create_fontdescriptor(fontmap, zround(stemV->getNum()));
249 +- if (fontdesc->dictLookup("CharSet", &charset) &&
250 +- charset->isString() && is_subsetable(fontmap))
251 +- epdf_mark_glyphs(fd, charset->getString()->getCString());
252 ++ stemV = fontdesc.dictLookup("StemV");
253 ++ fd = epdf_create_fontdescriptor(fontmap, zround(stemV.getNum()));
254 ++ charset = fontdesc.dictLookup("CharSet");
255 ++ if (!charset.isNull() &&
256 ++ charset.isString() && is_subsetable(fontmap))
257 ++ epdf_mark_glyphs(fd, (char *)charset.getString()->c_str());
258 + else
259 + embed_whole_font(fd);
260 +- addFontDesc(fontdescRef->getRef(), fd);
261 ++ addFontDesc(fontdescRef.getRef(), fd);
262 + copyName(tag);
263 + gfont = GfxFont::makeFont(xref, tag, fontRef->getRef(),
264 +- fontdict->getDict());
265 ++ fontdict.getDict());
266 + pdf_printf(" %d 0 R ", addFont(fontRef->getRef(), fd,
267 + addEncoding(gfont)));
268 + } else {
269 +@@ -451,24 +445,24 @@ static void copyFont(char *tag, Object * fontRef)
270 +
271 + static void copyFontResources(Object * obj)
272 + {
273 +- PdfObject fontRef;
274 ++ Object fontRef;
275 + int i, l;
276 + if (!obj->isDict())
277 + pdftex_fail("PDF inclusion: invalid font resources dict type <%s>",
278 + obj->getTypeName());
279 + pdf_puts("/Font << ");
280 + for (i = 0, l = obj->dictGetLength(); i < l; ++i) {
281 +- obj->dictGetValNF(i, &fontRef);
282 +- if (fontRef->isRef())
283 +- copyFont(obj->dictGetKey(i), &fontRef);
284 +- else if (fontRef->isDict()) { // some programs generate pdf with embedded font object
285 +- copyName(obj->dictGetKey(i));
286 ++ fontRef = obj->dictGetValNF(i).copy();
287 ++ if (fontRef.isRef())
288 ++ copyFont((char *)obj->dictGetKey(i), &fontRef);
289 ++ else if (fontRef.isDict()) { // some programs generate pdf with embedded font object
290 ++ copyName((char *)obj->dictGetKey(i));
291 + pdf_puts(" ");
292 + copyObject(&fontRef);
293 + }
294 + else
295 + pdftex_fail("PDF inclusion: invalid font in reference type <%s>",
296 +- fontRef->getTypeName());
297 ++ fontRef.getTypeName());
298 + }
299 + pdf_puts(">>\n");
300 + }
301 +@@ -557,7 +551,7 @@ static char *convertNumToPDF(double n)
302 +
303 + static void copyObject(Object * obj)
304 + {
305 +- PdfObject obj1;
306 ++ Object obj1;
307 + int i, l, c;
308 + Ref ref;
309 + char *p;
310 +@@ -571,8 +565,8 @@ static void copyObject(Object * obj)
311 + } else if (obj->isNum()) {
312 + pdf_printf("%s", convertNumToPDF(obj->getNum()));
313 + } else if (obj->isString()) {
314 +- s = obj->getString();
315 +- p = s->getCString();
316 ++ s = (GooString *)obj->getString();
317 ++ p = (char *)s->c_str();
318 + l = s->getLength();
319 + if (strlen(p) == (unsigned int) l) {
320 + pdf_puts("(");
321 +@@ -595,14 +589,14 @@ static void copyObject(Object * obj)
322 + pdf_puts(">");
323 + }
324 + } else if (obj->isName()) {
325 +- copyName(obj->getName());
326 ++ copyName((char *)obj->getName());
327 + } else if (obj->isNull()) {
328 + pdf_puts("null");
329 + } else if (obj->isArray()) {
330 + pdf_puts("[");
331 + for (i = 0, l = obj->arrayGetLength(); i < l; ++i) {
332 +- obj->arrayGetNF(i, &obj1);
333 +- if (!obj1->isName())
334 ++ obj1 = obj->arrayGetNF(i).copy();
335 ++ if (!obj1.isName())
336 + pdf_puts(" ");
337 + copyObject(&obj1);
338 + }
339 +@@ -612,9 +606,8 @@ static void copyObject(Object * obj)
340 + copyDict(obj);
341 + pdf_puts(">>");
342 + } else if (obj->isStream()) {
343 +- initDictFromDict(obj1, obj->streamGetDict());
344 + pdf_puts("<<\n");
345 +- copyDict(&obj1);
346 ++ copyDict(obj->getStream()->getDictObject());
347 + pdf_puts(">>\n");
348 + pdf_puts("stream\n");
349 + copyStream(obj->getStream()->getUndecodedStream());
350 +@@ -638,9 +631,8 @@ static void writeRefs()
351 + InObj *r;
352 + for (r = inObjList; r != 0; r = r->next) {
353 + if (!r->written) {
354 +- Object obj1;
355 + r->written = 1;
356 +- xref->fetch(r->ref.num, r->ref.gen, &obj1);
357 ++ Object obj1 = xref->fetch(r->ref.num, r->ref.gen);
358 + if (r->type == objFont) {
359 + assert(!obj1.isStream());
360 + pdfbeginobj(r->num, 2); // \pdfobjcompresslevel = 2 is for this
361 +@@ -656,7 +648,6 @@ static void writeRefs()
362 + pdf_puts("\n");
363 + pdfendobj();
364 + }
365 +- obj1.free();
366 + }
367 + }
368 + }
369 +@@ -673,7 +664,7 @@ static void writeEncodings()
370 + ("PDF inclusion: CID fonts are not supported"
371 + " (try to disable font replacement to fix this)");
372 + }
373 +- if ((s = ((Gfx8BitFont *) r->font)->getCharName(i)) != 0)
374 ++ if ((s = (char *)((Gfx8BitFont *) r->font)->getCharName(i)) != 0)
375 + glyphNames[i] = s;
376 + else
377 + glyphNames[i] = notdef;
378 +@@ -685,14 +676,14 @@ static void writeEncodings()
379 + #ifdef POPPLER_VERSION
380 + r->font->decRefCnt();
381 + #else
382 +- delete r->font;
383 ++#error POPPLER_VERSION should be defined.
384 + #endif
385 + delete r;
386 + }
387 + }
388 +
389 + // get the pagebox according to the pagebox_spec
390 +-static PDFRectangle *get_pagebox(Page * page, int pagebox_spec)
391 ++static const PDFRectangle *get_pagebox(Page * page, int pagebox_spec)
392 + {
393 + if (pagebox_spec == pdfboxspecmedia)
394 + return page->getMediaBox();
395 +@@ -724,17 +715,21 @@ read_pdf_info(char *image_name, char *page_name, int page_num,
396 + {
397 + PdfDocument *pdf_doc;
398 + Page *page;
399 +- PDFRectangle *pagebox;
400 ++ const PDFRectangle *pagebox;
401 + #ifdef POPPLER_VERSION
402 + int pdf_major_version_found, pdf_minor_version_found;
403 + #else
404 +- float pdf_version_found, pdf_version_wanted;
405 ++#error POPPLER_VERSION should be defined.
406 + #endif
407 + // initialize
408 + if (!isInit) {
409 +- globalParams = new GlobalParams();
410 +- globalParams->setErrQuiet(gFalse);
411 +- isInit = gTrue;
412 ++#if POPPLER_MAJOR_VERSION >= 1 || POPPLER_MINOR_VERSION >= 83
413 ++ globalParams.reset(new GlobalParams());
414 ++#else
415 ++ globalParams = std::make_unique<GlobalParams>();
416 ++#endif
417 ++ globalParams->setErrQuiet(false);
418 ++ isInit = true;
419 + }
420 + // open PDF file
421 + pdf_doc = find_add_document(image_name);
422 +@@ -760,19 +755,7 @@ read_pdf_info(char *image_name, char *page_name, int page_num,
423 + }
424 + }
425 + #else
426 +- pdf_version_found = pdf_doc->doc->getPDFVersion();
427 +- pdf_version_wanted = 1 + (minor_pdf_version_wanted * 0.1);
428 +- if (pdf_version_found > pdf_version_wanted + 0.01) {
429 +- char msg[] =
430 +- "PDF inclusion: found PDF version <%.1f>, but at most version <%.1f> allowed";
431 +- if (pdf_inclusion_errorlevel > 0) {
432 +- pdftex_fail(msg, pdf_version_found, pdf_version_wanted);
433 +- } else if (pdf_inclusion_errorlevel < 0) {
434 +- ; /* do nothing */
435 +- } else { /* = 0, give warning */
436 +- pdftex_warn(msg, pdf_version_found, pdf_version_wanted);
437 +- }
438 +- }
439 ++#error POPPLER_VERSION should be defined.
440 + #endif
441 + epdf_num_pages = pdf_doc->doc->getCatalog()->getNumPages();
442 + if (page_name) {
443 +@@ -782,7 +765,7 @@ read_pdf_info(char *image_name, char *page_name, int page_num,
444 + if (link == 0 || !link->isOk())
445 + pdftex_fail("PDF inclusion: invalid destination <%s>", page_name);
446 + Ref ref = link->getPageRef();
447 +- page_num = pdf_doc->doc->getCatalog()->findPage(ref.num, ref.gen);
448 ++ page_num = pdf_doc->doc->getCatalog()->findPage(ref);
449 + if (page_num == 0)
450 + pdftex_fail("PDF inclusion: destination is not a page <%s>",
451 + page_name);
452 +@@ -839,8 +822,8 @@ void write_epdf(void)
453 + Page *page;
454 + Ref *pageRef;
455 + Dict *pageDict;
456 +- PdfObject contents, obj1, obj2, pageObj, dictObj;
457 +- PdfObject groupDict;
458 ++ Object contents, obj1, obj2, pageObj, dictObj;
459 ++ Object groupDict;
460 + bool writeSepGroup = false;
461 + Object info;
462 + char *key;
463 +@@ -867,10 +850,10 @@ void write_epdf(void)
464 + encodingList = 0;
465 + page = pdf_doc->doc->getCatalog()->getPage(epdf_selected_page);
466 + pageRef = pdf_doc->doc->getCatalog()->getPageRef(epdf_selected_page);
467 +- xref->fetch(pageRef->num, pageRef->gen, &pageObj);
468 +- pageDict = pageObj->getDict();
469 ++ pageObj = xref->fetch(pageRef->num, pageRef->gen);
470 ++ pageDict = pageObj.getDict();
471 + rotate = page->getRotate();
472 +- PDFRectangle *pagebox;
473 ++ const PDFRectangle *pagebox;
474 + // write the Page header
475 + pdf_puts("/Type /XObject\n");
476 + pdf_puts("/Subtype /Form\n");
477 +@@ -886,7 +869,7 @@ void write_epdf(void)
478 + pdf_printf("/%s.PageNumber %i\n", pdfkeyprefix, (int) epdf_selected_page);
479 + }
480 + if ((suppress_ptex_info & MASK_SUPPRESS_PTEX_INFODICT) == 0) {
481 +- pdf_doc->doc->getDocInfoNF(&info);
482 ++ info = pdf_doc->doc->getDocInfoNF().copy();
483 + if (info.isRef()) {
484 + // the info dict must be indirect (PDF Ref p. 61)
485 + pdf_printf("/%s.InfoDict ", pdfkeyprefix);
486 +@@ -942,14 +925,14 @@ void write_epdf(void)
487 + pdf_puts(stripzeros(s));
488 +
489 + // Metadata validity check (as a stream it must be indirect)
490 +- pageDict->lookupNF("Metadata", &dictObj);
491 +- if (!dictObj->isNull() && !dictObj->isRef())
492 ++ dictObj = pageDict->lookupNF("Metadata").copy();
493 ++ if (!dictObj.isNull() && !dictObj.isRef())
494 + pdftex_warn("PDF inclusion: /Metadata must be indirect object");
495 +
496 + // copy selected items in Page dictionary except Resources & Group
497 + for (i = 0; pageDictKeys[i] != NULL; i++) {
498 +- pageDict->lookupNF(pageDictKeys[i], &dictObj);
499 +- if (!dictObj->isNull()) {
500 ++ dictObj = pageDict->lookupNF(pageDictKeys[i]).copy();
501 ++ if (!dictObj.isNull()) {
502 + pdf_newline();
503 + pdf_printf("/%s ", pageDictKeys[i]);
504 + copyObject(&dictObj); // preserves indirection
505 +@@ -957,8 +940,8 @@ void write_epdf(void)
506 + }
507 +
508 + // handle page group
509 +- pageDict->lookupNF("Group", &dictObj);
510 +- if (!dictObj->isNull()) {
511 ++ dictObj = pageDict->lookupNF("Group").copy();
512 ++ if (!dictObj.isNull()) {
513 + if (pdfpagegroupval == 0) {
514 + // another pdf with page group was included earlier on the
515 + // same page; copy the Group entry as is. See manual for
516 +@@ -972,11 +955,36 @@ void write_epdf(void)
517 + copyObject(&dictObj);
518 + } else {
519 + // write Group dict as a separate object, since the Page dict also refers to it
520 +- pageDict->lookup("Group", &dictObj);
521 +- if (!dictObj->isDict())
522 ++ dictObj = pageDict->lookup("Group");
523 ++ if (!dictObj.isDict())
524 + pdftex_fail("PDF inclusion: /Group dict missing");
525 + writeSepGroup = true;
526 +- initDictFromDict(groupDict, page->getGroup());
527 ++/*
528 ++This part is only a single line
529 ++ groupDict = Object(page->getGroup());
530 ++in the original patch. In this case, however, pdftex crashes at
531 ++"delete pdf_doc->doc" in "delete_document()" for inclusion of some
532 ++kind of pdf images, for example, figure_missing.pdf in gnuplot.
533 ++A change
534 ++ groupDict = Object(page->getGroup()).copy();
535 ++does not improve the situation.
536 ++The changes below seem to work fine.
537 ++*/
538 ++// begin modification
539 ++ groupDict = pageDict->lookup("Group");
540 ++ const Dict& dic1 = page->getGroup();
541 ++ const Dict& dic2 = groupDict.getDict();
542 ++ // replace dic2 in groupDict with dic1
543 ++ l = dic2.getLength();
544 ++ for (i = 0; i < l; i++) {
545 ++ groupDict.dictRemove(dic2.getKey(i));
546 ++ }
547 ++ l = dic1.getLength();
548 ++ for (i = 0; i < l; i++) {
549 ++ groupDict.dictAdd((const char *)copyString(dic1.getKey(i)),
550 ++ dic1.getValNF(i).copy());
551 ++ }
552 ++// end modification
553 + pdf_printf("/Group %ld 0 R\n", (long)pdfpagegroupval);
554 + }
555 + }
556 +@@ -989,28 +997,28 @@ void write_epdf(void)
557 + pdftex_warn
558 + ("PDF inclusion: /Resources missing. 'This practice is not recommended' (PDF Ref)");
559 + } else {
560 +- initDictFromDict(obj1, page->getResourceDict());
561 ++ Object *obj1 = page->getResourceDictObject();
562 + if (!obj1->isDict())
563 + pdftex_fail("PDF inclusion: invalid resources dict type <%s>",
564 + obj1->getTypeName());
565 + pdf_newline();
566 + pdf_puts("/Resources <<\n");
567 + for (i = 0, l = obj1->dictGetLength(); i < l; ++i) {
568 +- obj1->dictGetVal(i, &obj2);
569 +- key = obj1->dictGetKey(i);
570 ++ obj2 = obj1->dictGetVal(i);
571 ++ key = (char *)obj1->dictGetKey(i);
572 + if (strcmp("Font", key) == 0)
573 + copyFontResources(&obj2);
574 + else if (strcmp("ProcSet", key) == 0)
575 + copyProcSet(&obj2);
576 + else
577 +- copyOtherResources(&obj2, key);
578 ++ copyOtherResources(&obj2, (char *)key);
579 + }
580 + pdf_puts(">>\n");
581 + }
582 +
583 + // write the page contents
584 +- page->getContents(&contents);
585 +- if (contents->isStream()) {
586 ++ contents = page->getContents();
587 ++ if (contents.isStream()) {
588 +
589 + // Variant A: get stream and recompress under control
590 + // of \pdfcompresslevel
591 +@@ -1021,36 +1029,35 @@ void write_epdf(void)
592 +
593 + // Variant B: copy stream without recompressing
594 + //
595 +- contents->streamGetDict()->lookup("F", &obj1);
596 +- if (!obj1->isNull()) {
597 ++ obj1 = contents.streamGetDict()->lookup("F");
598 ++ if (!obj1.isNull()) {
599 + pdftex_fail("PDF inclusion: Unsupported external stream");
600 + }
601 +- contents->streamGetDict()->lookup("Length", &obj1);
602 +- assert(!obj1->isNull());
603 ++ obj1 = contents.streamGetDict()->lookup("Length");
604 ++ assert(!obj1.isNull());
605 + pdf_puts("/Length ");
606 + copyObject(&obj1);
607 + pdf_puts("\n");
608 +- contents->streamGetDict()->lookup("Filter", &obj1);
609 +- if (!obj1->isNull()) {
610 ++ obj1 = contents.streamGetDict()->lookup("Filter");
611 ++ if (!obj1.isNull()) {
612 + pdf_puts("/Filter ");
613 + copyObject(&obj1);
614 + pdf_puts("\n");
615 +- contents->streamGetDict()->lookup("DecodeParms", &obj1);
616 +- if (!obj1->isNull()) {
617 ++ obj1 = contents.streamGetDict()->lookup("DecodeParms");
618 ++ if (!obj1.isNull()) {
619 + pdf_puts("/DecodeParms ");
620 + copyObject(&obj1);
621 + pdf_puts("\n");
622 + }
623 + }
624 + pdf_puts(">>\nstream\n");
625 +- copyStream(contents->getStream()->getUndecodedStream());
626 ++ copyStream(contents.getStream()->getUndecodedStream());
627 + pdfendstream();
628 +- } else if (contents->isArray()) {
629 ++ } else if (contents.isArray()) {
630 + pdfbeginstream();
631 +- for (i = 0, l = contents->arrayGetLength(); i < l; ++i) {
632 +- Object contentsobj;
633 +- copyStream((contents->arrayGet(i, &contentsobj))->getStream());
634 +- contentsobj.free();
635 ++ for (i = 0, l = contents.arrayGetLength(); i < l; ++i) {
636 ++ Object contentsobj = contents.arrayGet(i);
637 ++ copyStream(contentsobj.getStream());
638 + if (i < l - 1)
639 + pdf_newline(); // add a newline after each stream except the last
640 + }
641 +@@ -1105,6 +1112,5 @@ void epdf_check_mem()
642 + delete_document(p);
643 + }
644 + // see above for globalParams
645 +- delete globalParams;
646 + }
647 + }
648 +diff --git a/texk/web2c/pdftexdir/pdftosrc.cc b/texk/web2c/pdftexdir/pdftosrc.cc
649 +index 67be229..b6700fd 100644
650 +--- a/texk/web2c/pdftexdir/pdftosrc.cc
651 ++++ b/texk/web2c/pdftexdir/pdftosrc.cc
652 +@@ -16,6 +16,14 @@ GNU General Public License for more details.
653 + You should have received a copy of the GNU General Public License along
654 + with this program. If not, see <http://www.gnu.org/licenses/>.
655 + */
656 ++
657 ++/*
658 ++This is based on the patch texlive-poppler-0.59.patch <2017-09-19> at
659 ++https://git.archlinux.org/svntogit/packages.git/plain/texlive-bin/trunk
660 ++by Arch Linux. The poppler should be 0.72.0 or newer versions.
661 ++POPPLER_VERSION should be defined.
662 ++*/
663 ++
664 + #include <w2c/config.h>
665 +
666 + #include <stdlib.h>
667 +@@ -32,16 +40,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
668 + #include <goo/gmem.h>
669 + #include <goo/gfile.h>
670 + #else
671 +-#include <aconf.h>
672 +-#include <GString.h>
673 +-#include <gmem.h>
674 +-#include <gfile.h>
675 ++#error POPPLER_VERSION should be defined.
676 + #endif
677 + #include <assert.h>
678 +
679 + #include "Object.h"
680 + #include "Stream.h"
681 +-#include "Lexer.h"
682 + #include "Parser.h"
683 + #include "Array.h"
684 + #include "Dict.h"
685 +@@ -74,7 +78,11 @@ int main(int argc, char *argv[])
686 + exit(1);
687 + }
688 + fileName = new GString(argv[1]);
689 +- globalParams = new GlobalParams();
690 ++#if POPPLER_MAJOR_VERSION >= 1 || POPPLER_MINOR_VERSION >= 83
691 ++ globalParams.reset(new GlobalParams());
692 ++#else
693 ++ globalParams = std::make_unique<GlobalParams>();
694 ++#endif
695 + doc = new PDFDoc(fileName);
696 + if (!doc->isOk()) {
697 + fprintf(stderr, "Invalid PDF file\n");
698 +@@ -86,36 +94,34 @@ int main(int argc, char *argv[])
699 + objgen = atoi(argv[3]);
700 + }
701 + xref = doc->getXRef();
702 +- catalogDict.initNull();
703 +- xref->getCatalog(&catalogDict);
704 ++ catalogDict = xref->getCatalog();
705 + if (!catalogDict.isDict("Catalog")) {
706 + fprintf(stderr, "No Catalog found\n");
707 + exit(1);
708 + }
709 +- srcStream.initNull();
710 ++ srcStream = Object(objNull);
711 + if (objnum == 0) {
712 +- catalogDict.dictLookup("SourceObject", &srcStream);
713 +- static char const_SourceFile[] = "SourceFile";
714 +- if (!srcStream.isStream(const_SourceFile)) {
715 ++ srcStream = catalogDict.dictLookup("SourceObject");
716 ++ static const char *const_SourceFile = "SourceFile";
717 ++ if (!srcStream.isDict(const_SourceFile)) {
718 + fprintf(stderr, "No SourceObject found\n");
719 + exit(1);
720 + }
721 +- srcName.initNull();
722 +- srcStream.getStream()->getDict()->lookup("SourceName", &srcName);
723 ++ srcName = srcStream.getStream()->getDict()->lookup("SourceName");
724 + if (!srcName.isString()) {
725 + fprintf(stderr, "No SourceName found\n");
726 + exit(1);
727 + }
728 +- outname = srcName.getString()->getCString();
729 ++ outname = (char *)srcName.getString()->c_str();
730 + // We cannot free srcName, as objname shares its string.
731 + // srcName.free();
732 + } else if (objnum > 0) {
733 +- xref->fetch(objnum, objgen, &srcStream);
734 ++ srcStream = xref->fetch(objnum, objgen);
735 + if (!srcStream.isStream()) {
736 + fprintf(stderr, "Not a Stream object\n");
737 + exit(1);
738 + }
739 +- sprintf(buf, "%s", fileName->getCString());
740 ++ sprintf(buf, "%s", fileName->c_str());
741 + if ((p = strrchr(buf, '.')) == 0)
742 + p = strchr(buf, 0);
743 + if (objgen == 0)
744 +@@ -125,7 +131,7 @@ int main(int argc, char *argv[])
745 + outname = buf;
746 + } else { // objnum < 0 means we are extracting the XRef table
747 + extract_xref_table = true;
748 +- sprintf(buf, "%s", fileName->getCString());
749 ++ sprintf(buf, "%s", fileName->c_str());
750 + if ((p = strrchr(buf, '.')) == 0)
751 + p = strchr(buf, 0);
752 + sprintf(p, ".xref");
753 +@@ -153,41 +159,32 @@ int main(int argc, char *argv[])
754 + (e->type == xrefEntryFree ? "f" : "n"));
755 + else { // e->offset is the object number of the object stream
756 + Stream *str;
757 +- Lexer *lexer;
758 + Parser *parser;
759 + Object objStr, obj1, obj2;
760 + int nObjects, first, n;
761 + int localOffset = 0;
762 +- Guint firstOffset;
763 ++ unsigned int firstOffset;
764 +
765 +- assert(xref->fetch(e->offset, 0, &objStr)->isStream());
766 +- nObjects = objStr.streamGetDict()->lookup("N", &obj1)->getInt();
767 +- obj1.free();
768 +- first = objStr.streamGetDict()->lookup("First", &obj1)->getInt();
769 +- obj1.free();
770 ++ objStr = xref->fetch(e->offset, 0);
771 ++ assert(objStr.isStream());
772 ++ obj1 = objStr.streamGetDict()->lookup("N");
773 ++ nObjects = obj1.getInt();
774 ++ obj1 = objStr.streamGetDict()->lookup("First");
775 ++ first = obj1.getInt();
776 + firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
777 +
778 + // parse the header: object numbers and offsets
779 + objStr.streamReset();
780 +- obj1.initNull();
781 +- str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
782 +- lexer = new Lexer(xref, str);
783 +- parser = new Parser(xref, lexer, gFalse);
784 ++ str = new EmbedStream(objStr.getStream(), Object(objNull), true, first);
785 ++ parser = new Parser(xref, str, false);
786 + for (n = 0; n < nObjects; ++n) {
787 +- parser->getObj(&obj1);
788 +- parser->getObj(&obj2);
789 ++ obj1 = parser->getObj();
790 ++ obj2 = parser->getObj();
791 + if (n == e->gen)
792 + localOffset = obj2.getInt();
793 +- obj1.free();
794 +- obj2.free();
795 + }
796 +-#if defined(POPPLER_VERSION) || defined(XPDF304)
797 + while (str->getChar() != EOF) ;
798 +-#else /* xpdf 4.00 */
799 +- lexer->skipToEOF();
800 +-#endif
801 + delete parser;
802 +- objStr.free();
803 +
804 + fprintf(outfile, "%.10lu 00000 n\n",
805 + (long unsigned)(firstOffset + localOffset));
806 +@@ -198,7 +195,6 @@ int main(int argc, char *argv[])
807 + s->reset();
808 + while ((c = s->getChar()) != EOF)
809 + fputc(c, outfile);
810 +- srcStream.free();
811 + }
812 + if (objnum == 0)
813 + fprintf(stderr, "Source file extracted to %s\n", outname);
814 +@@ -207,7 +203,5 @@ int main(int argc, char *argv[])
815 + else
816 + fprintf(stderr, "Cross-reference table extracted to %s\n", outname);
817 + fclose(outfile);
818 +- catalogDict.free();
819 + delete doc;
820 +- delete globalParams;
821 + }
822 +--
823 +2.24.1
824 +