From 8ae83ca81bbaebcc0ff0abe82300d56d2c94e6f9 Mon Sep 17 00:00:00 2001
From: KrIr17 <elendil.krir17@gmail.com>
Date: Sun, 6 Jul 2025 15:42:13 +0200
Subject: [PATCH 1/2] Fix building with Poppler 25.07.0

Fix building issues with

1. [`GfxState::shift()`](https://gitlab.freedesktop.org/poppler/poppler/-/commit/71bf5552d448a6fdb666f2b61764b61ca197617d)

2. [`FoFiTrueType::make` and `FoFiType1C::make`](FoFiTrueType::make)

3. Fix typo from 5c4c6d116dae5250d75d34a45f0d9220824d2e20
---
 src/extension/internal/pdfinput/pdf-parser.cpp   |  4 ++--
 .../pdfinput/poppler-cairo-font-engine.cpp       | 16 +++++++++++-----
 .../internal/pdfinput/poppler-transition-api.h   | 14 ++++++++++++++
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
index 0773e389085..c444a71724d 100644
--- a/src/extension/internal/pdfinput/pdf-parser.cpp
+++ b/src/extension/internal/pdfinput/pdf-parser.cpp
@@ -2313,11 +2313,11 @@ void PdfParser::doShowText(GooString *s) {
         state->textTransformDelta(originX, originY, &tOriginX, &tOriginY);
 
         // In Gfx.cc this is drawChar(...)
-        builder->addChar(state, state->getCurX() + riseX, state->getCurY() + riseY,
+        builder->addChar(state, state->_POPPLER_GET_CUR_TEXT_X() + riseX, state->_POPPLER_GET_CUR_TEXT_Y() + riseY,
                          dx, dy, ax, ay, tOriginX, tOriginY, code, n, u, uLen);
 
         // Move onto next unicode character.
-        state->shift(tdx, tdy);
+        state->_POPPLER_TEXT_SHIFT_WITH_USER_COORDS(tdx, tdy);
         p += n;
         len -= n;
     }
diff --git a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
index dff615cb616..97cd9a07a5c 100644
--- a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
+++ b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
@@ -315,7 +315,11 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
 #endif
     char **enc;
     const char *name;
+#if POPPLER_CHECK_VERSION(25, 7, 0)
+    std::unique_ptr<FoFiType1C> ff1c;
+#else
     FoFiType1C *ff1c;
+#endif
     std::optional<FreeTypeFontFace> font_face;
     std::vector<int> codeToGID;
     bool substitute = false;
@@ -426,7 +430,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
                 FoFiTrueType *ff;
 #endif
                 if (!font_data.empty()) {
-                    ff = FoFiTrueType::make((fontchar)font_data.data(), font_data.size(), 0);
+                    ff = _POPPLER_FOFI_TRUETYPE_MAKE(font_data, 0);
                 } else {
                     ff = FoFiTrueType::load(fileName.c_str(), 0);
                 }
@@ -456,7 +460,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
             FoFiTrueType *ff;
 #endif
             if (!font_data.empty()) {
-                ff = FoFiTrueType::make((fontchar)font_data.data(), font_data.size(), 0);
+                ff = _POPPLER_FOFI_TRUETYPE_MAKE(font_data, 0);
             } else {
                 ff = FoFiTrueType::load(fileName.c_str(), 0);
             }
@@ -490,7 +494,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
         case fontCIDType0C:
             if (!useCIDs) {
                 if (!font_data.empty()) {
-                    ff1c = FoFiType1C::make((fontchar)font_data.data(), font_data.size());
+                    ff1c = _POPPLER_FOFI_TYPE1C_MAKE(font_data);
                 } else {
                     ff1c = FoFiType1C::load(fileName.c_str());
                 }
@@ -503,7 +507,9 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
                     codeToGID.insert(codeToGID.begin(), src, src + n);
                     gfree(src);
 #endif
+#if !(POPPLER_CHECK_VERSION(25, 7, 0))
                     delete ff1c;
+#endif
                 }
             }
 
@@ -539,13 +545,13 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
                     FoFiTrueType *ff;
 #endif
                     if (!font_data.empty()) {
-                        ff = FoFiTrueType::make((fontchar)font_data.data(), font_data.size(), 0);
+                        ff = _POPPLER_FOFI_TRUETYPE_MAKE(font_data, 0);
                     } else {
                         ff = FoFiTrueType::load(fileName.c_str(), 0);
                     }
                     if (ff) {
                         if (ff->isOpenTypeCFF()) {
-                            auto src = ff1c->_POPPLER_GET_CID_TO_GID_MAP(&n);
+                            auto src = ff->_POPPLER_GET_CID_TO_GID_MAP(&n);
 #if POPPLER_CHECK_VERSION(25,2,0)
                             codeToGID = std::move(src);
 #else
diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h
index d04412757bc..866b630bb67 100644
--- a/src/extension/internal/pdfinput/poppler-transition-api.h
+++ b/src/extension/internal/pdfinput/poppler-transition-api.h
@@ -15,6 +15,20 @@
 #include <glib/poppler-features.h>
 #include <poppler/UTF.h>
 
+#if POPPLER_CHECK_VERSION(25, 7, 0)
+#define _POPPLER_TEXT_SHIFT_WITH_USER_COORDS(dx, dy) textShiftWithUserCoords(dx, dy)
+#define _POPPLER_FOFI_TRUETYPE_MAKE(font_data, faceIndex) FoFiTrueType::make(std::span(font_data), faceIndex)
+#define _POPPLER_FOFI_TYPE1C_MAKE(font_data) FoFiType1C::make(std::span(font_data))
+#define _POPPLER_GET_CUR_TEXT_X() getCurTextX()
+#define _POPPLER_GET_CUR_TEXT_Y() getCurTextY()
+#else
+#define _POPPLER_TEXT_SHIFT_WITH_USER_COORDS(dx, dy) shift(dx, dy)
+#define _POPPLER_FOFI_TRUETYPE_MAKE(font_data, faceIndex) FoFiTrueType::make((fontchar)font_data.data(), font_data.size(), faceIndex)
+#define _POPPLER_FOFI_TYPE1C_MAKE(font_data) FoFiType1C::make((fontchar)font_data.data(), font_data.size())
+#define _POPPLER_GET_CUR_TEXT_X() getCurX()
+#define _POPPLER_GET_CUR_TEXT_Y() getCurY()
+#endif
+
 #if POPPLER_CHECK_VERSION(25, 6, 0)
 #define _POPPLER_DECLARE_TRANSFER_FUNCTION_VECTOR(name) std::vector<std::unique_ptr<Function>> name(4)
 #define _POPPLER_DELETE_TRANSFER_FUNCTION(name) name.reset()
-- 
GitLab


From f48b429827dca510b41a5671d467e574ef348625 Mon Sep 17 00:00:00 2001
From: mike kowalski <michal_kowalski@hotmail.com>
Date: Tue, 2 Sep 2025 07:17:25 -0700
Subject: [PATCH 2/2] Fix build with poppler 25.09.0

API changes: double* -> std::array necessitates fixes in Inkscape.
The goal is to make it build with older poppler versions too.
---
 src/extension/internal/pdfinput/pdf-parser.cpp                | 3 +--
 src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp | 2 +-
 src/extension/internal/pdfinput/poppler-utils.cpp             | 4 ++++
 src/extension/internal/pdfinput/poppler-utils.h               | 4 ++++
 src/extension/internal/pdfinput/svg-builder.cpp               | 4 ++--
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp
index c444a71724d..0d62c20875a 100644
--- a/src/extension/internal/pdfinput/pdf-parser.cpp
+++ b/src/extension/internal/pdfinput/pdf-parser.cpp
@@ -1650,12 +1650,11 @@ void PdfParser::doFunctionShFill1(GfxFunctionShading *shading,
   GfxColor color0M, color1M, colorM0, colorM1, colorMM;
   GfxColor colors2[4];
   double functionColorDelta = colorDeltas[pdfFunctionShading-1];
-  const double *matrix;
   double xM, yM;
   int nComps, i, j;
 
   nComps = shading->getColorSpace()->getNComps();
-  matrix = shading->getMatrix();
+  const auto& matrix = shading->getMatrix();
 
   // compare the four corner colors
   for (i = 0; i < 4; ++i) {
diff --git a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
index 97cd9a07a5c..b6ed11c8c0a 100644
--- a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
+++ b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
@@ -632,7 +632,7 @@ static cairo_status_t _init_type3_glyph(cairo_scaled_font_t *scaled_font, cairo_
 
     info = (type3_font_info_t *)cairo_font_face_get_user_data(cairo_scaled_font_get_font_face(scaled_font),
                                                               &type3_font_key);
-    const double *mat = info->font->getFontBBox();
+    const auto& mat = info->font->getFontBBox();
     extents->ascent = mat[3];   /* y2 */
     extents->descent = -mat[3]; /* -y1 */
     extents->height = extents->ascent + extents->descent;
diff --git a/src/extension/internal/pdfinput/poppler-utils.cpp b/src/extension/internal/pdfinput/poppler-utils.cpp
index a579ffcacf3..8110a3e0858 100644
--- a/src/extension/internal/pdfinput/poppler-utils.cpp
+++ b/src/extension/internal/pdfinput/poppler-utils.cpp
@@ -38,6 +38,10 @@ Geom::Affine ctmToAffine(const double *ctm)
     return Geom::Affine(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
 }
 
+Geom::Affine ctmToAffine(const std::array<double, 6>& ctm) {
+    return ctmToAffine(ctm.data());
+}
+
 void ctmout(const char *label, const double *ctm)
 {
     std::cout << "C:" << label << ":" << ctm[0] << "," << ctm[1] << "," << ctm[2] << "," << ctm[3] << "," << ctm[4]
diff --git a/src/extension/internal/pdfinput/poppler-utils.h b/src/extension/internal/pdfinput/poppler-utils.h
index 2bcd307e176..e51d6a9da32 100644
--- a/src/extension/internal/pdfinput/poppler-utils.h
+++ b/src/extension/internal/pdfinput/poppler-utils.h
@@ -13,6 +13,7 @@
 #ifndef POPPLER_UTILS_H
 #define POPPLER_UTILS_H
 
+#include <array>
 #include <map>
 #include <memory>
 #include <string>
@@ -36,7 +37,10 @@ class Ref;
 class XRef;
 
 Geom::Affine stateToAffine(GfxState *state);
+// this function is for Poppler older than v25.09.0
 Geom::Affine ctmToAffine(const double *ctm);
+// this flavor is for Poppler v25.09.0 and above
+Geom::Affine ctmToAffine(const std::array<double, 6>& ctm);
 
 void ctmout(const char *label, const double *ctm);
 void affout(const char *label, Geom::Affine affine);
diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp
index f14be1ec62e..4f259831f1d 100644
--- a/src/extension/internal/pdfinput/svg-builder.cpp
+++ b/src/extension/internal/pdfinput/svg-builder.cpp
@@ -1089,7 +1089,7 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern,
     pattern_node->setAttribute("patternUnits", "userSpaceOnUse");
     // Set pattern tiling
     // FIXME: don't ignore XStep and YStep
-    const double *bbox = tiling_pattern->getBBox();
+    const auto& bbox = tiling_pattern->getBBox();
     pattern_node->setAttributeSvgDouble("x", 0.0);
     pattern_node->setAttributeSvgDouble("y", 0.0);
     pattern_node->setAttributeSvgDouble("width", bbox[2] - bbox[0]);
@@ -1319,7 +1319,7 @@ void SvgBuilder::updateFont(GfxState *state, std::shared_ptr<CairoFont> cairo_fo
 
     auto new_font_size = state->getFontSize();
     if (font->getType() == fontType3) {
-        const double *font_matrix = font->getFontMatrix();
+        const auto& font_matrix = font->getFontMatrix();
         if (font_matrix[0] != 0.0) {
             new_font_size *= font_matrix[3] / font_matrix[0];
         }
-- 
GitLab

