summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-09-16 14:25:56 +0200
committerCarl Hetherington <cth@carlh.net>2025-09-16 14:25:56 +0200
commit4e92b51166abe50693c6f71d1a148a59452c1704 (patch)
tree7347147c164cb6653581b8cd90511fcc4f521116 /src
parent81b7a682585d35e8077feffef28d605bef746107 (diff)
Split HTMLFormatter methods out to a .cc
Diffstat (limited to 'src')
-rw-r--r--src/html_formatter.cc140
-rw-r--r--src/html_formatter.h90
-rw-r--r--src/wscript1
3 files changed, 154 insertions, 77 deletions
diff --git a/src/html_formatter.cc b/src/html_formatter.cc
new file mode 100644
index 00000000..07773645
--- /dev/null
+++ b/src/html_formatter.cc
@@ -0,0 +1,140 @@
+/*
+ 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 "html_formatter.h"
+#include <boost/filesystem.hpp>
+
+
+using namespace dcp;
+
+
+
+HTMLFormatter::HTMLFormatter(boost::filesystem::path file)
+ : Formatter(file)
+{
+
+}
+
+
+void
+HTMLFormatter::heading(std::string const& text)
+{
+ tagged("h1", text);
+}
+
+
+void
+HTMLFormatter::subheading(std::string const& text)
+{
+ tagged("h2", text);
+}
+
+
+Formatter::Wrap
+HTMLFormatter::document()
+{
+ 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;
+}
+
+
+Formatter::Wrap
+HTMLFormatter::body()
+{
+ return wrapped("body");
+}
+
+
+Formatter::Wrap
+HTMLFormatter::unordered_list()
+{
+ return wrapped("ul");
+}
+
+
+void
+HTMLFormatter::list_item(std::string const& text, boost::optional<std::string> type)
+{
+ 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)>
+HTMLFormatter::process_string()
+{
+ return [](std::string s) {
+ boost::replace_all(s, "<", "&lt;");
+ boost::replace_all(s, ">", "&gt;");
+ return s;
+ };
+}
+
+
+std::function<std::string (std::string)>
+HTMLFormatter::process_filename()
+{
+ return [](std::string s) {
+ return String::compose("<code>%1</code>", s);
+ };
+}
+
+
+void
+HTMLFormatter::tagged(std::string tag, std::string content)
+{
+ _file.puts(String::compose("<%1>%2</%3>\n", tag, content, tag).c_str());
+}
+
+
+HTMLFormatter::Wrap
+HTMLFormatter::wrapped(std::string const& tag)
+{
+ _file.puts(String::compose("<%1>", tag).c_str());
+ return Wrap(this, String::compose("</%1>", tag));
+}
+
diff --git a/src/html_formatter.h b/src/html_formatter.h
index 4b537190..ab46ee2d 100644
--- a/src/html_formatter.h
+++ b/src/html_formatter.h
@@ -28,85 +28,21 @@ 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);
- };
- }
+ HTMLFormatter(boost::filesystem::path file);
+
+ void heading(std::string const& text) override;
+ void subheading(std::string const& text) override;
+ Wrap document() override;
+ Wrap body() override;
+ Wrap unordered_list() override;
+ void list_item(std::string const& text, boost::optional<std::string> type = {}) override;
+
+ std::function<std::string (std::string)> process_string() override;
+ std::function<std::string (std::string)> process_filename() override;
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));
- };
+ void tagged(std::string tag, std::string content);
+ Wrap wrapped(std::string const& tag);
};
}
diff --git a/src/wscript b/src/wscript
index 352cd196..1c75f2a4 100644
--- a/src/wscript
+++ b/src/wscript
@@ -63,6 +63,7 @@ def build(bld):
fsk.cc
gamma_transfer_function.cc
h_align.cc
+ html_formatter.cc
identity_transfer_function.cc
interop_load_font_node.cc
interop_text_asset.cc