2 Copyright (C) 2014-2021 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 #include "string_text_file_content.h"
24 #include "string_text_file.h"
27 #include "text_content.h"
28 #include <dcp/raw_convert.h>
29 #include <libxml++/libxml++.h>
37 using std::make_shared;
38 using std::shared_ptr;
40 using boost::optional;
41 using dcp::raw_convert;
42 using namespace dcpomatic;
45 StringTextFileContent::StringTextFileContent (boost::filesystem::path path)
48 text.push_back (make_shared<TextContent>(this, TextType::OPEN_SUBTITLE, TextType::UNKNOWN));
52 StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int version)
54 , _length (node->number_child<ContentTime::Type>("Length"))
56 text = TextContent::from_xml (this, node, version);
61 StringTextFileContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
63 Content::examine (film, job);
64 StringTextFile s (shared_from_this());
66 /* Default to turning these subtitles on */
67 only_text()->set_use (true);
69 boost::mutex::scoped_lock lm (_mutex);
70 _length = s.length ();
71 only_text()->add_font (make_shared<Font>(TEXT_FONT_ID));
76 StringTextFileContent::summary () const
78 return path_summary() + " " + _("[subtitles]");
83 StringTextFileContent::technical_summary () const
85 return Content::technical_summary() + " - " + _("Text subtitles");
91 StringTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const
93 node->add_child("Type")->add_child_text("TextSubtitle");
94 Content::as_xml (node, with_paths);
97 only_text()->as_xml(node);
100 node->add_child("Length")->add_child_text(raw_convert<string>(_length.get ()));
105 StringTextFileContent::full_length (shared_ptr<const Film> film) const
107 FrameRateChange const frc (film, shared_from_this());
108 return DCPTime (_length, frc);
113 StringTextFileContent::approximate_length () const
115 return DCPTime (_length, FrameRateChange());
120 StringTextFileContent::identifier () const
122 auto s = Content::identifier ();
123 s += "_" + only_text()->identifier();