2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
20 #include "subtitle_node.h"
22 #include "font_node.h"
23 #include "text_node.h"
24 #include <libcxml/cxml.h>
25 #include <boost/lexical_cast.hpp>
29 using boost::optional;
30 using boost::shared_ptr;
31 using boost::lexical_cast;
34 SubtitleNode::SubtitleNode (boost::shared_ptr<const cxml::Node> node, int tcr, string font_id_attribute)
36 in = Time (node->string_attribute ("TimeIn"), tcr);
37 out = Time (node->string_attribute ("TimeOut"), tcr);
39 list<cxml::NodePtr> f = node->node_children ("Font");
40 for (list<cxml::NodePtr>::iterator i = f.begin(); i != f.end(); ++i) {
41 font_nodes.push_back (shared_ptr<FontNode> (new FontNode (*i, tcr, font_id_attribute)));
44 list<cxml::NodePtr> t = node->node_children ("Text");
45 for (list<cxml::NodePtr>::iterator i = t.begin(); i != t.end(); ++i) {
46 text_nodes.push_back (shared_ptr<TextNode> (new TextNode (*i, tcr, font_id_attribute)));
49 fade_up_time = fade_time (node, "FadeUpTime", tcr);
50 fade_down_time = fade_time (node, "FadeDownTime", tcr);
54 SubtitleNode::fade_time (shared_ptr<const cxml::Node> node, string name, int tcr)
56 string const u = node->optional_string_attribute (name).get_value_or ("");
60 t = Time (0, 0, 0, 20, 250);
61 } else if (u.find (":") != string::npos) {
64 t = Time (0, 0, 0, lexical_cast<int> (u), tcr);
67 if (t > Time (0, 0, 8, 0, 250)) {
68 t = Time (0, 0, 8, 0, 250);