X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstring_text_file_content.cc;h=934144fa411d6d6fdd7ddfe1c4158501b2e5e948;hb=e6ebc314597b0e52ebfdbc7190d847adc5c6adcb;hp=9c941c2bb14842c813a6d78f7a3f2b54218bfeec;hpb=24dcab1d4d8d7a28a939c7c4d786197684f155f6;p=dcpomatic.git diff --git a/src/lib/string_text_file_content.cc b/src/lib/string_text_file_content.cc index 9c941c2bb..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,79 +18,131 @@ */ -#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 (shared_ptr film, boost::filesystem::path path) - : Content (film, path) + +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 (shared_ptr film, cxml::ConstNodePtr node, int version) - : Content (film, node) - , _length (node->number_child ("Length")) + +StringTextFileContent::StringTextFileContent (cxml::ConstNodePtr node, int version, list& notes) + : Content (node) + , _length (node->number_child("Length")) { - text = TextContent::from_xml (this, node, version); + text = TextContent::from_xml (this, node, version, notes); } + void -StringTextFileContent::examine (boost::shared_ptr job) +StringTextFileContent::examine (shared_ptr film, shared_ptr job) { - Content::examine (job); - StringTextFile s (shared_from_this ()); + 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& 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 () const +StringTextFileContent::full_length (shared_ptr film) const { - FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ()); + FrameRateChange const frc (film, shared_from_this()); 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; +}