diff options
Diffstat (limited to 'src/lib/text_content.cc')
| -rw-r--r-- | src/lib/text_content.cc | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index 92a35b822..03336f15d 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -19,11 +19,12 @@ */ -#include "text_content.h" -#include "util.h" +#include "content.h" #include "exceptions.h" #include "font.h" -#include "content.h" +#include "text_content.h" +#include "util.h" +#include "variant.h" #include <dcp/raw_convert.h> #include <libcxml/cxml.h> #include <libxml++/libxml++.h> @@ -32,13 +33,13 @@ #include "i18n.h" -using std::string; -using std::vector; using std::cout; +using std::dynamic_pointer_cast; using std::list; -using std::shared_ptr; using std::make_shared; -using std::dynamic_pointer_cast; +using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; using dcp::raw_convert; using namespace dcpomatic; @@ -235,17 +236,20 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version, if (lang) { try { _language = dcp::LanguageTag(lang->content()); - auto add = lang->optional_bool_attribute("Additional"); - _language_is_additional = add && *add; + auto additional = lang->optional_bool_attribute("Additional"); + if (!additional) { + additional = lang->optional_bool_attribute("additional"); + } + _language_is_additional = additional.get_value_or(false); } catch (dcp::LanguageTagError&) { /* The language tag can be empty or invalid if it was loaded from a * 2.14.x metadata file; we'll just ignore it in that case. */ if (version <= 37) { if (!lang->content().empty()) { - notes.push_back (String::compose( + notes.push_back(String::compose( _("A subtitle or closed caption file in this project is marked with the language '%1', " - "which DCP-o-matic does not recognise. The file's language has been cleared."), lang->content())); + "which %2 does not recognise. The file's language has been cleared."), lang->content(), variant::dcpomatic())); } } else { throw; @@ -353,63 +357,63 @@ TextContent::TextContent (Content* parent, vector<shared_ptr<Content>> c) /** _mutex must not be held on entry */ void -TextContent::as_xml (xmlpp::Node* root) const +TextContent::as_xml(xmlpp::Element* root) const { boost::mutex::scoped_lock lm (_mutex); - auto text = root->add_child ("Text"); + auto text = cxml::add_child(root, "Text"); - text->add_child("Use")->add_child_text (_use ? "1" : "0"); - text->add_child("Burn")->add_child_text (_burn ? "1" : "0"); - text->add_child("XOffset")->add_child_text (raw_convert<string> (_x_offset)); - text->add_child("YOffset")->add_child_text (raw_convert<string> (_y_offset)); - text->add_child("XScale")->add_child_text (raw_convert<string> (_x_scale)); - text->add_child("YScale")->add_child_text (raw_convert<string> (_y_scale)); + cxml::add_text_child(text, "Use", _use ? "1" : "0"); + cxml::add_text_child(text, "Burn", _burn ? "1" : "0"); + cxml::add_text_child(text, "XOffset", raw_convert<string>(_x_offset)); + cxml::add_text_child(text, "YOffset", raw_convert<string>(_y_offset)); + cxml::add_text_child(text, "XScale", raw_convert<string>(_x_scale)); + cxml::add_text_child(text, "YScale", raw_convert<string>(_y_scale)); if (_colour) { - text->add_child("Red")->add_child_text (raw_convert<string> (_colour->r)); - text->add_child("Green")->add_child_text (raw_convert<string> (_colour->g)); - text->add_child("Blue")->add_child_text (raw_convert<string> (_colour->b)); + cxml::add_text_child(text, "Red", raw_convert<string>(_colour->r)); + cxml::add_text_child(text, "Green", raw_convert<string>(_colour->g)); + cxml::add_text_child(text, "Blue", raw_convert<string>(_colour->b)); } if (_effect) { switch (*_effect) { case dcp::Effect::NONE: - text->add_child("Effect")->add_child_text("none"); + cxml::add_text_child(text, "Effect", "none"); break; case dcp::Effect::BORDER: - text->add_child("Effect")->add_child_text("outline"); + cxml::add_text_child(text, "Effect", "outline"); break; case dcp::Effect::SHADOW: - text->add_child("Effect")->add_child_text("shadow"); + cxml::add_text_child(text, "Effect", "shadow"); break; } } if (_effect_colour) { - text->add_child("EffectRed")->add_child_text (raw_convert<string> (_effect_colour->r)); - text->add_child("EffectGreen")->add_child_text (raw_convert<string> (_effect_colour->g)); - text->add_child("EffectBlue")->add_child_text (raw_convert<string> (_effect_colour->b)); + cxml::add_text_child(text, "EffectRed", raw_convert<string>(_effect_colour->r)); + cxml::add_text_child(text, "EffectGreen", raw_convert<string>(_effect_colour->g)); + cxml::add_text_child(text, "EffectBlue", raw_convert<string>(_effect_colour->b)); } - text->add_child("LineSpacing")->add_child_text (raw_convert<string> (_line_spacing)); + cxml::add_text_child(text, "LineSpacing", raw_convert<string>(_line_spacing)); if (_fade_in) { - text->add_child("FadeIn")->add_child_text (raw_convert<string> (_fade_in->get())); + cxml::add_text_child(text, "FadeIn", raw_convert<string>(_fade_in->get())); } if (_fade_out) { - text->add_child("FadeOut")->add_child_text (raw_convert<string> (_fade_out->get())); + cxml::add_text_child(text, "FadeOut", raw_convert<string>(_fade_out->get())); } - text->add_child("OutlineWidth")->add_child_text (raw_convert<string> (_outline_width)); + cxml::add_text_child(text, "OutlineWidth", raw_convert<string>(_outline_width)); for (auto i: _fonts) { - i->as_xml (text->add_child("Font")); + i->as_xml(cxml::add_child(text, "Font")); } - text->add_child("Type")->add_child_text (text_type_to_string(_type)); - text->add_child("OriginalType")->add_child_text (text_type_to_string(_original_type)); + cxml::add_text_child(text, "Type", text_type_to_string(_type)); + cxml::add_text_child(text, "OriginalType", text_type_to_string(_original_type)); if (_dcp_track) { - _dcp_track->as_xml(text->add_child("DCPTrack")); + _dcp_track->as_xml(cxml::add_child(text, "DCPTrack")); } if (_language) { - auto lang = text->add_child("Language"); + auto lang = cxml::add_child(text, "Language"); lang->add_child_text (_language->to_string()); - lang->set_attribute ("Additional", _language_is_additional ? "1" : "0"); + lang->set_attribute("additional", _language_is_additional ? "1" : "0"); } } |
