Skip to content

Commit

Permalink
global params (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Jan 8, 2025
1 parent 1149724 commit 0a8cecb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 32 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
60 changes: 60 additions & 0 deletions src/odr/global_params.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <odr/global_params.hpp>

#include <odr/internal/project_info.hpp>

#ifdef ODR_WITH_PDF2HTMLEX
#include <poppler/GlobalParams.h>
#endif

namespace odr {

GlobalParams &GlobalParams::instance() {
static GlobalParams instance;
return instance;
}

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::poppler_data_path() {
return instance().m_poppler_data_path;
}

const std::string &GlobalParams::pdf2htmlex_data_path() {
return instance().m_pdf2htmlex_data_path;
}

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_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) {
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());
}

} // namespace odr
30 changes: 30 additions & 0 deletions src/odr/global_params.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <string>

namespace odr {

class GlobalParams {
public:
static const std::string &odr_core_data_path();
static const std::string &fontforge_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_poppler_data_path(const std::string &path);
static void set_pdf2htmlex_data_path(const std::string &path);

private:
static GlobalParams &instance();

GlobalParams();

std::string m_odr_core_data_path;
std::string m_fontforge_data_path;
std::string m_poppler_data_path;
std::string m_pdf2htmlex_data_path;
};

} // namespace odr
7 changes: 0 additions & 7 deletions src/odr/html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#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 @@ -26,12 +25,6 @@ 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: 0 additions & 7 deletions src/odr/html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ 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
24 changes: 6 additions & 18 deletions src/odr/internal/html/pdf2htmlex_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <odr/exceptions.hpp>
#include <odr/file.hpp>
#include <odr/global_params.hpp>
#include <odr/html.hpp>

#include <odr/internal/html/common.hpp>
Expand All @@ -13,7 +14,6 @@
#include <pdf2htmlEX/HTMLRenderer/HTMLRenderer.h>
#include <pdf2htmlEX/Param.h>

#include <poppler/GlobalParams.h>
#include <poppler/PDFDoc.h>

namespace odr::internal::html {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -220,19 +220,12 @@ html::create_poppler_pdf_service(const PopplerPdfFile &pdf_file,
}
}

globalParams = std::make_unique<GlobalParams>(
!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<pdf2htmlEX::HTMLRenderer>(
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);

Expand All @@ -259,17 +252,12 @@ Html html::translate_poppler_pdf_file(const PopplerPdfFile &pdf_file,
}
}

globalParams = std::make_unique<GlobalParams>(
!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"}}};
Expand Down

0 comments on commit 0a8cecb

Please sign in to comment.