diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-12-15 22:58:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-12-22 01:21:00 +0100 |
| commit | dd0db15b82a0b40b1271bad122c874d458c0fef4 (patch) | |
| tree | 201b4efac6915353e9635f230b3a08297be87dd7 /src | |
| parent | 82c72bf1a25891d5053b7b4fb1f7d2bab9d7fd13 (diff) | |
Add fix_empty_font_ids() to replace empty Font ids with a dummy string.
Diffstat (limited to 'src')
| -rw-r--r-- | src/subtitle_asset.cc | 40 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 2 | ||||
| -rw-r--r-- | src/subtitle_string.h | 4 | ||||
| -rw-r--r-- | src/util.cc | 17 | ||||
| -rw-r--r-- | src/util.h | 1 |
5 files changed, 63 insertions, 1 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index bb7b0b1c..083a8040 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net> This file is part of libdcp. @@ -40,6 +40,7 @@ #include "subtitle_string.h" #include "subtitle_image.h" #include "dcp_assert.h" +#include "load_font_node.h" #include <asdcp/AS_DCP.h> #include <asdcp/KM_util.h> #include <libxml++/nodes/element.h> @@ -655,3 +656,40 @@ SubtitleAsset::fonts_with_load_ids () const } return out; } + +/** Replace empty IDs in any <LoadFontId> and <Font> tags with + * a dummy string. Some systems give errors with empty font IDs + * (see DCP-o-matic bug #1689). + */ +void +SubtitleAsset::fix_empty_font_ids () +{ + bool have_empty = false; + list<string> ids; + BOOST_FOREACH (shared_ptr<LoadFontNode> i, load_font_nodes()) { + if (i->id == "") { + have_empty = true; + } else { + ids.push_back (i->id); + } + } + + if (!have_empty) { + return; + } + + string const empty_id = unique_string (ids, "font"); + + BOOST_FOREACH (shared_ptr<LoadFontNode> i, load_font_nodes()) { + if (i->id == "") { + i->id = empty_id; + } + } + + BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) { + shared_ptr<SubtitleString> j = dynamic_pointer_cast<SubtitleString> (i); + if (j && j->font() && j->font().get() == "") { + j->set_font (empty_id); + } + } +} diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 96a56a9c..9792ce05 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -101,6 +101,8 @@ public: Time latest_subtitle_out () const; + void fix_empty_font_ids (); + virtual std::list<boost::shared_ptr<LoadFontNode> > load_font_nodes () const = 0; protected: diff --git a/src/subtitle_string.h b/src/subtitle_string.h index c274152b..7e84d103 100644 --- a/src/subtitle_string.h +++ b/src/subtitle_string.h @@ -125,6 +125,10 @@ public: return _aspect_adjust; } + void set_font (std::string id) { + _font = id; + } + void set_size (int s) { _size = s; } diff --git a/src/util.cc b/src/util.cc index c6313b4c..533ee466 100644 --- a/src/util.cc +++ b/src/util.cc @@ -410,3 +410,20 @@ dcp::day_greater_than_or_equal (struct tm a, LocalTime b) return a.tm_mday >= b.day(); } + +/** Try quite hard to find a string which starts with \ref base and is + * not in \ref existing. + */ +string +dcp::unique_string (list<string> existing, string base) +{ + int const max_tries = existing.size() + 1; + for (int i = 0; i < max_tries; ++i) { + string trial = String::compose("%1%2", base, i); + if (find(existing.begin(), existing.end(), trial) == existing.end()) { + return trial; + } + } + + DCP_ASSERT (false); +} @@ -78,6 +78,7 @@ extern std::string spaces (int n); extern void indent (xmlpp::Element* element, int initial); extern bool day_less_than_or_equal (struct tm a, LocalTime b); extern bool day_greater_than_or_equal (struct tm a, LocalTime b); +extern std::string unique_string (std::list<std::string> existing, std::string base); } |
