From 917eaf28db474a4c605eaaa8347a3e9a86b70aa0 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 26 May 2016 10:41:51 +0100 Subject: [PATCH] Tidy up image/text subtitle distinction with FFmpeg sources. --- src/lib/ffmpeg_subtitle_stream.cc | 12 ++++++++++++ src/lib/ffmpeg_subtitle_stream.h | 3 +++ src/lib/subtitle_content.h | 11 ++++++----- src/wx/subtitle_panel.cc | 30 ++++++++++++++++++------------ 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/lib/ffmpeg_subtitle_stream.cc b/src/lib/ffmpeg_subtitle_stream.cc index f00254ae2..6028d10a9 100644 --- a/src/lib/ffmpeg_subtitle_stream.cc +++ b/src/lib/ffmpeg_subtitle_stream.cc @@ -197,3 +197,15 @@ FFmpegSubtitleStream::set_colour (RGBA from, RGBA to) { _colours[from] = to; } + +bool +FFmpegSubtitleStream::has_text () const +{ + return !_text_subtitles.empty (); +} + +bool +FFmpegSubtitleStream::has_image () const +{ + return !_image_subtitles.empty (); +} diff --git a/src/lib/ffmpeg_subtitle_stream.h b/src/lib/ffmpeg_subtitle_stream.h index c03004b32..f79e7aca7 100644 --- a/src/lib/ffmpeg_subtitle_stream.h +++ b/src/lib/ffmpeg_subtitle_stream.h @@ -42,6 +42,9 @@ public: void set_colour (RGBA from, RGBA to); std::map colours () const; + bool has_text () const; + bool has_image () const; + private: typedef std::map PeriodMap; diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h index 502fad427..2aa33f172 100644 --- a/src/lib/subtitle_content.h +++ b/src/lib/subtitle_content.h @@ -44,6 +44,12 @@ public: static int const OUTLINE_COLOUR; }; +/** @class SubtitleContent + * @brief Description of how some subtitle content should be presented. + * + * There are `image' subtitles (bitmaps) and `text' subtitles (plain text), + * and not all of the settings in this class correspond to both types. + */ class SubtitleContent : public ContentPart { public: @@ -53,11 +59,6 @@ public: void as_xml (xmlpp::Node *) const; std::string identifier () const; - bool has_image_subtitles () const { - /* XXX */ - return true; - } - void add_font (boost::shared_ptr font); void set_use (bool); diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index 31b4e96ac..52b23f5a2 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -235,35 +235,40 @@ SubtitlePanel::setup_sensitivity () int any_subs = 0; int ffmpeg_subs = 0; int text_subs = 0; - int dcp_subs = 0; int image_subs = 0; ContentList sel = _parent->selected_subtitle (); BOOST_FOREACH (shared_ptr i, sel) { + /* These are the content types that could include subtitles */ shared_ptr fc = boost::dynamic_pointer_cast (i); shared_ptr sc = boost::dynamic_pointer_cast (i); shared_ptr dsc = boost::dynamic_pointer_cast (i); if (fc) { if (fc->subtitle) { + /* This content has some subtitles; check the selected stream to decide what type */ + if (fc->subtitle_stream()->has_text()) { + ++text_subs; + } else if (fc->subtitle_stream()->has_image()) { + ++image_subs; + } ++ffmpeg_subs; ++any_subs; } - } else if (sc) { + } else if (sc || dsc) { + /* XXX: in the future there could be bitmap subs from DCPs */ ++text_subs; ++any_subs; - } else if (dsc) { - ++dcp_subs; - ++any_subs; - } else { - ++any_subs; } + } - if (i->subtitle->has_image_subtitles ()) { - ++image_subs; + if (image_subs) { + BOOST_FOREACH (shared_ptr i, sel) { /* We must burn image subtitles at the moment */ i->subtitle->set_burn (true); } } + /* Decide whether we can reference these subs */ + shared_ptr dcp; if (sel.size() == 1) { dcp = dynamic_pointer_cast (sel.front ()); @@ -275,6 +280,7 @@ SubtitlePanel::setup_sensitivity () bool const reference = _reference->GetValue (); + /* Set up sensitivity */ _use->Enable (!reference && any_subs > 0); bool const use = _use->GetValue (); _burn->Enable (!reference && any_subs > 0 && use && image_subs == 0); @@ -284,9 +290,9 @@ SubtitlePanel::setup_sensitivity () _y_scale->Enable (!reference && any_subs > 0 && use); _language->Enable (!reference && any_subs > 0 && use); _stream->Enable (!reference && ffmpeg_subs == 1); - _subtitle_view_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1)); - _fonts_dialog_button->Enable (!reference && (text_subs == 1 || dcp_subs == 1)); - _appearance_dialog_button->Enable (!reference && (ffmpeg_subs == 1 || text_subs == 1)); + _subtitle_view_button->Enable (!reference && text_subs == 1); + _fonts_dialog_button->Enable (!reference && text_subs == 1); + _appearance_dialog_button->Enable (!reference); } void -- 2.30.2