From 2098725584aa20502789f3c7a5407c26db5f9cb7 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Thu, 9 Jan 2025 16:23:57 +0100 Subject: [PATCH] fix recursive initialization --- src/odr/global_params.cpp | 35 +++++++++++++------- src/odr/global_params.hpp | 6 ++-- src/odr/internal/html/pdf2htmlex_wrapper.cpp | 4 +-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/odr/global_params.cpp b/src/odr/global_params.cpp index f4ac7bab..347e4296 100644 --- a/src/odr/global_params.cpp +++ b/src/odr/global_params.cpp @@ -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() { @@ -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) { @@ -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 diff --git a/src/odr/global_params.hpp b/src/odr/global_params.hpp index 665dc7bc..9888be17 100644 --- a/src/odr/global_params.hpp +++ b/src/odr/global_params.hpp @@ -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); @@ -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; }; diff --git a/src/odr/internal/html/pdf2htmlex_wrapper.cpp b/src/odr/internal/html/pdf2htmlex_wrapper.cpp index b05df278..0d94fdd3 100644 --- a/src/odr/internal/html/pdf2htmlex_wrapper.cpp +++ b/src/odr/internal/html/pdf2htmlex_wrapper.cpp @@ -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( - 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 = @@ -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);