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, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
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);
246 _grid->Add (offset, wxGBPosition(r, 1));
248 offset = new wxBoxSizer (wxHORIZONTAL);
250 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
251 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
252 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
253 _grid->Add (offset, wxGBPosition (r, 1));
256 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
257 wxBoxSizer* scale = new wxBoxSizer (wxHORIZONTAL);
258 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
259 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
260 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
262 _grid->Add (scale, wxGBPosition(r, 1));
264 scale = new wxBoxSizer (wxHORIZONTAL);
266 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
267 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
268 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
269 _grid->Add (scale, wxGBPosition (r, 1));
273 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
274 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
275 s->Add (_line_spacing);
276 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
277 _grid->Add (s, wxGBPosition (r, 1));
284 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
285 _grid->Add (_stream, wxGBPosition (r, 1));
289 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
291 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
292 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
293 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
295 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
303 TextPanel::update_dcp_track_selection ()
305 DCPOMATIC_ASSERT (_dcp_track);
307 optional<DCPTextTrack> selected;
309 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
310 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
312 optional<DCPTextTrack> dt = t->dcp_track();
313 if (dt && selected && *dt != *selected) {
315 } else if (!selected) {
322 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
323 if (!many && selected && *selected == i) {
324 _dcp_track->SetSelection (n);
329 if (!selected || many) {
330 _dcp_track->SetSelection (wxNOT_FOUND);
335 TextPanel::update_dcp_tracks ()
337 DCPOMATIC_ASSERT (_dcp_track);
339 _dcp_track->Clear ();
340 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
341 /* XXX: don't display the "magic" track which has empty name and language;
342 this is a nasty hack (see also Film::closed_caption_tracks)
344 if (!i.name.empty() || !i.language.empty()) {
345 _dcp_track->Append (std_to_wx(i.summary()));
349 if (_parent->film()->closed_caption_tracks().size() < 6) {
350 _dcp_track->Append (_("Add new..."));
353 update_dcp_track_selection ();
357 TextPanel::dcp_track_changed ()
359 optional<DCPTextTrack> track;
361 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
362 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
363 if (d->ShowModal() == wxID_OK) {
368 /* Find the DCPTextTrack that was selected */
369 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
370 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
377 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
378 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
379 if (t && t->type() == TEXT_CLOSED_CAPTION) {
380 t->set_dcp_track(*track);
385 update_dcp_tracks ();
389 TextPanel::film_changed (Film::Property property)
391 if (property == Film::CONTENT || property == Film::REEL_TYPE || property == Film::INTEROP) {
392 setup_sensitivity ();
397 TextPanel::film_content_changed (int property)
399 FFmpegContentList fc = _parent->selected_ffmpeg ();
400 ContentList sc = _parent->selected_text ();
402 shared_ptr<FFmpegContent> fcs;
403 if (fc.size() == 1) {
407 shared_ptr<Content> scs;
408 if (sc.size() == 1) {
412 shared_ptr<TextContent> text;
414 text = scs->text_of_original_type(_original_type);
417 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
420 vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
421 for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
422 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
425 if (fcs->subtitle_stream()) {
426 checked_set (_stream, fcs->subtitle_stream()->identifier ());
428 _stream->SetSelection (wxNOT_FOUND);
431 setup_sensitivity ();
432 clear_outline_subtitles ();
433 } else if (property == TextContentProperty::USE) {
434 checked_set (_use, text ? text->use() : false);
435 setup_sensitivity ();
436 clear_outline_subtitles ();
437 } else if (property == TextContentProperty::TYPE) {
439 switch (text->type()) {
440 case TEXT_OPEN_SUBTITLE:
441 _type->SetSelection (0);
443 case TEXT_CLOSED_CAPTION:
444 _type->SetSelection (1);
447 DCPOMATIC_ASSERT (false);
450 _type->SetSelection (0);
452 setup_sensitivity ();
454 } else if (property == TextContentProperty::BURN) {
455 checked_set (_burn, text ? text->burn() : false);
456 } else if (property == TextContentProperty::X_OFFSET) {
457 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
458 update_outline_subtitles_in_viewer ();
459 } else if (property == TextContentProperty::Y_OFFSET) {
460 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
461 update_outline_subtitles_in_viewer ();
462 } else if (property == TextContentProperty::X_SCALE) {
463 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
464 clear_outline_subtitles ();
465 } else if (property == TextContentProperty::Y_SCALE) {
466 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
467 clear_outline_subtitles ();
468 } else if (property == TextContentProperty::LINE_SPACING) {
469 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
470 clear_outline_subtitles ();
471 } else if (property == TextContentProperty::LANGUAGE) {
473 checked_set (_language, text ? text->language() : "");
475 } else if (property == TextContentProperty::DCP_TRACK) {
477 update_dcp_track_selection ();
479 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
481 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
482 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
484 checked_set (_reference, false);
487 setup_sensitivity ();
488 } else if (property == DCPContentProperty::TEXTS) {
489 setup_sensitivity ();
494 TextPanel::use_toggled ()
496 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
497 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
501 /** @return the text type that is currently selected in the drop-down */
503 TextPanel::current_type () const
505 switch (_type->GetSelection()) {
507 return TEXT_OPEN_SUBTITLE;
509 return TEXT_CLOSED_CAPTION;
516 TextPanel::type_changed ()
518 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
519 i->text_of_original_type(_original_type)->set_type (current_type ());
526 TextPanel::burn_toggled ()
528 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
529 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
534 TextPanel::setup_sensitivity ()
537 /* We currently assume that FFmpeg subtitles are bitmapped */
539 /* DCP subs can't have their line spacing changed */
541 ContentList sel = _parent->selected_text ();
542 BOOST_FOREACH (shared_ptr<Content> i, sel) {
543 /* These are the content types that could include subtitles */
544 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
545 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
546 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
547 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
549 if (!fc->text.empty()) {
553 } else if (dc || dsc) {
557 /* XXX: in the future there could be bitmap subs from DCPs */
562 /* Decide whether we can reference these subs */
564 shared_ptr<DCPContent> dcp;
565 if (sel.size() == 1) {
566 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
570 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
572 if (why_not.empty()) {
573 cannot = _("Cannot reference this DCP's subtitles or captions.");
575 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
577 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
579 bool const reference = _reference->GetValue ();
581 TextType const type = current_type ();
585 _type->Append (_("open subtitles"));
586 if (ffmpeg_subs == 0) {
587 _type->Append (_("closed captions"));
591 case TEXT_OPEN_SUBTITLE:
592 _type->SetSelection (0);
594 case TEXT_CLOSED_CAPTION:
595 if (_type->GetCount() > 1) {
596 _type->SetSelection (1);
603 /* Set up sensitivity */
604 _use->Enable (!reference && any_subs > 0);
605 bool const use = _use->GetValue ();
606 if (_outline_subtitles) {
607 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TEXT_OPEN_SUBTITLE);
609 _type->Enable (!reference && any_subs > 0 && use);
610 _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
611 _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
612 _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
613 _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
614 _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
615 _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE && dcp_subs < any_subs);
616 _stream->Enable (!reference && ffmpeg_subs == 1);
617 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
618 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
619 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
620 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
624 TextPanel::stream_changed ()
626 FFmpegContentList fc = _parent->selected_ffmpeg ();
627 if (fc.size() != 1) {
631 shared_ptr<FFmpegContent> fcs = fc.front ();
633 vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
634 vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
635 string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
636 while (i != a.end() && (*i)->identifier () != s) {
641 fcs->set_subtitle_stream (*i);
646 TextPanel::x_offset_changed ()
648 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
649 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
654 TextPanel::y_offset_changed ()
656 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
657 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
662 TextPanel::x_scale_changed ()
664 ContentList c = _parent->selected_text ();
666 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
671 TextPanel::y_scale_changed ()
673 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
674 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
679 TextPanel::line_spacing_changed ()
681 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
682 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
687 TextPanel::language_changed ()
689 DCPOMATIC_ASSERT (_language);
690 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
691 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
696 TextPanel::content_selection_changed ()
698 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
699 film_content_changed (TextContentProperty::USE);
700 film_content_changed (TextContentProperty::BURN);
701 film_content_changed (TextContentProperty::X_OFFSET);
702 film_content_changed (TextContentProperty::Y_OFFSET);
703 film_content_changed (TextContentProperty::X_SCALE);
704 film_content_changed (TextContentProperty::Y_SCALE);
705 film_content_changed (TextContentProperty::LINE_SPACING);
706 film_content_changed (TextContentProperty::LANGUAGE);
707 film_content_changed (TextContentProperty::FONTS);
708 film_content_changed (TextContentProperty::TYPE);
709 film_content_changed (TextContentProperty::DCP_TRACK);
710 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
714 TextPanel::text_view_clicked ()
717 _text_view->Destroy ();
721 ContentList c = _parent->selected_text ();
722 DCPOMATIC_ASSERT (c.size() == 1);
724 shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
727 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
733 TextPanel::fonts_dialog_clicked ()
736 _fonts_dialog->Destroy ();
740 ContentList c = _parent->selected_text ();
741 DCPOMATIC_ASSERT (c.size() == 1);
743 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
744 _fonts_dialog->Show ();
748 TextPanel::reference_clicked ()
750 ContentList c = _parent->selected ();
755 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
760 d->set_reference_text (_original_type, _reference->GetValue ());
764 TextPanel::appearance_dialog_clicked ()
766 ContentList c = _parent->selected_text ();
767 DCPOMATIC_ASSERT (c.size() == 1);
769 SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
770 if (d->ShowModal () == wxID_OK) {
778 /** The user has clicked on the outline subtitles check box */
780 TextPanel::outline_subtitles_changed ()
782 if (_outline_subtitles->GetValue()) {
783 _analysis_content = _parent->selected_text().front();
784 try_to_load_analysis ();
786 clear_outline_subtitles ();
792 TextPanel::try_to_load_analysis ()
794 if (_loading_analysis) {
798 _loading_analysis = true;
799 setup_sensitivity ();
802 shared_ptr<Content> content = _analysis_content.lock ();
804 _loading_analysis = false;
805 setup_sensitivity ();
809 boost::filesystem::path const path = _parent->film()->subtitle_analysis_path(content);
811 if (!boost::filesystem::exists(path)) {
812 BOOST_FOREACH (shared_ptr<Job> i, JobManager::instance()->get()) {
813 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
818 JobManager::instance()->analyse_subtitles (
819 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
825 _analysis.reset (new SubtitleAnalysis(path));
826 } catch (OldFormatError& e) {
827 /* An old analysis file: recreate it */
828 JobManager::instance()->analyse_subtitles (
829 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
834 update_outline_subtitles_in_viewer ();
835 _loading_analysis = false;
836 setup_sensitivity ();
841 TextPanel::update_outline_subtitles_in_viewer ()
843 shared_ptr<FilmViewer> fv = _parent->film_viewer().lock();
849 optional<dcpomatic::Rect<double> > rect = _analysis->bounding_box ();
851 shared_ptr<Content> content = _analysis_content.lock ();
852 DCPOMATIC_ASSERT (content);
853 rect->x += content->text.front()->x_offset();
854 rect->y += content->text.front()->y_offset();
856 fv->set_outline_subtitles (rect);
858 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
863 /** Remove any current subtitle outline display */
865 TextPanel::clear_outline_subtitles ()
868 update_outline_subtitles_in_viewer ();
869 if (_outline_subtitles) {
870 _outline_subtitles->SetValue (false);
876 TextPanel::analysis_finished ()
878 shared_ptr<Content> content = _analysis_content.lock ();
880 _loading_analysis = false;
881 setup_sensitivity ();
885 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
886 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
889 error_dialog (_parent->window(), _("Could not analyse subtitles."));
890 clear_outline_subtitles ();
891 _loading_analysis = false;
892 setup_sensitivity ();
896 _loading_analysis = false;
897 try_to_load_analysis ();