2 Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/render_text_test.cc
23 * @brief Check markup of subtitles for rendering.
28 #include "lib/image.h"
29 #include "lib/image_png.h"
30 #include "lib/render_text.h"
31 #include "lib/string_text.h"
33 #include <dcp/subtitle_string.h>
34 #include <boost/test/unit_test.hpp>
37 using std::make_shared;
38 using std::shared_ptr;
42 add(std::vector<StringText>& s, std::string text, bool italic, bool bold, bool underline)
47 boost::optional<std::string> (),
51 dcp::Colour (255, 255, 255),
64 dcp::Colour (0, 0, 0),
68 std::vector<dcp::Ruby>()
71 std::shared_ptr<dcpomatic::Font>(),
72 dcp::SubtitleStandard::SMPTE_2014
78 BOOST_AUTO_TEST_CASE (marked_up_test1)
80 std::vector<StringText> s;
81 add (s, "Hello", false, false, false);
82 BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
86 BOOST_AUTO_TEST_CASE (marked_up_test2)
88 std::vector<StringText> s;
89 add (s, "Hello", false, true, false);
90 BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
94 BOOST_AUTO_TEST_CASE (marked_up_test3)
96 std::vector<StringText> s;
97 add (s, "Hello", true, true, false);
98 BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
101 BOOST_AUTO_TEST_CASE (marked_up_test4)
103 std::vector<StringText> s;
104 add (s, "Hello", true, true, true);
105 BOOST_CHECK_EQUAL(marked_up(s, 1024, 1, ""), "<span style=\"italic\" weight=\"bold\" underline=\"single\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span>");
108 BOOST_AUTO_TEST_CASE (marked_up_test5)
110 std::vector<StringText> s;
111 add (s, "Hello", false, true, false);
112 add (s, " world.", false, false, false);
113 BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\"> world.</span>");
116 BOOST_AUTO_TEST_CASE (marked_up_test6)
118 std::vector<StringText> s;
119 add (s, "Hello", true, false, false);
120 add (s, " world ", false, false, false);
121 add (s, "we are bold.", false, true, false);
122 BOOST_CHECK_EQUAL (marked_up(s, 1024, 1, ""), "<span style=\"italic\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">Hello</span><span size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\"> world </span><span weight=\"bold\" size=\"41705\" alpha=\"65535\" color=\"#FFFFFF\">we are bold.</span>");
126 BOOST_AUTO_TEST_CASE(render_text_with_newline_test)
128 std::list<dcp::SubtitleString> ss = {
130 {}, true, false, false, dcp::Colour(255, 255, 255), 42, 1.0,
131 dcp::Time(0, 0, 0, 0, 24), dcp::Time(0, 0, 1, 0, 24),
132 0.5, dcp::HAlign::CENTER,
133 0.5, dcp::VAlign::CENTER,
137 dcp::Effect::NONE, dcp::Colour(0, 0, 0),
140 std::vector<dcp::Ruby>()
143 {}, true, false, false, dcp::Colour(255, 255, 255), 42, 1.0,
144 dcp::Time(0, 0, 0, 0, 24), dcp::Time(0, 0, 1, 0, 24),
145 0.5, dcp::HAlign::CENTER,
146 0.5, dcp::VAlign::CENTER,
150 dcp::Effect::NONE, dcp::Colour(0, 0, 0),
153 std::vector<dcp::Ruby>()
157 std::vector<StringText> st;
159 st.push_back({i, 0, make_shared<dcpomatic::Font>("foo"), dcp::SubtitleStandard::SMPTE_2014});
162 auto images = render_text(st, dcp::Size(1998, 1080), {}, 24);
164 BOOST_CHECK_EQUAL(images.size(), 1U);
165 image_as_png(Image::ensure_alignment(images.front().image, Image::Alignment::PADDED)).write("build/test/render_text_with_newline_test.png");
166 #if defined(DCPOMATIC_OSX)
167 check_image("test/data/mac/render_text_with_newline_test.png", "build/test/render_text_with_newline_test.png");
168 #elif defined(DCPOMATIC_WINDOWS)
169 check_image("test/data/windows/render_text_with_newline_test.png", "build/test/render_text_with_newline_test.png");
171 check_image("test/data/render_text_with_newline_test.png", "build/test/render_text_with_newline_test.png");
178 BOOST_AUTO_TEST_CASE (render_text_test)
180 auto dcp_string = dcp::SubtitleString(
181 {}, false, false, false, dcp::Colour(255, 255, 255), 42, 1.0,
182 dcp::Time(0, 0, 0, 0, 24), dcp::Time(0, 0, 1, 0, 24),
183 0.5, dcp::HAlign::CENTER,
184 0.5, dcp::VAlign::CENTER,
187 dcp::Effect::NONE, dcp::Colour(0, 0, 0),
192 auto string_text = StringText(dcp_string, 0, shared_ptr<dcpomatic::Font>());
194 auto images = render_text({ string_text }, dcp::Size(1998, 1080), {}, 24);
196 BOOST_CHECK_EQUAL(images.size(), 1U);
197 image_as_png(Image::ensure_alignment(images.front().image, Image::Alignment::PADDED)).write("build/test/render_text_test.png");