Remove in-place translations support.
[dcpomatic.git] / src / lib / text_content.cc
index 5ae8dd45eb47724454b6ebd18397e4755ec3dd45..92a35b8220cbca3f41c7302d9d8f0536a0b22ab9 100644 (file)
@@ -81,10 +81,10 @@ 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>>
-TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version)
+vector<shared_ptr<TextContent>>
+TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, list<string>& notes)
 {
        if (version < 34) {
                /* With old metadata FFmpeg content has the subtitle-related tags even with no
@@ -101,18 +101,19 @@ TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version)
                if (!node->optional_number_child<double>("SubtitleXOffset") && !node->optional_number_child<double>("SubtitleOffset")) {
                        return {};
                }
-               return { make_shared<TextContent>(parent, node, version) };
+               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));
+               content.push_back(make_shared<TextContent>(parent, i, version, notes));
        }
 
-       return c;
+       return content;
 }
 
-TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version)
+
+TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version, list<string>& notes)
        : ContentPart (parent)
        , _use (false)
        , _burn (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");
@@ -234,9 +233,24 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version)
 
        auto lang = node->optional_node_child("Language");
        if (lang) {
-               _language = dcp::LanguageTag(lang->content());
-               auto add = lang->optional_bool_attribute("Additional");
-               _language_is_additional = add && *add;
+               try {
+                       _language = dcp::LanguageTag(lang->content());
+                       auto add = lang->optional_bool_attribute("Additional");
+                       _language_is_additional = add && *add;
+               } 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(
+                                               _("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()));
+                               }
+                       } else {
+                               throw;
+                       }
+               }
        }
 }
 
@@ -430,6 +444,9 @@ TextContent::identifier () const
 void
 TextContent::add_font (shared_ptr<Font> font)
 {
+       boost::mutex::scoped_lock lm(_mutex);
+
+       DCPOMATIC_ASSERT(!get_font_unlocked(font->id()));
        _fonts.push_back (font);
        connect_to_fonts ();
 }
@@ -632,3 +649,36 @@ TextContent::take_settings_from (shared_ptr<const TextContent> c)
        set_language (c->_language);
        set_language_is_additional (c->_language_is_additional);
 }
+
+
+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;
+       });
+
+       if (iter == _fonts.end()) {
+               return {};
+       }
+
+       return *iter;
+}
+
+
+void
+TextContent::clear_fonts()
+{
+       boost::mutex::scoped_lock lm(_mutex);
+
+       _fonts.clear();
+}
+