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/>.
24 #include "font_config.h"
25 #include "string_text_file.h"
26 #include "string_text_file_content.h"
27 #include "text_content.h"
29 #include <dcp/raw_convert.h>
30 #include <fontconfig/fontconfig.h>
31 #include <libxml++/libxml++.h>
40 using std::make_shared;
41 using std::shared_ptr;
43 using boost::optional;
44 using dcp::raw_convert;
45 using namespace dcpomatic;
48 StringTextFileContent::StringTextFileContent (boost::filesystem::path path)
51 text.push_back (make_shared<TextContent>(this, TextType::OPEN_SUBTITLE, TextType::UNKNOWN));
55 StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int version, list<string>& notes)
57 , _length (node->number_child<ContentTime::Type>("Length"))
59 text = TextContent::from_xml (this, node, version, notes);
64 StringTextFileContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
66 Content::examine (film, job);
67 StringTextFile file (shared_from_this());
69 /* Default to turning these subtitles on */
70 only_text()->set_use (true);
72 std::set<string> names;
73 for (auto const& subtitle: file.subtitles()) {
74 for (auto const& line: subtitle.lines) {
75 for (auto const& block: line.blocks) {
76 names.insert(block.font.get_value_or(""));
81 for (auto name: names) {
82 optional<boost::filesystem::path> path;
84 path = FontConfig::instance()->system_font_with_name(name);
87 only_text()->add_font(make_shared<Font>(name, *path));
89 only_text()->add_font(make_shared<Font>(name));
93 boost::mutex::scoped_lock lm (_mutex);
94 _length = file.length();
99 StringTextFileContent::summary () const
101 return path_summary() + " " + _("[subtitles]");
106 StringTextFileContent::technical_summary () const
108 return Content::technical_summary() + " - " + _("Text subtitles");
114 StringTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const
116 node->add_child("Type")->add_child_text("TextSubtitle");
117 Content::as_xml (node, with_paths);
120 only_text()->as_xml(node);
123 node->add_child("Length")->add_child_text(raw_convert<string>(_length.get ()));
128 StringTextFileContent::full_length (shared_ptr<const Film> film) const
130 FrameRateChange const frc (film, shared_from_this());
131 return DCPTime (_length, frc);
136 StringTextFileContent::approximate_length () const
138 return DCPTime (_length, FrameRateChange());
143 StringTextFileContent::identifier () const
145 auto s = Content::identifier ();
146 s += "_" + only_text()->identifier();