cpp/poppler-document-private.h | 3 +++ cpp/poppler-document.cpp | 15 ++++++++++++++- cpp/poppler-global.cpp | 17 +++++++++++++++++ cpp/poppler-global.h | 2 ++ 4 files changed, 36 insertions(+), 1 deletion(-)
New commits: commit 5cba64142f716f5df61c2136175b86e6d7256526 Author: Adam Reichold <[email protected]> Date: Mon Dec 24 23:20:45 2018 +0100 Add API to cpp frontend to specify a custom data directory for initialization of global parameters. diff --git a/cpp/poppler-document-private.h b/cpp/poppler-document-private.h index 661c9774..fbf330e8 100644 --- a/cpp/poppler-document-private.h +++ b/cpp/poppler-document-private.h @@ -44,9 +44,12 @@ public: initer(const initer &) = delete; initer& operator=(const initer &) = delete; + static bool set_data_dir(const std::string &new_data_dir); + private: static std::mutex mutex; static unsigned int count; + static std::string data_dir; }; class document_private : private initer diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp index 6895ecb1..4ce4f780 100644 --- a/cpp/poppler-document.cpp +++ b/cpp/poppler-document.cpp @@ -44,13 +44,14 @@ using namespace poppler; std::mutex poppler::initer::mutex; unsigned int poppler::initer::count = 0U; +std::string poppler::initer::data_dir; initer::initer() { std::lock_guard<std::mutex> lock{mutex}; if (!count) { - globalParams = new GlobalParams(); + globalParams = new GlobalParams(!data_dir.empty() ? data_dir.c_str() : nullptr); setErrorCallback(detail::error_function, nullptr); } count++; @@ -69,6 +70,18 @@ initer::~initer() } } +bool initer::set_data_dir(const std::string &new_data_dir) +{ + std::lock_guard<std::mutex> lock{mutex}; + + if (count == 0) { + data_dir = new_data_dir; + return true; + } + + return false; +} + document_private::document_private(GooString *file_path, const std::string &owner_password, const std::string &user_password) diff --git a/cpp/poppler-global.cpp b/cpp/poppler-global.cpp index 4468d447..67a58d3f 100644 --- a/cpp/poppler-global.cpp +++ b/cpp/poppler-global.cpp @@ -25,6 +25,7 @@ #include "poppler-global.h" #include "poppler-private.h" +#include "poppler-document-private.h" #include "DateInfo.h" @@ -357,6 +358,22 @@ std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array) } /** + * Sets a custom data directory for initialization of global parameters + * + * If no instances of \see document currently exist, this will save the + * given path as a custom data directory to be used when the first instance + * of the \see document is constructed. + * + * \returns true on success, false on failure + * + * \since 0.73.0 + */ +bool poppler::set_data_dir(const std::string &new_data_dir) +{ + return initer::set_data_dir(new_data_dir); +} + +/** \typedef poppler::debug_func Debug/error function. diff --git a/cpp/poppler-global.h b/cpp/poppler-global.h index eb7ec244..3902d359 100644 --- a/cpp/poppler-global.h +++ b/cpp/poppler-global.h @@ -107,6 +107,8 @@ POPPLER_CPP_EXPORT time_type convert_date(const std::string &date); POPPLER_CPP_EXPORT std::ostream& operator<<(std::ostream& stream, const byte_array &array); +POPPLER_CPP_EXPORT bool set_data_dir(const std::string &new_data_dir); + typedef void(*debug_func)(const std::string &, void *); POPPLER_CPP_EXPORT void set_debug_error_function(debug_func debug_function, void *closure); _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
