2 Copyright (C) 2012-2020 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/>.
21 #include "text_panel.h"
22 #include "film_editor.h"
24 #include "text_view.h"
25 #include "content_panel.h"
26 #include "fonts_dialog.h"
27 #include "dcp_text_track_dialog.h"
28 #include "subtitle_appearance_dialog.h"
29 #include "static_text.h"
30 #include "check_box.h"
31 #include "dcpomatic_button.h"
32 #include "film_viewer.h"
33 #include "lib/job_manager.h"
34 #include "lib/ffmpeg_content.h"
35 #include "lib/string_text_file_content.h"
36 #include "lib/ffmpeg_subtitle_stream.h"
37 #include "lib/dcp_subtitle_content.h"
38 #include "lib/string_text_file_decoder.h"
39 #include "lib/dcp_subtitle_decoder.h"
40 #include "lib/dcp_content.h"
41 #include "lib/text_content.h"
42 #include "lib/decoder_factory.h"
43 #include "lib/analyse_subtitles_job.h"
44 #include "lib/subtitle_analysis.h"
45 #include <wx/spinctrl.h>
46 #include <boost/foreach.hpp>
52 using boost::shared_ptr;
53 using boost::optional;
54 using boost::dynamic_pointer_cast;
57 /** @param t Original text type of the content, if known */
58 TextPanel::TextPanel (ContentPanel* p, TextType t)
59 : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
60 , _outline_subtitles (0)
61 , _dcp_track_label (0)
68 , _loading_analysis (false)
70 wxString refer = _("Use this DCP's subtitle as OV and make VF");
71 if (t == TEXT_CLOSED_CAPTION) {
72 refer = _("Use this DCP's closed caption as OV and make VF");
75 _reference = new CheckBox (this, refer);
76 _reference_note = new StaticText (this, wxT(""));
77 _reference_note->Wrap (200);
78 wxFont font = _reference_note->GetFont();
79 font.SetStyle(wxFONTSTYLE_ITALIC);
80 font.SetPointSize(font.GetPointSize() - 1);
81 _reference_note->SetFont(font);
83 _use = new CheckBox (this, _("Use as"));
84 _type = new wxChoice (this, wxID_ANY);
85 _type->Append (_("open subtitles"));
86 _type->Append (_("closed captions"));
88 _burn = new CheckBox (this, _("Burn subtitles into image"));
91 int const spin_width = 118;
93 int const spin_width = 56;
96 _offset_label = create_label (this, _("Offset"), true);
97 _x_offset_label = create_label (this, _("X"), true);
98 _x_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
99 _x_offset_pc_label = new StaticText (this, _("%"));
100 _y_offset_label = create_label (this, _("Y"), true);
101 _y_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
102 _y_offset_pc_label = new StaticText (this, _("%"));
104 _scale_label = create_label (this, _("Scale"), true);
105 _x_scale_label = create_label (this, _("X"), true);
106 _x_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
107 _x_scale_pc_label = new StaticText (this, _("%"));
108 _y_scale_label = create_label (this, S_("Coord|Y"), true);
109 _y_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(spin_width, -1));
110 _y_scale_pc_label = new StaticText (this, _("%"));
112 _line_spacing_label = create_label (this, _("Line spacing"), true);
113 _line_spacing = new wxSpinCtrl (this);
114 _line_spacing_pc_label = new StaticText (this, _("%"));
116 _stream_label = create_label (this, _("Stream"), true);
117 _stream = new wxChoice (this, wxID_ANY);
119 _text_view_button = new Button (this, _("View..."));
120 _fonts_dialog_button = new Button (this, _("Fonts..."));
121 _appearance_dialog_button = new Button (this, _("Appearance..."));
123 _x_offset->SetRange (-100, 100);
124 _y_offset->SetRange (-100, 100);
125 _x_scale->SetRange (10, 1000);
126 _y_scale->SetRange (10, 1000);
127 _line_spacing->SetRange (10, 1000);
129 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
130 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
131 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
132 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
133 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
134 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
135 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
136 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
137 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
138 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
139 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
140 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
141 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
144 content_selection_changed ();
148 TextPanel::setup_visibility ()
150 switch (current_type()) {
151 case TEXT_OPEN_SUBTITLE:
152 if (_dcp_track_label) {
153 _dcp_track_label->Destroy ();
154 _dcp_track_label = 0;
157 _dcp_track->Destroy ();
160 if (!_language_label) {
161 _language_label = create_label (this, _("Language"), true);
162 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_language_row, 0));
165 _language = new wxTextCtrl (this, wxID_ANY);
166 _language->Bind (wxEVT_TEXT, boost::bind(&TextPanel::language_changed, this));
167 _grid->Add (_language, wxGBPosition(_language_row, 1), wxDefaultSpan, wxEXPAND);
168 film_content_changed (TextContentProperty::LANGUAGE);
170 if (!_outline_subtitles) {
171 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
172 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
173 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
177 case TEXT_CLOSED_CAPTION:
178 if (_language_label) {
179 _language_label->Destroy ();
183 _language->Destroy ();
186 if (!_dcp_track_label) {
187 _dcp_track_label = create_label (this, _("CCAP track"), true);
188 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_language_row, 0));
191 _dcp_track = new wxChoice (this, wxID_ANY);
192 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
193 _grid->Add (_dcp_track, wxGBPosition(_language_row, 1), wxDefaultSpan, wxEXPAND);
194 update_dcp_tracks ();
195 film_content_changed (TextContentProperty::DCP_TRACK);
197 if (_outline_subtitles) {
198 _outline_subtitles->Destroy ();
199 _outline_subtitles = 0;
200 clear_outline_subtitles ();
211 TextPanel::add_to_grid ()
213 Config::Interface const interface = Config::instance()->interface_complexity();
217 _reference->Show (interface == Config::INTERFACE_FULL);
218 _reference_note->Show (interface == Config::INTERFACE_FULL);
220 if (interface == Config::INTERFACE_FULL) {
221 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
222 reference_sizer->Add (_reference, 0);
223 reference_sizer->Add (_reference_note, 0);
224 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
228 wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
229 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
230 use->Add (_type, 1, wxEXPAND, 0);
231 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
234 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
237 _outline_subtitles_row = r;
240 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
241 wxBoxSizer* offset = new wxBoxSizer (wxHORIZONTAL);
242 add_label_to_sizer (offset, _x_offset_label, true);
243 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
244 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
245 add_label_to_sizer (offset, _y_offset_label, true);
246 offset->Add (_y_offset, 0);
247 add_label_to_sizer (offset, _y_offset_pc_label, false);
248 _grid->Add (offset, wxGBPosition (r, 1));
251 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
252 wxBoxSizer* scale = new wxBoxSizer (wxHORIZONTAL);
253 add_label_to_sizer (scale, _x_scale_label, true);
254 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
255 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
256 add_label_to_sizer (scale, _y_scale_label, true);
257 scale->Add (_y_scale, 0);
258 add_label_to_sizer (scale, _y_scale_pc_label, false);
259 _grid->Add (scale, wxGBPosition (r, 1));
263 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
264 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
265 s->Add (_line_spacing);
266 add_label_to_sizer (s, _line_spacing_pc_label, false);
267 _grid->Add (s, wxGBPosition (r, 1));
274 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
275 _grid->Add (_stream, wxGBPosition (r, 1));
279 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
281 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
282 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
283 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
285 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
293 TextPanel::update_dcp_track_selection ()
295 DCPOMATIC_ASSERT (_dcp_track);
297 optional<DCPTextTrack> selected;
299 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
300 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
302 optional<DCPTextTrack> dt = t->dcp_track();
303 if (dt && selected && *dt != *selected) {
305 } else if (!selected) {
312 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
313 if (!many && selected && *selected == i) {
314 _dcp_track->SetSelection (n);
319 if (!selected || many) {
320 _dcp_track->SetSelection (wxNOT_FOUND);
325 TextPanel::update_dcp_tracks ()
327 DCPOMATIC_ASSERT (_dcp_track);
329 _dcp_track->Clear ();
330 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
331 /* XXX: don't display the "magic" track which has empty name and language;
332 this is a nasty hack (see also Film::closed_caption_tracks)
334 if (!i.name.empty() || !i.language.empty()) {
335 _dcp_track->Append (std_to_wx(i.summary()));
339 if (_parent->film()->closed_caption_tracks().size() < 6) {
340 _dcp_track->Append (_("Add new..."));
343 update_dcp_track_selection ();
347 TextPanel::dcp_track_changed ()
349 optional<DCPTextTrack> track;
351 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
352 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
353 if (d->ShowModal() == wxID_OK) {
358 /* Find the DCPTextTrack that was selected */
359 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
360 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
367 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
368 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
369 if (t && t->type() == TEXT_CLOSED_CAPTION) {
370 t->set_dcp_track(*track);
375 update_dcp_tracks ();
379 TextPanel::film_changed (Film::Property property)
381 if (property == Film::CONTENT || property == Film::REEL_TYPE || property == Film::INTEROP) {
382 setup_sensitivity ();
387 TextPanel::film_content_changed (int property)
389 FFmpegContentList fc = _parent->selected_ffmpeg ();
390 ContentList sc = _parent->selected_text ();
392 shared_ptr<FFmpegContent> fcs;
393 if (fc.size() == 1) {
397 shared_ptr<Content> scs;
398 if (sc.size() == 1) {
402 shared_ptr<TextContent> text;
404 text = scs->text_of_original_type(_original_type);
407 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
410 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
411 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
412 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
415 if (fcs->subtitle_stream()) {
416 checked_set (_stream, fcs->subtitle_stream()->identifier ());
418 _stream->SetSelection (wxNOT_FOUND);
421 setup_sensitivity ();
422 clear_outline_subtitles ();
423 } else if (property == TextContentProperty::USE) {
424 checked_set (_use, text ? text->use() : false);
425 setup_sensitivity ();
426 clear_outline_subtitles ();
427 } else if (property == TextContentProperty::TYPE) {
429 switch (text->type()) {
430 case TEXT_OPEN_SUBTITLE:
431 _type->SetSelection (0);
433 case TEXT_CLOSED_CAPTION:
434 _type->SetSelection (1);
437 DCPOMATIC_ASSERT (false);
440 _type->SetSelection (0);
442 setup_sensitivity ();
444 } else if (property == TextContentProperty::BURN) {
445 checked_set (_burn, text ? text->burn() : false);
446 } else if (property == TextContentProperty::X_OFFSET) {
447 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
448 update_outline_subtitles_in_viewer ();
449 } else if (property == TextContentProperty::Y_OFFSET) {
450 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
451 update_outline_subtitles_in_viewer ();
452 } else if (property == TextContentProperty::X_SCALE) {
453 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
454 clear_outline_subtitles ();
455 } else if (property == TextContentProperty::Y_SCALE) {
456 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
457 clear_outline_subtitles ();
458 } else if (property == TextContentProperty::LINE_SPACING) {
459 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
460 clear_outline_subtitles ();
461 } else if (property == TextContentProperty::LANGUAGE) {
463 checked_set (_language, text ? text->language() : "");
465 } else if (property == TextContentProperty::DCP_TRACK) {
467 update_dcp_track_selection ();
469 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
471 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
472 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
474 checked_set (_reference, false);
477 setup_sensitivity ();
478 } else if (property == DCPContentProperty::TEXTS) {
479 setup_sensitivity ();
484 TextPanel::use_toggled ()
486 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
487 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
491 /** @return the text type that is currently selected in the drop-down */
493 TextPanel::current_type () const
495 switch (_type->GetSelection()) {
497 return TEXT_OPEN_SUBTITLE;
499 return TEXT_CLOSED_CAPTION;
506 TextPanel::type_changed ()
508 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
509 i->text_of_original_type(_original_type)->set_type (current_type ());
516 TextPanel::burn_toggled ()
518 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
519 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
524 TextPanel::setup_sensitivity ()
527 /* We currently assume that FFmpeg subtitles are bitmapped */
529 /* DCP subs can't have their line spacing changed */
531 ContentList sel = _parent->selected_text ();
532 BOOST_FOREACH (shared_ptr<Content> i, sel) {
533 /* These are the content types that could include subtitles */
534 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
535 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
536 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
537 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
539 if (!fc->text.empty()) {
543 } else if (dc || dsc) {
547 /* XXX: in the future there could be bitmap subs from DCPs */
552 /* Decide whether we can reference these subs */
554 shared_ptr<DCPContent> dcp;
555 if (sel.size() == 1) {
556 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
560 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
562 if (why_not.empty()) {
563 cannot = _("Cannot reference this DCP's subtitles or captions.");
565 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
567 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
569 bool const reference = _reference->GetValue ();
571 TextType const type = current_type ();
575 _type->Append (_("open subtitles"));
576 if (ffmpeg_subs == 0) {
577 _type->Append (_("closed captions"));
581 case TEXT_OPEN_SUBTITLE:
582 _type->SetSelection (0);
584 case TEXT_CLOSED_CAPTION:
585 if (_type->GetCount() > 1) {
586 _type->SetSelection (1);
593 /* Set up sensitivity */
594 _use->Enable (!reference && any_subs > 0);
595 bool const use = _use->GetValue ();
596 if (_outline_subtitles) {
597 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TEXT_OPEN_SUBTITLE);
599 _type->Enable (!reference && any_subs > 0 && use);
600 _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
601 _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
602 _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
603 _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
604 _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
605 _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE && dcp_subs < any_subs);
606 _stream->Enable (!reference && ffmpeg_subs == 1);
607 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
608 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
609 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
610 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
614 TextPanel::stream_changed ()
616 FFmpegContentList fc = _parent->selected_ffmpeg ();
617 if (fc.size() != 1) {
621 shared_ptr<FFmpegContent> fcs = fc.front ();
623 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
624 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
625 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
626 while (i != a.end() && (*i)->identifier () != s) {
631 fcs->set_subtitle_stream (*i);
636 TextPanel::x_offset_changed ()
638 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
639 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
644 TextPanel::y_offset_changed ()
646 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
647 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
652 TextPanel::x_scale_changed ()
654 ContentList c = _parent->selected_text ();
656 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
661 TextPanel::y_scale_changed ()
663 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
664 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
669 TextPanel::line_spacing_changed ()
671 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
672 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
677 TextPanel::language_changed ()
679 DCPOMATIC_ASSERT (_language);
680 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
681 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
686 TextPanel::content_selection_changed ()
688 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
689 film_content_changed (TextContentProperty::USE);
690 film_content_changed (TextContentProperty::BURN);
691 film_content_changed (TextContentProperty::X_OFFSET);
692 film_content_changed (TextContentProperty::Y_OFFSET);
693 film_content_changed (TextContentProperty::X_SCALE);
694 film_content_changed (TextContentProperty::Y_SCALE);
695 film_content_changed (TextContentProperty::LINE_SPACING);
696 film_content_changed (TextContentProperty::LANGUAGE);
697 film_content_changed (TextContentProperty::FONTS);
698 film_content_changed (TextContentProperty::TYPE);
699 film_content_changed (TextContentProperty::DCP_TRACK);
700 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
704 TextPanel::text_view_clicked ()
707 _text_view->Destroy ();
711 ContentList c = _parent->selected_text ();
712 DCPOMATIC_ASSERT (c.size() == 1);
714 shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
717 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
723 TextPanel::fonts_dialog_clicked ()
726 _fonts_dialog->Destroy ();
730 ContentList c = _parent->selected_text ();
731 DCPOMATIC_ASSERT (c.size() == 1);
733 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
734 _fonts_dialog->Show ();
738 TextPanel::reference_clicked ()
740 ContentList c = _parent->selected ();
745 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
750 d->set_reference_text (_original_type, _reference->GetValue ());
754 TextPanel::appearance_dialog_clicked ()
756 ContentList c = _parent->selected_text ();
757 DCPOMATIC_ASSERT (c.size() == 1);
759 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
760 if (d->ShowModal () == wxID_OK) {
768 /** The user has clicked on the outline subtitles check box */
770 TextPanel::outline_subtitles_changed ()
772 if (_outline_subtitles->GetValue()) {
773 _analysis_content = _parent->selected_text().front();
774 try_to_load_analysis ();
776 clear_outline_subtitles ();
782 TextPanel::try_to_load_analysis ()
784 if (_loading_analysis) {
788 _loading_analysis = true;
789 setup_sensitivity ();
792 shared_ptr<Content> content = _analysis_content.lock ();
794 _loading_analysis = false;
795 setup_sensitivity ();
799 boost::filesystem::path const path = _parent->film()->subtitle_analysis_path(content);
801 if (!boost::filesystem::exists(path)) {
802 BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
803 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
808 JobManager::instance()->analyse_subtitles (
809 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
815 _analysis.reset (new SubtitleAnalysis(path));
816 } catch (OldFormatError& e) {
817 /* An old analysis file: recreate it */
818 JobManager::instance()->analyse_subtitles (
819 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
824 update_outline_subtitles_in_viewer ();
825 _loading_analysis = false;
826 setup_sensitivity ();
831 TextPanel::update_outline_subtitles_in_viewer ()
833 shared_ptr<FilmViewer> fv = _parent->film_viewer().lock();
839 optional<dcpomatic::Rect<double> > rect = _analysis->bounding_box ();
841 shared_ptr<Content> content = _analysis_content.lock ();
842 DCPOMATIC_ASSERT (content);
843 rect->x += content->text.front()->x_offset();
844 rect->y += content->text.front()->y_offset();
846 fv->set_outline_subtitles (rect);
848 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
853 /** Remove any current subtitle outline display */
855 TextPanel::clear_outline_subtitles ()
858 update_outline_subtitles_in_viewer ();
859 if (_outline_subtitles) {
860 _outline_subtitles->SetValue (false);
866 TextPanel::analysis_finished ()
868 shared_ptr<Content> content = _analysis_content.lock ();
870 _loading_analysis = false;
871 setup_sensitivity ();
875 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
876 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
879 error_dialog (_parent->window(), _("Could not analyse subtitles."));
880 clear_outline_subtitles ();
881 _loading_analysis = false;
882 setup_sensitivity ();
886 _loading_analysis = false;
887 try_to_load_analysis ();