Submitted By:            Douglas R. Reno <renodr at linuxfromscratch dot org>
Date:                    2022-04-19
Initial Package Version: 1.1.2
Origin:                  Upstream (commit d989cdf1)
Upstream Status:         Applied
Description:             Fixes building Inkscape-1.1.2 with Poppler-22.04.0.
                         This is needed due to API changes in poppler-22.04.0.

diff -Naurp inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/pdf-parser.cpp inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/pdf-parser.cpp
--- inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/pdf-parser.cpp	2022-02-04 19:12:19.000000000 -0600
+++ inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/pdf-parser.cpp	2022-04-19 10:54:44.072984165 -0500
@@ -30,6 +30,7 @@
 #include "Gfx.h"
 #include "pdf-parser.h"
 #include "util/units.h"
+#include "poppler-transition-api.h"
 
 #include "glib/poppler-features.h"
 #include "goo/gmem.h"
@@ -2158,7 +2159,7 @@ void PdfParser::opSetCharSpacing(Object
 // TODO not good that numArgs is ignored but args[] is used:
 void PdfParser::opSetFont(Object args[], int /*numArgs*/)
 {
-  GfxFont *font = res->lookupFont(args[0].getName());
+  auto font = res->lookupFont(args[0].getName());
 
   if (!font) {
     // unsetting the font (drawing no text) is better than using the
@@ -2179,7 +2180,9 @@ void PdfParser::opSetFont(Object args[],
     fflush(stdout);
   }
 
+#if !POPPLER_CHECK_VERSION(22, 4, 0)
   font->incRefCnt();
+#endif
   state->setFont(font, args[1].getNum());
   fontChanged = gTrue;
 }
@@ -2373,7 +2376,6 @@ void PdfParser::doShowText(const GooStri
 #else
 void PdfParser::doShowText(GooString *s) {
 #endif
-  GfxFont *font;
   int wMode;
   double riseX, riseY;
   CharCode code;
@@ -2392,7 +2394,7 @@ void PdfParser::doShowText(GooString *s)
 #endif
   int len, n, uLen;
 
-  font = state->getFont();
+  auto font = state->getFont();
   wMode = font->getWMode();
 
   builder->beginString(state);
@@ -2445,8 +2447,8 @@ void PdfParser::doShowText(GooString *s)
       //out->updateCTM(state, 1, 0, 0, 1, 0, 0);
       if (false){ /*!out->beginType3Char(state, curX + riseX, curY + riseY, tdx, tdy,
 			       code, u, uLen)) {*/
-        _POPPLER_CALL_ARGS(charProc, ((Gfx8BitFont *)font)->getCharProc, code);
-	if ((resDict = ((Gfx8BitFont *)font)->getResources())) {
+        _POPPLER_CALL_ARGS(charProc, _POPPLER_FONTPTR_TO_GFX8(font)->getCharProc, code);
+	if (resDict = _POPPLER_FONTPTR_TO_GFX8(font)->getResources()) {
 	  pushResources(resDict);
 	}
 	if (charProc.isStream()) {
diff -Naurp inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/poppler-transition-api.h inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/poppler-transition-api.h
--- inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/poppler-transition-api.h	2022-02-04 19:12:19.000000000 -0600
+++ inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/poppler-transition-api.h	2022-04-19 10:55:53.747415032 -0500
@@ -14,6 +14,12 @@
 
 #include <glib/poppler-features.h>
 
+#if POPPLER_CHECK_VERSION(22, 4, 0)
+#define _POPPLER_FONTPTR_TO_GFX8(font_ptr) ((Gfx8BitFont *)font_ptr.get())
+#else
+#define _POPPLER_FONTPTR_TO_GFX8(font_ptr) ((Gfx8BitFont *)font_ptr)
+#endif
+
 #if POPPLER_CHECK_VERSION(0, 83, 0)
 #define _POPPLER_CONST_83 const
 #else
diff -Naurp inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/svg-builder.cpp inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/svg-builder.cpp
--- inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/svg-builder.cpp	2022-02-04 19:21:47.000000000 -0600
+++ inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/svg-builder.cpp	2022-04-19 10:57:25.660664575 -0500
@@ -108,7 +108,6 @@ SvgBuilder::~SvgBuilder() = default;
 
 void SvgBuilder::_init() {
     _font_style = nullptr;
-    _current_font = nullptr;
     _font_specification = nullptr;
     _font_scaling = 1;
     _need_font_update = true;
@@ -1021,11 +1020,8 @@ void SvgBuilder::updateFont(GfxState *st
     _need_font_update = false;
     updateTextMatrix(state);    // Ensure that we have a text matrix built
 
-    if (_font_style) {
-        //sp_repr_css_attr_unref(_font_style);
-    }
     _font_style = sp_repr_css_attr_new();
-    GfxFont *font = state->getFont();
+    auto font = state->getFont();
     // Store original name
     if (font->getName()) {
         _font_specification = font->getName()->getCString();
@@ -1171,7 +1167,6 @@ void SvgBuilder::updateFont(GfxState *st
         sp_repr_css_set_property(_font_style, "writing-mode", "tb");
     }
 
-    _current_font = font;
     _invalidated_style = true;
 }
 
diff -Naurp inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/svg-builder.h inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/svg-builder.h
--- inkscape-1.1.2_2022-02-04_0a00cf5339.orig/src/extension/internal/pdfinput/svg-builder.h	2022-02-04 19:21:47.000000000 -0600
+++ inkscape-1.1.2_2022-02-04_0a00cf5339/src/extension/internal/pdfinput/svg-builder.h	2022-04-19 10:57:44.630509731 -0500
@@ -203,7 +203,6 @@ private:
     std::vector<SvgGraphicsState> _state_stack;
 
     SPCSSAttr *_font_style;          // Current font style
-    GfxFont *_current_font;
     const char *_font_specification;
     double _font_scaling;
     bool _need_font_update;
