X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstring_text_file_content.cc;h=934144fa411d6d6fdd7ddfe1c4158501b2e5e948;hb=e6ebc314597b0e52ebfdbc7190d847adc5c6adcb;hp=b4362a7d0e7bb9e4b40ef97e6b7f779170ff991a;hpb=673ba43fb66eb0dee43807501753749f144254a7;p=dcpomatic.git diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index b4362a7d0..934144fa4 100644 --- a/src/lib/string_text_file_content.cc +++ b/src/lib/string_text_file_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,76 +18,112 @@ */ -#include "string_text_file_content.h" -#include "util.h" -#include "string_text_file.h" + #include "film.h" #include "font.h" +#include "font_config.h" +#include "string_text_file.h" +#include "string_text_file_content.h" #include "text_content.h" +#include "util.h" #include +#include #include #include + #include "i18n.h" -using std::string; + using std::cout; -using boost::shared_ptr; +using std::list; +using std::make_shared; +using std::shared_ptr; +using std::string; using boost::optional; using dcp::raw_convert; +using namespace dcpomatic; + StringTextFileContent::StringTextFileContent (boost::filesystem::path path) : Content (path) { - text.push_back (shared_ptr (new TextContent (this, TEXT_OPEN_SUBTITLE, TEXT_UNKNOWN))); + text.push_back (make_shared(this, TextType::OPEN_SUBTITLE, TextType::UNKNOWN)); } -StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int version) + +StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int version, list& notes) : Content (node) - , _length (node->number_child ("Length")) + , _length (node->number_child("Length")) { - text = TextContent::from_xml (this, node, version); + text = TextContent::from_xml (this, node, version, notes); } + void StringTextFileContent::examine (shared_ptr film, shared_ptr job) { Content::examine (film, job); - StringTextFile s (shared_from_this ()); + 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& line: subtitle.lines) { + for (auto const& block: line.blocks) { + names.insert(block.font.get_value_or("")); + } + } + } + + for (auto name: names) { + optional path; + if (!name.empty()) { + path = FontConfig::instance()->system_font_with_name(name); + } + if (path) { + only_text()->add_font(make_shared(name, *path)); + } else { + only_text()->add_font(make_shared(name)); + } + } + boost::mutex::scoped_lock lm (_mutex); - _length = s.length (); - only_text()->add_font (shared_ptr (new Font (TEXT_FONT_ID))); + _length = file.length(); } + string StringTextFileContent::summary () const { return path_summary() + " " + _("[subtitles]"); } + string StringTextFileContent::technical_summary () const { return Content::technical_summary() + " - " + _("Text subtitles"); + } + void StringTextFileContent::as_xml (xmlpp::Node* node, bool with_paths) const { - node->add_child("Type")->add_child_text ("TextSubtitle"); + node->add_child("Type")->add_child_text("TextSubtitle"); Content::as_xml (node, with_paths); if (only_text()) { - only_text()->as_xml (node); + only_text()->as_xml(node); } - node->add_child("Length")->add_child_text (raw_convert (_length.get ())); + node->add_child("Length")->add_child_text(raw_convert(_length.get ())); } + DCPTime StringTextFileContent::full_length (shared_ptr film) const { @@ -95,8 +131,18 @@ StringTextFileContent::full_length (shared_ptr film) const return DCPTime (_length, frc); } + DCPTime StringTextFileContent::approximate_length () const { return DCPTime (_length, FrameRateChange()); } + + +string +StringTextFileContent::identifier () const +{ + auto s = Content::identifier (); + s += "_" + only_text()->identifier(); + return s; +}