Skip to content

Commit

Permalink
config data paths (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Dec 29, 2024
1 parent a2c6c33 commit 00899d4
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 31 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions src/odr/html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <odr/internal/html/wvware_wrapper.hpp>
#include <odr/internal/oldms_wvware/wvware_oldms_file.hpp>
#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp>
#include <odr/internal/project_info.hpp>

#include <filesystem>

Expand All @@ -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<HtmlPage> pages)
: m_file_type{file_type}, m_config{std::move(config)},
m_pages{std::move(pages)} {}
Expand Down
7 changes: 7 additions & 0 deletions src/odr/html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/odr/internal/git_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 4 additions & 15 deletions src/odr/internal/html/pdf2htmlex_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <odr/html.hpp>

#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp>
#include <odr/internal/project_info.hpp>

#include <pdf2htmlEX/HTMLRenderer/HTMLRenderer.h>
#include <pdf2htmlEX/Param.h>
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down
36 changes: 36 additions & 0 deletions src/odr/internal/project_info.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions src/odr/internal/project_info.hpp
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions src/odr/internal/project_info.hpp.in

This file was deleted.

0 comments on commit 00899d4

Please sign in to comment.