summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-05-16 23:12:40 +0200
committerCarl Hetherington <cth@carlh.net>2023-05-16 23:12:40 +0200
commitf68a99a93b7a735d9983d8946f058a71f5b11cd4 (patch)
treea9b58d25a1a3268b3448e75d3205214c3f0c1ead
parent245faa7fc2eb88a761e8d52603766b27b5a880c8 (diff)
Make it possible to write subtitle assets without any <Font> tags.2525-ccap-fonts
-rw-r--r--src/interop_subtitle_asset.cc8
-rw-r--r--src/interop_subtitle_asset.h4
-rw-r--r--src/smpte_subtitle_asset.cc8
-rw-r--r--src/smpte_subtitle_asset.h4
-rw-r--r--src/subtitle_asset.cc21
-rw-r--r--src/subtitle_asset.h12
6 files changed, 38 insertions, 19 deletions
diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc
index 8fb115a7..57468908 100644
--- a/src/interop_subtitle_asset.cc
+++ b/src/interop_subtitle_asset.cc
@@ -107,7 +107,7 @@ InteropSubtitleAsset::InteropSubtitleAsset ()
string
-InteropSubtitleAsset::xml_as_string () const
+InteropSubtitleAsset::xml_as_string(FontTags font_tags) const
{
xmlpp::Document doc;
auto root = doc.create_root_node ("DCSubtitle");
@@ -124,7 +124,7 @@ InteropSubtitleAsset::xml_as_string () const
load_font->set_attribute ("URI", i->uri);
}
- subtitles_as_xml (root, 250, Standard::INTEROP);
+ subtitles_as_xml(root, 250, Standard::INTEROP, font_tags);
return format_xml(doc, {});
}
@@ -190,14 +190,14 @@ InteropSubtitleAsset::load_font_nodes () const
void
-InteropSubtitleAsset::write (boost::filesystem::path p) const
+InteropSubtitleAsset::write(boost::filesystem::path p, FontTags font_tags) const
{
File f(p, "wb");
if (!f) {
throw FileError ("Could not open file for writing", p, -1);
}
- _raw_xml = xml_as_string ();
+ _raw_xml = xml_as_string(font_tags);
/* length() here gives bytes not characters */
f.write(_raw_xml->c_str(), 1, _raw_xml->length());
diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h
index 3005c8fc..83f552fd 100644
--- a/src/interop_subtitle_asset.h
+++ b/src/interop_subtitle_asset.h
@@ -76,10 +76,10 @@ public:
void add_font (std::string load_id, dcp::ArrayData data) override;
- std::string xml_as_string () const override;
+ std::string xml_as_string(FontTags font_tags = FontTags::INCLUDE) const override;
/** Write this content to an XML file with its fonts alongside */
- void write (boost::filesystem::path path) const override;
+ void write(boost::filesystem::path path, FontTags font_tags = FontTags::INCLUDE) const override;
void resolve_fonts (std::vector<std::shared_ptr<Asset>> assets);
void set_font_file (std::string load_id, boost::filesystem::path file);
diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc
index 3a58ba8e..9bdbf35c 100644
--- a/src/smpte_subtitle_asset.cc
+++ b/src/smpte_subtitle_asset.cc
@@ -349,7 +349,7 @@ SMPTESubtitleAsset::valid_mxf (boost::filesystem::path file)
string
-SMPTESubtitleAsset::xml_as_string () const
+SMPTESubtitleAsset::xml_as_string(FontTags font_tags) const
{
xmlpp::Document doc;
auto root = doc.create_root_node ("SubtitleReel");
@@ -379,14 +379,14 @@ SMPTESubtitleAsset::xml_as_string () const
load_font->set_attribute ("ID", i->id);
}
- subtitles_as_xml (root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE);
+ subtitles_as_xml(root->add_child("SubtitleList"), _time_code_rate, Standard::SMPTE, font_tags);
return format_xml(doc, std::make_pair(string{}, schema_namespace()));
}
void
-SMPTESubtitleAsset::write (boost::filesystem::path p) const
+SMPTESubtitleAsset::write(boost::filesystem::path p, FontTags font_tags) const
{
EncryptionContext enc (key(), Standard::SMPTE);
@@ -444,7 +444,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
boost::throw_exception (FileError ("could not open subtitle MXF for writing", p.string(), r));
}
- _raw_xml = xml_as_string ();
+ _raw_xml = xml_as_string(font_tags);
r = writer.WriteTimedTextResource (*_raw_xml, enc.context(), enc.hmac());
if (ASDCP_FAILURE (r)) {
diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h
index 2632e0a5..47433610 100644
--- a/src/smpte_subtitle_asset.h
+++ b/src/smpte_subtitle_asset.h
@@ -90,10 +90,10 @@ public:
std::vector<std::shared_ptr<LoadFontNode>> load_font_nodes () const override;
- std::string xml_as_string () const override;
+ std::string xml_as_string(FontTags font_tags = FontTags::INCLUDE) const override;
/** Write this content to a MXF file */
- void write (boost::filesystem::path path) const override;
+ void write(boost::filesystem::path path, FontTags font_tags = FontTags::INCLUDE) const override;
void add (std::shared_ptr<Subtitle>) override;
void add_font (std::string id, dcp::ArrayData data) override;
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index f35b47ef..176ee02b 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -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 */
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index bc5fa882..88f05659 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -115,8 +115,13 @@ public:
std::map<std::string, ArrayData> font_data () const;
std::map<std::string, boost::filesystem::path> font_filenames () const;
- virtual void write (boost::filesystem::path) const = 0;
- virtual std::string xml_as_string () const = 0;
+ enum class FontTags {
+ OMIT,
+ INCLUDE
+ };
+
+ virtual void write(boost::filesystem::path, FontTags font_tags = FontTags::INCLUDE) const = 0;
+ virtual std::string xml_as_string(FontTags font_tags = FontTags::INCLUDE) const = 0;
Time latest_subtitle_out () const;
@@ -178,7 +183,7 @@ protected:
Time fade_time (xmlpp::Element const * node, std::string name, boost::optional<int> tcr) const;
void position_align (ParseState& ps, xmlpp::Element const * node) const;
- void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const;
+ void subtitles_as_xml(xmlpp::Element* root, int time_code_rate, Standard standard, FontTags fonts) const;
/** All our subtitles, in no particular order */
std::vector<std::shared_ptr<Subtitle>> _subtitles;
@@ -220,6 +225,7 @@ private:
void maybe_add_subtitle (std::string text, std::vector<ParseState> const & parse_state, float space_before, Standard standard);
static void pull_fonts (std::shared_ptr<order::Part> part);
+ static void clear_fonts(std::shared_ptr<order::Part> part);
};