Simplify time representation; better in-tree DCP subtitle parser.
[libsub.git] / src / dcp / 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 "text.h"
22 #include <libcxml/cxml.h>
23 #include <boost/foreach.hpp>
24
25 using std::string;
26 using std::list;
27 using boost::shared_ptr;
28 using boost::optional;
29 using namespace sub;
30
31 dcp::Font::Font (cxml::ConstNodePtr node)
32 {
33         id = node->optional_string_attribute ("Id");
34         size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
35         italic = node->optional_bool_attribute ("Italic");
36         optional<string> c = node->optional_string_attribute ("Color");
37         if (c) {
38                 colour = Colour (c.get ());
39         }
40         optional<string> const e = node->optional_string_attribute ("Effect");
41         if (e) {
42                 effect = string_to_effect (e.get ());
43         }
44         c = node->optional_string_attribute ("EffectColor");
45         if (c) {
46                 effect_colour = Colour (c.get ());
47         }
48 }
49
50 dcp::Font::Font (std::list<boost::shared_ptr<Font> > const & font_nodes)
51         : size (0)
52         , italic (false)
53         , colour ("FFFFFFFF")
54         , effect_colour ("FFFFFFFF")
55 {
56         for (list<shared_ptr<Font> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
57                 if ((*i)->id) {
58                         id = (*i)->id;
59                 }
60                 if ((*i)->size != 0) {
61                         size = (*i)->size;
62                 }
63                 if ((*i)->italic) {
64                         italic = (*i)->italic.get ();
65                 }
66                 if ((*i)->colour) {
67                         colour = (*i)->colour.get ();
68                 }
69                 if ((*i)->effect) {
70                         effect = (*i)->effect.get ();
71                 }
72                 if ((*i)->effect_colour) {
73                         effect_colour = (*i)->effect_colour.get ();
74                 }
75         }
76 }