Still more licence fixups.
[libdcp.git] / src / font_node.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
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, string font_id_attribute)
35 {
36         text = node->content ();
37
38         id = node->optional_string_attribute (font_id_attribute);
39         size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
40         aspect_adjust = node->optional_number_attribute<float> ("AspectAdjust");
41         italic = node->optional_bool_attribute ("Italic");
42         bold = node->optional_string_attribute("Weight").get_value_or("normal") == "bold";
43         optional<string> c = node->optional_string_attribute ("Color");
44         if (c) {
45                 colour = Colour (c.get ());
46         }
47         optional<string> const e = node->optional_string_attribute ("Effect");
48         if (e) {
49                 effect = string_to_effect (e.get ());
50         }
51         c = node->optional_string_attribute ("EffectColor");
52         if (c) {
53                 effect_colour = Colour (c.get ());
54         }
55
56         list<cxml::NodePtr> s = node->node_children ("Subtitle");
57         BOOST_FOREACH (cxml::NodePtr& i, s) {
58                 subtitle_nodes.push_back (shared_ptr<SubtitleNode> (new SubtitleNode (i, tcr, font_id_attribute)));
59         }
60
61         list<cxml::NodePtr> f = node->node_children ("Font");
62         BOOST_FOREACH (cxml::NodePtr& i, f) {
63                 font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr, font_id_attribute)));
64         }
65
66         list<cxml::NodePtr> t = node->node_children ("Text");
67         BOOST_FOREACH (cxml::NodePtr& i, t) {
68                 text_nodes.push_back (shared_ptr<TextNode> (new TextNode (i, tcr, font_id_attribute)));
69         }
70 }
71
72 FontNode::FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes)
73         : size (0)
74         , italic (false)
75         , bold (false)
76         , colour ("FFFFFFFF")
77         , effect_colour ("FFFFFFFF")
78 {
79         for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
80                 if ((*i)->id) {
81                         id = (*i)->id;
82                 }
83                 if ((*i)->size != 0) {
84                         size = (*i)->size;
85                 }
86                 if ((*i)->aspect_adjust) {
87                         aspect_adjust = (*i)->aspect_adjust.get ();
88                 }
89                 if ((*i)->italic) {
90                         italic = (*i)->italic.get ();
91                 }
92                 if ((*i)->bold) {
93                         bold = (*i)->bold.get ();
94                 }
95                 if ((*i)->colour) {
96                         colour = (*i)->colour.get ();
97                 }
98                 if ((*i)->effect) {
99                         effect = (*i)->effect.get ();
100                 }
101                 if ((*i)->effect_colour) {
102                         effect_colour = (*i)->effect_colour.get ();
103                 }
104         }
105 }