Merge branch '1.0' of ssh://main.carlh.net/home/carl/git/libdcp into 1.0
[libdcp.git] / src / font_node.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "types.h"
21 #include "raw_convert.h"
22 #include "font_node.h"
23 #include "xml.h"
24 #include "text_node.h"
25 #include <libcxml/cxml.h>
26 #include <boost/foreach.hpp>
27
28 using std::string;
29 using std::list;
30 using boost::shared_ptr;
31 using boost::optional;
32 using namespace dcp;
33
34 FontNode::FontNode (cxml::ConstNodePtr node, int tcr)
35 {
36         text = node->content ();
37         
38         id = node->optional_string_attribute ("Id");
39         size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
40         italic = node->optional_bool_attribute ("Italic");
41         optional<string> c = node->optional_string_attribute ("Color");
42         if (c) {
43                 colour = Colour (c.get ());
44         }
45         optional<string> const e = node->optional_string_attribute ("Effect");
46         if (e) {
47                 effect = string_to_effect (e.get ());
48         }
49         c = node->optional_string_attribute ( "EffectColor");
50         if (c) {
51                 effect_colour = Colour (c.get ());
52         }
53
54         list<cxml::NodePtr> s = node->node_children ("Subtitle");
55         BOOST_FOREACH (cxml::NodePtr& i, s) {
56                 subtitle_nodes.push_back (shared_ptr<SubtitleNode> (new SubtitleNode (i, tcr)));
57         }
58
59         list<cxml::NodePtr> f = node->node_children ("Font");
60         BOOST_FOREACH (cxml::NodePtr& i, f) {
61                 font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr)));
62         }
63         
64         list<cxml::NodePtr> t = node->node_children ("Text");
65         BOOST_FOREACH (cxml::NodePtr& i, t) {
66                 text_nodes.push_back (shared_ptr<TextNode> (new TextNode (i, tcr)));
67         }
68 }
69
70 FontNode::FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes)
71         : size (0)
72         , italic (false)
73         , colour ("FFFFFFFF")
74         , effect_colour ("FFFFFFFF")
75 {
76         for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
77                 if ((*i)->id) {
78                         id = (*i)->id;
79                 }
80                 if ((*i)->size != 0) {
81                         size = (*i)->size;
82                 }
83                 if ((*i)->italic) {
84                         italic = (*i)->italic.get ();
85                 }
86                 if ((*i)->colour) {
87                         colour = (*i)->colour.get ();
88                 }
89                 if ((*i)->effect) {
90                         effect = (*i)->effect.get ();
91                 }
92                 if ((*i)->effect_colour) {
93                         effect_colour = (*i)->effect_colour.get ();
94                 }
95         }
96 }