]> git.pld-linux.org Git - packages/inkscape.git/blob - inkscape-poppler.patch
cf8bb197216e5ec3f8a2e0a473b2d491abdcec7e
[packages/inkscape.git] / inkscape-poppler.patch
1 From a600c6438fef2f4c06f9a4a7d933d99fb054a973 Mon Sep 17 00:00:00 2001
2 From: Eduard Braun <eduard.braun2@gmx.de>
3 Date: Tue, 24 Apr 2018 19:18:26 +0200
4 Subject: [PATCH] Fix compilation with poppler 0.64
5
6 ---
7  src/extension/internal/pdfinput/pdf-parser.cpp  | 10 +++++-----
8  src/extension/internal/pdfinput/pdf-parser.h    |  2 +-
9  src/extension/internal/pdfinput/svg-builder.cpp |  4 ++--
10  src/extension/internal/pdfinput/svg-builder.h   |  3 +--
11  4 files changed, 9 insertions(+), 10 deletions(-)
12
13 diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
14 index 15bc2d746d..6c498f9812 100644
15 --- a/src/extension/internal/pdfinput/pdf-parser.cpp
16 +++ b/src/extension/internal/pdfinput/pdf-parser.cpp
17 @@ -2582,7 +2582,7 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/)
18    }
19  }
20  
21 -void PdfParser::doShowText(GooString *s) {
22 +void PdfParser::doShowText(const GooString *s) {
23    GfxFont *font;
24    int wMode;
25    double riseX, riseY;
26 @@ -2601,7 +2601,7 @@ void PdfParser::doShowText(GooString *s) {
27    font = state->getFont();
28    wMode = font->getWMode();
29  
30 -  builder->beginString(state, s);
31 +  builder->beginString(state);
32  
33    // handle a Type 3 char
34    if (font->getType() == fontType3 && 0) {//out->interpretType3Chars()) {
35 @@ -2631,7 +2631,7 @@ void PdfParser::doShowText(GooString *s) {
36      double lineX = state->getLineX();
37      double lineY = state->getLineY();
38      oldParser = parser;
39 -    p = s->getCString();
40 +    p = g_strdup(s->getCString());
41      len = s->getLength();
42      while (len > 0) {
43        n = font->getNextChar(p, len, &code,
44 @@ -2686,7 +2686,7 @@ void PdfParser::doShowText(GooString *s) {
45  
46    } else {
47      state->textTransformDelta(0, state->getRise(), &riseX, &riseY);
48 -    p = s->getCString();
49 +    p = g_strdup(s->getCString());
50      len = s->getLength();
51      while (len > 0) {
52        n = font->getNextChar(p, len, &code,
53 @@ -2732,7 +2732,7 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/)
54  {
55    Object obj1, obj2, obj3, refObj;
56  
57 -  char *name = args[0].getName();
58 +  char *name = g_strdup(args[0].getName());
59  #if defined(POPPLER_NEW_OBJECT_API)
60    if ((obj1 = res->lookupXObject(name)).isNull()) {
61  #else
62 diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h
63 index e28fecc2e1..f985b15cad 100644
64 --- a/src/extension/internal/pdfinput/pdf-parser.h
65 +++ b/src/extension/internal/pdfinput/pdf-parser.h
66 @@ -287,7 +287,7 @@ private:
67    void opMoveShowText(Object args[], int numArgs);
68    void opMoveSetShowText(Object args[], int numArgs);
69    void opShowSpaceText(Object args[], int numArgs);
70 -  void doShowText(GooString *s);
71 +  void doShowText(const GooString *s);
72  
73    // XObject operators
74    void opXObject(Object args[], int numArgs);
75 diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
76 index 158c5ae068..8e5a5f6396 100644
77 --- a/src/extension/internal/pdfinput/svg-builder.cpp
78 +++ b/src/extension/internal/pdfinput/svg-builder.cpp
79 @@ -1021,7 +1021,7 @@ void SvgBuilder::updateFont(GfxState *state) {
80      GfxFont *font = state->getFont();
81      // Store original name
82      if (font->getName()) {
83 -        _font_specification = font->getName()->getCString();
84 +        _font_specification = g_strdup(font->getName()->getCString());
85      } else {
86          _font_specification = (char*) "Arial";
87      }
88 @@ -1362,7 +1362,7 @@ void SvgBuilder::_flushText() {
89      _glyphs.clear();
90  }
91  
92 -void SvgBuilder::beginString(GfxState *state, GooString * /*s*/) {
93 +void SvgBuilder::beginString(GfxState *state) {
94      if (_need_font_update) {
95          updateFont(state);
96      }
97 diff --git a/src/extension/internal/pdfinput/svg-builder.h b/src/extension/internal/pdfinput/svg-builder.h
98 index ad15c9c06f..ed2a4d48e0 100644
99 --- a/src/extension/internal/pdfinput/svg-builder.h
100 +++ b/src/extension/internal/pdfinput/svg-builder.h
101 @@ -29,7 +29,6 @@ namespace Inkscape {
102  #include <glibmm/ustring.h>
103  
104  #include "CharTypes.h"
105 -class GooString;
106  class Function;
107  class GfxState;
108  struct GfxColor;
109 @@ -136,7 +135,7 @@ public:
110      void clearSoftMask(GfxState *state);
111  
112      // Text handling
113 -    void beginString(GfxState *state, GooString *s);
114 +    void beginString(GfxState *state);
115      void endString(GfxState *state);
116      void addChar(GfxState *state, double x, double y,
117                   double dx, double dy,
118 -- 
119 2.18.1
120
121 From 722e121361d0f784083d10e897155b7d4e44e515 Mon Sep 17 00:00:00 2001
122 From: Eduard Braun <eduard.braun2@gmx.de>
123 Date: Wed, 5 Sep 2018 00:31:06 +0200
124 Subject: [PATCH] Modified fix for compatibility with poppler 0.64
125
126 This is slightly uglier than a600c6438fef2f4c06f9a4a7d933d99fb054a973
127 but avoids duplicating strings (which is unnecessary and leaked memory).
128
129 It's also closer to what upstream intended with the changes in 0.64.
130 ---
131  .../internal/pdfinput/pdf-parser.cpp          | 19 ++++++++++++++++---
132  src/extension/internal/pdfinput/pdf-parser.h  |  6 ++++++
133  .../internal/pdfinput/svg-builder.cpp         |  6 +++---
134  src/extension/internal/pdfinput/svg-builder.h |  4 ++--
135  4 files changed, 27 insertions(+), 8 deletions(-)
136
137 diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
138 index 5fa21263ab..a3a8ff25a6 100644
139 --- a/src/extension/internal/pdfinput/pdf-parser.cpp
140 +++ b/src/extension/internal/pdfinput/pdf-parser.cpp
141 @@ -32,6 +32,7 @@
142  #include "pdf-parser.h"
143  #include "util/units.h"
144  
145 +#include "glib/poppler-features.h"
146  #include "goo/gmem.h"
147  #include "goo/GooString.h"
148  #include "GlobalParams.h"
149 @@ -2577,7 +2578,11 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/)
150    }
151  }
152  
153 +#if POPPLER_CHECK_VERSION(0,64,0)
154  void PdfParser::doShowText(const GooString *s) {
155 +#else
156 +void PdfParser::doShowText(GooString *s) {
157 +#endif
158    GfxFont *font;
159    int wMode;
160    double riseX, riseY;
161 @@ -2590,7 +2595,11 @@ void PdfParser::doShowText(const GooString *s) {
162    Object charProc;
163    Dict *resDict;
164    Parser *oldParser;
165 +#if POPPLER_CHECK_VERSION(0,64,0)
166 +  const char *p;
167 +#else
168    char *p;
169 +#endif
170    int len, n, uLen;
171  
172    font = state->getFont();
173 @@ -2626,7 +2635,7 @@ void PdfParser::doShowText(const GooString *s) {
174      double lineX = state->getLineX();
175      double lineY = state->getLineY();
176      oldParser = parser;
177 -    p = g_strdup(s->getCString());
178 +    p = s->getCString();
179      len = s->getLength();
180      while (len > 0) {
181        n = font->getNextChar(p, len, &code,
182 @@ -2681,7 +2690,7 @@ void PdfParser::doShowText(const GooString *s) {
183  
184    } else {
185      state->textTransformDelta(0, state->getRise(), &riseX, &riseY);
186 -    p = g_strdup(s->getCString());
187 +    p = s->getCString();
188      len = s->getLength();
189      while (len > 0) {
190        n = font->getNextChar(p, len, &code,
191 @@ -2727,7 +2736,11 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/)
192  {
193    Object obj1, obj2, obj3, refObj;
194  
195 -  char *name = g_strdup(args[0].getName());
196 +#if POPPLER_CHECK_VERSION(0,64,0)
197 +  const char *name = args[0].getName();
198 +#else
199 +  char *name = args[0].getName();
200 +#endif
201  #if defined(POPPLER_NEW_OBJECT_API)
202    if ((obj1 = res->lookupXObject(name)).isNull()) {
203  #else
204 diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h
205 index 755e6741b0..b27a29cfbf 100644
206 --- a/src/extension/internal/pdfinput/pdf-parser.h
207 +++ b/src/extension/internal/pdfinput/pdf-parser.h
208 @@ -25,6 +25,7 @@ namespace Inkscape {
209  // TODO clean up and remove using:
210  using Inkscape::Extension::Internal::SvgBuilder;
211  
212 +#include "glib/poppler-features.h"
213  #include "goo/gtypes.h"
214  #include "Object.h"
215  
216 @@ -287,7 +288,12 @@ private:
217    void opMoveShowText(Object args[], int numArgs);
218    void opMoveSetShowText(Object args[], int numArgs);
219    void opShowSpaceText(Object args[], int numArgs);
220 +#if POPPLER_CHECK_VERSION(0,64,0)
221    void doShowText(const GooString *s);
222 +#else
223 +  void doShowText(GooString *s);
224 +#endif
225 +  
226  
227    // XObject operators
228    void opXObject(Object args[], int numArgs);
229 diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
230 index 50a7685b89..9d0df7c04d 100644
231 --- a/src/extension/internal/pdfinput/svg-builder.cpp
232 +++ b/src/extension/internal/pdfinput/svg-builder.cpp
233 @@ -1020,9 +1020,9 @@ void SvgBuilder::updateFont(GfxState *state) {
234      GfxFont *font = state->getFont();
235      // Store original name
236      if (font->getName()) {
237 -        _font_specification = g_strdup(font->getName()->getCString());
238 +        _font_specification = font->getName()->getCString();
239      } else {
240 -        _font_specification = (char*) "Arial";
241 +        _font_specification = "Arial";
242      }
243  
244      // Prune the font name to get the correct font family name
245 @@ -1030,7 +1030,7 @@ void SvgBuilder::updateFont(GfxState *state) {
246      char *font_family = NULL;
247      char *font_style = NULL;
248      char *font_style_lowercase = NULL;
249 -    char *plus_sign = strstr(_font_specification, "+");
250 +    const char *plus_sign = strstr(_font_specification, "+");
251      if (plus_sign) {
252          font_family = g_strdup(plus_sign + 1);
253          _font_specification = plus_sign + 1;
254 diff --git a/src/extension/internal/pdfinput/svg-builder.h b/src/extension/internal/pdfinput/svg-builder.h
255 index 499724a4cd..729cdc944c 100644
256 --- a/src/extension/internal/pdfinput/svg-builder.h
257 +++ b/src/extension/internal/pdfinput/svg-builder.h
258 @@ -80,7 +80,7 @@ struct SvgGlyph {
259      bool style_changed;  // Set to true if style has to be reset
260      SPCSSAttr *style;
261      int render_mode;    // Text render mode
262 -    char *font_specification;   // Pointer to current font specification
263 +    const char *font_specification;   // Pointer to current font specification
264  };
265  
266  /**
267 @@ -202,7 +202,7 @@ private:
268  
269      SPCSSAttr *_font_style;          // Current font style
270      GfxFont *_current_font;
271 -    char *_font_specification;
272 +    const char *_font_specification;
273      double _font_scaling;
274      bool _need_font_update;
275      Geom::Affine _text_matrix;
276 -- 
277 2.18.1
278
279 From 402c0274420fe39fd2f3393bc7d8d8879d436358 Mon Sep 17 00:00:00 2001
280 From: Thomas Holder <thomas@thomas-holder.de>
281 Date: Fri, 28 Sep 2018 18:05:30 +0000
282 Subject: [PATCH] fix 1789208 poppler 0.69
283
284 ---
285  CMakeScripts/DefineDependsandFlags.cmake      | 12 -----
286  src/extension/internal/pdfinput/pdf-input.cpp |  2 +-
287  src/extension/internal/pdfinput/pdf-input.h   |  1 +
288  .../internal/pdfinput/pdf-parser.cpp          | 46 ++++++++-----------
289  src/extension/internal/pdfinput/pdf-parser.h  | 12 +++--
290  .../pdfinput/poppler-transition-api.h         | 39 ++++++++++++++++
291  .../internal/pdfinput/svg-builder.cpp         | 22 ++++-----
292  src/extension/internal/pdfinput/svg-builder.h |  3 +-
293  8 files changed, 80 insertions(+), 57 deletions(-)
294  create mode 100644 src/extension/internal/pdfinput/poppler-transition-api.h
295
296 diff --git a/CMakeScripts/DefineDependsandFlags.cmake b/CMakeScripts/DefineDependsandFlags.cmake
297 index 40ca7aa65c..9457d58df0 100644
298 --- a/CMakeScripts/DefineDependsandFlags.cmake
299 +++ b/CMakeScripts/DefineDependsandFlags.cmake
300 @@ -126,18 +126,6 @@ if(ENABLE_POPPLER)
301                 set(HAVE_POPPLER_GLIB ON)
302             endif()
303         endif()
304 -       if(POPPLER_VERSION VERSION_GREATER "0.26.0" OR
305 -               POPPLER_VERSION VERSION_EQUAL   "0.26.0")
306 -           set(POPPLER_EVEN_NEWER_COLOR_SPACE_API ON)
307 -       endif()
308 -       if(POPPLER_VERSION VERSION_GREATER "0.29.0" OR
309 -               POPPLER_VERSION VERSION_EQUAL   "0.29.0")
310 -           set(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API ON)
311 -       endif()
312 -       if(POPPLER_VERSION VERSION_GREATER "0.58.0" OR
313 -               POPPLER_VERSION VERSION_EQUAL   "0.58.0")
314 -            set(POPPLER_NEW_OBJECT_API ON)
315 -       endif()
316      else()
317         set(ENABLE_POPPLER_CAIRO OFF)
318      endif()
319 diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp
320 index fa9942230b..21a91fa34f 100644
321 --- a/src/extension/internal/pdfinput/pdf-input.cpp
322 +++ b/src/extension/internal/pdfinput/pdf-input.cpp
323 @@ -804,7 +804,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
324              dlg->getImportSettings(prefs);
325  
326          // Apply crop settings
327 -        PDFRectangle *clipToBox = NULL;
328 +        _POPPLER_CONST PDFRectangle *clipToBox = NULL;
329          double crop_setting;
330          sp_repr_get_double(prefs, "cropTo", &crop_setting);
331  
332 diff --git a/src/extension/internal/pdfinput/pdf-input.h b/src/extension/internal/pdfinput/pdf-input.h
333 index ddcb8f222b..88a894f1c0 100644
334 --- a/src/extension/internal/pdfinput/pdf-input.h
335 +++ b/src/extension/internal/pdfinput/pdf-input.h
336 @@ -15,6 +15,7 @@
337  #endif
338  
339  #ifdef HAVE_POPPLER
340 +#include "poppler-transition-api.h"
341  
342  #include <gtkmm/dialog.h>
343  
344 diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
345 index a3a8ff25a6..96313e1f19 100644
346 --- a/src/extension/internal/pdfinput/pdf-parser.cpp
347 +++ b/src/extension/internal/pdfinput/pdf-parser.cpp
348 @@ -291,8 +291,8 @@ PdfParser::PdfParser(XRef *xrefA,
349                       int /*pageNum*/,
350                      int rotate,
351                      Dict *resDict,
352 -                     PDFRectangle *box,
353 -                    PDFRectangle *cropBox) :
354 +                     _POPPLER_CONST PDFRectangle *box,
355 +                     _POPPLER_CONST PDFRectangle *cropBox) :
356      xref(xrefA),
357      builder(builderA),
358      subPage(gFalse),
359 @@ -314,7 +314,7 @@ PdfParser::PdfParser(XRef *xrefA,
360    builder->setDocumentSize(Inkscape::Util::Quantity::convert(state->getPageWidth(), "pt", "px"),
361                             Inkscape::Util::Quantity::convert(state->getPageHeight(), "pt", "px"));
362  
363 -  double *ctm = state->getCTM();
364 +  const double *ctm = state->getCTM();
365    double scaledCTM[6];
366    for (int i = 0; i < 6; ++i) {
367      baseMatrix[i] = ctm[i];
368 @@ -349,7 +349,7 @@ PdfParser::PdfParser(XRef *xrefA,
369  PdfParser::PdfParser(XRef *xrefA,
370                      Inkscape::Extension::Internal::SvgBuilder *builderA,
371                       Dict *resDict,
372 -                    PDFRectangle *box) :
373 +                    _POPPLER_CONST PDFRectangle *box) :
374      xref(xrefA),
375      builder(builderA),
376      subPage(gTrue),
377 @@ -568,7 +568,7 @@ const char *PdfParser::getPreviousOperator(unsigned int look_back) {
378  
379  void PdfParser::execOp(Object *cmd, Object args[], int numArgs) {
380    PdfOperator *op;
381 -  char *name;
382 +  const char *name;
383    Object *argPtr;
384    int i;
385  
386 @@ -616,7 +616,7 @@ void PdfParser::execOp(Object *cmd, Object args[], int numArgs) {
387    (this->*op->func)(argPtr, numArgs);
388  }
389  
390 -PdfOperator* PdfParser::findOp(char *name) {
391 +PdfOperator* PdfParser::findOp(const char *name) {
392    int a = -1;
393    int b = numOps;
394    int cmp = -1;
395 @@ -1748,7 +1748,7 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat,
396                                               GBool stroke, GBool eoFill) {
397    GfxShading *shading;
398    GfxPath *savedPath;
399 -  double *ctm, *btm, *ptm;
400 +  const double *ctm, *btm, *ptm;
401    double m[6], ictm[6], m1[6];
402    double xMin, yMin, xMax, yMax;
403    double det;
404 @@ -1990,7 +1990,7 @@ void PdfParser::doFunctionShFill1(GfxFunctionShading *shading,
405    GfxColor color0M, color1M, colorM0, colorM1, colorMM;
406    GfxColor colors2[4];
407    double functionColorDelta = colorDeltas[pdfFunctionShading-1];
408 -  double *matrix;
409 +  const double *matrix;
410    double xM, yM;
411    int nComps, i, j;
412  
413 @@ -2170,7 +2170,7 @@ void PdfParser::doPatchMeshShFill(GfxPatchMeshShading *shading) {
414    }
415  }
416  
417 -void PdfParser::fillPatch(GfxPatch *patch, int nComps, int depth) {
418 +void PdfParser::fillPatch(_POPPLER_CONST GfxPatch *patch, int nComps, int depth) {
419    GfxPatch patch00 = blankPatch();
420    GfxPatch patch01 = blankPatch();
421    GfxPatch patch10 = blankPatch();
422 @@ -2591,7 +2591,7 @@ void PdfParser::doShowText(GooString *s) {
423    double x, y, dx, dy, tdx, tdy;
424    double originX, originY, tOriginX, tOriginY;
425    double oldCTM[6], newCTM[6];
426 -  double *mat;
427 +  const double *mat;
428    Object charProc;
429    Dict *resDict;
430    Parser *oldParser;
431 @@ -3665,7 +3665,6 @@ void PdfParser::opBeginImage(Object /*args*/[], int /*numArgs*/)
432  Stream *PdfParser::buildImageStream() {
433    Object dict;
434    Object obj;
435 -  char *key;
436    Stream *str;
437  
438    // build dictionary
439 @@ -3683,26 +3682,17 @@ Stream *PdfParser::buildImageStream() {
440        obj.free();
441  #endif
442      } else {
443 -      key = copyString(obj.getName());
444 -#if defined(POPPLER_NEW_OBJECT_API)
445 -      obj = parser->getObj();
446 -#else
447 -      obj.free();
448 -      parser->getObj(&obj);
449 -#endif
450 -      if (obj.isEOF() || obj.isError()) {
451 -       gfree(key);
452 +      Object obj2;
453 +      _POPPLER_CALL(obj2, parser->getObj);
454 +      if (obj2.isEOF() || obj2.isError()) {
455 +        _POPPLER_FREE(obj);
456         break;
457        }
458 -#if defined(POPPLER_NEW_OBJECT_API)
459 -      dict.dictAdd(key, std::move(obj));
460 +      _POPPLER_DICTADD(dict, obj.getName(), obj2);
461 +      _POPPLER_FREE(obj);
462 +      _POPPLER_FREE(obj2);
463      }
464 -    obj = parser->getObj();
465 -#else
466 -      dict.dictAdd(key, &obj);
467 -    }
468 -    parser->getObj(&obj);
469 -#endif
470 +    _POPPLER_CALL(obj, parser->getObj);
471    }
472    if (obj.isEOF()) {
473      error(errSyntaxError, getPos(), "End of file in inline image");
474 diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h
475 index b27a29cfbf..17eb025468 100644
476 --- a/src/extension/internal/pdfinput/pdf-parser.h
477 +++ b/src/extension/internal/pdfinput/pdf-parser.h
478 @@ -9,6 +9,7 @@
479  #define PDF_PARSER_H
480  
481  #ifdef HAVE_POPPLER
482 +#include "poppler-transition-api.h"
483  
484  #ifdef USE_GCC_PRAGMAS
485  #pragma interface
486 @@ -128,11 +129,14 @@ public:
487  
488    // Constructor for regular output.
489    PdfParser(XRef *xrefA, SvgBuilder *builderA, int pageNum, int rotate,
490 -            Dict *resDict, PDFRectangle *box, PDFRectangle *cropBox);
491 +            Dict *resDict,
492 +            _POPPLER_CONST PDFRectangle *box,
493 +            _POPPLER_CONST PDFRectangle *cropBox);
494  
495    // Constructor for a sub-page object.
496    PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA,
497 -            Dict *resDict, PDFRectangle *box);
498 +            Dict *resDict,
499 +            _POPPLER_CONST PDFRectangle *box);
500  
501    virtual ~PdfParser();
502  
503 @@ -186,7 +190,7 @@ private:
504  
505    void go(GBool topLevel);
506    void execOp(Object *cmd, Object args[], int numArgs);
507 -  PdfOperator *findOp(char *name);
508 +  PdfOperator *findOp(const char *name);
509    GBool checkArg(Object *arg, TchkType type);
510    int getPos();
511  
512 @@ -257,7 +261,7 @@ private:
513                            double x2, double y2, GfxColor *color2,
514                            int nComps, int depth);
515    void doPatchMeshShFill(GfxPatchMeshShading *shading);
516 -  void fillPatch(GfxPatch *patch, int nComps, int depth);
517 +  void fillPatch(_POPPLER_CONST GfxPatch *patch, int nComps, int depth);
518    void doEndPath();
519  
520    // path clipping operators
521 diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
522 new file mode 100644
523 index 0000000000..898e64bf2b
524 --- /dev/null
525 +++ b/src/extension/internal/pdfinput/poppler-transition-api.h
526 @@ -0,0 +1,39 @@
527 +#ifndef SEEN_POPPLER_TRANSITION_API_H
528 +#define SEEN_POPPLER_TRANSITION_API_H
529 +
530 +#include <glib/poppler-features.h>
531 +
532 +#if POPPLER_CHECK_VERSION(0,70,0)
533 +#define _POPPLER_CONST const
534 +#else
535 +#define _POPPLER_CONST
536 +#endif
537 +
538 +#if POPPLER_CHECK_VERSION(0,69,0)
539 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(key, std::move(obj))
540 +#elif POPPLER_CHECK_VERSION(0,58,0)
541 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(copyString(key), std::move(obj))
542 +#else
543 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(copyString(key), &obj)
544 +#endif
545 +
546 +#if POPPLER_CHECK_VERSION(0,58,0)
547 +#define POPPLER_NEW_OBJECT_API
548 +#define _POPPLER_FREE(obj)
549 +#define _POPPLER_CALL(ret, func) (ret = func())
550 +#define _POPPLER_CALL_ARGS(ret, func, ...) (ret = func(__VA_ARGS__))
551 +#else
552 +#define _POPPLER_FREE(obj) (obj).free()
553 +#define _POPPLER_CALL(ret, func) (*func(&ret))
554 +#define _POPPLER_CALL_ARGS(ret, func, ...) (*func(__VA_ARGS__, &ret))
555 +#endif
556 +
557 +#if POPPLER_CHECK_VERSION(0, 29, 0)
558 +#define POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API
559 +#endif
560 +
561 +#if POPPLER_CHECK_VERSION(0, 25, 0)
562 +#define POPPLER_EVEN_NEWER_COLOR_SPACE_API
563 +#endif
564 +
565 +#endif
566 diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
567 index 9d0df7c04d..a59397a100 100644
568 --- a/src/extension/internal/pdfinput/svg-builder.cpp
569 +++ b/src/extension/internal/pdfinput/svg-builder.cpp
570 @@ -625,7 +625,7 @@ gchar *SvgBuilder::_createPattern(GfxPattern *pattern, GfxState *state, bool is_
571      if ( pattern != nullptr ) {
572          if ( pattern->getType() == 2 ) {  // Shading pattern
573              GfxShadingPattern *shading_pattern = static_cast<GfxShadingPattern *>(pattern);
574 -            double *ptm;
575 +            const double *ptm;
576              double m[6] = {1, 0, 0, 1, 0, 0};
577              double det;
578  
579 @@ -672,7 +672,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
580  
581      Inkscape::XML::Node *pattern_node = _xml_doc->createElement("svg:pattern");
582      // Set pattern transform matrix
583 -    double *p2u = tiling_pattern->getMatrix();
584 +    const double *p2u = tiling_pattern->getMatrix();
585      double m[6] = {1, 0, 0, 1, 0, 0};
586      double det;
587      det = _ttm[0] * _ttm[3] - _ttm[1] * _ttm[2];    // see LP Bug 1168908
588 @@ -698,7 +698,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
589      pattern_node->setAttribute("patternUnits", "userSpaceOnUse");
590      // Set pattern tiling
591      // FIXME: don't ignore XStep and YStep
592 -    double *bbox = tiling_pattern->getBBox();
593 +    const double *bbox = tiling_pattern->getBBox();
594      sp_repr_set_svg_double(pattern_node, "x", 0.0);
595      sp_repr_set_svg_double(pattern_node, "y", 0.0);
596      sp_repr_set_svg_double(pattern_node, "width", bbox[2] - bbox[0]);
597 @@ -751,7 +751,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
598   */
599  gchar *SvgBuilder::_createGradient(GfxShading *shading, double *matrix, bool for_shading) {
600      Inkscape::XML::Node *gradient;
601 -    Function *func;
602 +    _POPPLER_CONST Function *func;
603      int num_funcs;
604      bool extend0, extend1;
605  
606 @@ -865,7 +865,7 @@ static bool svgGetShadingColorRGB(GfxShading *shading, double offset, GfxRGB *re
607  
608  #define INT_EPSILON 8
609  bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
610 -                                   Function *func) {
611 +                                   _POPPLER_CONST Function *func) {
612      int type = func->getType();
613      if ( type == 0 || type == 2 ) {  // Sampled or exponential function
614          GfxRGB stop1, stop2;
615 @@ -877,9 +877,9 @@ bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *sh
616              _addStopToGradient(gradient, 1.0, &stop2, 1.0);
617          }
618      } else if ( type == 3 ) { // Stitching
619 -        StitchingFunction *stitchingFunc = static_cast<StitchingFunction*>(func);
620 -        double *bounds = stitchingFunc->getBounds();
621 -        double *encode = stitchingFunc->getEncode();
622 +        auto stitchingFunc = static_cast<_POPPLER_CONST StitchingFunction*>(func);
623 +        const double *bounds = stitchingFunc->getBounds();
624 +        const double *encode = stitchingFunc->getEncode();
625          int num_funcs = stitchingFunc->getNumFuncs();
626  
627          // Add stops from all the stitched functions
628 @@ -890,7 +890,7 @@ bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *sh
629              svgGetShadingColorRGB(shading, bounds[i + 1], &color);
630              // Add stops
631              if (stitchingFunc->getFunc(i)->getType() == 2) {    // process exponential fxn
632 -                double expE = (static_cast<ExponentialFunction*>(stitchingFunc->getFunc(i)))->getE();
633 +                double expE = (static_cast<_POPPLER_CONST ExponentialFunction*>(stitchingFunc->getFunc(i)))->getE();
634                  if (expE > 1.0) {
635                      expE = (bounds[i + 1] - bounds[i])/expE;    // approximate exponential as a single straight line at x=1
636                      if (encode[2*i] == 0) {    // normal sequence
637 @@ -1148,7 +1148,7 @@ void SvgBuilder::updateFont(GfxState *state) {
638      Inkscape::CSSOStringStream os_font_size;
639      double css_font_size = _font_scaling * state->getFontSize();
640      if ( font->getType() == fontType3 ) {
641 -        double *font_matrix = font->getFontMatrix();
642 +        const double *font_matrix = font->getFontMatrix();
643          if ( font_matrix[0] != 0.0 ) {
644              css_font_size *= font_matrix[3] / font_matrix[0];
645          }
646 @@ -1193,7 +1193,7 @@ void SvgBuilder::updateTextPosition(double tx, double ty) {
647  void SvgBuilder::updateTextMatrix(GfxState *state) {
648      _flushText();
649      // Update text matrix
650 -    double *text_matrix = state->getTextMat();
651 +    const double *text_matrix = state->getTextMat();
652      double w_scale = sqrt( text_matrix[0] * text_matrix[0] + text_matrix[2] * text_matrix[2] );
653      double h_scale = sqrt( text_matrix[1] * text_matrix[1] + text_matrix[3] * text_matrix[3] );
654      double max_scale;
655 diff --git a/src/extension/internal/pdfinput/svg-builder.h b/src/extension/internal/pdfinput/svg-builder.h
656 index 729cdc944c..7fdb0b5fcd 100644
657 --- a/src/extension/internal/pdfinput/svg-builder.h
658 +++ b/src/extension/internal/pdfinput/svg-builder.h
659 @@ -15,6 +15,7 @@
660  #endif
661  
662  #ifdef HAVE_POPPLER
663 +#include "poppler-transition-api.h"
664  
665  class SPDocument;
666  namespace Inkscape {
667 @@ -174,7 +175,7 @@ private:
668      void _addStopToGradient(Inkscape::XML::Node *gradient, double offset,
669                              GfxRGB *color, double opacity);
670      bool _addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
671 -                           Function *func);
672 +                           _POPPLER_CONST Function *func);
673      gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
674                                  bool is_stroke=false);
675      // Image/mask creation
676 -- 
677 2.18.1
678
679 From 0ab3449247d9356f57c75893e1ecfa195d43b681 Mon Sep 17 00:00:00 2001
680 From: Thomas Holder <thomas@thomas-holder.de>
681 Date: Sun, 30 Sep 2018 19:05:48 +0200
682 Subject: [PATCH] use poppler-transition-api instead of ifdefs
683
684 ---
685  .../internal/pdfinput/pdf-parser.cpp          | 906 ++++--------------
686  .../pdfinput/poppler-transition-api.h         |   4 +-
687  2 files changed, 208 insertions(+), 702 deletions(-)
688
689 diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
690 index 96313e1f19..9e4cd583fa 100644
691 --- a/src/extension/internal/pdfinput/pdf-parser.cpp
692 +++ b/src/extension/internal/pdfinput/pdf-parser.cpp
693 @@ -410,21 +410,13 @@ void PdfParser::parse(Object *obj, GBool topLevel) {
694  
695    if (obj->isArray()) {
696      for (int i = 0; i < obj->arrayGetLength(); ++i) {
697 -#if defined(POPPLER_NEW_OBJECT_API)
698 -      obj2 = obj->arrayGet(i);
699 -#else
700 -      obj->arrayGet(i, &obj2);
701 -#endif
702 +      _POPPLER_CALL_ARGS(obj2, obj->arrayGet, i);
703        if (!obj2.isStream()) {
704         error(errInternal, -1, "Weird page contents");
705 -#if !defined(POPPLER_NEW_OBJECT_API)
706 -       obj2.free();
707 -#endif
708 +       _POPPLER_FREE(obj2);
709         return;
710        }
711 -#if !defined(POPPLER_NEW_OBJECT_API)
712 -      obj2.free();
713 -#endif
714 +      _POPPLER_FREE(obj2);
715      }
716    } else if (!obj->isStream()) {
717         error(errInternal, -1, "Weird page contents");
718 @@ -443,11 +435,7 @@ void PdfParser::go(GBool /*topLevel*/)
719  
720    // scan a sequence of objects
721    int numArgs = 0;
722 -#if defined(POPPLER_NEW_OBJECT_API)
723 -  obj = parser->getObj();
724 -#else
725 -  parser->getObj(&obj);
726 -#endif
727 +  _POPPLER_CALL(obj, parser->getObj);
728    while (!obj.isEOF()) {
729  
730      // got a command - execute it
731 @@ -466,19 +454,15 @@ void PdfParser::go(GBool /*topLevel*/)
732        execOp(&obj, args, numArgs);
733  
734  #if !defined(POPPLER_NEW_OBJECT_API)
735 -      obj.free();
736 +      _POPPLER_FREE(obj);
737        for (int i = 0; i < numArgs; ++i)
738 -       args[i].free();
739 +       _POPPLER_FREE(args[i]);
740  #endif
741        numArgs = 0;
742  
743      // got an argument - save it
744      } else if (numArgs < maxArgs) {
745 -#if defined(POPPLER_NEW_OBJECT_API)
746        args[numArgs++] = std::move(obj);
747 -#else
748 -      args[numArgs++] = obj;
749 -#endif
750  
751      // too many arguments - something is wrong
752      } else {
753 @@ -489,21 +473,13 @@ void PdfParser::go(GBool /*topLevel*/)
754         printf("\n");
755         fflush(stdout);
756        }
757 -#if !defined(POPPLER_NEW_OBJECT_API)
758 -      obj.free();
759 -#endif
760 +      _POPPLER_FREE(obj);
761      }
762  
763      // grab the next object
764 -#if defined(POPPLER_NEW_OBJECT_API)
765 -    obj = parser->getObj();
766 -#else
767 -    parser->getObj(&obj);
768 -#endif
769 +    _POPPLER_CALL(obj, parser->getObj);
770    }
771 -#if !defined(POPPLER_NEW_OBJECT_API)
772 -  obj.free();
773 -#endif
774 +  _POPPLER_FREE(obj);
775  
776    // args at end with no command
777    if (numArgs > 0) {
778 @@ -519,7 +495,7 @@ void PdfParser::go(GBool /*topLevel*/)
779      }
780  #if !defined(POPPLER_NEW_OBJECT_API)
781      for (int i = 0; i < numArgs; ++i)
782 -      args[i].free();
783 +      _POPPLER_FREE(args[i]);
784  #endif
785    }
786  }
787 @@ -716,13 +692,9 @@ void PdfParser::opSetDash(Object args[], int /*numArgs*/)
788    if (length != 0) {
789      dash = (double *)gmallocn(length, sizeof(double));
790      for (int i = 0; i < length; ++i) {
791 -#if defined(POPPLER_NEW_OBJECT_API)
792 -      dash[i] = a->get(i).getNum();
793 -#else
794        Object obj;
795 -      dash[i] = a->get(i, &obj)->getNum();
796 -      obj.free();
797 -#endif
798 +      dash[i] = _POPPLER_CALL_ARGS_DEREF(obj, a->get, i).getNum();
799 +      _POPPLER_FREE(obj);
800      }
801    }
802    state->setLineDash(dash, length, args[1].getNum());
803 @@ -772,18 +744,13 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
804    GBool haveBackdropColor = gFalse;
805    GBool alpha = gFalse;
806  
807 -#if defined(POPPLER_NEW_OBJECT_API)
808 -  if ((obj1 = res->lookupGState(args[0].getName())).isNull()) {
809 -#else
810 -  if (!res->lookupGState(args[0].getName(), &obj1)) {
811 -#endif
812 +  _POPPLER_CALL_ARGS(obj1, res->lookupGState, args[0].getName());
813 +  if (obj1.isNull()) {
814      return;
815    }
816    if (!obj1.isDict()) {
817      error(errSyntaxError, getPos(), "ExtGState '{0:s}' is wrong type"), args[0].getName();
818 -#if !defined(POPPLER_NEW_OBJECT_API)
819 -    obj1.free();
820 -#endif
821 +    _POPPLER_FREE(obj1);
822      return;
823    }
824    if (printCommands) {
825 @@ -793,11 +760,7 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
826    }
827  
828    // transparency support: blend mode, fill/stroke opacity
829 -#if defined(POPPLER_NEW_OBJECT_API)
830 -  if (!((obj2 = obj1.dictLookup(const_cast<char*>("BM"))).isNull())) {
831 -#else
832 -  if (!obj1.dictLookup(const_cast<char*>("BM"), &obj2)->isNull()) {
833 -#endif
834 +  if (!_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "BM").isNull()) {
835      GfxBlendMode mode = gfxBlendNormal;
836      if (state->parseBlendMode(&obj2, &mode)) {
837        state->setBlendMode(mode);
838 @@ -805,71 +768,40 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
839        error(errSyntaxError, getPos(), "Invalid blend mode in ExtGState");
840      }
841    }
842 -#if defined(POPPLER_NEW_OBJECT_API)
843 -  if ((obj2 = obj1.dictLookup(const_cast<char*>("ca"))).isNum()) {
844 -#else
845 -  obj2.free();
846 -  if (obj1.dictLookup(const_cast<char*>("ca"), &obj2)->isNum()) {
847 -#endif
848 +  _POPPLER_FREE(obj2);
849 +  if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "ca").isNum()) {
850      state->setFillOpacity(obj2.getNum());
851    }
852 -#if defined(POPPLER_NEW_OBJECT_API)
853 -  if ((obj2 = obj1.dictLookup(const_cast<char*>("CA"))).isNum()) {
854 -#else
855 -  obj2.free();
856 -  if (obj1.dictLookup(const_cast<char*>("CA"), &obj2)->isNum()) {
857 -#endif
858 +  _POPPLER_FREE(obj2);
859 +  if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "CA").isNum()) {
860      state->setStrokeOpacity(obj2.getNum());
861    }
862 -#if !defined(POPPLER_NEW_OBJECT_API)
863 -  obj2.free();
864 -#endif
865 +  _POPPLER_FREE(obj2);
866  
867    // fill/stroke overprint
868    GBool haveFillOP = gFalse;
869 -#if defined(POPPLER_NEW_OBJECT_API)
870 -  if ((haveFillOP = (obj2 = obj1.dictLookup(const_cast<char*>("op"))).isBool())) {
871 -#else
872 -  if ((haveFillOP = (obj1.dictLookup(const_cast<char*>("op"), &obj2)->isBool()))) {
873 -#endif
874 +  if ((haveFillOP = _POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "op").isBool())) {
875      state->setFillOverprint(obj2.getBool());
876    }
877 -#if defined(POPPLER_NEW_OBJECT_API)
878 -  if ((obj2 = obj1.dictLookup(const_cast<char*>("OP"))).isBool()) {
879 -#else
880 -  obj2.free();
881 -  if (obj1.dictLookup(const_cast<char*>("OP"), &obj2)->isBool()) {
882 -#endif
883 +  _POPPLER_FREE(obj2);
884 +  if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "OP").isBool()) {
885      state->setStrokeOverprint(obj2.getBool());
886      if (!haveFillOP) {
887        state->setFillOverprint(obj2.getBool());
888      }
889    }
890 -#if !defined(POPPLER_NEW_OBJECT_API)
891 -  obj2.free();
892 -#endif
893 +  _POPPLER_FREE(obj2);
894  
895    // stroke adjust
896 -#if defined(POPPLER_NEW_OBJECT_API)
897 -  if ((obj2 = obj1.dictLookup(const_cast<char*>("SA"))).isBool()) {
898 -#else
899 -  if (obj1.dictLookup(const_cast<char*>("SA"), &obj2)->isBool()) {
900 -#endif
901 +  if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "SA").isBool()) {
902      state->setStrokeAdjust(obj2.getBool());
903    }
904 -#if !defined(POPPLER_NEW_OBJECT_API)
905 -  obj2.free();
906 -#endif
907 +  _POPPLER_FREE(obj2);
908  
909    // transfer function
910 -#if defined(POPPLER_NEW_OBJECT_API)
911 -  if ((obj2 = obj1.dictLookup(const_cast<char*>("TR2"))).isNull()) {
912 -    obj2 = obj1.dictLookup(const_cast<char*>("TR"));
913 -#else
914 -  if (obj1.dictLookup(const_cast<char*>("TR2"), &obj2)->isNull()) {
915 -    obj2.free();
916 -    obj1.dictLookup(const_cast<char*>("TR"), &obj2);
917 -#endif
918 +  if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "TR2").isNull()) {
919 +    _POPPLER_FREE(obj2);
920 +    _POPPLER_CALL_ARGS(obj2, obj1.dictLookup, "TR");
921    }
922    if (obj2.isName(const_cast<char*>("Default")) ||
923        obj2.isName(const_cast<char*>("Identity"))) {
924 @@ -878,15 +810,9 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
925    } else if (obj2.isArray() && obj2.arrayGetLength() == 4) {
926      int pos = 4;
927      for (int i = 0; i < 4; ++i) {
928 -#if defined(POPPLER_NEW_OBJECT_API)
929 -      obj3 = obj2.arrayGet(i);
930 -#else
931 -      obj2.arrayGet(i, &obj3);
932 -#endif
933 +      _POPPLER_CALL_ARGS(obj3, obj2.arrayGet, i);
934        funcs[i] = Function::parse(&obj3);
935 -#if !defined(POPPLER_NEW_OBJECT_API)
936 -      obj3.free();
937 -#endif
938 +      _POPPLER_FREE(obj3);
939        if (!funcs[i]) {
940         pos = i;
941         break;
942 @@ -903,37 +829,21 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
943    } else if (!obj2.isNull()) {
944      error(errSyntaxError, getPos(), "Invalid transfer function in ExtGState");
945    }
946 -#if !defined(POPPLER_NEW_OBJECT_API)
947 -  obj2.free();
948 -#endif
949 +  _POPPLER_FREE(obj2);
950  
951    // soft mask
952 -#if defined(POPPLER_NEW_OBJECT_API)
953 -  if (!((obj2 = obj1.dictLookup(const_cast<char*>("SMask"))).isNull())) {
954 -#else
955 -  if (!obj1.dictLookup(const_cast<char*>("SMask"), &obj2)->isNull()) {
956 -#endif
957 +  if (!_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "SMask").isNull()) {
958      if (obj2.isName(const_cast<char*>("None"))) {
959        builder->clearSoftMask(state);
960      } else if (obj2.isDict()) {
961 -#if defined(POPPLER_NEW_OBJECT_API)
962 -      if ((obj3 = obj2.dictLookup(const_cast<char*>("S"))).isName(const_cast<char*>("Alpha"))) {
963 -#else
964 -      if (obj2.dictLookup(const_cast<char*>("S"), &obj3)->isName(const_cast<char*>("Alpha"))) {
965 -#endif
966 +      if (_POPPLER_CALL_ARGS_DEREF(obj3, obj2.dictLookup, "S").isName("Alpha")) {
967         alpha = gTrue;
968        } else { // "Luminosity"
969         alpha = gFalse;
970        }
971 -#if !defined(POPPLER_NEW_OBJECT_API)
972 -      obj3.free();
973 -#endif
974 +      _POPPLER_FREE(obj3);
975        funcs[0] = NULL;
976 -#if defined(POPPLER_NEW_OBJECT_API)
977 -      if (!((obj3 = obj2.dictLookup(const_cast<char*>("TR"))).isNull())) {
978 -#else
979 -      if (!obj2.dictLookup(const_cast<char*>("TR"), &obj3)->isNull()) {
980 -#endif
981 +      if (!_POPPLER_CALL_ARGS_DEREF(obj3, obj2.dictLookup, "TR").isNull()) {
982         funcs[0] = Function::parse(&obj3);
983         if (funcs[0]->getInputSize() != 1 ||
984             funcs[0]->getOutputSize() != 1) {
985 @@ -942,45 +852,26 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
986           funcs[0] = NULL;
987         }
988        }
989 -#if defined(POPPLER_NEW_OBJECT_API)
990 -      if ((haveBackdropColor = (obj3 = obj2.dictLookup(const_cast<char*>("BC"))).isArray())) {
991 -#else
992 -      obj3.free();
993 -      if ((haveBackdropColor = obj2.dictLookup(const_cast<char*>("BC"), &obj3)->isArray())) {
994 -#endif
995 +      _POPPLER_FREE(obj3);
996 +      if ((haveBackdropColor = _POPPLER_CALL_ARGS_DEREF(obj3, obj2.dictLookup, "BC").isArray())) {
997         for (int i = 0; i < gfxColorMaxComps; ++i) {
998           backdropColor.c[i] = 0;
999         }
1000         for (int i = 0; i < obj3.arrayGetLength() && i < gfxColorMaxComps; ++i) {
1001 -#if defined(POPPLER_NEW_OBJECT_API)
1002 -         obj4 = obj3.arrayGet(i);
1003 -#else
1004 -         obj3.arrayGet(i, &obj4);
1005 -#endif
1006 +          _POPPLER_CALL_ARGS(obj4, obj3.arrayGet, i);
1007           if (obj4.isNum()) {
1008             backdropColor.c[i] = dblToCol(obj4.getNum());
1009           }
1010 -#if !defined(POPPLER_NEW_OBJECT_API)
1011 -         obj4.free();
1012 -#endif
1013 +         _POPPLER_FREE(obj4);
1014         }
1015        }
1016 -#if defined(POPPLER_NEW_OBJECT_API)
1017 -      if ((obj3 = obj2.dictLookup(const_cast<char*>("G"))).isStream()) {
1018 -       if ((obj4 = obj3.streamGetDict()->lookup(const_cast<char*>("Group"))).isDict()) {
1019 -#else
1020 -      obj3.free();
1021 -      if (obj2.dictLookup(const_cast<char*>("G"), &obj3)->isStream()) {
1022 -       if (obj3.streamGetDict()->lookup(const_cast<char*>("Group"), &obj4)->isDict()) {
1023 -#endif
1024 +      _POPPLER_FREE(obj3);
1025 +      if (_POPPLER_CALL_ARGS_DEREF(obj3, obj2.dictLookup, "G").isStream()) {
1026 +       if (_POPPLER_CALL_ARGS_DEREF(obj4, obj3.streamGetDict()->lookup, "Group").isDict()) {
1027           GfxColorSpace *blendingColorSpace = 0;
1028           GBool isolated = gFalse;
1029           GBool knockout = gFalse;
1030 -#if defined(POPPLER_NEW_OBJECT_API)
1031 -         if (!((obj5 = obj4.dictLookup(const_cast<char*>("CS"))).isNull())) {
1032 -#else
1033 -         if (!obj4.dictLookup(const_cast<char*>("CS"), &obj5)->isNull()) {
1034 -#endif
1035 +         if (!_POPPLER_CALL_ARGS_DEREF(obj5, obj4.dictLookup, "CS").isNull()) {
1036  #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API)
1037             blendingColorSpace = GfxColorSpace::parse(NULL, &obj5, NULL, NULL);
1038  #elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API)
1039 @@ -989,25 +880,15 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
1040             blendingColorSpace = GfxColorSpace::parse(&obj5, NULL, NULL);
1041  #endif
1042           }
1043 -#if defined(POPPLER_NEW_OBJECT_API)
1044 -         if ((obj5 = obj4.dictLookup(const_cast<char*>("I"))).isBool()) {
1045 -#else
1046 -         obj5.free();
1047 -         if (obj4.dictLookup(const_cast<char*>("I"), &obj5)->isBool()) {
1048 -#endif
1049 +          _POPPLER_FREE(obj5);
1050 +         if (_POPPLER_CALL_ARGS_DEREF(obj5, obj4.dictLookup, "I").isBool()) {
1051             isolated = obj5.getBool();
1052           }
1053 -#if defined(POPPLER_NEW_OBJECT_API)
1054 -         if ((obj5 = obj4.dictLookup(const_cast<char*>("K"))).isBool()) {
1055 -#else
1056 -         obj5.free();
1057 -         if (obj4.dictLookup(const_cast<char*>("K"), &obj5)->isBool()) {
1058 -#endif
1059 +          _POPPLER_FREE(obj5);
1060 +         if (_POPPLER_CALL_ARGS_DEREF(obj5, obj4.dictLookup, "K").isBool()) {
1061             knockout = obj5.getBool();
1062           }
1063 -#if !defined(POPPLER_NEW_OBJECT_API)
1064 -         obj5.free();
1065 -#endif
1066 +         _POPPLER_FREE(obj5);
1067           if (!haveBackdropColor) {
1068             if (blendingColorSpace) {
1069               blendingColorSpace->getDefaultColor(&backdropColor);
1070 @@ -1026,24 +907,18 @@ void PdfParser::opSetExtGState(Object args[], int /*numArgs*/)
1071         } else {
1072           error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group");
1073         }
1074 -#if !defined(POPPLER_NEW_OBJECT_API)
1075 -       obj4.free();
1076 -#endif
1077 +       _POPPLER_FREE(obj4);
1078        } else {
1079         error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState - missing group");
1080        }
1081 -#if !defined(POPPLER_NEW_OBJECT_API)
1082 -      obj3.free();
1083 -#endif
1084 +      _POPPLER_FREE(obj3);
1085      } else if (!obj2.isNull()) {
1086        error(errSyntaxError, getPos(), "Invalid soft mask in ExtGState");
1087      }
1088    }
1089 -#if !defined(POPPLER_NEW_OBJECT_API)
1090 -  obj2.free();
1091 +  _POPPLER_FREE(obj2);
1092  
1093 -  obj1.free();
1094 -#endif
1095 +  _POPPLER_FREE(obj1);
1096  }
1097  
1098  void PdfParser::doSoftMask(Object *str, GBool alpha,
1099 @@ -1064,79 +939,43 @@ void PdfParser::doSoftMask(Object *str, GBool alpha,
1100    dict = str->streamGetDict();
1101  
1102    // check form type
1103 -#if defined(POPPLER_NEW_OBJECT_API)
1104 -  obj1 = dict->lookup(const_cast<char*>("FormType"));
1105 -#else
1106 -  dict->lookup(const_cast<char*>("FormType"), &obj1);
1107 -#endif
1108 +  _POPPLER_CALL_ARGS(obj1, dict->lookup, "FormType");
1109    if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) {
1110      error(errSyntaxError, getPos(), "Unknown form type");
1111    }
1112 -#if !defined(POPPLER_NEW_OBJECT_API)
1113 -  obj1.free();
1114 -#endif
1115 +  _POPPLER_FREE(obj1);
1116  
1117    // get bounding box
1118 -#if defined(POPPLER_NEW_OBJECT_API)
1119 -  obj1 = dict->lookup(const_cast<char*>("BBox"));
1120 -#else
1121 -  dict->lookup(const_cast<char*>("BBox"), &obj1);
1122 -#endif
1123 +  _POPPLER_CALL_ARGS(obj1, dict->lookup, "BBox");
1124    if (!obj1.isArray()) {
1125 -#if !defined(POPPLER_NEW_OBJECT_API)
1126 -    obj1.free();
1127 -#endif
1128 +    _POPPLER_FREE(obj1);
1129      error(errSyntaxError, getPos(), "Bad form bounding box");
1130      return;
1131    }
1132    for (i = 0; i < 4; ++i) {
1133 -#if defined(POPPLER_NEW_OBJECT_API)
1134 -    obj2 = obj1.arrayGet(i);
1135 -#else
1136 -    obj1.arrayGet(i, &obj2);
1137 -#endif
1138 +    _POPPLER_CALL_ARGS(obj2, obj1.arrayGet, i);
1139      bbox[i] = obj2.getNum();
1140 -#if defined(POPPLER_NEW_OBJECT_API)
1141 -  }
1142 -#else
1143 -    obj2.free();
1144 +    _POPPLER_FREE(obj2);
1145    }
1146 -  obj1.free();
1147 -#endif
1148 +  _POPPLER_FREE(obj1);
1149  
1150    // get matrix
1151 -#if defined(POPPLER_NEW_OBJECT_API)
1152 -  obj1 = dict->lookup(const_cast<char*>("Matrix"));
1153 -#else
1154 -  dict->lookup(const_cast<char*>("Matrix"), &obj1);
1155 -#endif
1156 +  _POPPLER_CALL_ARGS(obj1, dict->lookup, "Matrix");
1157    if (obj1.isArray()) {
1158      for (i = 0; i < 6; ++i) {
1159 -#if defined(POPPLER_NEW_OBJECT_API)
1160 -      obj2 = obj1.arrayGet(i);
1161 -#else
1162 -      obj1.arrayGet(i, &obj2);
1163 -#endif
1164 +      _POPPLER_CALL_ARGS(obj2, obj1.arrayGet, i);
1165        m[i] = obj2.getNum();
1166 -#if !defined(POPPLER_NEW_OBJECT_API)
1167 -      obj2.free();
1168 -#endif
1169 +      _POPPLER_FREE(obj2);
1170      }
1171    } else {
1172      m[0] = 1; m[1] = 0;
1173      m[2] = 0; m[3] = 1;
1174      m[4] = 0; m[5] = 0;
1175    }
1176 -#if !defined(POPPLER_NEW_OBJECT_API)
1177 -  obj1.free();
1178 -#endif
1179 +  _POPPLER_FREE(obj1);
1180  
1181    // get resources
1182 -#if defined(POPPLER_NEW_OBJECT_API)
1183 -  obj1 = dict->lookup(const_cast<char*>("Resources"));
1184 -#else
1185 -  dict->lookup(const_cast<char*>("Resources"), &obj1);
1186 -#endif
1187 +  _POPPLER_CALL_ARGS(obj1, dict->lookup, "Resources");
1188    resDict = obj1.isDict() ? obj1.getDict() : (Dict *)NULL;
1189  
1190    // draw it
1191 @@ -1149,9 +988,7 @@ void PdfParser::doSoftMask(Object *str, GBool alpha,
1192    if (blendingColorSpace) {
1193      delete blendingColorSpace;
1194    }
1195 -#if !defined(POPPLER_NEW_OBJECT_API)
1196 -  obj1.free();
1197 -#endif
1198 +  _POPPLER_FREE(obj1);
1199  }
1200  
1201  void PdfParser::opSetRenderingIntent(Object /*args*/[], int /*numArgs*/)
1202 @@ -1248,11 +1085,7 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/)
1203    Object obj;
1204  
1205    state->setFillPattern(NULL);
1206 -#if defined(POPPLER_NEW_OBJECT_API)
1207 -  obj = res->lookupColorSpace(args[0].getName());
1208 -#else
1209 -  res->lookupColorSpace(args[0].getName(), &obj);
1210 -#endif
1211 +  _POPPLER_CALL_ARGS(obj, res->lookupColorSpace, args[0].getName());
1212  
1213    GfxColorSpace *colorSpace = NULL;
1214  #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API)
1215 @@ -1274,9 +1107,7 @@ void PdfParser::opSetFillColorSpace(Object args[], int /*numArgs*/)
1216      colorSpace = GfxColorSpace::parse(&obj, NULL);
1217    }
1218  #endif
1219 -#if !defined(POPPLER_NEW_OBJECT_API)
1220 -  obj.free();
1221 -#endif
1222 +  _POPPLER_FREE(obj);
1223    if (colorSpace) {
1224    GfxColor color;
1225      state->setFillColorSpace(colorSpace);
1226 @@ -1295,11 +1126,7 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/)
1227    GfxColorSpace *colorSpace = NULL;
1228  
1229    state->setStrokePattern(NULL);
1230 -#if defined(POPPLER_NEW_OBJECT_API)
1231 -  obj = res->lookupColorSpace(args[0].getName());
1232 -#else
1233 -  res->lookupColorSpace(args[0].getName(), &obj);
1234 -#endif
1235 +  _POPPLER_CALL_ARGS(obj, res->lookupColorSpace, args[0].getName());
1236  #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API)
1237    if (obj.isNull()) {
1238      colorSpace = GfxColorSpace::parse(NULL, &args[0], NULL, NULL);
1239 @@ -1319,9 +1146,7 @@ void PdfParser::opSetStrokeColorSpace(Object args[], int /*numArgs*/)
1240      colorSpace = GfxColorSpace::parse(&obj, NULL);
1241    }
1242  #endif
1243 -#if !defined(POPPLER_NEW_OBJECT_API)
1244 -  obj.free();
1245 -#endif
1246 +  _POPPLER_FREE(obj);
1247    if (colorSpace) {
1248      GfxColor color;
1249      state->setStrokeColorSpace(colorSpace);
1250 @@ -2551,11 +2376,7 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/)
1251    wMode = state->getFont()->getWMode();
1252    a = args[0].getArray();
1253    for (int i = 0; i < a->getLength(); ++i) {
1254 -#if defined(POPPLER_NEW_OBJECT_API)
1255 -    obj = a->get(i);
1256 -#else
1257 -    a->get(i, &obj);
1258 -#endif
1259 +    _POPPLER_CALL_ARGS(obj, a->get, i);
1260      if (obj.isNum()) {
1261        // this uses the absolute value of the font size to match
1262        // Acrobat's behavior
1263 @@ -2572,9 +2393,7 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/)
1264      } else {
1265        error(errSyntaxError, getPos(), "Element of show/space array must be number or string");
1266      }
1267 -#if !defined(POPPLER_NEW_OBJECT_API)
1268 -    obj.free();
1269 -#endif
1270 +    _POPPLER_FREE(obj);
1271    }
1272  }
1273  
1274 @@ -2655,11 +2474,7 @@ void PdfParser::doShowText(GooString *s) {
1275        //out->updateCTM(state, 1, 0, 0, 1, 0, 0);
1276        if (false){ /*!out->beginType3Char(state, curX + riseX, curY + riseY, tdx, tdy,
1277                                code, u, uLen)) {*/
1278 -#if defined(POPPLER_NEW_OBJECT_API)
1279 -       charProc = ((Gfx8BitFont *)font)->getCharProc(code);
1280 -#else
1281 -       ((Gfx8BitFont *)font)->getCharProc(code, &charProc);
1282 -#endif
1283 +        _POPPLER_CALL_ARGS(charProc, ((Gfx8BitFont *)font)->getCharProc, code);
1284         if ((resDict = ((Gfx8BitFont *)font)->getResources())) {
1285           pushResources(resDict);
1286         }
1287 @@ -2672,9 +2487,7 @@ void PdfParser::doShowText(GooString *s) {
1288         if (resDict) {
1289           popResources();
1290         }
1291 -#if !defined(POPPLER_NEW_OBJECT_API)
1292 -       charProc.free();
1293 -#endif
1294 +       _POPPLER_FREE(charProc);
1295        }
1296        restoreState();
1297        // GfxState::restore() does *not* restore the current position,
1298 @@ -2741,43 +2554,24 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/)
1299  #else
1300    char *name = args[0].getName();
1301  #endif
1302 -#if defined(POPPLER_NEW_OBJECT_API)
1303 -  if ((obj1 = res->lookupXObject(name)).isNull()) {
1304 -#else
1305 -  if (!res->lookupXObject(name, &obj1)) {
1306 -#endif
1307 +  _POPPLER_CALL_ARGS(obj1, res->lookupXObject, name);
1308 +  if (obj1.isNull()) {
1309      return;
1310    }
1311    if (!obj1.isStream()) {
1312      error(errSyntaxError, getPos(), "XObject '{0:s}' is wrong type", name);
1313 -#if !defined(POPPLER_NEW_OBJECT_API)
1314 -    obj1.free();
1315 -#endif
1316 +    _POPPLER_FREE(obj1);
1317      return;
1318    }
1319 -#if defined(POPPLER_NEW_OBJECT_API)
1320 -  obj2 = obj1.streamGetDict()->lookup(const_cast<char*>("Subtype"));
1321 -#else
1322 -  obj1.streamGetDict()->lookup(const_cast<char*>("Subtype"), &obj2);
1323 -#endif
1324 +  _POPPLER_CALL_ARGS(obj2, obj1.streamGetDict()->lookup, "Subtype");
1325    if (obj2.isName(const_cast<char*>("Image"))) {
1326 -#if defined(POPPLER_NEW_OBJECT_API)
1327 -    refObj = res->lookupXObjectNF(name);
1328 -#else
1329 -    res->lookupXObjectNF(name, &refObj);
1330 -#endif
1331 +    _POPPLER_CALL_ARGS(refObj, res->lookupXObjectNF, name);
1332      doImage(&refObj, obj1.getStream(), gFalse);
1333 -#if !defined(POPPLER_NEW_OBJECT_API)
1334 -    refObj.free();
1335 -#endif
1336 +    _POPPLER_FREE(refObj);
1337    } else if (obj2.isName(const_cast<char*>("Form"))) {
1338      doForm(&obj1);
1339    } else if (obj2.isName(const_cast<char*>("PS"))) {
1340 -#if defined(POPPLER_NEW_OBJECT_API)
1341 -    obj3 = obj1.streamGetDict()->lookup(const_cast<char*>("Level1"));
1342 -#else
1343 -    obj1.streamGetDict()->lookup(const_cast<char*>("Level1"), &obj3);
1344 -#endif
1345 +    _POPPLER_CALL_ARGS(obj3, obj1.streamGetDict()->lookup, "Level1");
1346  /*    out->psXObject(obj1.getStream(),
1347                    obj3.isStream() ? obj3.getStream() : (Stream *)NULL);*/
1348    } else if (obj2.isName()) {
1349 @@ -2785,10 +2579,8 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/)
1350    } else {
1351      error(errSyntaxError, getPos(), "XObject subtype is missing or wrong type");
1352    }
1353 -#if !defined(POPPLER_NEW_OBJECT_API)
1354 -  obj2.free();
1355 -  obj1.free();
1356 -#endif
1357 +  _POPPLER_FREE(obj2);
1358 +  _POPPLER_FREE(obj1);
1359  }
1360  
1361  void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1362 @@ -2815,18 +2607,10 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1363      dict = str->getDict();
1364      
1365      // get size
1366 -#if defined(POPPLER_NEW_OBJECT_API)
1367 -    obj1 = dict->lookup(const_cast<char*>("Width"));
1368 -#else
1369 -    dict->lookup(const_cast<char*>("Width"), &obj1);
1370 -#endif
1371 +    _POPPLER_CALL_ARGS(obj1, dict->lookup, "Width");
1372      if (obj1.isNull()) {
1373 -#if defined(POPPLER_NEW_OBJECT_API)
1374 -        obj1 = dict->lookup(const_cast<char*>("W"));
1375 -#else
1376 -        obj1.free();
1377 -        dict->lookup(const_cast<char*>("W"), &obj1);
1378 -#endif
1379 +        _POPPLER_FREE(obj1);
1380 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "W");
1381      }
1382      if (obj1.isInt()){
1383          width = obj1.getInt();
1384 @@ -2837,19 +2621,11 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1385      else {
1386          goto err2;
1387      }
1388 -#if defined(POPPLER_NEW_OBJECT_API)
1389 -    obj1 = dict->lookup(const_cast<char*>("Height"));
1390 -#else
1391 -    obj1.free();
1392 -    dict->lookup(const_cast<char*>("Height"), &obj1);
1393 -#endif
1394 +    _POPPLER_FREE(obj1);
1395 +    _POPPLER_CALL_ARGS(obj1, dict->lookup, "Height");
1396      if (obj1.isNull()) {
1397 -#if defined(POPPLER_NEW_OBJECT_API)
1398 -        obj1 = dict->lookup(const_cast<char*>("H"));
1399 -#else
1400 -        obj1.free();
1401 -        dict->lookup(const_cast<char*>("H"), &obj1);
1402 -#endif
1403 +        _POPPLER_FREE(obj1);
1404 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "H");
1405      }
1406      if (obj1.isInt()) {
1407          height = obj1.getInt();
1408 @@ -2860,46 +2636,26 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1409      else {
1410          goto err2;
1411      }
1412 -#if !defined(POPPLER_NEW_OBJECT_API)
1413 -    obj1.free();
1414 -#endif
1415 +    _POPPLER_FREE(obj1);
1416      
1417      // image interpolation
1418 -#if defined(POPPLER_NEW_OBJECT_API)
1419 -    obj1 = dict->lookup("Interpolate");
1420 -#else
1421 -    dict->lookup("Interpolate", &obj1);
1422 -#endif
1423 +    _POPPLER_CALL_ARGS(obj1, dict->lookup, "Interpolate");
1424      if (obj1.isNull()) {
1425 -#if defined(POPPLER_NEW_OBJECT_API)
1426 -      obj1 = dict->lookup("I");
1427 -#else
1428 -      obj1.free();
1429 -      dict->lookup("I", &obj1);
1430 -#endif
1431 +      _POPPLER_FREE(obj1);
1432 +      _POPPLER_CALL_ARGS(obj1, dict->lookup, "I");
1433      }
1434      if (obj1.isBool())
1435        interpolate = obj1.getBool();
1436      else
1437        interpolate = gFalse;
1438 -#if !defined(POPPLER_NEW_OBJECT_API)
1439 -    obj1.free();
1440 -#endif
1441 +    _POPPLER_FREE(obj1);
1442      maskInterpolate = gFalse;
1443  
1444      // image or mask?
1445 -#if defined(POPPLER_NEW_OBJECT_API)
1446 -    obj1 = dict->lookup(const_cast<char*>("ImageMask"));
1447 -#else
1448 -    dict->lookup(const_cast<char*>("ImageMask"), &obj1);
1449 -#endif
1450 +    _POPPLER_CALL_ARGS(obj1, dict->lookup, "ImageMask");
1451      if (obj1.isNull()) {
1452 -#if defined(POPPLER_NEW_OBJECT_API)
1453 -        obj1 = dict->lookup(const_cast<char*>("IM"));
1454 -#else
1455 -        obj1.free();
1456 -        dict->lookup(const_cast<char*>("IM"), &obj1);
1457 -#endif
1458 +        _POPPLER_FREE(obj1);
1459 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "IM");
1460      }
1461      mask = gFalse;
1462      if (obj1.isBool()) {
1463 @@ -2908,24 +2664,14 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1464      else if (!obj1.isNull()) {
1465          goto err2;
1466      }
1467 -#if !defined(POPPLER_NEW_OBJECT_API)
1468 -    obj1.free();
1469 -#endif
1470 +    _POPPLER_FREE(obj1);
1471      
1472      // bit depth
1473      if (bits == 0) {
1474 -#if defined(POPPLER_NEW_OBJECT_API)
1475 -        obj1 = dict->lookup(const_cast<char*>("BitsPerComponent"));
1476 -#else
1477 -        dict->lookup(const_cast<char*>("BitsPerComponent"), &obj1);
1478 -#endif
1479 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "BitsPerComponent");
1480          if (obj1.isNull()) {
1481 -#if defined(POPPLER_NEW_OBJECT_API)
1482 -            obj1 = dict->lookup(const_cast<char*>("BPC"));
1483 -#else
1484 -            obj1.free();
1485 -            dict->lookup(const_cast<char*>("BPC"), &obj1);
1486 -#endif
1487 +            _POPPLER_FREE(obj1);
1488 +            _POPPLER_CALL_ARGS(obj1, dict->lookup, "BPC");
1489          }
1490          if (obj1.isInt()) {
1491              bits = obj1.getInt();
1492 @@ -2934,9 +2680,7 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1493          } else {
1494              goto err2;
1495          }
1496 -#if !defined(POPPLER_NEW_OBJECT_API)
1497 -        obj1.free();
1498 -#endif
1499 +        _POPPLER_FREE(obj1);
1500      }
1501      
1502      // display a mask
1503 @@ -2946,37 +2690,21 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1504              goto err1;
1505          }
1506          invert = gFalse;
1507 -#if defined(POPPLER_NEW_OBJECT_API)
1508 -        obj1 = dict->lookup(const_cast<char*>("Decode"));
1509 -#else
1510 -        dict->lookup(const_cast<char*>("Decode"), &obj1);
1511 -#endif
1512 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "Decode");
1513          if (obj1.isNull()) {
1514 -#if defined(POPPLER_NEW_OBJECT_API)
1515 -            obj1 = dict->lookup(const_cast<char*>("D"));
1516 -#else
1517 -            obj1.free();
1518 -            dict->lookup(const_cast<char*>("D"), &obj1);
1519 -#endif
1520 +            _POPPLER_FREE(obj1);
1521 +            _POPPLER_CALL_ARGS(obj1, dict->lookup, "D");
1522          }
1523          if (obj1.isArray()) {
1524 -#if defined(POPPLER_NEW_OBJECT_API)
1525 -            obj2 = obj1.arrayGet(0);
1526 -#else
1527 -            obj1.arrayGet(0, &obj2);
1528 -#endif
1529 +            _POPPLER_CALL_ARGS(obj2, obj1.arrayGet, 0);
1530              if (obj2.isInt() && obj2.getInt() == 1) {
1531                  invert = gTrue;
1532              }
1533 -#if !defined(POPPLER_NEW_OBJECT_API)
1534 -            obj2.free();
1535 -#endif
1536 +            _POPPLER_FREE(obj2);
1537          } else if (!obj1.isNull()) {
1538              goto err2;
1539          }
1540 -#if !defined(POPPLER_NEW_OBJECT_API)
1541 -        obj1.free();
1542 -#endif
1543 +        _POPPLER_FREE(obj1);
1544          
1545          // draw it
1546          builder->addImageMask(state, str, width, height, invert, interpolate);
1547 @@ -2984,36 +2712,18 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1548      } else {
1549          // get color space and color map
1550          GfxColorSpace *colorSpace;
1551 -#if defined(POPPLER_NEW_OBJECT_API)
1552 -        obj1 = dict->lookup(const_cast<char*>("ColorSpace"));
1553 -#else
1554 -        dict->lookup(const_cast<char*>("ColorSpace"), &obj1);
1555 -#endif
1556 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "ColorSpace");
1557          if (obj1.isNull()) {
1558 -#if defined(POPPLER_NEW_OBJECT_API)
1559 -            obj1 = dict->lookup(const_cast<char*>("CS"));
1560 -#else
1561 -            obj1.free();
1562 -            dict->lookup(const_cast<char*>("CS"), &obj1);
1563 -#endif
1564 +            _POPPLER_FREE(obj1);
1565 +            _POPPLER_CALL_ARGS(obj1, dict->lookup, "CS");
1566          }
1567          if (obj1.isName()) {
1568 -#if defined(POPPLER_NEW_OBJECT_API)
1569 -            obj2 = res->lookupColorSpace(obj1.getName());
1570 -#else
1571 -            res->lookupColorSpace(obj1.getName(), &obj2);
1572 -#endif
1573 +            _POPPLER_CALL_ARGS(obj2, res->lookupColorSpace, obj1.getName());
1574              if (!obj2.isNull()) {
1575 -#if defined(POPPLER_NEW_OBJECT_API)
1576 +                   _POPPLER_FREE(obj1);
1577                      obj1 = std::move(obj2);
1578 -#else
1579 -                   obj1.free();
1580 -                   obj1 = obj2;
1581 -#endif
1582              } else {
1583 -#if !defined(POPPLER_NEW_OBJECT_API)
1584 -                   obj2.free();
1585 -#endif
1586 +                   _POPPLER_FREE(obj2);
1587              }
1588          }
1589          if (!obj1.isNull()) {
1590 @@ -3033,29 +2743,17 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1591          } else {
1592              colorSpace = NULL;
1593          }
1594 -#if !defined(POPPLER_NEW_OBJECT_API)
1595 -        obj1.free();
1596 -#endif
1597 +        _POPPLER_FREE(obj1);
1598          if (!colorSpace) {
1599              goto err1;
1600          }
1601 -#if defined(POPPLER_NEW_OBJECT_API)
1602 -        obj1 = dict->lookup(const_cast<char*>("Decode"));
1603 -#else
1604 -        dict->lookup(const_cast<char*>("Decode"), &obj1);
1605 -#endif
1606 +        _POPPLER_CALL_ARGS(obj1, dict->lookup, "Decode");
1607          if (obj1.isNull()) {
1608 -#if defined(POPPLER_NEW_OBJECT_API)
1609 -            obj1 = dict->lookup(const_cast<char*>("D"));
1610 -#else
1611 -            obj1.free();
1612 -            dict->lookup(const_cast<char*>("D"), &obj1);
1613 -#endif
1614 +            _POPPLER_FREE(obj1);
1615 +            _POPPLER_CALL_ARGS(obj1, dict->lookup, "D");
1616          }
1617          GfxImageColorMap *colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
1618 -#if !defined(POPPLER_NEW_OBJECT_API)
1619 -        obj1.free();
1620 -#endif
1621 +        _POPPLER_FREE(obj1);
1622          if (!colorMap->isOk()) {
1623              delete colorMap;
1624              goto err1;
1625 @@ -3069,13 +2767,8 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1626          int maskHeight = 0;
1627          maskInvert = gFalse;
1628          GfxImageColorMap *maskColorMap = NULL;
1629 -#if defined(POPPLER_NEW_OBJECT_API)
1630 -        maskObj = dict->lookup(const_cast<char*>("Mask"));
1631 -        smaskObj = dict->lookup(const_cast<char*>("SMask"));
1632 -#else
1633 -        dict->lookup(const_cast<char*>("Mask"), &maskObj);
1634 -        dict->lookup(const_cast<char*>("SMask"), &smaskObj);
1635 -#endif
1636 +        _POPPLER_CALL_ARGS(maskObj, dict->lookup, "Mask");
1637 +        _POPPLER_CALL_ARGS(smaskObj, dict->lookup, "SMask");
1638          Dict* maskDict;
1639          if (smaskObj.isStream()) {
1640              // soft mask
1641 @@ -3084,108 +2777,58 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1642              }
1643              maskStr = smaskObj.getStream();
1644              maskDict = smaskObj.streamGetDict();
1645 -#if defined(POPPLER_NEW_OBJECT_API)
1646 -            obj1 = maskDict->lookup(const_cast<char*>("Width"));
1647 -#else
1648 -            maskDict->lookup(const_cast<char*>("Width"), &obj1);
1649 -#endif
1650 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Width");
1651              if (obj1.isNull()) {
1652 -#if defined(POPPLER_NEW_OBJECT_API)
1653 -                   obj1 = maskDict->lookup(const_cast<char*>("W"));
1654 -#else
1655 -                   obj1.free();
1656 -                   maskDict->lookup(const_cast<char*>("W"), &obj1);
1657 -#endif
1658 +                    _POPPLER_FREE(obj1);
1659 +                   _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "W");
1660              }
1661              if (!obj1.isInt()) {
1662                     goto err2;
1663              }
1664              maskWidth = obj1.getInt();
1665 -#if defined(POPPLER_NEW_OBJECT_API)
1666 -            obj1 = maskDict->lookup(const_cast<char*>("Height"));
1667 -#else
1668 -            obj1.free();
1669 -            maskDict->lookup(const_cast<char*>("Height"), &obj1);
1670 -#endif
1671 +            _POPPLER_FREE(obj1);
1672 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Height");
1673              if (obj1.isNull()) {
1674 -#if defined(POPPLER_NEW_OBJECT_API)
1675 -                    obj1 = maskDict->lookup(const_cast<char*>("H"));
1676 -#else
1677 -                   obj1.free();
1678 -                   maskDict->lookup(const_cast<char*>("H"), &obj1);
1679 -#endif
1680 +                   _POPPLER_FREE(obj1);
1681 +                    _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "H");
1682              }
1683              if (!obj1.isInt()) {
1684                     goto err2;
1685              }
1686              maskHeight = obj1.getInt();
1687 -#if defined(POPPLER_NEW_OBJECT_API)
1688 -            obj1 = maskDict->lookup(const_cast<char*>("BitsPerComponent"));
1689 -#else
1690 -            obj1.free();
1691 -            maskDict->lookup(const_cast<char*>("BitsPerComponent"), &obj1);
1692 -#endif
1693 +            _POPPLER_FREE(obj1);
1694 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "BitsPerComponent");
1695              if (obj1.isNull()) {
1696 -#if defined(POPPLER_NEW_OBJECT_API)
1697 -                    obj1 = maskDict->lookup(const_cast<char*>("BPC"));
1698 -#else
1699 -                   obj1.free();
1700 -                   maskDict->lookup(const_cast<char*>("BPC"), &obj1);
1701 -#endif
1702 +                    _POPPLER_FREE(obj1);
1703 +                    _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "BPC");
1704              }
1705              if (!obj1.isInt()) {
1706                     goto err2;
1707              }
1708              int maskBits = obj1.getInt();
1709 -#if defined(POPPLER_NEW_OBJECT_API)
1710 -            obj1 = maskDict->lookup(const_cast<char*>("Interpolate"));
1711 -#else
1712 -            obj1.free();
1713 -           maskDict->lookup("Interpolate", &obj1);
1714 -#endif
1715 +            _POPPLER_FREE(obj1);
1716 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Interpolate");
1717             if (obj1.isNull()) {
1718 -#if defined(POPPLER_NEW_OBJECT_API)
1719 -              obj1 = maskDict->lookup(const_cast<char*>("I"));
1720 -#else
1721 -             obj1.free();
1722 -             maskDict->lookup("I", &obj1);
1723 -#endif
1724 +             _POPPLER_FREE(obj1);
1725 +              _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "I");
1726             }
1727             if (obj1.isBool())
1728               maskInterpolate = obj1.getBool();
1729             else
1730               maskInterpolate = gFalse;
1731 -#if defined(POPPLER_NEW_OBJECT_API)
1732 -            obj1 = maskDict->lookup(const_cast<char*>("ColorSpace"));
1733 -#else
1734 -           obj1.free();
1735 -            maskDict->lookup(const_cast<char*>("ColorSpace"), &obj1);
1736 -#endif
1737 +           _POPPLER_FREE(obj1);
1738 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "ColorSpace");
1739              if (obj1.isNull()) {
1740 -#if defined(POPPLER_NEW_OBJECT_API)
1741 -                    obj1 = maskDict->lookup(const_cast<char*>("CS"));
1742 -#else
1743 -                   obj1.free();
1744 -                   maskDict->lookup(const_cast<char*>("CS"), &obj1);
1745 -#endif
1746 +                   _POPPLER_FREE(obj1);
1747 +                    _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "CS");
1748              }
1749              if (obj1.isName()) {
1750 -#if defined(POPPLER_NEW_OBJECT_API)
1751 -                   obj2 = res->lookupColorSpace(obj1.getName());
1752 -#else
1753 -                   res->lookupColorSpace(obj1.getName(), &obj2);
1754 -#endif
1755 +                   _POPPLER_CALL_ARGS(obj2, res->lookupColorSpace, obj1.getName());
1756                     if (!obj2.isNull()) {
1757 -#if defined(POPPLER_NEW_OBJECT_API)
1758 +                       _POPPLER_FREE(obj1);
1759                          obj1 = std::move(obj2);
1760 -#else
1761 -                       obj1.free();
1762 -                   obj1 = obj2;
1763 -#endif
1764                     } else {
1765 -#if !defined(POPPLER_NEW_OBJECT_API)
1766 -                       obj2.free();
1767 -#endif
1768 +                       _POPPLER_FREE(obj2);
1769                     }
1770              }
1771  #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API)
1772 @@ -3195,29 +2838,17 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1773  #else
1774              GfxColorSpace *maskColorSpace = GfxColorSpace::parse(&obj1, NULL);
1775  #endif
1776 -#if !defined(POPPLER_NEW_OBJECT_API)
1777 -            obj1.free();
1778 -#endif
1779 +            _POPPLER_FREE(obj1);
1780              if (!maskColorSpace || maskColorSpace->getMode() != csDeviceGray) {
1781                  goto err1;
1782              }
1783 -#if defined(POPPLER_NEW_OBJECT_API)
1784 -            obj1 = maskDict->lookup(const_cast<char*>("Decode"));
1785 -#else
1786 -            maskDict->lookup(const_cast<char*>("Decode"), &obj1);
1787 -#endif
1788 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Decode");
1789              if (obj1.isNull()) {
1790 -#if defined(POPPLER_NEW_OBJECT_API)
1791 -                obj1 = maskDict->lookup(const_cast<char*>("D"));
1792 -#else
1793 -                   obj1.free();
1794 -               maskDict->lookup(const_cast<char*>("D"), &obj1);
1795 -#endif
1796 +                _POPPLER_FREE(obj1);
1797 +                _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "D");
1798              }
1799              maskColorMap = new GfxImageColorMap(maskBits, &obj1, maskColorSpace);
1800 -#if !defined(POPPLER_NEW_OBJECT_API)
1801 -            obj1.free();
1802 -#endif
1803 +            _POPPLER_FREE(obj1);
1804              if (!maskColorMap->isOk()) {
1805                  delete maskColorMap;
1806                  goto err1;
1807 @@ -3228,15 +2859,9 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1808              // color key mask
1809              int i;
1810              for (i = 0; i < maskObj.arrayGetLength() && i < 2*gfxColorMaxComps; ++i) {
1811 -#if defined(POPPLER_NEW_OBJECT_API)
1812 -                obj1 = maskObj.arrayGet(i);
1813 -#else
1814 -                maskObj.arrayGet(i, &obj1);
1815 -#endif
1816 +                _POPPLER_CALL_ARGS(obj1, maskObj.arrayGet, i);
1817                  maskColors[i] = obj1.getInt();
1818 -#if !defined(POPPLER_NEW_OBJECT_API)
1819 -                obj1.free();
1820 -#endif
1821 +                _POPPLER_FREE(obj1);
1822              }
1823                haveColorKeyMask = gTrue;
1824          } else if (maskObj.isStream()) {
1825 @@ -3246,111 +2871,61 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1826              }
1827              maskStr = maskObj.getStream();
1828              maskDict = maskObj.streamGetDict();
1829 -#if defined(POPPLER_NEW_OBJECT_API)
1830 -            obj1 = maskDict->lookup(const_cast<char*>("Width"));
1831 -#else
1832 -            maskDict->lookup(const_cast<char*>("Width"), &obj1);
1833 -#endif
1834 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Width");
1835              if (obj1.isNull()) {
1836 -#if defined(POPPLER_NEW_OBJECT_API)
1837 -                obj1 = maskDict->lookup(const_cast<char*>("W"));
1838 -#else
1839 -                obj1.free();
1840 -                maskDict->lookup(const_cast<char*>("W"), &obj1);
1841 -#endif
1842 +                _POPPLER_FREE(obj1);
1843 +                _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "W");
1844              }
1845              if (!obj1.isInt()) {
1846                  goto err2;
1847              }
1848              maskWidth = obj1.getInt();
1849 -#if defined(POPPLER_NEW_OBJECT_API)
1850 -            obj1 = maskDict->lookup(const_cast<char*>("Height"));
1851 -#else
1852 -            obj1.free();
1853 -            maskDict->lookup(const_cast<char*>("Height"), &obj1);
1854 -#endif
1855 +            _POPPLER_FREE(obj1);
1856 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Height");
1857              if (obj1.isNull()) {
1858 -#if defined(POPPLER_NEW_OBJECT_API)
1859 -                obj1 = maskDict->lookup(const_cast<char*>("H"));
1860 -#else
1861 -                obj1.free();
1862 -                maskDict->lookup(const_cast<char*>("H"), &obj1);
1863 -#endif
1864 +                _POPPLER_FREE(obj1);
1865 +                _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "H");
1866              }
1867              if (!obj1.isInt()) {
1868                  goto err2;
1869              }
1870              maskHeight = obj1.getInt();
1871 -#if defined(POPPLER_NEW_OBJECT_API)
1872 -            obj1 = maskDict->lookup(const_cast<char*>("ImageMask"));
1873 -#else
1874 -            obj1.free();
1875 -            maskDict->lookup(const_cast<char*>("ImageMask"), &obj1);
1876 -#endif
1877 +            _POPPLER_FREE(obj1);
1878 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "ImageMask");
1879              if (obj1.isNull()) {
1880 -#if defined(POPPLER_NEW_OBJECT_API)
1881 -                obj1 = maskDict->lookup(const_cast<char*>("IM"));
1882 -#else
1883 -                obj1.free();
1884 -                maskDict->lookup(const_cast<char*>("IM"), &obj1);
1885 -#endif
1886 +                _POPPLER_FREE(obj1);
1887 +                _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "IM");
1888              }
1889              if (!obj1.isBool() || !obj1.getBool()) {
1890                  goto err2;
1891              }
1892 -#if defined(POPPLER_NEW_OBJECT_API)
1893 -            obj1 = maskDict->lookup("Interpolate");
1894 -#else
1895 -            obj1.free();
1896 -           maskDict->lookup("Interpolate", &obj1);
1897 -#endif
1898 +            _POPPLER_FREE(obj1);
1899 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Interpolate");
1900             if (obj1.isNull()) {
1901 -#if defined(POPPLER_NEW_OBJECT_API)
1902 -             obj1 = maskDict->lookup("I");
1903 -#else
1904 -             obj1.free();
1905 -             maskDict->lookup("I", &obj1);
1906 -#endif
1907 +             _POPPLER_FREE(obj1);
1908 +             _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "I");
1909             }
1910             if (obj1.isBool())
1911               maskInterpolate = obj1.getBool();
1912             else
1913               maskInterpolate = gFalse;
1914 -#if !defined(POPPLER_NEW_OBJECT_API)
1915 -           obj1.free();
1916 -#endif
1917 +           _POPPLER_FREE(obj1);
1918              maskInvert = gFalse;
1919 -#if defined(POPPLER_NEW_OBJECT_API)
1920 -            obj1 = maskDict->lookup(const_cast<char*>("Decode"));
1921 -#else
1922 -            maskDict->lookup(const_cast<char*>("Decode"), &obj1);
1923 -#endif
1924 +            _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "Decode");
1925              if (obj1.isNull()) {
1926 -#if defined(POPPLER_NEW_OBJECT_API)
1927 -                obj1 = maskDict->lookup(const_cast<char*>("D"));
1928 -#else
1929 -                obj1.free();
1930 -                maskDict->lookup(const_cast<char*>("D"), &obj1);
1931 -#endif
1932 +                _POPPLER_FREE(obj1);
1933 +                _POPPLER_CALL_ARGS(obj1, maskDict->lookup, "D");
1934              }
1935              if (obj1.isArray()) {
1936 -#if defined(POPPLER_NEW_OBJECT_API)
1937 -                obj2 = obj1.arrayGet(0);
1938 -#else
1939 -                obj1.arrayGet(0, &obj2);
1940 -#endif
1941 +                _POPPLER_CALL_ARGS(obj2, obj1.arrayGet, 0);
1942                  if (obj2.isInt() && obj2.getInt() == 1) {
1943                      maskInvert = gTrue;
1944                  }
1945 -#if !defined(POPPLER_NEW_OBJECT_API)
1946 -                obj2.free();
1947 -#endif
1948 +                _POPPLER_FREE(obj2);
1949              } else if (!obj1.isNull()) {
1950                  goto err2;
1951              }
1952 -#if !defined(POPPLER_NEW_OBJECT_API)
1953 -            obj1.free();
1954 -#endif
1955 +            _POPPLER_FREE(obj1);
1956              haveExplicitMask = gTrue;
1957          }
1958          
1959 @@ -3368,18 +2943,14 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg)
1960          }
1961          delete colorMap;
1962          
1963 -#if !defined(POPPLER_NEW_OBJECT_API)
1964 -        maskObj.free();
1965 -        smaskObj.free();
1966 -#endif
1967 +        _POPPLER_FREE(maskObj);
1968 +        _POPPLER_FREE(smaskObj);
1969      }
1970  
1971      return;
1972  
1973   err2:
1974 -#if !defined(POPPLER_NEW_OBJECT_API)
1975 -    obj1.free();
1976 -#endif
1977 +    _POPPLER_FREE(obj1);
1978   err1:
1979      error(errSyntaxError, getPos(), "Bad image parameters");
1980  }
1981 @@ -3404,97 +2975,52 @@ void PdfParser::doForm(Object *str) {
1982    dict = str->streamGetDict();
1983  
1984    // check form type
1985 -#if defined(POPPLER_NEW_OBJECT_API)
1986 -  obj1 = dict->lookup(const_cast<char*>("FormType"));
1987 -#else
1988 -  dict->lookup(const_cast<char*>("FormType"), &obj1);
1989 -#endif
1990 +  _POPPLER_CALL_ARGS(obj1, dict->lookup, "FormType");
1991    if (!(obj1.isNull() || (obj1.isInt() && obj1.getInt() == 1))) {
1992      error(errSyntaxError, getPos(), "Unknown form type");
1993    }
1994 -#if !defined(POPPLER_NEW_OBJECT_API)
1995 -  obj1.free();
1996 -#endif
1997 +  _POPPLER_FREE(obj1);
1998  
1999    // get bounding box
2000 -#if defined(POPPLER_NEW_OBJECT_API)
2001 -  bboxObj = dict->lookup(const_cast<char*>("BBox"));
2002 -#else
2003 -  dict->lookup(const_cast<char*>("BBox"), &bboxObj);
2004 -#endif
2005 +  _POPPLER_CALL_ARGS(bboxObj, dict->lookup, "BBox");
2006    if (!bboxObj.isArray()) {
2007 -#if !defined(POPPLER_NEW_OBJECT_API)
2008 -    bboxObj.free();
2009 -#endif
2010 +    _POPPLER_FREE(bboxObj);
2011      error(errSyntaxError, getPos(), "Bad form bounding box");
2012      return;
2013    }
2014    for (i = 0; i < 4; ++i) {
2015 -#if defined(POPPLER_NEW_OBJECT_API)
2016 -    obj1 = bboxObj.arrayGet(i);
2017 -#else
2018 -    bboxObj.arrayGet(i, &obj1);
2019 -#endif
2020 +    _POPPLER_CALL_ARGS(obj1, bboxObj.arrayGet, i);
2021      bbox[i] = obj1.getNum();
2022 -#if defined(POPPLER_NEW_OBJECT_API)
2023 -  }
2024 -#else
2025 -    obj1.free();
2026 +    _POPPLER_FREE(obj1);
2027    }
2028 -  bboxObj.free();
2029 -#endif
2030 +  _POPPLER_FREE(bboxObj);
2031  
2032    // get matrix
2033 -#if defined(POPPLER_NEW_OBJECT_API)
2034 -  matrixObj = dict->lookup(const_cast<char*>("Matrix"));
2035 -#else
2036 -  dict->lookup(const_cast<char*>("Matrix"), &matrixObj);
2037 -#endif
2038 +  _POPPLER_CALL_ARGS(matrixObj, dict->lookup, "Matrix");
2039    if (matrixObj.isArray()) {
2040      for (i = 0; i < 6; ++i) {
2041 -#if defined(POPPLER_NEW_OBJECT_API)
2042 -      obj1 = matrixObj.arrayGet(i);
2043 -#else
2044 -      matrixObj.arrayGet(i, &obj1);
2045 -#endif
2046 +      _POPPLER_CALL_ARGS(obj1, matrixObj.arrayGet, i);
2047        m[i] = obj1.getNum();
2048 -#if !defined(POPPLER_NEW_OBJECT_API)
2049 -      obj1.free();
2050 -#endif
2051 +      _POPPLER_FREE(obj1);
2052      }
2053    } else {
2054      m[0] = 1; m[1] = 0;
2055      m[2] = 0; m[3] = 1;
2056      m[4] = 0; m[5] = 0;
2057    }
2058 -#if !defined(POPPLER_NEW_OBJECT_API)
2059 -  matrixObj.free();
2060 -#endif
2061 +  _POPPLER_FREE(matrixObj);
2062  
2063    // get resources
2064 -#if defined(POPPLER_NEW_OBJECT_API)
2065 -  resObj = dict->lookup(const_cast<char*>("Resources"));
2066 -#else
2067 -  dict->lookup(const_cast<char*>("Resources"), &resObj);
2068 -#endif
2069 +  _POPPLER_CALL_ARGS(resObj, dict->lookup, "Resources");
2070    resDict = resObj.isDict() ? resObj.getDict() : (Dict *)NULL;
2071  
2072    // check for a transparency group
2073    transpGroup = isolated = knockout = gFalse;
2074    blendingColorSpace = NULL;
2075 -#if defined(POPPLER_NEW_OBJECT_API)
2076 -  if ((obj1 = dict->lookup(const_cast<char*>("Group"))).isDict()) {
2077 -    if ((obj2 = obj1.dictLookup(const_cast<char*>("S"))).isName(const_cast<char*>("Transparency"))) {
2078 -#else
2079 -  if (dict->lookup(const_cast<char*>("Group"), &obj1)->isDict()) {
2080 -    if (obj1.dictLookup(const_cast<char*>("S"), &obj2)->isName(const_cast<char*>("Transparency"))) {
2081 -#endif
2082 +  if (_POPPLER_CALL_ARGS_DEREF(obj1, dict->lookup, "Group").isDict()) {
2083 +    if (_POPPLER_CALL_ARGS_DEREF(obj2, obj1.dictLookup, "S").isName("Transparency")) {
2084        transpGroup = gTrue;
2085 -#if defined(POPPLER_NEW_OBJECT_API)
2086 -      if (!((obj3 = obj1.dictLookup(const_cast<char*>("CS"))).isNull())) {
2087 -#else
2088 -      if (!obj1.dictLookup(const_cast<char*>("CS"), &obj3)->isNull()) {
2089 -#endif
2090 +      if (!_POPPLER_CALL_ARGS_DEREF(obj3, obj1.dictLookup, "CS").isNull()) {
2091  #if defined(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API)
2092         blendingColorSpace = GfxColorSpace::parse(NULL, &obj3, NULL, NULL);
2093  #elif defined(POPPLER_EVEN_NEWER_COLOR_SPACE_API)
2094 @@ -3503,32 +3029,19 @@ void PdfParser::doForm(Object *str) {
2095         blendingColorSpace = GfxColorSpace::parse(&obj3, NULL);
2096  #endif
2097        }
2098 -#if defined(POPPLER_NEW_OBJECT_API)
2099 -      if ((obj3 = obj1.dictLookup(const_cast<char*>("I"))).isBool()) {
2100 -#else
2101 -      obj3.free();
2102 -      if (obj1.dictLookup(const_cast<char*>("I"), &obj3)->isBool()) {
2103 -#endif
2104 +      _POPPLER_FREE(obj3);
2105 +      if (_POPPLER_CALL_ARGS_DEREF(obj3, obj1.dictLookup, "I").isBool()) {
2106         isolated = obj3.getBool();
2107        }
2108 -#if defined(POPPLER_NEW_OBJECT_API)
2109 -      if ((obj3 = obj1.dictLookup(const_cast<char*>("K"))).isBool()) {
2110 -#else
2111 -      obj3.free();
2112 -      if (obj1.dictLookup(const_cast<char*>("K"), &obj3)->isBool()) {
2113 -#endif
2114 +      _POPPLER_FREE(obj3);
2115 +      if (_POPPLER_CALL_ARGS_DEREF(obj3, obj1.dictLookup, "K").isBool()) {
2116         knockout = obj3.getBool();
2117        }
2118 -#if defined(POPPLER_NEW_OBJECT_API)
2119 +      _POPPLER_FREE(obj3);
2120      }
2121 +    _POPPLER_FREE(obj2);
2122    }
2123 -#else
2124 -      obj3.free();
2125 -    }
2126 -    obj2.free();
2127 -  }
2128 -  obj1.free();
2129 -#endif
2130 +  _POPPLER_FREE(obj1);
2131  
2132    // draw it
2133    ++formDepth;
2134 @@ -3539,9 +3052,7 @@ void PdfParser::doForm(Object *str) {
2135    if (blendingColorSpace) {
2136      delete blendingColorSpace;
2137    }
2138 -#if !defined(POPPLER_NEW_OBJECT_API)
2139 -  resObj.free();
2140 -#endif
2141 +  _POPPLER_FREE(resObj);
2142  }
2143  
2144  void PdfParser::doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
2145 @@ -3670,17 +3181,14 @@ Stream *PdfParser::buildImageStream() {
2146    // build dictionary
2147  #if defined(POPPLER_NEW_OBJECT_API)
2148    dict = Object(new Dict(xref));
2149 -  obj = parser->getObj();
2150  #else
2151    dict.initDict(xref);
2152 -  parser->getObj(&obj);
2153  #endif
2154 +  _POPPLER_CALL(obj, parser->getObj);
2155    while (!obj.isCmd(const_cast<char*>("ID")) && !obj.isEOF()) {
2156      if (!obj.isName()) {
2157        error(errSyntaxError, getPos(), "Inline image dictionary key must be a name object");
2158 -#if !defined(POPPLER_NEW_OBJECT_API)
2159 -      obj.free();
2160 -#endif
2161 +      _POPPLER_FREE(obj);
2162      } else {
2163        Object obj2;
2164        _POPPLER_CALL(obj2, parser->getObj);
2165 @@ -3696,15 +3204,11 @@ Stream *PdfParser::buildImageStream() {
2166    }
2167    if (obj.isEOF()) {
2168      error(errSyntaxError, getPos(), "End of file in inline image");
2169 -#if !defined(POPPLER_NEW_OBJECT_API)
2170 -    obj.free();
2171 -    dict.free();
2172 -#endif
2173 +    _POPPLER_FREE(obj);
2174 +    _POPPLER_FREE(dict);
2175      return NULL;
2176    }
2177 -#if !defined(POPPLER_NEW_OBJECT_API)
2178 -  obj.free();
2179 -#endif
2180 +  _POPPLER_FREE(obj);
2181  
2182    // make stream
2183  #if defined(POPPLER_NEW_OBJECT_API)
2184 diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
2185 index 898e64bf2b..6ed911b04b 100644
2186 --- a/src/extension/internal/pdfinput/poppler-transition-api.h
2187 +++ b/src/extension/internal/pdfinput/poppler-transition-api.h
2188 @@ -22,10 +22,12 @@
2189  #define _POPPLER_FREE(obj)
2190  #define _POPPLER_CALL(ret, func) (ret = func())
2191  #define _POPPLER_CALL_ARGS(ret, func, ...) (ret = func(__VA_ARGS__))
2192 +#define _POPPLER_CALL_ARGS_DEREF _POPPLER_CALL_ARGS
2193  #else
2194  #define _POPPLER_FREE(obj) (obj).free()
2195  #define _POPPLER_CALL(ret, func) (*func(&ret))
2196 -#define _POPPLER_CALL_ARGS(ret, func, ...) (*func(__VA_ARGS__, &ret))
2197 +#define _POPPLER_CALL_ARGS(ret, func, ...) (func(__VA_ARGS__, &ret))
2198 +#define _POPPLER_CALL_ARGS_DEREF(...) (*_POPPLER_CALL_ARGS(__VA_ARGS__))
2199  #endif
2200  
2201  #if POPPLER_CHECK_VERSION(0, 29, 0)
2202 -- 
2203 2.18.1
2204
2205 From d047859d90cef3784e2d13e40887a70d8d517897 Mon Sep 17 00:00:00 2001
2206 From: =?UTF-8?q?Bart=C5=82omiej=20Szczepaniak?=
2207  <szczepaniak.bartek@gmail.com>
2208 Date: Tue, 6 Nov 2018 07:41:40 +0000
2209 Subject: [PATCH] fix poppler 0.71.0 build.
2210
2211 ---
2212  src/extension/internal/pdfinput/poppler-transition-api.h | 6 ++++++
2213  1 file changed, 6 insertions(+)
2214
2215 diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
2216 index 6ed911b04b..4437052593 100644
2217 --- a/src/extension/internal/pdfinput/poppler-transition-api.h
2218 +++ b/src/extension/internal/pdfinput/poppler-transition-api.h
2219 @@ -3,6 +3,12 @@
2220  
2221  #include <glib/poppler-features.h>
2222  
2223 +#if POPPLER_CHECK_VERSION(0,71,0)
2224 +typedef bool GBool;
2225 +#define gTrue true
2226 +#define gFalse false
2227 +#endif
2228 +
2229  #if POPPLER_CHECK_VERSION(0,70,0)
2230  #define _POPPLER_CONST const
2231  #else
2232 -- 
2233 2.18.1
2234
2235 From b3d59cc8106da3bf6020a6c47eeb3b8a7bbae1a9 Mon Sep 17 00:00:00 2001
2236 From: Thomas Holder <thomas@thomas-holder.de>
2237 Date: Sun, 9 Dec 2018 10:21:34 +0100
2238 Subject: [PATCH] fix poppler 0.72.0 build
2239
2240 ---
2241  src/extension/internal/pdfinput/pdf-parser.h             | 1 -
2242  src/extension/internal/pdfinput/poppler-transition-api.h | 4 ++++
2243  2 files changed, 4 insertions(+), 1 deletion(-)
2244
2245 diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h
2246 index 2d4441a22c..31c84d51bb 100644
2247 --- a/src/extension/internal/pdfinput/pdf-parser.h
2248 +++ b/src/extension/internal/pdfinput/pdf-parser.h
2249 @@ -37,7 +37,6 @@ namespace Inkscape {
2250  using Inkscape::Extension::Internal::SvgBuilder;
2251  
2252  #include "glib/poppler-features.h"
2253 -#include "goo/gtypes.h"
2254  #include "Object.h"
2255  
2256  class GooString;
2257 diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
2258 index 5141bf8a73..61a15083a0 100644
2259 --- a/src/extension/internal/pdfinput/poppler-transition-api.h
2260 +++ b/src/extension/internal/pdfinput/poppler-transition-api.h
2261 @@ -14,6 +14,10 @@
2262  
2263  #include <glib/poppler-features.h>
2264  
2265 +#if POPPLER_CHECK_VERSION(0, 72, 0)
2266 +#define getCString c_str
2267 +#endif
2268 +
2269  #if POPPLER_CHECK_VERSION(0,71,0)
2270  typedef bool GBool;
2271  #define gTrue true
2272 -- 
2273 2.18.1
2274
This page took 0.413262 seconds and 2 git commands to generate.