-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhtml.hpp
More file actions
290 lines (238 loc) · 8.89 KB
/
Copy pathhtml.hpp
File metadata and controls
290 lines (238 loc) · 8.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#pragma once
#include <odr/document.hpp>
#include <odr/file.hpp>
#include <odr/logger.hpp>
#include <odr/style.hpp>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>
namespace odr::internal::abstract {
class HtmlService;
class HtmlView;
class HtmlResource;
} // namespace odr::internal::abstract
namespace odr {
class Archive;
struct HtmlPage;
class HtmlService;
struct HtmlConfig;
enum class HtmlResourceType {
html_fragment,
css,
js,
image,
font,
};
class HtmlResource final {
public:
HtmlResource();
explicit HtmlResource(std::shared_ptr<internal::abstract::HtmlResource> impl);
[[nodiscard]] HtmlResourceType type() const;
[[nodiscard]] const std::string &mime_type() const;
[[nodiscard]] const std::string &name() const;
[[nodiscard]] const std::string &path() const;
[[nodiscard]] const std::optional<File> &file() const;
[[nodiscard]] bool is_shipped() const;
[[nodiscard]] bool is_external() const;
[[nodiscard]] bool is_accessible() const;
void write_resource(std::ostream &os) const;
private:
std::shared_ptr<internal::abstract::HtmlResource> m_impl;
};
using HtmlResourceLocation = std::optional<std::string>;
using HtmlResourceLocator = std::function<HtmlResourceLocation(
const HtmlResource &resource, const HtmlConfig &config)>;
using HtmlResources =
std::vector<std::pair<HtmlResource, HtmlResourceLocation>>;
/// @brief HTML table gridlines.
enum class HtmlTableGridlines {
none,
soft,
hard,
};
/// @brief HTML configuration.
struct HtmlConfig {
// document output file names
std::string document_output_file_name{"document.html"};
// document element output file names
std::string slide_output_file_name{"slide{index}.html"};
std::string sheet_output_file_name{"sheet{index}.html"};
std::string page_output_file_name{"page{index}.html"};
// embedding
bool embed_images{true};
bool embed_shipped_resources{true};
// resources
std::string resource_path;
bool relative_resource_paths{true};
// create editable output
bool editable{false};
// text document margin
bool text_document_margin{false};
// spreadsheet table limit
std::optional<TableDimensions> spreadsheet_limit{TableDimensions(10000, 500)};
bool spreadsheet_limit_by_content{true};
// spreadsheet gridlines
HtmlTableGridlines spreadsheet_gridlines{HtmlTableGridlines::soft};
// formatting
bool format_html{false};
std::uint8_t html_indent{2};
// background image
std::string background_image_format{"png"};
// drm
bool no_drm{false};
std::optional<std::string> output_path;
HtmlResourceLocator resource_locator;
HtmlConfig();
explicit HtmlConfig(std::string output_path_);
private:
void init();
};
/// @brief HTML output.
///
/// Represents the output of a translated file to HTML.
class Html final {
public:
Html(HtmlConfig config, std::vector<HtmlPage> pages);
[[nodiscard]] const HtmlConfig &config();
[[nodiscard]] const std::vector<HtmlPage> &pages() const;
private:
HtmlConfig m_config;
std::vector<HtmlPage> m_pages;
};
/// @brief HTML page.
///
/// Captures the name and path of an HTML page.
struct HtmlPage final {
std::string name;
std::string path;
HtmlPage(std::string name, std::string path);
};
class HtmlView final {
public:
HtmlView();
explicit HtmlView(std::shared_ptr<internal::abstract::HtmlView> impl);
[[nodiscard]] const std::string &name() const;
[[nodiscard]] const std::string &path() const;
[[nodiscard]] const HtmlConfig &config() const;
HtmlResources write_html(std::ostream &out) const;
[[nodiscard]] Html bring_offline(const std::string &output_path) const;
[[nodiscard]] const std::shared_ptr<internal::abstract::HtmlView> &
impl() const;
private:
std::shared_ptr<internal::abstract::HtmlView> m_impl;
};
using HtmlViews = std::vector<HtmlView>;
class HtmlService final {
public:
HtmlService();
explicit HtmlService(std::shared_ptr<internal::abstract::HtmlService> impl);
[[nodiscard]] const HtmlConfig &config() const;
[[nodiscard]] const HtmlViews &list_views() const;
void warmup() const;
[[nodiscard]] bool exists(const std::string &path) const;
[[nodiscard]] std::string mimetype(const std::string &path) const;
void write(const std::string &path, std::ostream &out) const;
HtmlResources write_html(const std::string &path, std::ostream &out) const;
[[nodiscard]] Html bring_offline(const std::string &output_path) const;
[[nodiscard]] Html bring_offline(const std::string &output_path,
const std::vector<HtmlView> &views) const;
[[nodiscard]] const std::shared_ptr<internal::abstract::HtmlService> &
impl() const;
private:
std::shared_ptr<internal::abstract::HtmlService> m_impl;
};
namespace html {
HtmlResourceLocator standard_resource_locator();
/// @brief Translates a decoded file to HTML.
///
/// @param file Decoded file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const DecodedFile &file, const std::string &cache_path,
const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates a text file to HTML.
///
/// @param text_file Text file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const TextFile &text_file, const std::string &cache_path,
const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates an image file to HTML.
///
/// @param image_file Image file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const ImageFile &image_file,
const std::string &cache_path, const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates an archive to HTML.
///
/// @param archive_file Archive file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const ArchiveFile &archive_file,
const std::string &cache_path, const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates a document to HTML.
///
/// @param document_file Document file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const DocumentFile &document_file,
const std::string &cache_path, const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates a PDF file to HTML.
///
/// @param pdf_file PDF file to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const PdfFile &pdf_file, const std::string &cache_path,
const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates an archive to HTML.
///
/// @param archive Archive to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const Archive &archive, const std::string &cache_path,
const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Translates a document to HTML.
///
/// @param document Document to translate.
/// @param cache_path Directory path for temporary output.
/// @param config Configuration for the HTML output.
/// @param logger Logger to use for logging.
/// @return HTML output.
HtmlService translate(const Document &document, const std::string &cache_path,
const HtmlConfig &config,
std::shared_ptr<Logger> logger = Logger::create_null());
/// @brief Edits a document with a diff.
///
/// @note The diff is generated by our JavaScript code in the browser.
///
/// @param document Document to edit.
/// @param diff Diff to apply.
/// @param logger Logger to use for logging.
void edit(const Document &document, const char *diff,
Logger &logger = Logger::null());
} // namespace html
} // namespace odr