Skip to content

Commit

Permalink
fix recursive initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Jan 9, 2025
1 parent 4ab79f3 commit 2098725
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
35 changes: 23 additions & 12 deletions src/odr/global_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
namespace odr {

GlobalParams &GlobalParams::instance() {
static GlobalParams instance;
return instance;
struct HolderAndInitializer {
GlobalParams params;
HolderAndInitializer() {
#ifdef ODR_WITH_PDF2HTMLEX
globalParams = std::make_unique<::GlobalParams>(
params.m_poppler_data_path.empty()
? nullptr
: params.m_poppler_data_path.c_str());
#endif
}
};
static HolderAndInitializer instance;

return instance.params;
}

const std::string &GlobalParams::odr_core_data_path() {
return instance().m_odr_core_data_path;
}

const std::string &GlobalParams::fontforge_data_path() {
return instance().m_fontforge_data_path;
const std::string &GlobalParams::fontconfig_data_path() {
return instance().m_fontconfig_data_path;
}

const std::string &GlobalParams::poppler_data_path() {
Expand All @@ -33,8 +45,8 @@ void GlobalParams::set_odr_core_data_path(const std::string &path) {
instance().m_odr_core_data_path = path;
}

void GlobalParams::set_fontforge_data_path(const std::string &path) {
instance().m_fontforge_data_path = path;
void GlobalParams::set_fontconfig_data_path(const std::string &path) {
instance().m_fontconfig_data_path = path;
}

void GlobalParams::set_poppler_data_path(const std::string &path) {
Expand All @@ -50,11 +62,10 @@ void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) {
instance().m_pdf2htmlex_data_path = path;
}

GlobalParams::GlobalParams() {
set_odr_core_data_path(""); // TODO
set_fontforge_data_path(internal::project_info::fontconfig_data_path());
set_poppler_data_path(internal::project_info::poppler_data_path());
set_pdf2htmlex_data_path(internal::project_info::pdf2htmlex_data_path());
}
GlobalParams::GlobalParams()
: m_odr_core_data_path{}, // TODO
m_fontconfig_data_path{internal::project_info::fontconfig_data_path()},
m_poppler_data_path{internal::project_info::poppler_data_path()},
m_pdf2htmlex_data_path{internal::project_info::pdf2htmlex_data_path()} {}

} // namespace odr
6 changes: 3 additions & 3 deletions src/odr/global_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace odr {
class GlobalParams {
public:
static const std::string &odr_core_data_path();
static const std::string &fontforge_data_path();
static const std::string &fontconfig_data_path();
static const std::string &poppler_data_path();
static const std::string &pdf2htmlex_data_path();

static void set_odr_core_data_path(const std::string &path);
static void set_fontforge_data_path(const std::string &path);
static void set_fontconfig_data_path(const std::string &path);
static void set_poppler_data_path(const std::string &path);
static void set_pdf2htmlex_data_path(const std::string &path);

Expand All @@ -22,7 +22,7 @@ class GlobalParams {
GlobalParams();

std::string m_odr_core_data_path;
std::string m_fontforge_data_path;
std::string m_fontconfig_data_path;
std::string m_poppler_data_path;
std::string m_pdf2htmlex_data_path;
};
Expand Down
4 changes: 2 additions & 2 deletions src/odr/internal/html/pdf2htmlex_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ html::create_poppler_pdf_service(const PopplerPdfFile &pdf_file,
// TODO not sure what the `progPath` is used for. it cannot be `nullptr`
// TODO potentially just a cache dir?
auto html_renderer = std::make_shared<pdf2htmlEX::HTMLRenderer>(
odr::GlobalParams::fontforge_data_path().c_str(), *html_renderer_param);
odr::GlobalParams::fontconfig_data_path().c_str(), *html_renderer_param);
html_renderer->process(&pdf_doc);

HtmlResourceLocator resource_locator =
Expand Down Expand Up @@ -259,7 +259,7 @@ Html html::translate_poppler_pdf_file(const PopplerPdfFile &pdf_file,

// TODO not sure what the `progPath` is used for. it cannot be `nullptr`
// TODO potentially just a cache dir?
pdf2htmlEX::HTMLRenderer(odr::GlobalParams::fontforge_data_path().c_str(),
pdf2htmlEX::HTMLRenderer(odr::GlobalParams::fontconfig_data_path().c_str(),
param)
.process(&pdf_doc);

Expand Down

0 comments on commit 2098725

Please sign in to comment.