2 Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 #include "subtitle_asset_internal.h"
35 #include "subtitle_string.h"
40 using boost::shared_ptr;
44 order::Context::xmlns () const
46 return standard == SMPTE ? "dcst" : "";
49 order::Font::Font (shared_ptr<SubtitleString> s, Standard standard)
52 if (standard == SMPTE) {
53 _values["ID"] = s->font().get ();
55 _values["Id"] = s->font().get ();
58 _values["Italic"] = s->italic() ? "yes" : "no";
59 _values["Color"] = s->colour().to_argb_string();
60 _values["Size"] = raw_convert<string> (s->size());
61 _values["AspectAdjust"] = raw_convert<string>(s->aspect_adjust(), 1, true);
62 _values["Effect"] = effect_to_string (s->effect());
63 _values["EffectColor"] = s->effect_colour().to_argb_string();
64 _values["Script"] = "normal";
65 if (standard == SMPTE) {
66 _values["Underline"] = s->underline() ? "yes" : "no";
68 _values["Underlined"] = s->underline() ? "yes" : "no";
70 _values["Weight"] = s->bold() ? "bold" : "normal";
74 order::Font::as_xml (xmlpp::Element* parent, Context& context) const
76 xmlpp::Element* e = parent->add_child ("Font", context.xmlns());
77 for (map<string, string>::const_iterator i = _values.begin(); i != _values.end(); ++i) {
78 e->set_attribute (i->first, i->second);
83 /** Modify our values so that they contain only those that are common to us and
87 order::Font::take_intersection (Font other)
89 map<string, string> inter;
91 for (map<string, string>::const_iterator i = other._values.begin(); i != other._values.end(); ++i) {
92 map<string, string>::iterator t = _values.find (i->first);
93 if (t != _values.end() && t->second == i->second) {
101 /** Modify our values so that it contains only those keys that are not in other */
103 order::Font::take_difference (Font other)
105 map<string, string> diff;
106 for (map<string, string>::const_iterator i = _values.begin(); i != _values.end(); ++i) {
107 if (other._values.find (i->first) == other._values.end ()) {
116 order::Font::empty () const
118 return _values.empty ();
122 order::Part::as_xml (xmlpp::Element* parent, Context &) const
128 order::String::as_xml (xmlpp::Element* parent, Context &) const
130 parent->add_child_text (text);
135 order::Part::write_xml (xmlpp::Element* parent, order::Context& context) const
137 if (!font.empty ()) {
138 parent = font.as_xml (parent, context);
141 parent = as_xml (parent, context);
143 BOOST_FOREACH (boost::shared_ptr<order::Part> i, children) {
144 i->write_xml (parent, context);
149 order::Text::as_xml (xmlpp::Element* parent, Context& context) const
151 xmlpp::Element* e = parent->add_child ("Text", context.xmlns());
153 if (_h_align != HALIGN_CENTER) {
154 if (context.standard == SMPTE) {
155 e->set_attribute ("Halign", halign_to_string (_h_align));
157 e->set_attribute ("HAlign", halign_to_string (_h_align));
161 if (fabs(_h_position) > ALIGN_EPSILON) {
162 if (context.standard == SMPTE) {
163 e->set_attribute ("Hposition", raw_convert<string> (_h_position * 100, 6));
165 e->set_attribute ("HPosition", raw_convert<string> (_h_position * 100, 6));
169 if (context.standard == SMPTE) {
170 e->set_attribute ("Valign", valign_to_string (_v_align));
172 e->set_attribute ("VAlign", valign_to_string (_v_align));
175 if (fabs(_v_position) > ALIGN_EPSILON) {
176 if (context.standard == SMPTE) {
177 e->set_attribute ("Vposition", raw_convert<string> (_v_position * 100, 6));
179 e->set_attribute ("VPosition", raw_convert<string> (_v_position * 100, 6));
182 if (context.standard == SMPTE) {
183 e->set_attribute ("Vposition", "0");
185 e->set_attribute ("VPosition", "0");
189 /* Interop only supports "horizontal" or "vertical" for direction, so only write this
192 if (_direction != DIRECTION_LTR && context.standard == SMPTE) {
193 e->set_attribute ("Direction", direction_to_string (_direction));
200 order::Subtitle::as_xml (xmlpp::Element* parent, Context& context) const
202 xmlpp::Element* e = parent->add_child ("Subtitle", context.xmlns());
203 e->set_attribute ("SpotNumber", raw_convert<string> (context.spot_number++));
204 e->set_attribute ("TimeIn", _in.rebase(context.time_code_rate).as_string(context.standard));
205 e->set_attribute ("TimeOut", _out.rebase(context.time_code_rate).as_string(context.standard));
206 if (context.standard == SMPTE) {
207 e->set_attribute ("FadeUpTime", _fade_up.rebase(context.time_code_rate).as_string(context.standard));
208 e->set_attribute ("FadeDownTime", _fade_down.rebase(context.time_code_rate).as_string(context.standard));
210 e->set_attribute ("FadeUpTime", raw_convert<string> (_fade_up.as_editable_units(context.time_code_rate)));
211 e->set_attribute ("FadeDownTime", raw_convert<string> (_fade_down.as_editable_units(context.time_code_rate)));
217 order::Font::operator== (Font const & other) const
219 return _values == other._values;
223 order::Font::clear ()