X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstring_text_file_content.cc;h=d8c195be77af1fe53ada9e66830d776ad4810826;hb=refs%2Fheads%2Fprores-debug;hp=934144fa411d6d6fdd7ddfe1c4158501b2e5e948;hpb=e6ebc314597b0e52ebfdbc7190d847adc5c6adcb;p=dcpomatic.git diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 934144fa4..d8c195be7 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -60,17 +60,13 @@ StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int versi } -void -StringTextFileContent::examine (shared_ptr film, shared_ptr job) +static +std::set +font_names(StringTextFile const& string_text_file) { - Content::examine (film, job); - StringTextFile file (shared_from_this()); - - /* Default to turning these subtitles on */ - only_text()->set_use (true); - std::set names; - for (auto const& subtitle: file.subtitles()) { + + 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("")); @@ -78,7 +74,22 @@ StringTextFileContent::examine (shared_ptr film, shared_ptr job } } - for (auto name: names) { + return names; +} + + +void +StringTextFileContent::examine (shared_ptr film, shared_ptr job) +{ + Content::examine (film, job); + StringTextFile file (shared_from_this()); + + only_text()->clear_fonts(); + + /* Default to turning these subtitles on */ + only_text()->set_use (true); + + for (auto name: font_names(file)) { optional path; if (!name.empty()) { path = FontConfig::instance()->system_font_with_name(name); @@ -146,3 +157,51 @@ 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 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 tag for every different font "id" (i.e. name) found in the source + * file (including a 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 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(); + optional legacy_font_file; + if (auto legacy_font = content->get_font("font")) { + legacy_font_file = legacy_font->file(); + } + + for (auto name: names) { + if (!content->get_font(name)) { + if (legacy_font_file) { + content->add_font(make_shared(name, *legacy_font_file)); + } else { + content->add_font(make_shared(name)); + } + } + } +} +