diff --git a/CMakeLists.txt b/CMakeLists.txt index 182373e0..ee9c00ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ set(ODR_SOURCE_FILES "src/odr/exceptions.cpp" "src/odr/file.cpp" "src/odr/filesystem.cpp" + "src/odr/global_params.cpp" "src/odr/html.cpp" "src/odr/html_service.cpp" "src/odr/open_document_reader.cpp" diff --git a/src/odr/global_params.cpp b/src/odr/global_params.cpp index c1ccc5c8..981062c5 100644 --- a/src/odr/global_params.cpp +++ b/src/odr/global_params.cpp @@ -2,6 +2,8 @@ #include +#include + namespace odr { GlobalParams &GlobalParams::instance() { @@ -35,6 +37,11 @@ void GlobalParams::set_fontforge_data_path(const std::string &path) { void GlobalParams::set_poppler_data_path(const std::string &path) { instance().m_poppler_data_path = path; + +#ifdef ODR_WITH_PDF2HTMLEX + globalParams = + std::make_unique<::GlobalParams>(path.empty() ? nullptr : path.c_str()); +#endif } void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) { diff --git a/src/odr/internal/html/pdf2htmlex_wrapper.cpp b/src/odr/internal/html/pdf2htmlex_wrapper.cpp index da2b8bc6..b1443227 100644 --- a/src/odr/internal/html/pdf2htmlex_wrapper.cpp +++ b/src/odr/internal/html/pdf2htmlex_wrapper.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -13,7 +14,6 @@ #include #include -#include #include namespace odr::internal::html { @@ -91,8 +91,8 @@ pdf2htmlEX::Param create_params(PDFDoc &pdf_doc, const HtmlConfig &config, // misc param.clean_tmp = 1; param.tmp_dir = output_path; - param.data_dir = config.pdf2htmlex_data_path; - param.poppler_data_dir = config.poppler_data_path; + param.data_dir = odr::GlobalParams::pdf2htmlex_data_path(); + param.poppler_data_dir = odr::GlobalParams::poppler_data_path(); param.debug = 0; param.proof = 0; param.quiet = 1; @@ -220,19 +220,12 @@ html::create_poppler_pdf_service(const PopplerPdfFile &pdf_file, } } - globalParams = std::make_unique( - !html_renderer_param->poppler_data_dir.empty() - ? html_renderer_param->poppler_data_dir.c_str() - : nullptr); - // 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( - config.fontforge_data_path.c_str(), *html_renderer_param); + odr::GlobalParams::fontforge_data_path().c_str(), *html_renderer_param); html_renderer->process(&pdf_doc); - globalParams.reset(); - HtmlResourceLocator resource_locator = local_resource_locator(output_path, config); @@ -259,17 +252,12 @@ Html html::translate_poppler_pdf_file(const PopplerPdfFile &pdf_file, } } - globalParams = std::make_unique( - !param.poppler_data_dir.empty() ? param.poppler_data_dir.c_str() - : nullptr); - // TODO not sure what the `progPath` is used for. it cannot be `nullptr` // TODO potentially just a cache dir? - pdf2htmlEX::HTMLRenderer(config.fontforge_data_path.c_str(), param) + pdf2htmlEX::HTMLRenderer(odr::GlobalParams::fontforge_data_path().c_str(), + param) .process(&pdf_doc); - globalParams.reset(); - return {FileType::portable_document_format, config, {{"document", output_path + "/document.html"}}};