From 5c4c6d116dae5250d75d34a45f0d9220824d2e20 Mon Sep 17 00:00:00 2001 From: KrIr17 Date: Sun, 9 Feb 2025 22:52:53 +0530 Subject: [PATCH] Fix building with poppler 25.02.0 1. `getCodeToGIDMap`, `getCIDToGID`, `getCIDToGIDMap` are now `std::vector` 2. `pdfDocEncodingToUTF16` returns an `std::string` --- .../pdfinput/poppler-cairo-font-engine.cpp | 50 +++++++++++++++---- .../pdfinput/poppler-transition-api.h | 20 +++++--- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp index 728b1d1aac4..bd1d4e49367 100644 --- a/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp +++ b/src/extension/internal/pdfinput/poppler-cairo-font-engine.cpp @@ -405,14 +405,22 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li break; case fontCIDType2: case fontCIDType2OT: +#if POPPLER_CHECK_VERSION(25,2,0) + if (!gfxcid->getCIDToGID().empty()) { + const auto src = gfxcid->getCIDToGID(); + codeToGID = std::move(src); + } +#else if (gfxcid->getCIDToGID()) { n = gfxcid->getCIDToGIDLen(); if (n) { - const int *src = gfxcid->getCIDToGID(); + const auto src = gfxcid->getCIDToGID(); codeToGID.reserve(n); codeToGID.insert(codeToGID.begin(), src, src + n); } - } else { + } +#endif + else { #if POPPLER_CHECK_VERSION(22, 1, 0) std::unique_ptr ff; #else @@ -427,13 +435,18 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li goto err2; } #if POPPLER_CHECK_VERSION(22, 1, 0) - int *src = gfxcid->getCodeToGIDMap(ff.get(), &n); + auto src = gfxcid->_POPPLER_GET_CODE_TO_GID_MAP(ff.get(), &n); #else - int *src = gfxcid->getCodeToGIDMap(ff, &n); + auto src = gfxcid->_POPPLER_GET_CODE_TO_GID_MAP(ff, &n); #endif + +#if POPPLER_CHECK_VERSION(25,2,0) + codeToGID = std::move(src); +#else codeToGID.reserve(n); codeToGID.insert(codeToGID.begin(), src, src + n); gfree(src); +#endif } /* Fall through */ case fontTrueType: @@ -455,13 +468,17 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li /* This might be set already for the CIDType2 case */ if (fontType == fontTrueType || fontType == fontTrueTypeOT) { #if POPPLER_CHECK_VERSION(22, 1, 0) - int *src = gfx8bit->getCodeToGIDMap(ff.get()); + auto src = gfx8bit->getCodeToGIDMap(ff.get()); #else - int *src = gfx8bit->getCodeToGIDMap(ff); + auto src = gfx8bit->getCodeToGIDMap(ff); #endif +#if POPPLER_CHECK_VERSION(25,2,0) + codeToGID = std::move(src); +#else codeToGID.reserve(256); codeToGID.insert(codeToGID.begin(), src, src + 256); gfree(src); +#endif } font_face = getFreeTypeFontFace(fontEngine, lib, fileName, std::move(font_data)); if (!font_face) { @@ -479,10 +496,14 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li ff1c = FoFiType1C::load(fileName.c_str()); } if (ff1c) { - int *src = ff1c->getCIDToGIDMap(&n); + auto src = ff1c->_POPPLER_GET_CID_TO_GID_MAP(&n); +#if POPPLER_CHECK_VERSION(25,2,0) + codeToGID = std::move(src); +#else codeToGID.reserve(n); codeToGID.insert(codeToGID.begin(), src, src + n); gfree(src); +#endif delete ff1c; } } @@ -495,14 +516,21 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li break; case fontCIDType0COT: +#if POPPLER_CHECK_VERSION(25,2,0) + if (!gfxcid->getCIDToGID().empty()) { + const auto src = gfxcid->getCIDToGID(); + codeToGID = std::move(src); + } +#else if (gfxcid->getCIDToGID()) { n = gfxcid->getCIDToGIDLen(); if (n) { - const int *src = gfxcid->getCIDToGID(); + const auto src = gfxcid->getCIDToGID(); codeToGID.reserve(n); codeToGID.insert(codeToGID.begin(), src, src + n); } } +#endif if (codeToGID.empty()) { if (!useCIDs) { @@ -518,10 +546,14 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li } if (ff) { if (ff->isOpenTypeCFF()) { - int *src = ff->getCIDToGIDMap(&n); + auto src = ff1c->_POPPLER_GET_CID_TO_GID_MAP(&n); +#if POPPLER_CHECK_VERSION(25,2,0) + codeToGID = std::move(src); +#else codeToGID.reserve(n); codeToGID.insert(codeToGID.begin(), src, src + n); gfree(src); +#endif } } } diff --git a/src/extension/internal/pdfinput/poppler-transition-api.h b/src/extension/internal/pdfinput/poppler-transition-api.h index b7a54828e74..a67132ba6bd 100644 --- a/src/extension/internal/pdfinput/poppler-transition-api.h +++ b/src/extension/internal/pdfinput/poppler-transition-api.h @@ -15,6 +15,20 @@ #include #include +#if POPPLER_CHECK_VERSION(25,2,0) +#define _POPPLER_GET_CODE_TO_GID_MAP(ff, len) getCodeToGIDMap(ff) +#define _POPPLER_GET_CID_TO_GID_MAP(len) getCIDToGIDMap() +#else +#define _POPPLER_GET_CODE_TO_GID_MAP(ff, len) getCodeToGIDMap(ff, len) +#define _POPPLER_GET_CID_TO_GID_MAP(len) getCIDToGIDMap(len) +#endif + +#if POPPLER_CHECK_VERSION(24,12,0) +#define _POPPLER_GET_IMAGE_PARAMS(bits, csMode, hasAlpha) getImageParams(bits, csMode, hasAlpha) +#else +#define _POPPLER_GET_IMAGE_PARAMS(bits, csMode, hasAlpha) getImageParams(bits, csMode) +#endif + #if POPPLER_CHECK_VERSION(24, 10, 0) #define _POPPLER_CONSUME_UNIQPTR_ARG(value) std::move(value) #else @@ -39,12 +53,6 @@ #define _POPPLER_FUNCTION_TYPE_STITCHING 3 #endif -#if POPPLER_CHECK_VERSION(24,12,0) -#define _POPPLER_GET_IMAGE_PARAMS(bits, csMode, hasAlpha) getImageParams(bits, csMode, hasAlpha) -#else -#define _POPPLER_GET_IMAGE_PARAMS(bits, csMode, hasAlpha) getImageParams(bits, csMode) -#endif - #if POPPLER_CHECK_VERSION(22, 4, 0) #define _POPPLER_FONTPTR_TO_GFX8(font_ptr) ((Gfx8BitFont *)font_ptr.get()) #else -- GitLab