krename/krename-5.0.2-podofo-0.10.patch

97 lines
4.7 KiB
Diff
Raw Normal View History

diff --git a/cmake/modules/FindPoDoFo.cmake b/cmake/modules/FindPoDoFo.cmake
index 34c1422..b7ded90 100644
--- a/cmake/modules/FindPoDoFo.cmake
+++ b/cmake/modules/FindPoDoFo.cmake
@@ -15,15 +15,8 @@
# SPDX-FileCopyrightText: 2016 Pino Toscano <pino@kde.org>
-find_path(PoDoFo_INCLUDE_DIRS
- NAMES podofo/podofo.h
-)
-find_library(PoDoFo_LIBRARIES
- NAMES libpodofo podofo
-)
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(PoDoFo DEFAULT_MSG PoDoFo_LIBRARIES PoDoFo_INCLUDE_DIRS)
+include(FindPkgConfig)
+pkg_search_module(PoDoFo libpodofo libpodofo-0)
set(PoDoFo_DEFINITIONS)
if(PoDoFo_FOUND)
@@ -40,17 +33,19 @@ if(PoDoFo_FOUND)
endif()
endif()
- # PoDoFo-0.9.5 unconditionally includes openssl/opensslconf.h in a public
- # header. The fix is in https://sourceforge.net/p/podofo/code/1830/ and will
- # hopefully be released soon with 0.9.6. Note that krename doesn't use
- # OpenSSL in any way.
- file(STRINGS "${PoDoFo_INCLUDE_DIRS}/podofo/base/podofo_config.h" PoDoFo_MAJOR_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_MAJOR[ \t]+[0-9]+$")
- file(STRINGS "${PoDoFo_INCLUDE_DIRS}/podofo/base/podofo_config.h" PoDoFo_MINOR_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_MINOR[ \t]+[0-9]+$")
- file(STRINGS "${PoDoFo_INCLUDE_DIRS}/podofo/base/podofo_config.h" PoDoFo_PATCH_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_PATCH[ \t]+[0-9]+$")
+ find_file(PoDoFo_CONFIG podofo_config.h PATHS ${PoDoFo_INCLUDE_DIRS} PATH_SUFFIXES auxiliary base)
+ file(STRINGS "${PoDoFo_CONFIG}" PoDoFo_MAJOR_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_MAJOR[ \t]+[0-9]+$")
+ file(STRINGS "${PoDoFo_CONFIG}" PoDoFo_MINOR_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_MINOR[ \t]+[0-9]+$")
+ file(STRINGS "${PoDoFo_CONFIG}" PoDoFo_PATCH_VER_LINE REGEX "^#define[ \t]+PODOFO_VERSION_PATCH[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+PODOFO_VERSION_MAJOR[ \t]+([0-9]+)$" "\\1" PoDoFo_MAJOR_VER "${PoDoFo_MAJOR_VER_LINE}")
string(REGEX REPLACE "^#define[ \t]+PODOFO_VERSION_MINOR[ \t]+([0-9]+)$" "\\1" PoDoFo_MINOR_VER "${PoDoFo_MINOR_VER_LINE}")
string(REGEX REPLACE "^#define[ \t]+PODOFO_VERSION_PATCH[ \t]+([0-9]+)$" "\\1" PoDoFo_PATCH_VER "${PoDoFo_PATCH_VER_LINE}")
set(PoDoFo_VERSION "${PoDoFo_MAJOR_VER}.${PoDoFo_MINOR_VER}.${PoDoFo_PATCH_VER}")
+
+ # PoDoFo-0.9.5 unconditionally includes openssl/opensslconf.h in a public
+ # header. The fix is in https://sourceforge.net/p/podofo/code/1830/ and will
+ # hopefully be released soon with 0.9.6. Note that krename doesn't use
+ # OpenSSL in any way.
if(PoDoFo_VERSION VERSION_EQUAL "0.9.5")
find_package(OpenSSL)
if (OpenSSL_FOUND)
@@ -63,4 +58,8 @@ if(PoDoFo_FOUND)
endif()
endif()
+if(PoDoFo_VERSION VERSION_GREATER_EQUAL 0.10.0)
+ set(CMAKE_CXX_STANDARD 17)
+endif()
+
mark_as_advanced(PoDoFo_INCLUDE_DIRS PoDoFo_LIBRARIES PoDoFo_DEFINITIONS)
diff --git a/src/podofoplugin.cpp b/src/podofoplugin.cpp
index 68d34d8..b74e65c 100644
--- a/src/podofoplugin.cpp
+++ b/src/podofoplugin.cpp
@@ -47,6 +47,25 @@ QString PodofoPlugin::processFile(BatchRenamer *b, int index, const QString &fil
try {
PdfMemDocument doc;
doc.Load(filename.toUtf8().data());
+#if (PODOFO_VERSION_MINOR>=10 || PODOFO_VERSION_MAJOR>=1)
+ const PdfInfo *info = doc.GetInfo();
+
+ if (token == "pdfauthor") {
+ return info->GetAuthor().has_value() ? QString::fromUtf8(info->GetAuthor()->GetString().c_str()) : QString();
+ } else if (token == "pdfcreator") {
+ return info->GetCreator().has_value() ? QString::fromUtf8(info->GetCreator()->GetString().c_str()) : QString();
+ } else if (token == "pdfkeywords") {
+ return info->GetKeywords().has_value() ? QString::fromUtf8(info->GetKeywords()->GetString().c_str()) : QString();
+ } else if (token == "pdfsubject") {
+ return info->GetSubject().has_value() ? QString::fromUtf8(info->GetSubject()->GetString().c_str()) : QString();
+ } else if (token == "pdftitle") {
+ return info->GetTitle().has_value() ? QString::fromUtf8(info->GetTitle()->GetString().c_str()) : QString();
+ } else if (token == "pdfproducer") {
+ return info->GetProducer().has_value() ? QString::fromUtf8(info->GetProducer()->GetString().c_str()) : QString();
+ } else if (token == "pdfpages") {
+ return QString::number(doc.GetPages().GetCount());
+ }
+#else
PdfInfo *info = doc.GetInfo();
if (token == "pdfauthor") {
@@ -64,6 +83,7 @@ QString PodofoPlugin::processFile(BatchRenamer *b, int index, const QString &fil
} else if (token == "pdfpages") {
return QString::number(doc.GetPageCount());
}
+#endif
} catch (PdfError &error) {
return QString::fromUtf8(error.what());
}