Normalise XML attribute names to be camelCase (#2241).
[dcpomatic.git] / src / lib / text_content.cc
index 9c925cbcfb6bb0c6849fba9a947c66c70e7fa36b..09f6e41b656a476d0367690e9d67a6bd99cb5b0a 100644 (file)
@@ -81,9 +81,9 @@ TextContent::TextContent (Content* parent, TextType type, TextType original_type
 }
 
 /** @return TextContents from node or <Text> nodes under node (according to version).
- *  The list could be empty if no TextContents are found.
+ *  The vector could be empty if no TextContents are found.
  */
-list<shared_ptr<TextContent>>
+vector<shared_ptr<TextContent>>
 TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, list<string>& notes)
 {
        if (version < 34) {
@@ -104,14 +104,15 @@ TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, li
                return { make_shared<TextContent>(parent, node, version, notes) };
        }
 
-       list<shared_ptr<TextContent>> c;
+       vector<shared_ptr<TextContent>> content;
        for (auto i: node->node_children("Text")) {
-               c.push_back (make_shared<TextContent>(parent, i, version, notes));
+               content.push_back(make_shared<TextContent>(parent, i, version, notes));
        }
 
-       return c;
+       return content;
 }
 
+
 TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version, list<string>& notes)
        : ContentPart (parent)
        , _use (false)
@@ -147,8 +148,6 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version,
                _effect = dcp::Effect::BORDER;
        } else if (node->optional_bool_child("Shadow").get_value_or(false)) {
                _effect = dcp::Effect::SHADOW;
-       } else {
-               _effect = dcp::Effect::NONE;
        }
 
        auto effect = node->optional_string_child("Effect");
@@ -236,8 +235,11 @@ 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.
@@ -410,7 +412,7 @@ TextContent::as_xml (xmlpp::Node* root) const
        if (_language) {
                auto lang = text->add_child("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");
        }
 }
 
@@ -445,7 +447,9 @@ TextContent::identifier () const
 void
 TextContent::add_font (shared_ptr<Font> font)
 {
-       DCPOMATIC_ASSERT(!get_font(font->id()));
+       boost::mutex::scoped_lock lm(_mutex);
+
+       DCPOMATIC_ASSERT(!get_font_unlocked(font->id()));
        _fonts.push_back (font);
        connect_to_fonts ();
 }
@@ -652,6 +656,14 @@ TextContent::take_settings_from (shared_ptr<const TextContent> c)
 
 shared_ptr<dcpomatic::Font>
 TextContent::get_font(string id) const
+{
+       boost::mutex::scoped_lock lm(_mutex);
+       return get_font_unlocked(id);
+}
+
+
+shared_ptr<dcpomatic::Font>
+TextContent::get_font_unlocked(string id) const
 {
        auto iter = std::find_if(_fonts.begin(), _fonts.end(), [&id](shared_ptr<dcpomatic::Font> font) {
                return font->id() == id;
@@ -664,3 +676,12 @@ TextContent::get_font(string id) const
        return *iter;
 }
 
+
+void
+TextContent::clear_fonts()
+{
+       boost::mutex::scoped_lock lm(_mutex);
+
+       _fonts.clear();
+}
+