static FcConfig* fc_config = 0;
static list<pair<FontFiles, string> > fc_config_fonts;
+string
+marked_up (list<dcp::SubtitleString> subtitles)
+{
+ string out;
+ bool italic = false;
+ bool bold = false;
+ bool underline = false;
+ BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
+ if (i.italic() && !italic) {
+ out += "<i>";
+ }
+ if (i.bold() && !bold) {
+ out += "<b>";
+ }
+ if (i.underline() && !underline) {
+ out += "<u>";
+ }
+
+ out += i.text ();
+
+ if (!i.underline() && underline) {
+ out += "</u>";
+ }
+ if (!i.bold() && bold) {
+ out += "</b>";
+ }
+ if (!i.italic() && italic) {
+ out += "</i>";
+ }
+
+ italic = i.italic ();
+ bold = i.bold ();
+ underline = i.underline ();
+ }
+
+ if (underline) {
+ out += "</u>";
+ }
+ if (bold) {
+ out += "</b>";
+ }
+ if (italic) {
+ out += "</i>";
+ }
+
+ return out;
+}
+
/** @param subtitles A list of subtitles that are all on the same line */
static PositionImage
render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target)
Pango::FontDescription font (font_name);
font.set_absolute_size (subtitles.front().size_in_pixels (target.height) * PANGO_SCALE);
layout->set_font_description (font);
-
- string marked_up;
- bool italic = false;
- bool bold = false;
- bool underline = false;
- BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
- if (i.italic() != italic) {
- if (i.italic()) {
- marked_up += "<i>";
- } else {
- marked_up += "</i>";
- }
- italic = i.italic ();
- }
-
- if (i.bold() != bold) {
- if (i.bold()) {
- marked_up += "<b>";
- } else {
- marked_up += "</b>";
- }
- bold = i.bold ();
- }
-
- if (i.underline() != underline) {
- if (i.underline()) {
- marked_up += "<u>";
- } else {
- marked_up += "</u>";
- }
- underline = i.underline ();
- }
-
- marked_up += i.text ();
- }
-
- if (italic) {
- marked_up += "</i>";
- }
-
- if (bold) {
- marked_up += "</b>";
- }
-
- if (underline) {
- marked_up += "</u>";
- }
-
- layout->set_markup (marked_up);
+ layout->set_markup (marked_up (subtitles));
/* Compute fade factor */
/* XXX */
--- /dev/null
+/*
+ Copyright (C) 2016 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 "lib/render_subtitles.h"
+#include <dcp/subtitle_string.h>
+#include <boost/test/unit_test.hpp>
+
+static void
+add (std::list<dcp::SubtitleString>& s, std::string text, bool italic, bool bold, bool underline)
+{
+ s.push_back (
+ dcp::SubtitleString (
+ boost::optional<std::string> (),
+ italic,
+ bold,
+ underline,
+ dcp::Colour (255, 255, 255),
+ 42,
+ 1,
+ dcp::Time (),
+ dcp::Time (),
+ 1,
+ dcp::HALIGN_LEFT,
+ 1,
+ dcp::VALIGN_TOP,
+ dcp::DIRECTION_LTR,
+ text,
+ dcp::NONE,
+ dcp::Colour (0, 0, 0),
+ dcp::Time (),
+ dcp::Time ()
+ )
+ );
+}
+
+/** Test marked_up() in render_subtitles.cc */
+BOOST_AUTO_TEST_CASE (render_markup_test1)
+{
+ std::list<dcp::SubtitleString> s;
+ add (s, "Hello", false, false, false);
+ BOOST_CHECK_EQUAL (marked_up (s), "Hello");
+}
+
+/** Test marked_up() in render_subtitles.cc */
+BOOST_AUTO_TEST_CASE (render_markup_test2)
+{
+ std::list<dcp::SubtitleString> s;
+ add (s, "Hello", false, true, false);
+ BOOST_CHECK_EQUAL (marked_up (s), "<b>Hello</b>");
+}
+
+
+/** Test marked_up() in render_subtitles.cc */
+BOOST_AUTO_TEST_CASE (render_markup_test3)
+{
+ std::list<dcp::SubtitleString> s;
+ add (s, "Hello", true, true, false);
+ BOOST_CHECK_EQUAL (marked_up (s), "<i><b>Hello</b></i>");
+}
+
+/** Test marked_up() in render_subtitles.cc */
+BOOST_AUTO_TEST_CASE (render_markup_test4)
+{
+ std::list<dcp::SubtitleString> s;
+ add (s, "Hello", true, true, true);
+ BOOST_CHECK_EQUAL (marked_up (s), "<i><b><u>Hello</u></b></i>");
+}