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/>.
22 * @brief TextNode class for parsing subtitle XML.
25 #include "text_node.h"
27 #include "font_node.h"
28 #include <libcxml/cxml.h>
29 #include <boost/foreach.hpp>
33 using boost::shared_ptr;
34 using boost::optional;
37 /** Read a <Text> node from a subtitle XML file, noting its contents
38 * in this object's member variables.
39 * @param node Node to read.
41 TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, string font_id_attribute)
43 , h_align (HALIGN_CENTER)
45 , v_align (VALIGN_CENTER)
46 , direction (DIRECTION_LTR)
48 text = node->content ();
50 optional<float> hp = node->optional_number_attribute<float> ("HPosition");
52 hp = node->optional_number_attribute<float> ("Hposition");
55 h_position = hp.get () / 100;
58 optional<string> ha = node->optional_string_attribute ("HAlign");
60 ha = node->optional_string_attribute ("Halign");
63 h_align = string_to_halign (ha.get ());
66 optional<float> vp = node->optional_number_attribute<float> ("VPosition");
68 vp = node->optional_number_attribute<float> ("Vposition");
71 v_position = vp.get () / 100;
74 optional<string> va = node->optional_string_attribute ("VAlign");
76 va = node->optional_string_attribute ("Valign");
79 v_align = string_to_valign (va.get ());
82 optional<string> d = node->optional_string_attribute ("Direction");
84 direction = string_to_direction (d.get ());
87 list<cxml::NodePtr> f = node->node_children ("Font");
88 BOOST_FOREACH (cxml::NodePtr& i, f) {
89 font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr, font_id_attribute)));