From 00899d44c270fc947f7afc869529ea7e017efd3f Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sun, 29 Dec 2024 16:43:42 +0100 Subject: [PATCH] config data paths (#392) --- CMakeLists.txt | 1 - src/odr/html.cpp | 7 ++++ src/odr/html.hpp | 7 ++++ src/odr/internal/git_info.hpp | 2 ++ src/odr/internal/html/pdf2htmlex_wrapper.cpp | 19 +++-------- src/odr/internal/project_info.cpp.in | 36 ++++++++++++++++++++ src/odr/internal/project_info.hpp | 17 +++++++++ src/odr/internal/project_info.hpp.in | 15 -------- 8 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 src/odr/internal/project_info.hpp delete mode 100644 src/odr/internal/project_info.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c869e538..797a2717 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,6 @@ find_package(uchardet REQUIRED) find_package(utf8cpp REQUIRED) configure_file("src/odr/internal/project_info.cpp.in" "src/odr/internal/project_info.cpp") -configure_file("src/odr/internal/project_info.hpp.in" "src/odr/internal/project_info.hpp") set(PRE_CONFIGURE_FILE "src/odr/internal/git_info.cpp.in") set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/src/odr/internal/git_info.cpp") diff --git a/src/odr/html.cpp b/src/odr/html.cpp index c619d33a..a5a0d570 100644 --- a/src/odr/html.cpp +++ b/src/odr/html.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -25,6 +26,12 @@ namespace fs = std::filesystem; namespace odr { +HtmlConfig::HtmlConfig() { + fontforge_data_path = internal::project_info::fontconfig_data_path(); + poppler_data_path = internal::project_info::poppler_data_path(); + pdf2htmlex_data_path = internal::project_info::pdf2htmlex_data_path(); +} + Html::Html(FileType file_type, HtmlConfig config, std::vector pages) : m_file_type{file_type}, m_config{std::move(config)}, m_pages{std::move(pages)} {} diff --git a/src/odr/html.hpp b/src/odr/html.hpp index 7996cb18..020bf218 100644 --- a/src/odr/html.hpp +++ b/src/odr/html.hpp @@ -61,6 +61,13 @@ struct HtmlConfig { // formatting bool format_html{false}; std::uint8_t html_indent{2}; + + // pdf2htmlex + std::string fontforge_data_path; + std::string poppler_data_path; + std::string pdf2htmlex_data_path; + + HtmlConfig(); }; /// @brief HTML output. diff --git a/src/odr/internal/git_info.hpp b/src/odr/internal/git_info.hpp index bf938671..168b0981 100644 --- a/src/odr/internal/git_info.hpp +++ b/src/odr/internal/git_info.hpp @@ -2,8 +2,10 @@ #define ODR_INTERNAL_GIT_INFO_HPP namespace odr::internal::git_info { + const char *commit() noexcept; bool is_dirty() noexcept; + } // namespace odr::internal::git_info #endif // ODR_INTERNAL_GIT_INFO_HPP diff --git a/src/odr/internal/html/pdf2htmlex_wrapper.cpp b/src/odr/internal/html/pdf2htmlex_wrapper.cpp index e8856b15..baa4a836 100644 --- a/src/odr/internal/html/pdf2htmlex_wrapper.cpp +++ b/src/odr/internal/html/pdf2htmlex_wrapper.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -20,17 +19,6 @@ Html html::translate_poppler_pdf_file(const PopplerPdfFile &pdf_file, const HtmlConfig &config) { PDFDoc &pdf_doc = pdf_file.pdf_doc(); - const char *fontconfig_path = std::getenv("FONTCONFIG_PATH"); - if (fontconfig_path == nullptr) { - // Storage is allocated and after successful putenv, it will never be freed. - // This is the way of putenv. - char *storage = strdup("FONTCONFIG_PATH=" FONTCONFIG_PATH); - if (0 != putenv(storage)) { - free(storage); - } - fontconfig_path = std::getenv("FONTCONFIG_PATH"); - } - pdf2htmlEX::Param param; // pages @@ -99,8 +87,8 @@ Html html::translate_poppler_pdf_file(const PopplerPdfFile &pdf_file, // misc param.clean_tmp = 1; param.tmp_dir = "/tmp"; - param.data_dir = PDF2HTMLEX_DATA_DIR; - param.poppler_data_dir = POPPLER_DATA_DIR; + param.data_dir = config.pdf2htmlex_data_path; + param.poppler_data_dir = config.poppler_data_path; param.debug = 0; param.proof = 0; param.quiet = 1; @@ -121,7 +109,8 @@ 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(fontconfig_path, param).process(&pdf_doc); + pdf2htmlEX::HTMLRenderer(config.fontforge_data_path.c_str(), param) + .process(&pdf_doc); globalParams.reset(); diff --git a/src/odr/internal/project_info.cpp.in b/src/odr/internal/project_info.cpp.in index 4effa6a4..c5569bec 100644 --- a/src/odr/internal/project_info.cpp.in +++ b/src/odr/internal/project_info.cpp.in @@ -4,4 +4,40 @@ namespace odr::internal { const char *project_info::version() noexcept { return "${CMAKE_PROJECT_VERSION}"; } +bool project_info::is_debug() noexcept { +#ifdef NDEBUG + return false; +#else + return true; +#endif +} + +bool project_info::with_wvware() noexcept { +#ifdef ODR_WITH_WVWARE + return true; +#else + return false; +#endif +} + +bool project_info::with_pdf2htmlex() noexcept{ +#ifdef ODR_WITH_PDF2HTMLEX + return true; +#else + return false; +#endif +} + +const char *project_info::fontconfig_data_path() noexcept { + return "${FONTCONFIG_PATH}"; +} + +const char *project_info::poppler_data_path() noexcept { + return "${POPPLER_DATA_DIR}"; +} + +const char *project_info::pdf2htmlex_data_path() noexcept{ + return "${PDF2HTMLEX_DATA_DIR}"; +} + } // namespace odr::internal diff --git a/src/odr/internal/project_info.hpp b/src/odr/internal/project_info.hpp new file mode 100644 index 00000000..272cdc21 --- /dev/null +++ b/src/odr/internal/project_info.hpp @@ -0,0 +1,17 @@ +#ifndef ODR_INTERNAL_PROJECT_INFO_HPP +#define ODR_INTERNAL_PROJECT_INFO_HPP + +namespace odr::internal::project_info { + +const char *version() noexcept; +bool is_debug() noexcept; + +bool with_wvware() noexcept; +bool with_pdf2htmlex() noexcept; +const char *fontconfig_data_path() noexcept; +const char *poppler_data_path() noexcept; +const char *pdf2htmlex_data_path() noexcept; + +} // namespace odr::internal::project_info + +#endif // ODR_INTERNAL_PROJECT_INFO_HPP diff --git a/src/odr/internal/project_info.hpp.in b/src/odr/internal/project_info.hpp.in deleted file mode 100644 index 0af208e4..00000000 --- a/src/odr/internal/project_info.hpp.in +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ODR_INTERNAL_PROJECT_INFO_HPP -#define ODR_INTERNAL_PROJECT_INFO_HPP - -namespace odr::internal::project_info { -const char *version() noexcept; -} // namespace odr::internal::project_info - -#cmakedefine WITH_PDF2HTMLEX 1 -#cmakedefine PDF2HTMLEX_DATA_DIR "@PDF2HTMLEX_DATA_DIR@" -#cmakedefine POPPLER_DATA_DIR "@POPPLER_DATA_DIR@" -#cmakedefine FONTCONFIG_PATH "@FONTCONFIG_PATH@" -#cmakedefine WITH_WVWARE 1 -#cmakedefine WVDATADIR "@WVDATADIR@" - -#endif // ODR_INTERNAL_PROJECT_INFO_HPP