From 9f294327cb59fce307c3a439f044d79b081376b0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 25 Aug 2020 22:00:06 +0200 Subject: [PATCH] Add option to export Interop subs with or without the font file / reference. --- src/lib/subtitle_encoder.cc | 14 +++++++++++++- src/lib/subtitle_encoder.h | 3 ++- src/tools/dcpomatic.cc | 4 ++-- src/wx/export_subtitles_dialog.cc | 17 +++++++++++++++-- src/wx/export_subtitles_dialog.h | 4 +++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index 2daa5086d..a94b9106a 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -18,6 +18,7 @@ */ +#include "font.h" #include "subtitle_encoder.h" #include "player.h" #include "compose.hpp" @@ -39,9 +40,11 @@ using boost::shared_ptr; using boost::optional; using dcp::raw_convert; -SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr job, boost::filesystem::path output, bool split_reels) +/** @param include_font true to refer to and export any font file (for Interop; ignored for SMPTE) */ +SubtitleEncoder::SubtitleEncoder (shared_ptr film, shared_ptr job, boost::filesystem::path output, bool split_reels, bool include_font) : Encoder (film, job) , _split_reels (split_reels) + , _include_font (include_font) , _reel_index (0) , _length (film->length()) { @@ -101,6 +104,12 @@ SubtitleEncoder::go () } } + if (!_film->interop() || _include_font) { + BOOST_FOREACH (shared_ptr j, _player->get_subtitle_fonts()) { + i->first->add_font (j->id(), default_font_file()); + } + } + i->first->write (i->second); ++reel; } @@ -145,6 +154,9 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional tr /* XXX: couldn't / shouldn't we use period here rather than getting time from the subtitle? */ i.set_in (i.in()); i.set_out (i.out()); + if (_film->interop() && !_include_font) { + i.unset_font (); + } _assets[_reel_index].first->add (shared_ptr(new dcp::SubtitleString(i))); } diff --git a/src/lib/subtitle_encoder.h b/src/lib/subtitle_encoder.h index 50485750d..b267c9bae 100644 --- a/src/lib/subtitle_encoder.h +++ b/src/lib/subtitle_encoder.h @@ -37,7 +37,7 @@ class Film; class SubtitleEncoder : public Encoder { public: - SubtitleEncoder (boost::shared_ptr film, boost::shared_ptr job, boost::filesystem::path output, bool split_reels); + SubtitleEncoder (boost::shared_ptr film, boost::shared_ptr job, boost::filesystem::path output, bool split_reels, bool include_font); void go (); @@ -54,6 +54,7 @@ private: std::vector, boost::filesystem::path> > _assets; std::vector _reels; bool _split_reels; + bool _include_font; int _reel_index; boost::optional _last; dcpomatic::DCPTime _length; diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 9401bc340..5c32fd487 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -990,7 +990,7 @@ private: void jobs_export_subtitles () { - ExportSubtitlesDialog* d = new ExportSubtitlesDialog (this, _film->isdcf_name(true)); + ExportSubtitlesDialog* d = new ExportSubtitlesDialog (this, _film->isdcf_name(true), _film->interop()); if (d->ShowModal() == wxID_OK) { if (boost::filesystem::exists(d->path())) { bool ok = confirm_dialog( @@ -1006,7 +1006,7 @@ private: shared_ptr job (new TranscodeJob (_film)); job->set_encoder ( - shared_ptr(new SubtitleEncoder(_film, job, d->path(), d->split_reels())) + shared_ptr(new SubtitleEncoder(_film, job, d->path(), d->split_reels(), d->include_font())) ); JobManager::instance()->add (job); } diff --git a/src/wx/export_subtitles_dialog.cc b/src/wx/export_subtitles_dialog.cc index 83e08feb4..bcc8adbe1 100644 --- a/src/wx/export_subtitles_dialog.cc +++ b/src/wx/export_subtitles_dialog.cc @@ -34,13 +34,19 @@ using std::string; using boost::bind; -ExportSubtitlesDialog::ExportSubtitlesDialog (wxWindow* parent, string name) +ExportSubtitlesDialog::ExportSubtitlesDialog (wxWindow* parent, string name, bool interop) : TableDialog (parent, _("Export subtitles"), 2, 1, true) , _initial_name (name) + , _include_font (0) { _split_reels = new CheckBox (this, _("Write reels into separate files")); add (_split_reels, false); add_spacer (); + if (interop) { + _include_font = new CheckBox (this, _("Define font in output and export font file")); + add (_include_font, false); + add_spacer (); + } add (_("Output file"), true); /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo @@ -77,10 +83,17 @@ ExportSubtitlesDialog::split_reels () const } +bool +ExportSubtitlesDialog::include_font () const +{ + return _include_font ? _include_font->GetValue () : true; +} + + void ExportSubtitlesDialog::file_changed () { - wxButton* ok = dynamic_cast (FindWindowById (wxID_OK, this)); + wxButton* ok = dynamic_cast (FindWindowById(wxID_OK, this)); DCPOMATIC_ASSERT (ok); ok->Enable (path().is_absolute()); } diff --git a/src/wx/export_subtitles_dialog.h b/src/wx/export_subtitles_dialog.h index d4405cb29..ee55729f7 100644 --- a/src/wx/export_subtitles_dialog.h +++ b/src/wx/export_subtitles_dialog.h @@ -27,15 +27,17 @@ class FilePickerCtrl; class ExportSubtitlesDialog : public TableDialog { public: - ExportSubtitlesDialog (wxWindow* parent, std::string name); + ExportSubtitlesDialog (wxWindow* parent, std::string name, bool interop); boost::filesystem::path path () const; bool split_reels () const; + bool include_font () const; private: void file_changed (); std::string _initial_name; wxCheckBox* _split_reels; + wxCheckBox* _include_font; FilePickerCtrl* _file; }; -- 2.30.2