summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-09-16 14:11:32 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-16 14:11:32 +0200
commit81b7a682585d35e8077feffef28d605bef746107 (patch)
treeafcef7af66b57c0f4def04e54011344f584422c7 /src
parent3b95566292358924dabb7b11d0abcb849c68769b (diff)
Move {HTML/Text}Formatter out to their own files.
Diffstat (limited to 'src')
-rw-r--r--src/html_formatter.h113
-rw-r--r--src/text_formatter.h81
-rw-r--r--src/verify_report.h144
-rw-r--r--src/wscript2
4 files changed, 203 insertions, 137 deletions
diff --git a/src/html_formatter.h b/src/html_formatter.h
new file mode 100644
index 00000000..4b537190
--- /dev/null
+++ b/src/html_formatter.h
@@ -0,0 +1,113 @@
+/*
+ Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "verify_report.h"
+
+
+namespace dcp {
+
+
+class HTMLFormatter : public Formatter
+{
+public:
+ HTMLFormatter(boost::filesystem::path file)
+ : Formatter(file)
+ {}
+
+ void heading(std::string const& text) override {
+ tagged("h1", text);
+ }
+
+ void subheading(std::string const& text) override {
+ tagged("h2", text);
+ }
+
+ Wrap document() override {
+ auto html = wrapped("html");
+ auto head = wrapped("head");
+ auto style = wrapped("style");
+ _file.puts("li {\n"
+ " margin: 2px;\n"
+ " padding: 2px 2px 2px 1em;\n"
+ "}\n"
+ );
+ _file.puts("li.ok {\n"
+ " background-color: #00ff00;\n"
+ "}\n"
+ "li.warning {\n"
+ " background-color: #ffa500;\n"
+ "}\n"
+ "li.error {\n"
+ " background-color: #ff0000;\n"
+ "}\n"
+ "li.bv21-error {\n"
+ " background-color: #ff6666;\n"
+ "}\n"
+ "ul {\n"
+ " list-style: none;\n"
+ "}\n"
+ );
+ return html;
+ }
+
+ Wrap body() override {
+ return wrapped("body");
+ }
+
+ Wrap unordered_list() override {
+ return wrapped("ul");
+ }
+
+ void list_item(std::string const& text, boost::optional<std::string> type = {}) override {
+ if (type) {
+ _file.puts(dcp::String::compose("<li class=\"%1\">%2</li>\n", *type, text).c_str());
+ } else {
+ _file.puts(dcp::String::compose("<li>%1</li>\n", text).c_str());
+ }
+ }
+
+ std::function<std::string (std::string)> process_string() override {
+ return [](std::string s) {
+ boost::replace_all(s, "<", "&lt;");
+ boost::replace_all(s, ">", "&gt;");
+ return s;
+ };
+ }
+
+ std::function<std::string (std::string)> process_filename() override {
+ return [](std::string s) {
+ return String::compose("<code>%1</code>", s);
+ };
+ }
+
+private:
+ void tagged(std::string tag, std::string content) {
+ _file.puts(String::compose("<%1>%2</%3>\n", tag, content, tag).c_str());
+ };
+
+ Wrap wrapped(std::string const& tag) {
+ _file.puts(String::compose("<%1>", tag).c_str());
+ return Wrap(this, String::compose("</%1>", tag));
+ };
+};
+
+}
+
diff --git a/src/text_formatter.h b/src/text_formatter.h
new file mode 100644
index 00000000..fed2d364
--- /dev/null
+++ b/src/text_formatter.h
@@ -0,0 +1,81 @@
+/*
+ Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "verify_report.h"
+
+
+namespace dcp {
+
+
+class TextFormatter : public Formatter
+{
+public:
+ TextFormatter(boost::filesystem::path file)
+ : Formatter(file)
+ {}
+
+ void heading(std::string const& text) override {
+ print(text);
+ }
+
+ void subheading(std::string const& text) override {
+ print("");
+ print(text);
+ }
+
+ Wrap unordered_list() override {
+ _indent++;
+ return Wrap(this, "", [this]() { _indent--; });
+ }
+
+ void list_item(std::string const& text, boost::optional<std::string> type = {}) override {
+ LIBDCP_UNUSED(type);
+ for (int i = 0; i < _indent * 2; ++i) {
+ _file.puts(" ");
+ }
+ _file.puts("* ");
+ print(text);
+ }
+
+ std::function<std::string (std::string)> process_string() override {
+ return [](std::string s) {
+ return s;
+ };
+ }
+
+ std::function<std::string (std::string)> process_filename() override {
+ return [](std::string s) {
+ return s;
+ };
+ }
+
+private:
+ void print(std::string const& text) {
+ _file.puts(text.c_str());
+ _file.puts("\n");
+ }
+
+ int _indent = 0;
+};
+
+
+}
+
diff --git a/src/verify_report.h b/src/verify_report.h
index b6b99391..a75450df 100644
--- a/src/verify_report.h
+++ b/src/verify_report.h
@@ -19,6 +19,10 @@
*/
+#ifndef DCP_VERIFY_REPORT_H
+#define DCP_VERIFY_REPORT_H
+
+
#include "compose.hpp"
#include "file.h"
#include "verify.h"
@@ -96,145 +100,11 @@ protected:
};
-class TextFormatter : public Formatter
-{
-public:
- TextFormatter(boost::filesystem::path file)
- : Formatter(file)
- {}
-
- void heading(std::string const& text) override {
- print(text);
- }
-
- void subheading(std::string const& text) override {
- print("");
- print(text);
- }
-
- Wrap unordered_list() override {
- _indent++;
- return Wrap(this, "", [this]() { _indent--; });
- }
-
- void list_item(std::string const& text, boost::optional<std::string> type = {}) override {
- LIBDCP_UNUSED(type);
- for (int i = 0; i < _indent * 2; ++i) {
- _file.puts(" ");
- }
- _file.puts("* ");
- print(text);
- }
-
- std::function<std::string (std::string)> process_string() override {
- return [](std::string s) {
- return s;
- };
- }
-
- std::function<std::string (std::string)> process_filename() override {
- return [](std::string s) {
- return s;
- };
- }
-
-private:
- void print(std::string const& text) {
- _file.puts(text.c_str());
- _file.puts("\n");
- }
-
- int _indent = 0;
-};
-
-
-class HTMLFormatter : public Formatter
-{
-public:
- HTMLFormatter(boost::filesystem::path file)
- : Formatter(file)
- {}
-
- void heading(std::string const& text) override {
- tagged("h1", text);
- }
-
- void subheading(std::string const& text) override {
- tagged("h2", text);
- }
-
- Wrap document() override {
- auto html = wrapped("html");
- auto head = wrapped("head");
- auto style = wrapped("style");
- _file.puts("li {\n"
- " margin: 2px;\n"
- " padding: 2px 2px 2px 1em;\n"
- "}\n"
- );
- _file.puts("li.ok {\n"
- " background-color: #00ff00;\n"
- "}\n"
- "li.warning {\n"
- " background-color: #ffa500;\n"
- "}\n"
- "li.error {\n"
- " background-color: #ff0000;\n"
- "}\n"
- "li.bv21-error {\n"
- " background-color: #ff6666;\n"
- "}\n"
- "ul {\n"
- " list-style: none;\n"
- "}\n"
- );
- return html;
- }
-
- Wrap body() override {
- return wrapped("body");
- }
-
- Wrap unordered_list() override {
- return wrapped("ul");
- }
-
- void list_item(std::string const& text, boost::optional<std::string> type = {}) override {
- if (type) {
- _file.puts(dcp::String::compose("<li class=\"%1\">%2</li>\n", *type, text).c_str());
- } else {
- _file.puts(dcp::String::compose("<li>%1</li>\n", text).c_str());
- }
- }
-
- std::function<std::string (std::string)> process_string() override {
- return [](std::string s) {
- boost::replace_all(s, "<", "&lt;");
- boost::replace_all(s, ">", "&gt;");
- return s;
- };
- }
-
- std::function<std::string (std::string)> process_filename() override {
- return [](std::string s) {
- return String::compose("<code>%1</code>", s);
- };
- }
-
-private:
- void tagged(std::string tag, std::string content) {
- _file.puts(String::compose("<%1>%2</%3>\n", tag, content, tag).c_str());
- };
-
- Wrap wrapped(std::string const& tag) {
- _file.puts(String::compose("<%1>", tag).c_str());
- return Wrap(this, String::compose("</%1>", tag));
- };
-};
-
-
extern void verify_report(std::vector<dcp::VerificationResult> const& results, Formatter& formatter);
}
+
+#endif
+
diff --git a/src/wscript b/src/wscript
index 1ef4f4ca..352cd196 100644
--- a/src/wscript
+++ b/src/wscript
@@ -174,6 +174,7 @@ def build(bld):
fsk.h
gamma_transfer_function.h
h_align.h
+ html_formatter.h
identity_transfer_function.h
interop_load_font_node.h
interop_text_asset.h
@@ -242,6 +243,7 @@ def build(bld):
text.h
text_asset.h
text_image.h
+ text_formatter.h
subtitle_standard.h
text_string.h
text_type.h