Cleanup: pass EqualityOptions as const&
[libdcp.git] / src / subtitle_asset.cc
index f707c6652fa1305e2cec62499904579cee213406..b7e75419d1d3dd4bc7c4bbb475623f1541acff94 100644 (file)
@@ -324,7 +324,11 @@ SubtitleAsset::parse_subtitles (xmlpp::Element const * node, vector<ParseState>&
 void
 SubtitleAsset::maybe_add_subtitle (string text, vector<ParseState> const & parse_state, float space_before, Standard standard)
 {
-       if (empty_or_white_space (text)) {
+       auto wanted = [](ParseState const& ps) {
+               return ps.type && (ps.type.get() == ParseState::Type::TEXT || ps.type.get() == ParseState::Type::IMAGE);
+       };
+
+       if (find_if(parse_state.begin(), parse_state.end(), wanted) == parse_state.end()) {
                return;
        }
 
@@ -537,7 +541,7 @@ SubtitleAsset::latest_subtitle_out () const
 
 
 bool
-SubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions options, NoteHandler note) const
+SubtitleAsset::equals(shared_ptr<const Asset> other_asset, EqualityOptions const& options, NoteHandler note) const
 {
        if (!Asset::equals (other_asset, options, note)) {
                return false;
@@ -889,23 +893,23 @@ format_xml_node (xmlpp::Node const* node, State& state)
  *  to <Text> nodes.  This is an attempt to avoid changing what is actually displayed as subtitles
  *  while also formatting the XML in such a way as to avoid DoM bug 2205.
  *
- *  namespace is a list of namespaces for the root node; it would be nicer to set these up with
- *  set_namespace_declaration in the caller and then to extract them here but I couldn't find a way
+ *  xml_namespace is an optional namespace for the root node; it would be nicer to set this up with
+ *  set_namespace_declaration in the caller and then to extract it here but I couldn't find a way
  *  to get all namespaces with the libxml++ API.
  */
 string
-SubtitleAsset::format_xml (xmlpp::Document const& document, vector<pair<string, string>> const& namespaces)
+SubtitleAsset::format_xml(xmlpp::Document const& document, optional<pair<string, string>> xml_namespace)
 {
        auto root = document.get_root_node();
 
        State state = {};
        state.xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<" + root->get_name();
 
-       for (auto const& ns: namespaces) {
-               if (ns.first.empty()) {
-                       state.xml += String::compose(" xmlns=\"%1\"", ns.second);
+       if (xml_namespace) {
+               if (xml_namespace->first.empty()) {
+                       state.xml += String::compose(" xmlns=\"%1\"", xml_namespace->second);
                } else {
-                       state.xml += String::compose(" xmlns:%1=\"%2\"", ns.first, ns.second);
+                       state.xml += String::compose(" xmlns:%1=\"%2\"", xml_namespace->first, xml_namespace->second);
                }
        }
 
@@ -924,3 +928,12 @@ SubtitleAsset::format_xml (xmlpp::Document const& document, vector<pair<string,
        return state.xml;
 }
 
+
+void
+SubtitleAsset::ensure_font(string load_id, dcp::ArrayData data)
+{
+       if (std::find_if(_fonts.begin(), _fonts.end(), [load_id](Font const& font) { return font.load_id == load_id; }) == _fonts.end()) {
+               add_font(load_id, data);
+       }
+}
+