X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ftext_content.cc;h=a85b271a88d23dbfca216491e5777e701c720f03;hb=c8bd4ead4c9e757d88136a7fdd556272f36be793;hp=c86150881418121b32c59e8d7187d72f6ca3aa18;hpb=e0a70cd5cfb11fc2de167f3146acdd437a6faa82;p=dcpomatic.git diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc index c86150881..a85b271a8 100644 --- a/src/lib/text_content.cc +++ b/src/lib/text_content.cc @@ -84,7 +84,7 @@ TextContent::TextContent (Content* parent, TextType type, TextType original_type * The list could be empty if no TextContents are found. */ list> -TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) +TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, list& notes) { if (version < 34) { /* With old metadata FFmpeg content has the subtitle-related tags even with no @@ -101,22 +101,18 @@ TextContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) if (!node->optional_number_child("SubtitleXOffset") && !node->optional_number_child("SubtitleOffset")) { return {}; } - return { make_shared(parent, node, version) }; - } - - if (!node->optional_node_child("Text")) { - return {}; + return { make_shared(parent, node, version, notes) }; } list> c; for (auto i: node->node_children("Text")) { - c.push_back (make_shared(parent, i, version)); + c.push_back (make_shared(parent, i, version, notes)); } return c; } -TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) +TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version, list& notes) : ContentPart (parent) , _use (false) , _burn (false) @@ -128,7 +124,6 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version) , _outline_width (node->optional_number_child("OutlineWidth").get_value_or(4)) , _type (TextType::OPEN_SUBTITLE) , _original_type (TextType::OPEN_SUBTITLE) - , _language ("en-US") { if (version >= 37) { _use = node->bool_child ("Use"); @@ -239,9 +234,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; + } + } } } @@ -435,6 +445,9 @@ TextContent::identifier () const void TextContent::add_font (shared_ptr font) { + boost::mutex::scoped_lock lm(_mutex); + + DCPOMATIC_ASSERT(!get_font_unlocked(font->id())); _fonts.push_back (font); connect_to_fonts (); } @@ -637,3 +650,36 @@ TextContent::take_settings_from (shared_ptr c) set_language (c->_language); set_language_is_additional (c->_language_is_additional); } + + +shared_ptr +TextContent::get_font(string id) const +{ + boost::mutex::scoped_lock lm(_mutex); + return get_font_unlocked(id); +} + + +shared_ptr +TextContent::get_font_unlocked(string id) const +{ + auto iter = std::find_if(_fonts.begin(), _fonts.end(), [&id](shared_ptr font) { + return font->id() == id; + }); + + if (iter == _fonts.end()) { + return {}; + } + + return *iter; +} + + +void +TextContent::clear_fonts() +{ + boost::mutex::scoped_lock lm(_mutex); + + _fonts.clear(); +} +