From b92995c1e67129ae9965810dd5d13c9642539acd Mon Sep 17 00:00:00 2001
From: KrIr17 <elendil.krir17@gmail.com>
Date: Sun, 6 Jul 2025 15:42:13 +0200
Subject: [PATCH] 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   |  2 +-
 .../pdfinput/poppler-cairo-font-engine.cpp       | 16 +++++++++++-----
 .../internal/pdfinput/poppler-transition-api.h   | 10 ++++++++++
 3 files changed, 22 insertions(+), 6 deletions(-)

--- inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/pdf-parser.cpp.orig
+++ inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/pdf-parser.cpp
@@ -2319,7 +2319,7 @@
                          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;
     }
--- inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp.orig
+++ inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp
@@ -318,7 +318,11 @@
 #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;
@@ -429,7 +433,7 @@
                 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);
                 }
@@ -459,7 +463,7 @@
             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);
             }
@@ -493,7 +497,7 @@
         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());
                 }
@@ -506,7 +510,9 @@
                     codeToGID.insert(codeToGID.begin(), src, src + n);
                     gfree(src);
 #endif
+#if !(POPPLER_CHECK_VERSION(25, 7, 0))
                     delete ff1c;
+#endif
                 }
             }
 
@@ -542,13 +548,13 @@
                     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
--- inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/poppler-transition-api.h.orig
+++ inkscape-1.4.2_2025-05-08_ebf0e940d0/src/extension/internal/pdfinput/poppler-transition-api.h
@@ -15,6 +15,16 @@
 #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))
+#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())
+#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()
