1 Fix compatibility with Poppler >= 0.69.
3 This is a combination of these upstream commits:
4 https://gitlab.com/inkscape/inkscape/commit/722e121361d0f784083d10e897155b7d4e44e515
5 https://gitlab.com/inkscape/inkscape/commit/402c0274420fe39fd2f3393bc7d8d8879d436358
7 ...with slight adjustments for the 0.92.3 release tarball.
9 diff --git a/CMakeScripts/DefineDependsandFlags.cmake b/CMakeScripts/DefineDependsandFlags.cmake
10 --- a/CMakeScripts/DefineDependsandFlags.cmake
11 +++ b/CMakeScripts/DefineDependsandFlags.cmake
12 @@ -116,18 +116,6 @@ if(ENABLE_POPPLER)
13 set(HAVE_POPPLER_GLIB ON)
16 - if(POPPLER_VERSION VERSION_GREATER "0.26.0" OR
17 - POPPLER_VERSION VERSION_EQUAL "0.26.0")
18 - set(POPPLER_EVEN_NEWER_COLOR_SPACE_API ON)
20 - if(POPPLER_VERSION VERSION_GREATER "0.29.0" OR
21 - POPPLER_VERSION VERSION_EQUAL "0.29.0")
22 - set(POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API ON)
24 - if(POPPLER_VERSION VERSION_GREATER "0.58.0" OR
25 - POPPLER_VERSION VERSION_EQUAL "0.58.0")
26 - set(POPPLER_NEW_OBJECT_API ON)
29 set(ENABLE_POPPLER_CAIRO OFF)
31 diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp
32 --- a/src/extension/internal/pdfinput/pdf-input.cpp
33 +++ b/src/extension/internal/pdfinput/pdf-input.cpp
34 @@ -793,7 +793,7 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) {
35 dlg->getImportSettings(prefs);
37 // Apply crop settings
38 - PDFRectangle *clipToBox = NULL;
39 + _POPPLER_CONST PDFRectangle *clipToBox = NULL;
41 sp_repr_get_double(prefs, "cropTo", &crop_setting);
43 diff --git a/src/extension/internal/pdfinput/pdf-input.h b/src/extension/internal/pdfinput/pdf-input.h
44 --- a/src/extension/internal/pdfinput/pdf-input.h
45 +++ b/src/extension/internal/pdfinput/pdf-input.h
50 +#include "poppler-transition-api.h"
52 #include <gtkmm/dialog.h>
54 diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
55 --- a/src/extension/internal/pdfinput/pdf-parser.cpp
56 +++ b/src/extension/internal/pdfinput/pdf-parser.cpp
57 @@ -36,6 +36,7 @@ extern "C" {
58 #include "pdf-parser.h"
59 #include "util/units.h"
61 +#include "glib/poppler-features.h"
63 #include "goo/GooString.h"
64 #include "GlobalParams.h"
65 @@ -294,8 +295,8 @@ PdfParser::PdfParser(XRef *xrefA,
70 - PDFRectangle *cropBox) :
71 + _POPPLER_CONST PDFRectangle *box,
72 + _POPPLER_CONST PDFRectangle *cropBox) :
76 @@ -317,7 +318,7 @@ PdfParser::PdfParser(XRef *xrefA,
77 builder->setDocumentSize(Inkscape::Util::Quantity::convert(state->getPageWidth(), "pt", "px"),
78 Inkscape::Util::Quantity::convert(state->getPageHeight(), "pt", "px"));
80 - double *ctm = state->getCTM();
81 + const double *ctm = state->getCTM();
83 for (int i = 0; i < 6; ++i) {
84 baseMatrix[i] = ctm[i];
85 @@ -352,7 +353,7 @@ PdfParser::PdfParser(XRef *xrefA,
86 PdfParser::PdfParser(XRef *xrefA,
87 Inkscape::Extension::Internal::SvgBuilder *builderA,
89 - PDFRectangle *box) :
90 + _POPPLER_CONST PDFRectangle *box) :
94 @@ -571,7 +572,7 @@ const char *PdfParser::getPreviousOperator(unsigned int look_back) {
96 void PdfParser::execOp(Object *cmd, Object args[], int numArgs) {
103 @@ -619,7 +620,7 @@ void PdfParser::execOp(Object *cmd, Object args[], int numArgs) {
104 (this->*op->func)(argPtr, numArgs);
107 -PdfOperator* PdfParser::findOp(char *name) {
108 +PdfOperator* PdfParser::findOp(const char *name) {
112 @@ -1751,7 +1752,7 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat,
113 GBool stroke, GBool eoFill) {
116 - double *ctm, *btm, *ptm;
117 + const double *ctm, *btm, *ptm;
118 double m[6], ictm[6], m1[6];
119 double xMin, yMin, xMax, yMax;
121 @@ -1993,7 +1994,7 @@ void PdfParser::doFunctionShFill1(GfxFunctionShading *shading,
122 GfxColor color0M, color1M, colorM0, colorM1, colorMM;
124 double functionColorDelta = colorDeltas[pdfFunctionShading-1];
126 + const double *matrix;
130 @@ -2173,7 +2174,7 @@ void PdfParser::doPatchMeshShFill(GfxPatchMeshShading *shading) {
134 -void PdfParser::fillPatch(GfxPatch *patch, int nComps, int depth) {
135 +void PdfParser::fillPatch(_POPPLER_CONST GfxPatch *patch, int nComps, int depth) {
136 GfxPatch patch00 = blankPatch();
137 GfxPatch patch01 = blankPatch();
138 GfxPatch patch10 = blankPatch();
139 @@ -2581,7 +2582,11 @@ void PdfParser::opShowSpaceText(Object args[], int /*numArgs*/)
143 +#if POPPLER_CHECK_VERSION(0,64,0)
144 void PdfParser::doShowText(const GooString *s) {
146 +void PdfParser::doShowText(GooString *s) {
151 @@ -2590,11 +2595,15 @@ void PdfParser::doShowText(const GooString *s) {
152 double x, y, dx, dy, tdx, tdy;
153 double originX, originY, tOriginX, tOriginY;
154 double oldCTM[6], newCTM[6];
160 +#if POPPLER_CHECK_VERSION(0,64,0)
167 font = state->getFont();
168 @@ -2630,7 +2639,7 @@ void PdfParser::doShowText(const GooString *s) {
169 double lineX = state->getLineX();
170 double lineY = state->getLineY();
172 - p = g_strdup(s->getCString());
173 + p = s->getCString();
174 len = s->getLength();
176 n = font->getNextChar(p, len, &code,
177 @@ -2685,7 +2694,7 @@ void PdfParser::doShowText(const GooString *s) {
180 state->textTransformDelta(0, state->getRise(), &riseX, &riseY);
181 - p = g_strdup(s->getCString());
182 + p = s->getCString();
183 len = s->getLength();
185 n = font->getNextChar(p, len, &code,
186 @@ -2731,7 +2740,11 @@ void PdfParser::opXObject(Object args[], int /*numArgs*/)
188 Object obj1, obj2, obj3, refObj;
190 - char *name = g_strdup(args[0].getName());
191 +#if POPPLER_CHECK_VERSION(0,64,0)
192 + const char *name = args[0].getName();
194 + char *name = args[0].getName();
196 #if defined(POPPLER_NEW_OBJECT_API)
197 if ((obj1 = res->lookupXObject(name)).isNull()) {
199 @@ -3656,7 +3669,6 @@ void PdfParser::opBeginImage(Object /*args*/[], int /*numArgs*/)
200 Stream *PdfParser::buildImageStream() {
207 @@ -3674,26 +3686,17 @@ Stream *PdfParser::buildImageStream() {
211 - key = copyString(obj.getName());
212 -#if defined(POPPLER_NEW_OBJECT_API)
213 - obj = parser->getObj();
216 - parser->getObj(&obj);
218 - if (obj.isEOF() || obj.isError()) {
221 + _POPPLER_CALL(obj2, parser->getObj);
222 + if (obj2.isEOF() || obj2.isError()) {
223 + _POPPLER_FREE(obj);
226 -#if defined(POPPLER_NEW_OBJECT_API)
227 - dict.dictAdd(key, std::move(obj));
229 - obj = parser->getObj();
231 - dict.dictAdd(key, &obj);
232 + _POPPLER_DICTADD(dict, obj.getName(), obj2);
233 + _POPPLER_FREE(obj);
234 + _POPPLER_FREE(obj2);
236 - parser->getObj(&obj);
238 + _POPPLER_CALL(obj, parser->getObj);
241 error(errSyntaxError, getPos(), "End of file in inline image");
242 diff --git a/src/extension/internal/pdfinput/pdf-parser.h b/src/extension/internal/pdfinput/pdf-parser.h
243 --- a/src/extension/internal/pdfinput/pdf-parser.h
244 +++ b/src/extension/internal/pdfinput/pdf-parser.h
249 +#include "poppler-transition-api.h"
251 #ifdef USE_GCC_PRAGMAS
253 @@ -25,6 +26,7 @@ namespace Inkscape {
254 // TODO clean up and remove using:
255 using Inkscape::Extension::Internal::SvgBuilder;
257 +#include "glib/poppler-features.h"
258 #include "goo/gtypes.h"
261 @@ -127,11 +129,14 @@ public:
263 // Constructor for regular output.
264 PdfParser(XRef *xrefA, SvgBuilder *builderA, int pageNum, int rotate,
265 - Dict *resDict, PDFRectangle *box, PDFRectangle *cropBox);
267 + _POPPLER_CONST PDFRectangle *box,
268 + _POPPLER_CONST PDFRectangle *cropBox);
270 // Constructor for a sub-page object.
271 PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *builderA,
272 - Dict *resDict, PDFRectangle *box);
274 + _POPPLER_CONST PDFRectangle *box);
276 virtual ~PdfParser();
278 @@ -185,7 +190,7 @@ private:
280 void go(GBool topLevel);
281 void execOp(Object *cmd, Object args[], int numArgs);
282 - PdfOperator *findOp(char *name);
283 + PdfOperator *findOp(const char *name);
284 GBool checkArg(Object *arg, TchkType type);
287 @@ -256,7 +261,7 @@ private:
288 double x2, double y2, GfxColor *color2,
289 int nComps, int depth);
290 void doPatchMeshShFill(GfxPatchMeshShading *shading);
291 - void fillPatch(GfxPatch *patch, int nComps, int depth);
292 + void fillPatch(_POPPLER_CONST GfxPatch *patch, int nComps, int depth);
295 // path clipping operators
296 @@ -287,7 +292,12 @@ private:
297 void opMoveShowText(Object args[], int numArgs);
298 void opMoveSetShowText(Object args[], int numArgs);
299 void opShowSpaceText(Object args[], int numArgs);
300 +#if POPPLER_CHECK_VERSION(0,64,0)
301 void doShowText(const GooString *s);
303 + void doShowText(GooString *s);
308 void opXObject(Object args[], int numArgs);
309 diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
312 +++ b/src/extension/internal/pdfinput/poppler-transition-api.h
314 +#ifndef SEEN_POPPLER_TRANSITION_API_H
315 +#define SEEN_POPPLER_TRANSITION_API_H
317 +#include <glib/poppler-features.h>
319 +#if POPPLER_CHECK_VERSION(0,70,0)
320 +#define _POPPLER_CONST const
322 +#define _POPPLER_CONST
325 +#if POPPLER_CHECK_VERSION(0,69,0)
326 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(key, std::move(obj))
327 +#elif POPPLER_CHECK_VERSION(0,58,0)
328 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(copyString(key), std::move(obj))
330 +#define _POPPLER_DICTADD(dict, key, obj) (dict).dictAdd(copyString(key), &obj)
333 +#if POPPLER_CHECK_VERSION(0,58,0)
334 +#define POPPLER_NEW_OBJECT_API
335 +#define _POPPLER_FREE(obj)
336 +#define _POPPLER_CALL(ret, func) (ret = func())
337 +#define _POPPLER_CALL_ARGS(ret, func, ...) (ret = func(__VA_ARGS__))
339 +#define _POPPLER_FREE(obj) (obj).free()
340 +#define _POPPLER_CALL(ret, func) (*func(&ret))
341 +#define _POPPLER_CALL_ARGS(ret, func, ...) (*func(__VA_ARGS__, &ret))
344 +#if POPPLER_CHECK_VERSION(0, 29, 0)
345 +#define POPPLER_EVEN_NEWER_NEW_COLOR_SPACE_API
348 +#if POPPLER_CHECK_VERSION(0, 25, 0)
349 +#define POPPLER_EVEN_NEWER_COLOR_SPACE_API
353 diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
354 --- a/src/extension/internal/pdfinput/svg-builder.cpp
355 +++ b/src/extension/internal/pdfinput/svg-builder.cpp
356 @@ -625,7 +625,7 @@ gchar *SvgBuilder::_createPattern(GfxPattern *pattern, GfxState *state, bool is_
357 if ( pattern != NULL ) {
358 if ( pattern->getType() == 2 ) { // Shading pattern
359 GfxShadingPattern *shading_pattern = static_cast<GfxShadingPattern *>(pattern);
362 double m[6] = {1, 0, 0, 1, 0, 0};
365 @@ -672,7 +672,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
367 Inkscape::XML::Node *pattern_node = _xml_doc->createElement("svg:pattern");
368 // Set pattern transform matrix
369 - double *p2u = tiling_pattern->getMatrix();
370 + const double *p2u = tiling_pattern->getMatrix();
371 double m[6] = {1, 0, 0, 1, 0, 0};
373 det = _ttm[0] * _ttm[3] - _ttm[1] * _ttm[2]; // see LP Bug 1168908
374 @@ -698,7 +698,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
375 pattern_node->setAttribute("patternUnits", "userSpaceOnUse");
376 // Set pattern tiling
377 // FIXME: don't ignore XStep and YStep
378 - double *bbox = tiling_pattern->getBBox();
379 + const double *bbox = tiling_pattern->getBBox();
380 sp_repr_set_svg_double(pattern_node, "x", 0.0);
381 sp_repr_set_svg_double(pattern_node, "y", 0.0);
382 sp_repr_set_svg_double(pattern_node, "width", bbox[2] - bbox[0]);
383 @@ -751,7 +751,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
385 gchar *SvgBuilder::_createGradient(GfxShading *shading, double *matrix, bool for_shading) {
386 Inkscape::XML::Node *gradient;
388 + _POPPLER_CONST Function *func;
390 bool extend0, extend1;
392 @@ -865,7 +865,7 @@ static bool svgGetShadingColorRGB(GfxShading *shading, double offset, GfxRGB *re
394 #define INT_EPSILON 8
395 bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
397 + _POPPLER_CONST Function *func) {
398 int type = func->getType();
399 if ( type == 0 || type == 2 ) { // Sampled or exponential function
401 @@ -877,9 +877,9 @@ bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *sh
402 _addStopToGradient(gradient, 1.0, &stop2, 1.0);
404 } else if ( type == 3 ) { // Stitching
405 - StitchingFunction *stitchingFunc = static_cast<StitchingFunction*>(func);
406 - double *bounds = stitchingFunc->getBounds();
407 - double *encode = stitchingFunc->getEncode();
408 + auto stitchingFunc = static_cast<_POPPLER_CONST StitchingFunction*>(func);
409 + const double *bounds = stitchingFunc->getBounds();
410 + const double *encode = stitchingFunc->getEncode();
411 int num_funcs = stitchingFunc->getNumFuncs();
413 // Add stops from all the stitched functions
414 @@ -890,7 +890,7 @@ bool SvgBuilder::_addGradientStops(Inkscape::XML::Node *gradient, GfxShading *sh
415 svgGetShadingColorRGB(shading, bounds[i + 1], &color);
417 if (stitchingFunc->getFunc(i)->getType() == 2) { // process exponential fxn
418 - double expE = (static_cast<ExponentialFunction*>(stitchingFunc->getFunc(i)))->getE();
419 + double expE = (static_cast<_POPPLER_CONST ExponentialFunction*>(stitchingFunc->getFunc(i)))->getE();
421 expE = (bounds[i + 1] - bounds[i])/expE; // approximate exponential as a single straight line at x=1
422 if (encode[2*i] == 0) { // normal sequence
423 @@ -1020,9 +1020,9 @@ void SvgBuilder::updateFont(GfxState *state) {
424 GfxFont *font = state->getFont();
425 // Store original name
426 if (font->getName()) {
427 - _font_specification = g_strdup(font->getName()->getCString());
428 + _font_specification = font->getName()->getCString();
430 - _font_specification = (char*) "Arial";
431 + _font_specification = "Arial";
434 // Prune the font name to get the correct font family name
435 @@ -1030,7 +1030,7 @@ void SvgBuilder::updateFont(GfxState *state) {
436 char *font_family = NULL;
437 char *font_style = NULL;
438 char *font_style_lowercase = NULL;
439 - char *plus_sign = strstr(_font_specification, "+");
440 + const char *plus_sign = strstr(_font_specification, "+");
442 font_family = g_strdup(plus_sign + 1);
443 _font_specification = plus_sign + 1;
444 @@ -1148,7 +1148,7 @@ void SvgBuilder::updateFont(GfxState *state) {
445 Inkscape::CSSOStringStream os_font_size;
446 double css_font_size = _font_scaling * state->getFontSize();
447 if ( font->getType() == fontType3 ) {
448 - double *font_matrix = font->getFontMatrix();
449 + const double *font_matrix = font->getFontMatrix();
450 if ( font_matrix[0] != 0.0 ) {
451 css_font_size *= font_matrix[3] / font_matrix[0];
453 @@ -1193,7 +1193,7 @@ void SvgBuilder::updateTextPosition(double tx, double ty) {
454 void SvgBuilder::updateTextMatrix(GfxState *state) {
456 // Update text matrix
457 - double *text_matrix = state->getTextMat();
458 + const double *text_matrix = state->getTextMat();
459 double w_scale = sqrt( text_matrix[0] * text_matrix[0] + text_matrix[2] * text_matrix[2] );
460 double h_scale = sqrt( text_matrix[1] * text_matrix[1] + text_matrix[3] * text_matrix[3] );
462 diff --git a/src/extension/internal/pdfinput/svg-builder.h b/src/extension/internal/pdfinput/svg-builder.h
463 --- a/src/extension/internal/pdfinput/svg-builder.h
464 +++ b/src/extension/internal/pdfinput/svg-builder.h
469 +#include "poppler-transition-api.h"
473 @@ -80,7 +81,7 @@ struct SvgGlyph {
474 bool style_changed; // Set to true if style has to be reset
476 int render_mode; // Text render mode
477 - char *font_specification; // Pointer to current font specification
478 + const char *font_specification; // Pointer to current font specification
482 @@ -174,7 +175,7 @@ private:
483 void _addStopToGradient(Inkscape::XML::Node *gradient, double offset,
484 GfxRGB *color, double opacity);
485 bool _addGradientStops(Inkscape::XML::Node *gradient, GfxShading *shading,
487 + _POPPLER_CONST Function *func);
488 gchar *_createTilingPattern(GfxTilingPattern *tiling_pattern, GfxState *state,
489 bool is_stroke=false);
490 // Image/mask creation
491 @@ -202,7 +203,7 @@ private:
493 SPCSSAttr *_font_style; // Current font style
494 GfxFont *_current_font;
495 - char *_font_specification;
496 + const char *_font_specification;
497 double _font_scaling;
498 bool _need_font_update;
499 Geom::Affine _text_matrix;