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