2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "check_box.h"
23 #include "content_panel.h"
24 #include "dcp_text_track_dialog.h"
25 #include "dcpomatic_button.h"
26 #include "dcpomatic_spin_ctrl.h"
27 #include "film_editor.h"
28 #include "film_viewer.h"
29 #include "fonts_dialog.h"
30 #include "static_text.h"
31 #include "subtitle_appearance_dialog.h"
32 #include "text_panel.h"
33 #include "text_view.h"
35 #include "lib/analyse_subtitles_job.h"
36 #include "lib/dcp_content.h"
37 #include "lib/dcp_subtitle_content.h"
38 #include "lib/dcp_subtitle_decoder.h"
39 #include "lib/decoder_factory.h"
40 #include "lib/ffmpeg_content.h"
41 #include "lib/ffmpeg_subtitle_stream.h"
42 #include "lib/job_manager.h"
43 #include "lib/string_text_file_content.h"
44 #include "lib/string_text_file_decoder.h"
45 #include "lib/subtitle_analysis.h"
46 #include "lib/text_content.h"
47 #include <wx/spinctrl.h>
54 using std::shared_ptr;
55 using boost::optional;
56 using std::dynamic_pointer_cast;
60 /** @param t Original text type of the content, if known */
61 TextPanel::TextPanel (ContentPanel* p, TextType t)
62 : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
63 , _outline_subtitles (0)
64 , _dcp_track_label (0)
69 , _loading_analysis (false)
71 wxString refer = _("Use this DCP's subtitle as OV and make VF");
72 if (t == TextType::CLOSED_CAPTION) {
73 refer = _("Use this DCP's closed caption as OV and make VF");
76 _reference = new CheckBox (this, refer);
77 _reference_note = new StaticText (this, wxT(""));
78 _reference_note->Wrap (200);
79 auto font = _reference_note->GetFont();
80 font.SetStyle(wxFONTSTYLE_ITALIC);
81 font.SetPointSize(font.GetPointSize() - 1);
82 _reference_note->SetFont(font);
84 _use = new CheckBox (this, _("Use as"));
85 _type = new wxChoice (this, wxID_ANY);
86 _type->Append (_("open subtitles"));
87 _type->Append (_("closed captions"));
89 _burn = new CheckBox (this, _("Burn subtitles into image"));
92 int const spin_width = 118;
94 int const spin_width = 56;
97 _offset_label = create_label (this, _("Offset"), true);
98 _x_offset_label = create_label (this, _("X"), true);
99 _x_offset = new SpinCtrl (this, spin_width);
100 _x_offset_pc_label = new StaticText (this, _("%"));
101 _y_offset_label = create_label (this, _("Y"), true);
102 _y_offset = new SpinCtrl (this, spin_width);
103 _y_offset_pc_label = new StaticText (this, _("%"));
105 _scale_label = create_label (this, _("Scale"), true);
106 _x_scale_label = create_label (this, _("X"), true);
107 _x_scale = new SpinCtrl (this, spin_width);
108 _x_scale_pc_label = new StaticText (this, _("%"));
109 _y_scale_label = create_label (this, S_("Coord|Y"), true);
110 _y_scale = new SpinCtrl (this, spin_width);
111 _y_scale_pc_label = new StaticText (this, _("%"));
113 _line_spacing_label = create_label (this, _("Line spacing"), true);
114 _line_spacing = new SpinCtrl (this, spin_width);
115 _line_spacing_pc_label = new StaticText (this, _("%"));
117 _stream_label = create_label (this, _("Stream"), true);
118 _stream = new wxChoice (this, wxID_ANY);
120 _text_view_button = new Button (this, _("View..."));
121 _fonts_dialog_button = new Button (this, _("Fonts..."));
122 _appearance_dialog_button = new Button (this, _("Appearance..."));
124 _x_offset->SetRange (-100, 100);
125 _y_offset->SetRange (-100, 100);
126 _x_scale->SetRange (0, 1000);
127 _y_scale->SetRange (0, 1000);
128 _line_spacing->SetRange (0, 1000);
130 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
131 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
132 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
133 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
134 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
135 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
136 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
137 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
138 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
139 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
140 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
141 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
142 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
145 content_selection_changed ();
150 TextPanel::setup_visibility ()
152 switch (current_type()) {
153 case TextType::OPEN_SUBTITLE:
154 if (_dcp_track_label) {
155 _dcp_track_label->Destroy ();
156 _dcp_track_label = 0;
159 _dcp_track->Destroy ();
160 _dcp_track = nullptr;
162 if (!_outline_subtitles) {
163 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
164 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
165 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
169 case TextType::CLOSED_CAPTION:
170 if (!_dcp_track_label) {
171 _dcp_track_label = create_label (this, _("CCAP track"), true);
172 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_row, 0));
175 _dcp_track = new wxChoice (this, wxID_ANY);
176 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
177 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_row, 1), wxDefaultSpan, wxEXPAND);
178 update_dcp_tracks ();
179 film_content_changed (TextContentProperty::DCP_TRACK);
181 if (_outline_subtitles) {
182 _outline_subtitles->Destroy ();
183 _outline_subtitles = 0;
184 clear_outline_subtitles ();
196 TextPanel::add_to_grid ()
200 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
201 reference_sizer->Add (_reference, 0);
202 reference_sizer->Add (_reference_note, 0);
203 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
206 auto use = new wxBoxSizer (wxHORIZONTAL);
207 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
208 use->Add (_type, 1, wxEXPAND, 0);
209 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
212 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
215 _outline_subtitles_row = r;
218 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
219 auto offset = new wxBoxSizer (wxHORIZONTAL);
220 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
221 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
222 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
224 _grid->Add (offset, wxGBPosition(r, 1));
226 offset = new wxBoxSizer (wxHORIZONTAL);
228 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
229 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
230 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
231 _grid->Add (offset, wxGBPosition (r, 1));
234 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
235 auto scale = new wxBoxSizer (wxHORIZONTAL);
236 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
237 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
238 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
240 _grid->Add (scale, wxGBPosition(r, 1));
242 scale = new wxBoxSizer (wxHORIZONTAL);
244 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
245 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
246 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
247 _grid->Add (scale, wxGBPosition (r, 1));
251 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
252 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
253 s->Add (_line_spacing);
254 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
255 _grid->Add (s, wxGBPosition (r, 1));
262 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
263 _grid->Add (_stream, wxGBPosition (r, 1));
267 auto s = new wxBoxSizer (wxHORIZONTAL);
269 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
270 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
271 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
273 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
282 TextPanel::update_dcp_track_selection ()
284 DCPOMATIC_ASSERT (_dcp_track);
286 optional<DCPTextTrack> selected;
288 for (auto i: _parent->selected_text()) {
289 auto t = i->text_of_original_type(_original_type);
291 auto dt = t->dcp_track();
292 if (dt && selected && *dt != *selected) {
294 } else if (!selected) {
301 for (auto i: _parent->film()->closed_caption_tracks()) {
302 if (!many && selected && *selected == i) {
303 _dcp_track->SetSelection (n);
308 if (!selected || many) {
309 _dcp_track->SetSelection (wxNOT_FOUND);
315 TextPanel::update_dcp_tracks ()
317 DCPOMATIC_ASSERT (_dcp_track);
319 _dcp_track->Clear ();
320 for (auto i: _parent->film()->closed_caption_tracks()) {
321 /* XXX: don't display the "magic" track which has empty name and language;
322 this is a nasty hack (see also Film::closed_caption_tracks)
324 if (!i.name.empty() || !i.language.empty()) {
325 _dcp_track->Append (std_to_wx(i.summary()));
329 if (_parent->film()->closed_caption_tracks().size() < 6) {
330 _dcp_track->Append (_("Add new..."));
333 update_dcp_track_selection ();
338 TextPanel::dcp_track_changed ()
340 optional<DCPTextTrack> track;
342 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
343 auto d = new DCPTextTrackDialog (this);
344 if (d->ShowModal() == wxID_OK) {
349 /* Find the DCPTextTrack that was selected */
350 for (auto i: _parent->film()->closed_caption_tracks()) {
351 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
358 for (auto i: _parent->selected_text()) {
359 auto t = i->text_of_original_type(_original_type);
360 if (t && t->type() == TextType::CLOSED_CAPTION) {
361 t->set_dcp_track(*track);
366 update_dcp_tracks ();
371 TextPanel::film_changed (Film::Property property)
373 if (property == Film::Property::CONTENT || property == Film::Property::REEL_TYPE || property == Film::Property::INTEROP) {
374 setup_sensitivity ();
380 TextPanel::film_content_changed (int property)
382 auto fc = _parent->selected_ffmpeg ();
383 auto sc = _parent->selected_text ();
385 shared_ptr<FFmpegContent> fcs;
386 if (fc.size() == 1) {
390 shared_ptr<Content> scs;
391 if (sc.size() == 1) {
395 shared_ptr<TextContent> text;
397 text = scs->text_of_original_type(_original_type);
400 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
403 for (auto i: fcs->subtitle_streams()) {
404 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
407 if (fcs->subtitle_stream()) {
408 checked_set (_stream, fcs->subtitle_stream()->identifier ());
410 _stream->SetSelection (wxNOT_FOUND);
413 setup_sensitivity ();
414 clear_outline_subtitles ();
415 } else if (property == TextContentProperty::USE) {
416 checked_set (_use, text ? text->use() : false);
417 setup_sensitivity ();
418 clear_outline_subtitles ();
419 } else if (property == TextContentProperty::TYPE) {
421 switch (text->type()) {
422 case TextType::OPEN_SUBTITLE:
423 _type->SetSelection (0);
425 case TextType::CLOSED_CAPTION:
426 _type->SetSelection (1);
429 DCPOMATIC_ASSERT (false);
432 _type->SetSelection (0);
434 setup_sensitivity ();
436 } else if (property == TextContentProperty::BURN) {
437 checked_set (_burn, text ? text->burn() : false);
438 } else if (property == TextContentProperty::X_OFFSET) {
439 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
440 update_outline_subtitles_in_viewer ();
441 } else if (property == TextContentProperty::Y_OFFSET) {
442 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
443 update_outline_subtitles_in_viewer ();
444 } else if (property == TextContentProperty::X_SCALE) {
445 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
446 clear_outline_subtitles ();
447 } else if (property == TextContentProperty::Y_SCALE) {
448 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
449 clear_outline_subtitles ();
450 } else if (property == TextContentProperty::LINE_SPACING) {
451 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
452 clear_outline_subtitles ();
453 } else if (property == TextContentProperty::DCP_TRACK) {
455 update_dcp_track_selection ();
457 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
459 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
460 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
462 checked_set (_reference, false);
465 setup_sensitivity ();
466 } else if (property == DCPContentProperty::TEXTS) {
467 setup_sensitivity ();
468 } else if (property == ContentProperty::TRIM_START) {
469 setup_sensitivity ();
475 TextPanel::use_toggled ()
477 for (auto i: _parent->selected_text()) {
478 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
483 /** @return the text type that is currently selected in the drop-down */
485 TextPanel::current_type () const
487 switch (_type->GetSelection()) {
489 return TextType::OPEN_SUBTITLE;
491 return TextType::CLOSED_CAPTION;
494 return TextType::UNKNOWN;
499 TextPanel::type_changed ()
501 for (auto i: _parent->selected_text()) {
502 i->text_of_original_type(_original_type)->set_type (current_type ());
510 TextPanel::burn_toggled ()
512 for (auto i: _parent->selected_text ()) {
513 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
519 TextPanel::setup_sensitivity ()
522 /* We currently assume that FFmpeg subtitles are bitmapped */
524 /* DCP subs can't have their line spacing changed */
526 auto sel = _parent->selected_text ();
528 /* These are the content types that could include subtitles */
529 auto fc = std::dynamic_pointer_cast<const FFmpegContent> (i);
530 auto sc = std::dynamic_pointer_cast<const StringTextFileContent> (i);
531 auto dc = std::dynamic_pointer_cast<const DCPContent> (i);
532 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent> (i);
534 if (!fc->text.empty()) {
538 } else if (dc || dsc) {
542 /* XXX: in the future there could be bitmap subs from DCPs */
547 /* Decide whether we can reference these subs */
549 shared_ptr<DCPContent> dcp;
550 if (sel.size() == 1) {
551 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
555 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
557 if (why_not.empty()) {
558 cannot = _("Cannot reference this DCP's subtitles or captions.");
560 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
562 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
564 bool const reference = _reference->GetValue ();
566 TextType const type = current_type ();
570 _type->Append (_("open subtitles"));
571 if (ffmpeg_subs == 0) {
572 _type->Append (_("closed captions"));
576 case TextType::OPEN_SUBTITLE:
577 _type->SetSelection (0);
579 case TextType::CLOSED_CAPTION:
580 if (_type->GetCount() > 1) {
581 _type->SetSelection (1);
588 /* Set up sensitivity */
589 _use->Enable (!reference && any_subs > 0);
590 bool const use = _use->GetValue ();
591 if (_outline_subtitles) {
592 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
594 _type->Enable (!reference && any_subs > 0 && use);
595 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
596 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
597 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
598 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
599 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
600 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
601 _stream->Enable (!reference && ffmpeg_subs == 1);
602 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
603 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
604 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
605 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
610 TextPanel::stream_changed ()
612 auto fc = _parent->selected_ffmpeg ();
613 if (fc.size() != 1) {
617 auto fcs = fc.front ();
619 auto a = fcs->subtitle_streams ();
621 auto const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
622 while (i != a.end() && (*i)->identifier () != s) {
627 fcs->set_subtitle_stream (*i);
633 TextPanel::x_offset_changed ()
635 for (auto i: _parent->selected_text ()) {
636 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
642 TextPanel::y_offset_changed ()
644 for (auto i: _parent->selected_text ()) {
645 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
651 TextPanel::x_scale_changed ()
653 for (auto i: _parent->selected_text ()) {
654 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
660 TextPanel::y_scale_changed ()
662 for (auto i: _parent->selected_text ()) {
663 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
669 TextPanel::line_spacing_changed ()
671 for (auto i: _parent->selected_text ()) {
672 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
678 TextPanel::content_selection_changed ()
680 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
681 film_content_changed (TextContentProperty::USE);
682 film_content_changed (TextContentProperty::BURN);
683 film_content_changed (TextContentProperty::X_OFFSET);
684 film_content_changed (TextContentProperty::Y_OFFSET);
685 film_content_changed (TextContentProperty::X_SCALE);
686 film_content_changed (TextContentProperty::Y_SCALE);
687 film_content_changed (TextContentProperty::LINE_SPACING);
688 film_content_changed (TextContentProperty::FONTS);
689 film_content_changed (TextContentProperty::TYPE);
690 film_content_changed (TextContentProperty::DCP_TRACK);
691 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
696 TextPanel::text_view_clicked ()
699 _text_view->Destroy ();
703 auto c = _parent->selected_text ();
704 DCPOMATIC_ASSERT (c.size() == 1);
706 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
709 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
716 TextPanel::fonts_dialog_clicked ()
719 _fonts_dialog->Destroy ();
720 _fonts_dialog = nullptr;
723 auto c = _parent->selected_text ();
724 DCPOMATIC_ASSERT (c.size() == 1);
726 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
727 _fonts_dialog->Show ();
732 TextPanel::reference_clicked ()
734 auto c = _parent->selected ();
739 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
744 d->set_reference_text (_original_type, _reference->GetValue ());
749 TextPanel::appearance_dialog_clicked ()
751 auto c = _parent->selected_text ();
752 DCPOMATIC_ASSERT (c.size() == 1);
754 auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
755 if (d->ShowModal () == wxID_OK) {
763 /** The user has clicked on the outline subtitles check box */
765 TextPanel::outline_subtitles_changed ()
767 if (_outline_subtitles->GetValue()) {
768 _analysis_content = _parent->selected_text().front();
769 try_to_load_analysis ();
771 clear_outline_subtitles ();
777 TextPanel::try_to_load_analysis ()
779 if (_loading_analysis) {
783 _loading_analysis = true;
784 setup_sensitivity ();
787 auto content = _analysis_content.lock ();
789 _loading_analysis = false;
790 setup_sensitivity ();
794 auto const path = _parent->film()->subtitle_analysis_path(content);
796 if (!boost::filesystem::exists(path)) {
797 for (auto i: JobManager::instance()->get()) {
798 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
803 JobManager::instance()->analyse_subtitles (
804 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
810 _analysis.reset (new SubtitleAnalysis(path));
811 } catch (OldFormatError& e) {
812 /* An old analysis file: recreate it */
813 JobManager::instance()->analyse_subtitles (
814 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
819 update_outline_subtitles_in_viewer ();
820 _loading_analysis = false;
821 setup_sensitivity ();
826 TextPanel::update_outline_subtitles_in_viewer ()
828 auto fv = _parent->film_viewer().lock();
834 auto rect = _analysis->bounding_box ();
836 auto content = _analysis_content.lock ();
837 DCPOMATIC_ASSERT (content);
838 rect->x += content->text.front()->x_offset();
839 rect->y += content->text.front()->y_offset();
841 fv->set_outline_subtitles (rect);
843 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
848 /** Remove any current subtitle outline display */
850 TextPanel::clear_outline_subtitles ()
853 update_outline_subtitles_in_viewer ();
854 if (_outline_subtitles) {
855 _outline_subtitles->SetValue (false);
861 TextPanel::analysis_finished ()
863 auto content = _analysis_content.lock ();
865 _loading_analysis = false;
866 setup_sensitivity ();
870 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
871 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
874 error_dialog (_parent->window(), _("Could not analyse subtitles."));
875 clear_outline_subtitles ();
876 _loading_analysis = false;
877 setup_sensitivity ();
881 _loading_analysis = false;
882 try_to_load_analysis ();