Commit 5cba6414 authored by Adam Reichold's avatar Adam Reichold
Browse files

Add API to cpp frontend to specify a custom data directory for initialization of global parameters.

parent 72c316d1
Pipeline #13354 passed with stage
in 7 minutes and 24 seconds
......@@ -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
......
......@@ -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)
......
......@@ -25,6 +25,7 @@
#include "poppler-global.h"
#include "poppler-private.h"
#include "poppler-document-private.h"
#include "DateInfo.h"
......@@ -356,6 +357,22 @@ std::ostream& poppler::operator<<(std::ostream& stream, const byte_array &array)
return stream;
}
/**
* 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
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment