2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "dcp_reader.h"
21 #include "vertical_reference.h"
26 #include "dcp/subtitle.h"
27 #include <libcxml/cxml.h>
28 #include <libxml++/libxml++.h>
34 using boost::shared_ptr;
35 using boost::optional;
39 DCPReader::parse_common (cxml::NodePtr root, optional<int> tcr)
41 _reel_number = root->string_child ("ReelNumber");
42 _language = root->string_child ("Language");
44 ParseState parse_state;
45 parse_node (root->node(), parse_state, tcr);
49 DCPReader::parse_node (xmlpp::Node const * node, ParseState& parse_state, optional<int> tcr)
51 xmlpp::Node::NodeList children = node->get_children ();
52 for (xmlpp::Node::NodeList::iterator i = children.begin(); i != children.end(); ++i) {
53 xmlpp::ContentNode const * c = dynamic_cast<xmlpp::ContentNode const *> (*i);
55 maybe_add_subtitle (c->get_content (), parse_state);
58 xmlpp::Element* e = dynamic_cast<xmlpp::Element *> (*i);
60 cxml::NodePtr n (new cxml::Node (e));
61 if (n->name() == "Font") {
62 parse_state.font_nodes.push_back (shared_ptr<dcp::Font> (new dcp::Font (n)));
63 parse_node (e, parse_state, tcr);
64 parse_state.font_nodes.pop_back ();
65 } else if (n->name() == "Text") {
66 parse_state.text_nodes.push_back (shared_ptr<dcp::Text> (new dcp::Text (n)));
67 parse_node (e, parse_state, tcr);
68 parse_state.text_nodes.pop_back ();
69 } else if (n->name() == "Subtitle") {
70 parse_state.subtitle_nodes.push_back (shared_ptr<dcp::Subtitle> (new dcp::Subtitle (n, tcr)));
71 parse_node (e, parse_state, tcr);
72 parse_state.subtitle_nodes.pop_back ();
73 } else if (n->name() == "SubtitleList") {
74 parse_node (e, parse_state, tcr);
81 DCPReader::maybe_add_subtitle (string text, ParseState const & parse_state)
83 if (empty_or_white_space (text)) {
87 if (parse_state.text_nodes.empty() || parse_state.subtitle_nodes.empty ()) {
91 dcp::Font effective_font (parse_state.font_nodes);
92 dcp::Text effective_text (*parse_state.text_nodes.back ());
93 dcp::Subtitle effective_subtitle (*parse_state.subtitle_nodes.back ());
98 rs.font = effective_font.id;
99 rs.font_size.set_proportional (float (effective_font.size) / (72 * 11));
100 rs.effect = effective_font.effect;
101 rs.effect_colour = effective_font.effect_colour;
102 rs.colour = effective_font.colour.get();
104 rs.italic = effective_font.italic.get();
105 rs.underline = false;
106 rs.vertical_position.proportional = float (effective_text.v_position) / 100;
107 rs.vertical_position.reference = effective_text.v_align;
108 rs.from = effective_subtitle.in;
109 rs.to = effective_subtitle.out;
110 rs.fade_up = effective_subtitle.fade_up_time;
111 rs.fade_down = effective_subtitle.fade_down_time;
113 _subs.push_back (rs);