Skip to content

Commit 932a8b5

Browse files
authored
handle light dark mode (#418)
1 parent 1dda2a4 commit 932a8b5

9 files changed

Lines changed: 48 additions & 33 deletions

File tree

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def requirements(self):
4444
self.requires("uchardet/0.0.8")
4545
self.requires("utfcpp/4.0.4")
4646
if self.options.get_safe("with_pdf2htmlEX", False):
47-
self.requires("pdf2htmlex/0.18.8.rc1-odr-pr1")
47+
self.requires("pdf2htmlex/0.18.8.rc1-odr-git-eb5d291")
4848
if self.options.get_safe("with_wvWare", False):
4949
self.requires("wvware/1.2.9-odr")
5050
self.requires("cpp-httplib/0.16.3")

src/odr/internal/html/document.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,26 @@
2222
#include <mutex>
2323

2424
namespace odr::internal::html {
25-
2625
namespace {
2726

2827
void front(const Document &document, const WritingState &state) {
28+
HtmlWriter &out = state.out();
29+
2930
bool paged_content = ((document.document_type() == DocumentType::text) &&
3031
state.config().text_document_margin) ||
3132
document.document_type() == DocumentType::presentation ||
3233
document.document_type() == DocumentType::drawing;
3334

34-
state.out().write_begin();
35-
state.out().write_header_begin();
36-
state.out().write_header_charset("UTF-8");
37-
state.out().write_header_target("_blank");
38-
state.out().write_header_title("odr");
35+
out.write_begin();
36+
out.write_header_begin();
37+
out.write_header_charset("UTF-8");
38+
out.write_header_target("_blank");
39+
out.write_header_title("odr");
40+
out.write_header_meta("color-scheme", "light dark");
3941
if (paged_content) {
40-
state.out().write_header_viewport("width=device-width,user-scalable=yes");
42+
out.write_header_viewport("width=device-width,user-scalable=yes");
4143
} else {
42-
state.out().write_header_viewport(
44+
out.write_header_viewport(
4345
"width=device-width,initial-scale=1.0,user-scalable=yes");
4446
}
4547

@@ -52,11 +54,11 @@ void front(const Document &document, const WritingState &state) {
5254
state.config().resource_locator(odr_css_resource, state.config());
5355
state.resources().emplace_back(std::move(odr_css_resource), odr_css_location);
5456
if (odr_css_location.has_value()) {
55-
state.out().write_header_style(odr_css_location.value());
57+
out.write_header_style(odr_css_location.value());
5658
} else {
57-
state.out().write_header_style_begin();
58-
util::stream::pipe(*odr_css_file.stream(), state.out().out());
59-
state.out().write_header_style_end();
59+
out.write_header_style_begin();
60+
util::stream::pipe(*odr_css_file.stream(), out.out());
61+
out.write_header_style_end();
6062
}
6163

6264
if (document.document_type() == DocumentType::spreadsheet) {
@@ -72,15 +74,15 @@ void front(const Document &document, const WritingState &state) {
7274
state.resources().emplace_back(std::move(odr_spreadsheet_css_resource),
7375
odr_spreadsheet_css_location);
7476
if (odr_spreadsheet_css_location.has_value()) {
75-
state.out().write_header_style(odr_spreadsheet_css_location.value());
77+
out.write_header_style(odr_spreadsheet_css_location.value());
7678
} else {
77-
state.out().write_header_style_begin();
78-
util::stream::pipe(*odr_spreadsheet_css_file.stream(), state.out().out());
79-
state.out().write_header_style_end();
79+
out.write_header_style_begin();
80+
util::stream::pipe(*odr_spreadsheet_css_file.stream(), out.out());
81+
out.write_header_style_end();
8082
}
8183
}
8284

83-
state.out().write_header_end();
85+
out.write_header_end();
8486

8587
std::string body_clazz = "odr-body";
8688
if (paged_content) {
@@ -101,22 +103,23 @@ void front(const Document &document, const WritingState &state) {
101103
}
102104
}
103105

104-
state.out().write_body_begin(HtmlElementOptions().set_class(body_clazz));
106+
out.write_body_begin(HtmlElementOptions().set_class(body_clazz));
105107

106108
if (paged_content) {
107-
state.out().write_element_begin(
108-
"div", HtmlElementOptions().set_class("odr-pages"));
109+
out.write_element_begin("div", HtmlElementOptions().set_class("odr-pages"));
109110
}
110111
}
111112

112113
void back(const Document &document, const WritingState &state) {
114+
HtmlWriter &out = state.out();
115+
113116
bool paged_content = ((document.document_type() == DocumentType::text) &&
114117
state.config().text_document_margin) ||
115118
document.document_type() == DocumentType::presentation ||
116119
document.document_type() == DocumentType::drawing;
117120

118121
if (paged_content) {
119-
state.out().write_element_end("div");
122+
out.write_element_end("div");
120123
}
121124

122125
auto odr_js_file = File(
@@ -128,15 +131,15 @@ void back(const Document &document, const WritingState &state) {
128131
state.config().resource_locator(odr_js_resource, state.config());
129132
state.resources().emplace_back(std::move(odr_js_resource), odr_js_location);
130133
if (odr_js_location.has_value()) {
131-
state.out().write_script(odr_js_location.value());
134+
out.write_script(odr_js_location.value());
132135
} else {
133-
state.out().write_script_begin();
134-
util::stream::pipe(*odr_js_file.stream(), state.out().out());
135-
state.out().write_script_end();
136+
out.write_script_begin();
137+
util::stream::pipe(*odr_js_file.stream(), out.out());
138+
out.write_script_end();
136139
}
137140

138-
state.out().write_body_end();
139-
state.out().write_end();
141+
out.write_body_end();
142+
out.write_end();
140143
}
141144

142145
std::string fill_path_variables(const std::string &path,
@@ -407,7 +410,6 @@ class PageHtmlFragment final : public HtmlFragmentBase {
407410
};
408411

409412
} // namespace
410-
411413
} // namespace odr::internal::html
412414

413415
namespace odr::internal {

src/odr/internal/html/filesystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class HtmlServiceImpl : public HtmlService {
7171
out.write_header_charset("UTF-8");
7272
out.write_header_target("_blank");
7373
out.write_header_title("odr");
74+
out.write_header_meta("color-scheme", "light dark");
7475
out.write_header_viewport(
7576
"width=device-width,initial-scale=1.0,user-scalable=yes");
7677
out.write_header_style_begin();

src/odr/internal/html/html_writer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,19 @@ void HtmlWriter::write_header_title(const std::string &title) {
158158
out() << "<title>" << title << "</title>";
159159
}
160160

161-
void HtmlWriter::write_header_viewport(const std::string &viewport) {
161+
void HtmlWriter::write_header_meta(const std::string &name,
162+
const std::string &content) {
162163
write_new_line();
163164

164-
out() << R"(<meta name="viewport" content=")";
165-
out() << viewport;
166-
out() << "\"/>";
165+
out() << R"(<meta name=")";
166+
out() << name;
167+
out() << R"(" content=")";
168+
out() << content;
169+
out() << R"("/>)";
170+
}
171+
172+
void HtmlWriter::write_header_viewport(const std::string &viewport) {
173+
write_header_meta("viewport", viewport);
167174
}
168175

169176
void HtmlWriter::write_header_target(const std::string &target) {

src/odr/internal/html/html_writer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class HtmlWriter {
5757
void write_header_begin();
5858
void write_header_end();
5959
void write_header_title(const std::string &title);
60+
void write_header_meta(const std::string &name, const std::string &content);
6061
void write_header_viewport(const std::string &viewport);
6162
void write_header_target(const std::string &target);
6263
void write_header_charset(const std::string &charset);

src/odr/internal/html/image_file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class HtmlServiceImpl : public HtmlService {
7070
out.write_header_begin();
7171
out.write_header_charset("UTF-8");
7272
out.write_header_target("_blank");
73+
out.write_header_meta("color-scheme", "light dark");
7374
out.write_header_title("odr");
7475
out.write_header_viewport(
7576
"width=device-width,initial-scale=1.0,user-scalable=yes");

src/odr/internal/html/pdf_file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class HtmlServiceImpl : public HtmlService {
9898
out.write_header_charset("UTF-8");
9999
out.write_header_target("_blank");
100100
out.write_header_title("odr");
101+
out.write_header_meta("color-scheme", "light dark");
101102
out.write_header_viewport(
102103
"width=device-width,initial-scale=1.0,user-scalable=yes");
103104
out.write_header_end();

src/odr/internal/html/text_file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class HtmlServiceImpl : public HtmlService {
7171
out.write_header_begin();
7272
out.write_header_charset("UTF-8");
7373
out.write_header_target("_blank");
74+
out.write_header_meta("color-scheme", "light dark");
7475
out.write_header_title("odr");
7576
out.write_header_viewport(
7677
"width=device-width,initial-scale=1.0,user-scalable=yes");

src/odr/internal/html/wvware_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ class HtmlServiceImpl : public HtmlService {
866866
out.write_header_charset("UTF-8");
867867
out.write_header_target("_blank");
868868
out.write_header_title("odr");
869+
out.write_header_meta("color-scheme", "light dark");
869870
out.write_header_viewport(
870871
"width=device-width,initial-scale=1.0,user-scalable=yes");
871872
out.write_header_end();

0 commit comments

Comments
 (0)