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/>.
21 #include "check_box.h"
22 #include "content_panel.h"
23 #include "dcp_text_track_dialog.h"
24 #include "dcpomatic_button.h"
25 #include "dcpomatic_spin_ctrl.h"
26 #include "film_editor.h"
27 #include "film_viewer.h"
28 #include "fonts_dialog.h"
29 #include "language_tag_widget.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)))
65 wxString refer = _("Use this DCP's subtitle as OV and make VF");
66 if (t == TextType::CLOSED_CAPTION) {
67 refer = _("Use this DCP's closed caption as OV and make VF");
70 _reference = new CheckBox (this, refer);
71 _reference_note = new StaticText (this, wxT(""));
72 _reference_note->Wrap (200);
73 auto font = _reference_note->GetFont();
74 font.SetStyle(wxFONTSTYLE_ITALIC);
75 font.SetPointSize(font.GetPointSize() - 1);
76 _reference_note->SetFont(font);
78 _use = new CheckBox (this, _("Use as"));
79 _type = new wxChoice (this, wxID_ANY);
80 _type->Append (_("open subtitles"));
81 _type->Append (_("closed captions"));
83 _burn = new CheckBox (this, _("Burn subtitles into image"));
86 int const spin_width = 118;
88 int const spin_width = 56;
91 _offset_label = create_label (this, _("Offset"), true);
92 _x_offset_label = create_label (this, _("X"), true);
93 _x_offset = new SpinCtrl (this, spin_width);
94 _x_offset_pc_label = new StaticText (this, _("%"));
95 _y_offset_label = create_label (this, _("Y"), true);
96 _y_offset = new SpinCtrl (this, spin_width);
97 _y_offset_pc_label = new StaticText (this, _("%"));
99 _scale_label = create_label (this, _("Scale"), true);
100 _x_scale_label = create_label (this, _("X"), true);
101 _x_scale = new SpinCtrl (this, spin_width);
102 _x_scale_pc_label = new StaticText (this, _("%"));
103 _y_scale_label = create_label (this, S_("Coord|Y"), true);
104 _y_scale = new SpinCtrl (this, spin_width);
105 _y_scale_pc_label = new StaticText (this, _("%"));
107 _line_spacing_label = create_label (this, _("Line spacing"), true);
108 _line_spacing = new SpinCtrl (this, spin_width);
109 _line_spacing_pc_label = new StaticText (this, _("%"));
111 _stream_label = create_label (this, _("Stream"), true);
112 _stream = new wxChoice (this, wxID_ANY);
114 _text_view_button = new Button (this, _("View..."));
115 _fonts_dialog_button = new Button (this, _("Fonts..."));
116 _appearance_dialog_button = new Button (this, _("Appearance..."));
118 _x_offset->SetRange (-100, 100);
119 _y_offset->SetRange (-100, 100);
120 _x_scale->SetRange (0, 1000);
121 _y_scale->SetRange (0, 1000);
122 _line_spacing->SetRange (0, 1000);
124 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
125 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
126 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
127 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
128 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
129 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
130 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
131 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
132 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
133 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
134 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
135 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
136 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
139 content_selection_changed ();
144 TextPanel::setup_visibility ()
146 switch (current_type()) {
147 case TextType::OPEN_SUBTITLE:
148 if (_dcp_track_label) {
149 _dcp_track_label->Destroy ();
150 _dcp_track_label = nullptr;
153 _dcp_track->Destroy ();
154 _dcp_track = nullptr;
156 if (!_outline_subtitles) {
157 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
158 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
159 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
162 _language_label = create_label (this, _("Language"), true);
163 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
164 _language_sizer = new wxBoxSizer (wxHORIZONTAL);
165 _language = new LanguageTagWidget (this, _("Language of these subtitles"), boost::none, wxString("en-US-"));
166 _language->Changed.connect (boost::bind(&TextPanel::language_changed, this));
167 _language_sizer->Add (_language->sizer(), 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
168 _language_type = new wxChoice (this, wxID_ANY);
169 /// TRANSLATORS: Main and Additional here are a choice for whether a set of subtitles is in the "main" language of the
170 /// film or an "additional" language.
171 _language_type->Append (_("Main"));
172 _language_type->Append (_("Additional"));
173 _language_type->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::language_is_additional_changed, this));
174 _language_sizer->Add (_language_type, 0);
175 _grid->Add (_language_sizer, wxGBPosition(_ccap_track_or_language_row, 1), wxGBSpan(1, 2));
176 film_content_changed (TextContentProperty::LANGUAGE);
177 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
180 case TextType::CLOSED_CAPTION:
181 if (_language_label) {
182 _language_label->Destroy ();
183 _language_label = nullptr;
184 _grid->Remove (_language->sizer());
186 _grid->Remove (_language_sizer);
187 _language_sizer = nullptr;
189 _language_type->Destroy ();
190 _language_type = nullptr;
192 if (!_dcp_track_label) {
193 _dcp_track_label = create_label (this, _("CCAP track"), true);
194 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
197 _dcp_track = new wxChoice (this, wxID_ANY);
198 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
199 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_or_language_row, 1), wxDefaultSpan, wxEXPAND);
200 update_dcp_tracks ();
201 film_content_changed (TextContentProperty::DCP_TRACK);
203 if (_outline_subtitles) {
204 _outline_subtitles->Destroy ();
205 _outline_subtitles = nullptr;
206 clear_outline_subtitles ();
218 TextPanel::add_to_grid ()
222 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
223 reference_sizer->Add (_reference, 0);
224 reference_sizer->Add (_reference_note, 0);
225 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
228 auto 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 auto 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 auto 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 auto 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));
281 _ccap_track_or_language_row = r;
284 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
285 _grid->Add (_stream, wxGBPosition (r, 1));
289 auto 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));
304 TextPanel::update_dcp_track_selection ()
306 DCPOMATIC_ASSERT (_dcp_track);
308 optional<DCPTextTrack> selected;
310 for (auto i: _parent->selected_text()) {
311 auto t = i->text_of_original_type(_original_type);
313 auto dt = t->dcp_track();
314 if (dt && selected && *dt != *selected) {
316 } else if (!selected) {
323 for (auto i: _parent->film()->closed_caption_tracks()) {
324 if (!many && selected && *selected == i) {
325 _dcp_track->SetSelection (n);
330 if (!selected || many) {
331 _dcp_track->SetSelection (wxNOT_FOUND);
337 TextPanel::update_dcp_tracks ()
339 DCPOMATIC_ASSERT (_dcp_track);
341 _dcp_track->Clear ();
342 for (auto i: _parent->film()->closed_caption_tracks()) {
343 /* XXX: don't display the "magic" track which has empty name and language;
344 this is a nasty hack (see also Film::closed_caption_tracks)
346 if (!i.name.empty() || !i.language.empty()) {
347 _dcp_track->Append (std_to_wx(i.summary()));
351 if (_parent->film()->closed_caption_tracks().size() < 6) {
352 _dcp_track->Append (_("Add new..."));
355 update_dcp_track_selection ();
360 TextPanel::dcp_track_changed ()
362 optional<DCPTextTrack> track;
364 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
365 auto d = new DCPTextTrackDialog (this);
366 if (d->ShowModal() == wxID_OK) {
371 /* Find the DCPTextTrack that was selected */
372 for (auto i: _parent->film()->closed_caption_tracks()) {
373 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
380 for (auto i: _parent->selected_text()) {
381 auto t = i->text_of_original_type(_original_type);
382 if (t && t->type() == TextType::CLOSED_CAPTION) {
383 t->set_dcp_track(*track);
388 update_dcp_tracks ();
393 TextPanel::film_changed (Film::Property property)
395 if (property == Film::Property::CONTENT || property == Film::Property::REEL_TYPE || property == Film::Property::INTEROP) {
396 setup_sensitivity ();
402 TextPanel::film_content_changed (int property)
404 auto fc = _parent->selected_ffmpeg ();
405 auto sc = _parent->selected_text ();
407 shared_ptr<FFmpegContent> fcs;
408 if (fc.size() == 1) {
412 shared_ptr<Content> scs;
413 if (sc.size() == 1) {
417 shared_ptr<TextContent> text;
419 text = scs->text_of_original_type(_original_type);
422 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
425 for (auto i: fcs->subtitle_streams()) {
426 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
429 if (fcs->subtitle_stream()) {
430 checked_set (_stream, fcs->subtitle_stream()->identifier ());
432 _stream->SetSelection (wxNOT_FOUND);
435 setup_sensitivity ();
436 clear_outline_subtitles ();
437 } else if (property == TextContentProperty::USE) {
438 checked_set (_use, text ? text->use() : false);
439 setup_sensitivity ();
440 clear_outline_subtitles ();
441 } else if (property == TextContentProperty::TYPE) {
443 switch (text->type()) {
444 case TextType::OPEN_SUBTITLE:
445 _type->SetSelection (0);
447 case TextType::CLOSED_CAPTION:
448 _type->SetSelection (1);
451 DCPOMATIC_ASSERT (false);
454 _type->SetSelection (0);
456 setup_sensitivity ();
458 } else if (property == TextContentProperty::BURN) {
459 checked_set (_burn, text ? text->burn() : false);
460 } else if (property == TextContentProperty::X_OFFSET) {
461 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
462 update_outline_subtitles_in_viewer ();
463 } else if (property == TextContentProperty::Y_OFFSET) {
464 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
465 update_outline_subtitles_in_viewer ();
466 } else if (property == TextContentProperty::X_SCALE) {
467 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
468 clear_outline_subtitles ();
469 } else if (property == TextContentProperty::Y_SCALE) {
470 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
471 clear_outline_subtitles ();
472 } else if (property == TextContentProperty::LINE_SPACING) {
473 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
474 clear_outline_subtitles ();
475 } else if (property == TextContentProperty::DCP_TRACK) {
477 update_dcp_track_selection ();
479 } else if (property == TextContentProperty::LANGUAGE) {
481 _language->set (text ? text->language() : boost::none);
483 } else if (property == TextContentProperty::LANGUAGE_IS_ADDITIONAL) {
484 if (_language_type) {
485 _language_type->SetSelection (text ? (text->language_is_additional() ? 1 : 0) : 0);
487 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
489 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
490 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
492 checked_set (_reference, false);
495 setup_sensitivity ();
496 } else if (property == DCPContentProperty::TEXTS) {
497 setup_sensitivity ();
498 } else if (property == ContentProperty::TRIM_START) {
499 setup_sensitivity ();
505 TextPanel::use_toggled ()
507 for (auto i: _parent->selected_text()) {
508 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
513 /** @return the text type that is currently selected in the drop-down */
515 TextPanel::current_type () const
517 switch (_type->GetSelection()) {
519 return TextType::OPEN_SUBTITLE;
521 return TextType::CLOSED_CAPTION;
524 return TextType::UNKNOWN;
529 TextPanel::type_changed ()
531 for (auto i: _parent->selected_text()) {
532 i->text_of_original_type(_original_type)->set_type (current_type ());
540 TextPanel::burn_toggled ()
542 for (auto i: _parent->selected_text ()) {
543 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
549 TextPanel::setup_sensitivity ()
552 /* We currently assume that FFmpeg subtitles are bitmapped */
554 /* DCP subs can't have their line spacing changed */
556 auto sel = _parent->selected_text ();
558 /* These are the content types that could include subtitles */
559 auto fc = std::dynamic_pointer_cast<const FFmpegContent>(i);
560 auto sc = std::dynamic_pointer_cast<const StringTextFileContent>(i);
561 auto dc = std::dynamic_pointer_cast<const DCPContent>(i);
562 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent>(i);
564 if (!fc->text.empty()) {
568 } else if (dc || dsc) {
572 /* XXX: in the future there could be bitmap subs from DCPs */
577 /* Decide whether we can reference these subs */
579 shared_ptr<DCPContent> dcp;
580 if (sel.size() == 1) {
581 dcp = dynamic_pointer_cast<DCPContent>(sel.front());
585 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
587 if (why_not.empty()) {
588 cannot = _("Cannot reference this DCP's subtitles or captions.");
590 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
592 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
594 bool const reference = _reference->GetValue ();
596 auto const type = current_type ();
600 _type->Append (_("open subtitles"));
601 if (ffmpeg_subs == 0) {
602 _type->Append (_("closed captions"));
606 case TextType::OPEN_SUBTITLE:
607 _type->SetSelection (0);
609 case TextType::CLOSED_CAPTION:
610 if (_type->GetCount() > 1) {
611 _type->SetSelection (1);
618 /* Set up sensitivity */
619 _use->Enable (!reference && any_subs > 0);
620 bool const use = _use->GetValue ();
621 if (_outline_subtitles) {
622 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
624 _type->Enable (!reference && any_subs > 0 && use);
625 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
626 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
627 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
628 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
629 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
630 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
631 _stream->Enable (!reference && ffmpeg_subs == 1);
632 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
633 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
634 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
635 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
640 TextPanel::stream_changed ()
642 auto fc = _parent->selected_ffmpeg ();
643 if (fc.size() != 1) {
647 auto fcs = fc.front ();
649 auto a = fcs->subtitle_streams ();
651 auto const s = string_client_data (_stream->GetClientObject(_stream->GetSelection()));
652 while (i != a.end() && (*i)->identifier () != s) {
657 fcs->set_subtitle_stream (*i);
663 TextPanel::x_offset_changed ()
665 for (auto i: _parent->selected_text ()) {
666 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
672 TextPanel::y_offset_changed ()
674 for (auto i: _parent->selected_text ()) {
675 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
681 TextPanel::x_scale_changed ()
683 for (auto i: _parent->selected_text ()) {
684 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
690 TextPanel::y_scale_changed ()
692 for (auto i: _parent->selected_text ()) {
693 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
699 TextPanel::line_spacing_changed ()
701 for (auto i: _parent->selected_text ()) {
702 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
708 TextPanel::content_selection_changed ()
710 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
711 film_content_changed (TextContentProperty::USE);
712 film_content_changed (TextContentProperty::BURN);
713 film_content_changed (TextContentProperty::X_OFFSET);
714 film_content_changed (TextContentProperty::Y_OFFSET);
715 film_content_changed (TextContentProperty::X_SCALE);
716 film_content_changed (TextContentProperty::Y_SCALE);
717 film_content_changed (TextContentProperty::LINE_SPACING);
718 film_content_changed (TextContentProperty::FONTS);
719 film_content_changed (TextContentProperty::TYPE);
720 film_content_changed (TextContentProperty::DCP_TRACK);
721 film_content_changed (TextContentProperty::LANGUAGE);
722 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
723 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
728 TextPanel::text_view_clicked ()
731 _text_view->Destroy ();
732 _text_view = nullptr;
735 auto c = _parent->selected_text ();
736 DCPOMATIC_ASSERT (c.size() == 1);
738 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
741 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
748 TextPanel::fonts_dialog_clicked ()
751 _fonts_dialog->Destroy ();
752 _fonts_dialog = nullptr;
755 auto c = _parent->selected_text ();
756 DCPOMATIC_ASSERT (c.size() == 1);
758 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
759 _fonts_dialog->Show ();
764 TextPanel::reference_clicked ()
766 auto c = _parent->selected ();
771 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
776 d->set_reference_text (_original_type, _reference->GetValue ());
781 TextPanel::appearance_dialog_clicked ()
783 auto c = _parent->selected_text ();
784 DCPOMATIC_ASSERT (c.size() == 1);
786 auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
787 if (d->ShowModal () == wxID_OK) {
794 /** The user has clicked on the outline subtitles check box */
796 TextPanel::outline_subtitles_changed ()
798 if (_outline_subtitles->GetValue()) {
799 _analysis_content = _parent->selected_text().front();
800 try_to_load_analysis ();
802 clear_outline_subtitles ();
808 TextPanel::try_to_load_analysis ()
810 if (_loading_analysis) {
814 _loading_analysis = true;
815 setup_sensitivity ();
818 auto content = _analysis_content.lock ();
820 _loading_analysis = false;
821 setup_sensitivity ();
825 auto const path = _parent->film()->subtitle_analysis_path(content);
827 if (!boost::filesystem::exists(path)) {
828 for (auto i: JobManager::instance()->get()) {
829 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
834 JobManager::instance()->analyse_subtitles (
835 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
841 _analysis.reset (new SubtitleAnalysis(path));
842 } catch (OldFormatError& e) {
843 /* An old analysis file: recreate it */
844 JobManager::instance()->analyse_subtitles (
845 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
850 update_outline_subtitles_in_viewer ();
851 _loading_analysis = false;
852 setup_sensitivity ();
857 TextPanel::update_outline_subtitles_in_viewer ()
859 auto fv = _parent->film_viewer().lock();
865 auto rect = _analysis->bounding_box ();
867 auto content = _analysis_content.lock ();
868 DCPOMATIC_ASSERT (content);
869 rect->x += content->text.front()->x_offset();
870 rect->y += content->text.front()->y_offset();
872 fv->set_outline_subtitles (rect);
874 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
879 /** Remove any current subtitle outline display */
881 TextPanel::clear_outline_subtitles ()
884 update_outline_subtitles_in_viewer ();
885 if (_outline_subtitles) {
886 _outline_subtitles->SetValue (false);
892 TextPanel::analysis_finished ()
894 auto content = _analysis_content.lock ();
896 _loading_analysis = false;
897 setup_sensitivity ();
901 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
902 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
905 error_dialog (_parent->window(), _("Could not analyse subtitles."));
906 clear_outline_subtitles ();
907 _loading_analysis = false;
908 setup_sensitivity ();
912 _loading_analysis = false;
913 try_to_load_analysis ();
918 TextPanel::language_changed ()
920 for (auto i: _parent->selected_text()) {
921 auto t = i->text_of_original_type(_original_type);
923 t->set_language (_language->get());
930 TextPanel::language_is_additional_changed ()
932 for (auto i: _parent->selected_text()) {
933 auto t = i->text_of_original_type(_original_type);
935 t->set_language_is_additional (_language_type->GetSelection() == 1);