diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-06-09 22:40:02 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-06-10 23:12:24 +0200 |
| commit | 14e02ad2f79bdc6fbc320ec7b9282b5faabdb825 (patch) | |
| tree | cfc09ceb9c3298e48eab0ce1b5c8d940a895ec04 /src/lib | |
| parent | e68386830c8812f80cb4b3af9871170226b916b4 (diff) | |
Fix problems when loading old projects with the new subtitle font code (#2271).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/check_content_job.cc | 10 | ||||
| -rw-r--r-- | src/lib/string_text_file_content.cc | 72 | ||||
| -rw-r--r-- | src/lib/string_text_file_content.h | 2 |
3 files changed, 76 insertions, 8 deletions
diff --git a/src/lib/check_content_job.cc b/src/lib/check_content_job.cc index a789ed9e0..2b6e25da8 100644 --- a/src/lib/check_content_job.cc +++ b/src/lib/check_content_job.cc @@ -24,12 +24,14 @@ #include "examine_content_job.h" #include "film.h" #include "job_manager.h" +#include "string_text_file_content.h" #include <iostream> #include "i18n.h" using std::cout; +using std::dynamic_pointer_cast; using std::make_shared; using std::shared_ptr; using std::string; @@ -74,6 +76,14 @@ CheckContentJob::run () set_message (_("Some files have been changed since they were added to the project.\n\nThese files will now be re-examined, so you may need to check their settings.")); } + if (_film->last_written_by_earlier_than(2, 16, 14)) { + for (auto c: content) { + if (auto stf = dynamic_pointer_cast<StringTextFileContent>(c)) { + stf->check_font_ids(); + } + } + } + set_progress (1); set_state (FINISHED_OK); } diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 95a282174..7ee870e18 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -60,6 +60,24 @@ StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int versi } +static +std::set<string> +font_names(StringTextFile const& string_text_file) +{ + std::set<string> names; + + for (auto const& subtitle: string_text_file.subtitles()) { + for (auto const& line: subtitle.lines) { + for (auto const& block: line.blocks) { + names.insert(block.font.get_value_or("")); + } + } + } + + return names; +} + + void StringTextFileContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) { @@ -71,14 +89,7 @@ StringTextFileContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job /* Default to turning these subtitles on */ only_text()->set_use (true); - std::set<string> names; - for (auto const& subtitle: file.subtitles()) { - for (auto const& line: subtitle.lines) { - for (auto const& block: line.blocks) { - names.insert(block.font.get_value_or("")); - } - } - } + std::set<string> names = font_names(file); for (auto name: names) { optional<boost::filesystem::path> path; @@ -148,3 +159,48 @@ StringTextFileContent::identifier () const s += "_" + only_text()->identifier(); return s; } + + +/** In 5a820bb8fae34591be5ac6d19a73461b9dab532a there were some changes to subtitle font management. + * + * With StringTextFileContent we used to write a <Font> tag to the metadata with the id "font". Users + * could then set a font file that content should use, and (with some luck) it would end up in the DCP + * that way. + * + * After the changes we write a <Font> tag for every different font "id" (i.e. name) found in the source + * file (including a <Font> with id "" in the .srt case where there are no font names). + * + * However, this meant that making DCPs from old projects would fail, as the new code would see a font name + * in the source, then lookup a Font object for it from the Content, and fail in doing so (since the content + * only contains a font called "font"). + * + * To put it another way: after the changes, the code expects that any font ID (i.e. name) used in some content + * will have a <Font> in the metadata and so a Font object in the TextContent. Without that, making DCPs fails. + * + * To work around this problem, this check_font_ids() is called for all subtitle content written by DoM versions + * before 2.16.14. We find all the font IDs in the content and map them all to the "legacy" font name (if there + * is one). This is more-or-less a re-examine()-ation, except that we try to preserve any settings that + * the user had previously set up. + * + * See #2271. + */ +void +StringTextFileContent::check_font_ids() +{ + StringTextFile file (shared_from_this()); + auto names = font_names(file); + + auto content = only_text(); + auto legacy_font_file = content->get_font("font")->file(); + + for (auto name: names) { + if (!content->get_font(name)) { + if (legacy_font_file) { + content->add_font(make_shared<Font>(name, *legacy_font_file)); + } else { + content->add_font(make_shared<Font>(name)); + } + } + } +} + diff --git a/src/lib/string_text_file_content.h b/src/lib/string_text_file_content.h index 9c7d4cea0..30f543381 100644 --- a/src/lib/string_text_file_content.h +++ b/src/lib/string_text_file_content.h @@ -50,6 +50,8 @@ public: dcpomatic::DCPTime approximate_length () const override; std::string identifier () const override; + void check_font_ids(); + private: dcpomatic::ContentTime _length; }; |
