Rename color -> colour.
[libdcp.git] / src / font.cc
1 /*
2     Copyright (C) 2012-2014 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.h"
23 #include "xml.h"
24 #include "text.h"
25 #include <libcxml/cxml.h>
26
27 using std::string;
28 using std::list;
29 using boost::shared_ptr;
30 using boost::optional;
31 using namespace dcp;
32
33 Font::Font (boost::shared_ptr<const cxml::Node> node)
34 {
35         text = node->content ();
36         
37         id = node->optional_string_attribute ("Id");
38         size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
39         italic = node->optional_bool_attribute ("Italic");
40         optional<string> c = node->optional_string_attribute ("Color");
41         if (c) {
42                 colour = Colour (c.get ());
43         }
44         optional<string> const e = node->optional_string_attribute ("Effect");
45         if (e) {
46                 effect = string_to_effect (e.get ());
47         }
48         c = node->optional_string_attribute ( "EffectColor");
49         if (c) {
50                 effect_colour = Colour (c.get ());
51         }
52         subtitle_nodes = type_children<Subtitle> (node, "Subtitle");
53         font_nodes = type_children<Font> (node, "Font");
54         text_nodes = type_children<Text> (node, "Text");
55 }
56
57 Font::Font (std::list<boost::shared_ptr<Font> > const & font_nodes)
58         : size (0)
59         , italic (false)
60         , colour ("FFFFFFFF")
61         , effect_colour ("FFFFFFFF")
62 {
63         for (list<shared_ptr<Font> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
64                 if ((*i)->id) {
65                         id = (*i)->id;
66                 }
67                 if ((*i)->size != 0) {
68                         size = (*i)->size;
69                 }
70                 if ((*i)->italic) {
71                         italic = (*i)->italic.get ();
72                 }
73                 if ((*i)->colour) {
74                         colour = (*i)->colour.get ();
75                 }
76                 if ((*i)->effect) {
77                         effect = (*i)->effect.get ();
78                 }
79                 if ((*i)->effect_colour) {
80                         effect_colour = (*i)->effect_colour.get ();
81                 }
82         }
83 }