Make it possible to write subtitle assets without any <Font> tags.
[libdcp.git] / src / subtitle_asset.cc
index f35b47ef223f0b7e9ae74aa66a936594f6792531..176ee02b53c6c89ad499144f0e7cb65032520466 100644 (file)
@@ -662,11 +662,21 @@ SubtitleAsset::pull_fonts (shared_ptr<order::Part> part)
 }
 
 
+void
+SubtitleAsset::clear_fonts(shared_ptr<order::Part> part)
+{
+       part->font.clear();
+       for (auto child: part->children) {
+               clear_fonts(child);
+       }
+}
+
+
 /** @param standard Standard (INTEROP or SMPTE); this is used rather than putting things in the child
  *  class because the differences between the two are fairly subtle.
  */
 void
-SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, Standard standard) const
+SubtitleAsset::subtitles_as_xml(xmlpp::Element* xml_root, int time_code_rate, Standard standard, FontTags fonts) const
 {
        auto sorted = _subtitles;
        std::stable_sort(sorted.begin(), sorted.end(), SubtitleSorter());
@@ -741,9 +751,12 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S
                }
        }
 
-       /* Pull font changes as high up the hierarchy as we can */
-
-       pull_fonts (root);
+       if (fonts == FontTags::INCLUDE) {
+               /* Pull font changes as high up the hierarchy as we can */
+               pull_fonts(root);
+       } else {
+               clear_fonts(root);
+       }
 
        /* Write XML */