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"));
90 _offset_label = create_label (this, _("Offset"), true);
91 _x_offset_label = create_label (this, _("X"), true);
92 _x_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
93 _x_offset_pc_label = new StaticText (this, _("%"));
94 _y_offset_label = create_label (this, _("Y"), true);
95 _y_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
96 _y_offset_pc_label = new StaticText (this, _("%"));
98 _scale_label = create_label (this, _("Scale"), true);
99 _x_scale_label = create_label (this, _("X"), true);
100 _x_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
101 _x_scale_pc_label = new StaticText (this, _("%"));
102 _y_scale_label = create_label (this, S_("Coord|Y"), true);
103 _y_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
104 _y_scale_pc_label = new StaticText (this, _("%"));
106 _line_spacing_label = create_label (this, _("Line spacing"), true);
107 _line_spacing = new wxSpinCtrl (this);
108 _line_spacing_pc_label = new StaticText (this, _("%"));
110 _stream_label = create_label (this, _("Stream"), true);
111 _stream = new wxChoice (this, wxID_ANY);
113 _text_view_button = new Button (this, _("View..."));
114 _fonts_dialog_button = new Button (this, _("Fonts..."));
115 _appearance_dialog_button = new Button (this, _("Appearance..."));
117 _x_offset->SetRange (-100, 100);
118 _y_offset->SetRange (-100, 100);
119 _x_scale->SetRange (10, 1000);
120 _y_scale->SetRange (10, 1000);
121 _line_spacing->SetRange (10, 1000);
123 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
124 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
125 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
126 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
127 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
128 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
129 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
130 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
131 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
132 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
133 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
134 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
135 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
138 content_selection_changed ();
142 TextPanel::setup_visibility ()
144 switch (current_type()) {
145 case TEXT_OPEN_SUBTITLE:
146 if (_dcp_track_label) {
147 _dcp_track_label->Destroy ();
148 _dcp_track_label = 0;
151 _dcp_track->Destroy ();
154 if (!_language_label) {
155 _language_label = create_label (this, _("Language"), true);
156 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_language_row, 0));
159 _language = new wxTextCtrl (this, wxID_ANY);
160 _language->Bind (wxEVT_TEXT, boost::bind(&TextPanel::language_changed, this));
161 _grid->Add (_language, wxGBPosition(_language_row, 1), wxDefaultSpan, wxEXPAND);
162 film_content_changed (TextContentProperty::LANGUAGE);
164 if (!_outline_subtitles) {
165 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
166 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
167 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
171 case TEXT_CLOSED_CAPTION:
172 if (_language_label) {
173 _language_label->Destroy ();
177 _language->Destroy ();
180 if (!_dcp_track_label) {
181 _dcp_track_label = create_label (this, _("CCAP track"), true);
182 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_language_row, 0));
185 _dcp_track = new wxChoice (this, wxID_ANY);
186 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
187 _grid->Add (_dcp_track, wxGBPosition(_language_row, 1), wxDefaultSpan, wxEXPAND);
188 update_dcp_tracks ();
189 film_content_changed (TextContentProperty::DCP_TRACK);
191 if (_outline_subtitles) {
192 _outline_subtitles->Destroy ();
193 _outline_subtitles = 0;
194 clear_outline_subtitles ();
205 TextPanel::add_to_grid ()
207 Config::Interface const interface = Config::instance()->interface_complexity();
211 _reference->Show (interface == Config::INTERFACE_FULL);
212 _reference_note->Show (interface == Config::INTERFACE_FULL);
214 if (interface == Config::INTERFACE_FULL) {
215 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
216 reference_sizer->Add (_reference, 0);
217 reference_sizer->Add (_reference_note, 0);
218 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
222 wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
223 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
224 use->Add (_type, 1, wxEXPAND, 0);
225 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
228 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
231 _outline_subtitles_row = r;
234 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
235 wxBoxSizer* offset = new wxBoxSizer (wxHORIZONTAL);
236 add_label_to_sizer (offset, _x_offset_label, true);
237 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
238 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
239 add_label_to_sizer (offset, _y_offset_label, true);
240 offset->Add (_y_offset, 0);
241 add_label_to_sizer (offset, _y_offset_pc_label, false);
242 _grid->Add (offset, wxGBPosition (r, 1));
245 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
246 wxBoxSizer* scale = new wxBoxSizer (wxHORIZONTAL);
247 add_label_to_sizer (scale, _x_scale_label, true);
248 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
249 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
250 add_label_to_sizer (scale, _y_scale_label, true);
251 scale->Add (_y_scale, 0);
252 add_label_to_sizer (scale, _y_scale_pc_label, false);
253 _grid->Add (scale, wxGBPosition (r, 1));
257 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
258 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
259 s->Add (_line_spacing);
260 add_label_to_sizer (s, _line_spacing_pc_label, false);
261 _grid->Add (s, wxGBPosition (r, 1));
268 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
269 _grid->Add (_stream, wxGBPosition (r, 1));
273 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
275 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
276 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
277 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
279 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
287 TextPanel::update_dcp_track_selection ()
289 DCPOMATIC_ASSERT (_dcp_track);
291 optional<DCPTextTrack> selected;
293 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
294 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
296 optional<DCPTextTrack> dt = t->dcp_track();
297 if (dt && selected && *dt != *selected) {
299 } else if (!selected) {
306 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
307 if (!many && selected && *selected == i) {
308 _dcp_track->SetSelection (n);
313 if (!selected || many) {
314 _dcp_track->SetSelection (wxNOT_FOUND);
319 TextPanel::update_dcp_tracks ()
321 DCPOMATIC_ASSERT (_dcp_track);
323 _dcp_track->Clear ();
324 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
325 /* XXX: don't display the "magic" track which has empty name and language;
326 this is a nasty hack (see also Film::closed_caption_tracks)
328 if (!i.name.empty() || !i.language.empty()) {
329 _dcp_track->Append (std_to_wx(i.summary()));
333 if (_parent->film()->closed_caption_tracks().size() < 6) {
334 _dcp_track->Append (_("Add new..."));
337 update_dcp_track_selection ();
341 TextPanel::dcp_track_changed ()
343 optional<DCPTextTrack> track;
345 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
346 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
347 if (d->ShowModal() == wxID_OK) {
352 /* Find the DCPTextTrack that was selected */
353 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
354 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
361 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
362 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
363 if (t && t->type() == TEXT_CLOSED_CAPTION) {
364 t->set_dcp_track(*track);
369 update_dcp_tracks ();
373 TextPanel::film_changed (Film::Property property)
375 if (property == Film::CONTENT || property == Film::REEL_TYPE || property == Film::INTEROP) {
376 setup_sensitivity ();
381 TextPanel::film_content_changed (int property)
383 FFmpegContentList fc = _parent->selected_ffmpeg ();
384 ContentList sc = _parent->selected_text ();
386 shared_ptr<FFmpegContent> fcs;
387 if (fc.size() == 1) {
391 shared_ptr<Content> scs;
392 if (sc.size() == 1) {
396 shared_ptr<TextContent> text;
398 text = scs->text_of_original_type(_original_type);
401 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
404 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
405 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
406 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
409 if (fcs->subtitle_stream()) {
410 checked_set (_stream, fcs->subtitle_stream()->identifier ());
412 _stream->SetSelection (wxNOT_FOUND);
415 setup_sensitivity ();
416 clear_outline_subtitles ();
417 } else if (property == TextContentProperty::USE) {
418 checked_set (_use, text ? text->use() : false);
419 setup_sensitivity ();
420 clear_outline_subtitles ();
421 } else if (property == TextContentProperty::TYPE) {
423 switch (text->type()) {
424 case TEXT_OPEN_SUBTITLE:
425 _type->SetSelection (0);
427 case TEXT_CLOSED_CAPTION:
428 _type->SetSelection (1);
431 DCPOMATIC_ASSERT (false);
434 _type->SetSelection (0);
436 setup_sensitivity ();
438 } else if (property == TextContentProperty::BURN) {
439 checked_set (_burn, text ? text->burn() : false);
440 } else if (property == TextContentProperty::X_OFFSET) {
441 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
442 update_outline_subtitles_in_viewer ();
443 } else if (property == TextContentProperty::Y_OFFSET) {
444 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
445 update_outline_subtitles_in_viewer ();
446 } else if (property == TextContentProperty::X_SCALE) {
447 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
448 clear_outline_subtitles ();
449 } else if (property == TextContentProperty::Y_SCALE) {
450 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
451 clear_outline_subtitles ();
452 } else if (property == TextContentProperty::LINE_SPACING) {
453 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
454 clear_outline_subtitles ();
455 } else if (property == TextContentProperty::LANGUAGE) {
457 checked_set (_language, text ? text->language() : "");
459 } else if (property == TextContentProperty::DCP_TRACK) {
461 update_dcp_track_selection ();
463 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
465 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
466 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
468 checked_set (_reference, false);
471 setup_sensitivity ();
472 } else if (property == DCPContentProperty::TEXTS) {
473 setup_sensitivity ();
478 TextPanel::use_toggled ()
480 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
481 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
485 /** @return the text type that is currently selected in the drop-down */
487 TextPanel::current_type () const
489 switch (_type->GetSelection()) {
491 return TEXT_OPEN_SUBTITLE;
493 return TEXT_CLOSED_CAPTION;
500 TextPanel::type_changed ()
502 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
503 i->text_of_original_type(_original_type)->set_type (current_type ());
510 TextPanel::burn_toggled ()
512 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
513 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
518 TextPanel::setup_sensitivity ()
521 /* We currently assume that FFmpeg subtitles are bitmapped */
523 /* DCP subs can't have their line spacing changed */
525 ContentList sel = _parent->selected_text ();
526 BOOST_FOREACH (shared_ptr<Content> i, sel) {
527 /* These are the content types that could include subtitles */
528 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
529 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
530 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
531 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
533 if (!fc->text.empty()) {
537 } else if (dc || dsc) {
541 /* XXX: in the future there could be bitmap subs from DCPs */
546 /* Decide whether we can reference these subs */
548 shared_ptr<DCPContent> dcp;
549 if (sel.size() == 1) {
550 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
554 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
556 if (why_not.empty()) {
557 cannot = _("Cannot reference this DCP's subtitles or captions.");
559 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
561 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
563 bool const reference = _reference->GetValue ();
565 TextType const type = current_type ();
569 _type->Append (_("open subtitles"));
570 if (ffmpeg_subs == 0) {
571 _type->Append (_("closed captions"));
575 case TEXT_OPEN_SUBTITLE:
576 _type->SetSelection (0);
578 case TEXT_CLOSED_CAPTION:
579 if (_type->GetCount() > 1) {
580 _type->SetSelection (1);
587 /* Set up sensitivity */
588 _use->Enable (!reference && any_subs > 0);
589 bool const use = _use->GetValue ();
590 if (_outline_subtitles) {
591 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TEXT_OPEN_SUBTITLE);
593 _type->Enable (!reference && any_subs > 0 && use);
594 _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
595 _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
596 _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
597 _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
598 _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
599 _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE && dcp_subs < any_subs);
600 _stream->Enable (!reference && ffmpeg_subs == 1);
601 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
602 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
603 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
604 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
608 TextPanel::stream_changed ()
610 FFmpegContentList fc = _parent->selected_ffmpeg ();
611 if (fc.size() != 1) {
615 shared_ptr<FFmpegContent> fcs = fc.front ();
617 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
618 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
619 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
620 while (i != a.end() && (*i)->identifier () != s) {
625 fcs->set_subtitle_stream (*i);
630 TextPanel::x_offset_changed ()
632 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
633 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
638 TextPanel::y_offset_changed ()
640 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
641 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
646 TextPanel::x_scale_changed ()
648 ContentList c = _parent->selected_text ();
650 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
655 TextPanel::y_scale_changed ()
657 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
658 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
663 TextPanel::line_spacing_changed ()
665 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
666 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
671 TextPanel::language_changed ()
673 DCPOMATIC_ASSERT (_language);
674 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
675 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
680 TextPanel::content_selection_changed ()
682 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
683 film_content_changed (TextContentProperty::USE);
684 film_content_changed (TextContentProperty::BURN);
685 film_content_changed (TextContentProperty::X_OFFSET);
686 film_content_changed (TextContentProperty::Y_OFFSET);
687 film_content_changed (TextContentProperty::X_SCALE);
688 film_content_changed (TextContentProperty::Y_SCALE);
689 film_content_changed (TextContentProperty::LINE_SPACING);
690 film_content_changed (TextContentProperty::LANGUAGE);
691 film_content_changed (TextContentProperty::FONTS);
692 film_content_changed (TextContentProperty::TYPE);
693 film_content_changed (TextContentProperty::DCP_TRACK);
694 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
698 TextPanel::text_view_clicked ()
701 _text_view->Destroy ();
705 ContentList c = _parent->selected_text ();
706 DCPOMATIC_ASSERT (c.size() == 1);
708 shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
711 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
717 TextPanel::fonts_dialog_clicked ()
720 _fonts_dialog->Destroy ();
724 ContentList c = _parent->selected_text ();
725 DCPOMATIC_ASSERT (c.size() == 1);
727 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
728 _fonts_dialog->Show ();
732 TextPanel::reference_clicked ()
734 ContentList c = _parent->selected ();
739 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
744 d->set_reference_text (_original_type, _reference->GetValue ());
748 TextPanel::appearance_dialog_clicked ()
750 ContentList c = _parent->selected_text ();
751 DCPOMATIC_ASSERT (c.size() == 1);
753 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
754 if (d->ShowModal () == wxID_OK) {
762 /** The user has clicked on the outline subtitles check box */
764 TextPanel::outline_subtitles_changed ()
766 if (_outline_subtitles->GetValue()) {
767 _analysis_content = _parent->selected_text().front();
768 try_to_load_analysis ();
770 clear_outline_subtitles ();
776 TextPanel::try_to_load_analysis ()
778 _loading_analysis = true;
779 setup_sensitivity ();
782 shared_ptr<Content> content = _analysis_content.lock ();
784 _loading_analysis = false;
785 setup_sensitivity ();
789 boost::filesystem::path const path = _parent->film()->subtitle_analysis_path(content);
791 if (!boost::filesystem::exists(path)) {
792 BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
793 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
798 JobManager::instance()->analyse_subtitles (
799 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
805 _analysis.reset (new SubtitleAnalysis(path));
806 } catch (OldFormatError& e) {
807 /* An old analysis file: recreate it */
808 JobManager::instance()->analyse_subtitles (
809 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
814 update_outline_subtitles_in_viewer ();
815 _loading_analysis = false;
816 setup_sensitivity ();
821 TextPanel::update_outline_subtitles_in_viewer ()
823 shared_ptr<FilmViewer> fv = _parent->film_viewer().lock();
829 optional<dcpomatic::Rect<double> > rect = _analysis->bounding_box ();
831 shared_ptr<Content> content = _analysis_content.lock ();
832 DCPOMATIC_ASSERT (content);
833 rect->x += content->text.front()->x_offset();
834 rect->y += content->text.front()->y_offset();
836 fv->set_outline_subtitles (rect);
838 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
843 /** Remove any current subtitle outline display */
845 TextPanel::clear_outline_subtitles ()
848 update_outline_subtitles_in_viewer ();
849 if (_outline_subtitles) {
850 _outline_subtitles->SetValue (false);
856 TextPanel::analysis_finished ()
858 shared_ptr<Content> content = _analysis_content.lock ();
860 _loading_analysis = false;
861 setup_sensitivity ();
865 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
866 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
869 error_dialog (_parent->window(), _("Could not analyse subtitles."));
870 clear_outline_subtitles ();
871 _loading_analysis = false;
872 setup_sensitivity ();
876 try_to_load_analysis ();