|
9 | 9 | #include <odr/internal/html/document.hpp> |
10 | 10 | #include <odr/internal/html/filesystem.hpp> |
11 | 11 | #include <odr/internal/html/image_file.hpp> |
| 12 | +#include <odr/internal/html/pdf_file.hpp> |
12 | 13 | #include <odr/internal/html/text_file.hpp> |
13 | 14 |
|
14 | | -#include <nlohmann/json.hpp> |
15 | | - |
16 | 15 | #include <filesystem> |
17 | 16 |
|
| 17 | +#include <nlohmann/json.hpp> |
| 18 | + |
18 | 19 | using namespace odr::internal; |
19 | 20 | namespace fs = std::filesystem; |
20 | 21 |
|
@@ -53,21 +54,32 @@ Html html::translate(const File &file, const std::string &output_path, |
53 | 54 | const PasswordCallback &password_callback) { |
54 | 55 | auto decoded_file = DecodedFile(file); |
55 | 56 |
|
56 | | - if (decoded_file.file_category() == FileCategory::text) { |
57 | | - return translate(decoded_file.text_file(), output_path, config); |
58 | | - } else if (decoded_file.file_category() == FileCategory::image) { |
59 | | - return translate(decoded_file.image_file(), output_path, config); |
60 | | - } else if (decoded_file.file_category() == FileCategory::archive) { |
61 | | - return translate(decoded_file.archive_file().archive(), output_path, |
62 | | - config); |
63 | | - } else if (decoded_file.file_category() == FileCategory::document) { |
| 57 | + if (decoded_file.is_document_file()) { |
64 | 58 | DocumentFile document_file = decoded_file.document_file(); |
65 | 59 | if (document_file.password_encrypted()) { |
66 | 60 | if (!document_file.decrypt(password_callback())) { |
67 | 61 | throw WrongPassword(); |
68 | 62 | } |
69 | 63 | } |
70 | | - return translate(document_file.document(), output_path, config); |
| 64 | + } |
| 65 | + |
| 66 | + return translate(decoded_file, output_path, config); |
| 67 | +} |
| 68 | + |
| 69 | +Html html::translate(const DecodedFile &decoded_file, |
| 70 | + const std::string &output_path, const HtmlConfig &config) { |
| 71 | + if (decoded_file.is_text_file()) { |
| 72 | + return translate(decoded_file.text_file(), output_path, config); |
| 73 | + } else if (decoded_file.is_image_file()) { |
| 74 | + return translate(decoded_file.image_file(), output_path, config); |
| 75 | + } else if (decoded_file.is_archive_file()) { |
| 76 | + return translate(decoded_file.archive_file().archive(), output_path, |
| 77 | + config); |
| 78 | + } else if (decoded_file.is_document_file()) { |
| 79 | + return translate(decoded_file.document_file().document(), output_path, |
| 80 | + config); |
| 81 | + } else if (decoded_file.is_pdf_file()) { |
| 82 | + return translate(decoded_file.pdf_file(), output_path, config); |
71 | 83 | } |
72 | 84 |
|
73 | 85 | throw UnsupportedFileType(decoded_file.file_type()); |
@@ -98,6 +110,12 @@ Html html::translate(const Document &document, const std::string &output_path, |
98 | 110 | return internal::html::translate_document(document, output_path, config); |
99 | 111 | } |
100 | 112 |
|
| 113 | +Html html::translate(const PdfFile &pdf_file, const std::string &output_path, |
| 114 | + const HtmlConfig &config) { |
| 115 | + fs::create_directories(output_path); |
| 116 | + return internal::html::translate_pdf_file(pdf_file, output_path, config); |
| 117 | +} |
| 118 | + |
101 | 119 | void html::edit(const Document &document, const char *diff) { |
102 | 120 | auto json = nlohmann::json::parse(diff); |
103 | 121 | for (const auto &[key, value] : json["modifiedText"].items()) { |
|
0 commit comments