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)))
72 wxString refer = _("Use this DCP's subtitle as OV and make VF");
73 if (_original_type == TextType::CLOSED_CAPTION) {
74 refer = _("Use this DCP's closed caption as OV and make VF");
77 _reference = new CheckBox (this, refer);
78 _reference_note = new StaticText (this, wxT(""));
79 _reference_note->Wrap (200);
80 auto font = _reference_note->GetFont();
81 font.SetStyle(wxFONTSTYLE_ITALIC);
82 font.SetPointSize(font.GetPointSize() - 1);
83 _reference_note->SetFont(font);
85 _use = new CheckBox (this, _("Use as"));
86 _type = new wxChoice (this, wxID_ANY);
87 _type->Append (_("open subtitles"));
88 _type->Append (_("closed captions"));
90 _burn = new CheckBox (this, _("Burn subtitles into image"));
92 _offset_label = create_label (this, _("Offset"), true);
93 _x_offset_label = create_label (this, _("X"), true);
94 _x_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
95 _x_offset_pc_label = new StaticText (this, _("%"));
96 _y_offset_label = create_label (this, _("Y"), true);
97 _y_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
98 _y_offset_pc_label = new StaticText (this, _("%"));
100 _scale_label = create_label (this, _("Scale"), true);
101 _x_scale_label = create_label (this, _("X"), true);
102 _x_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
103 _x_scale_pc_label = new StaticText (this, _("%"));
104 _y_scale_label = create_label (this, S_("Coord|Y"), true);
105 _y_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
106 _y_scale_pc_label = new StaticText (this, _("%"));
108 _line_spacing_label = create_label (this, _("Line spacing"), true);
109 _line_spacing = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
110 _line_spacing_pc_label = new StaticText (this, _("%"));
112 _stream_label = create_label (this, _("Stream"), true);
113 _stream = new wxChoice (this, wxID_ANY);
115 _text_view_button = new Button (this, _("View..."));
116 _fonts_dialog_button = new Button (this, _("Fonts..."));
117 _appearance_dialog_button = new Button (this, _("Appearance..."));
119 _x_offset->SetRange (-100, 100);
120 _y_offset->SetRange (-100, 100);
121 _x_scale->SetRange (0, 1000);
122 _y_scale->SetRange (0, 1000);
123 _line_spacing->SetRange (0, 1000);
125 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
126 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
127 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
128 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
129 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
130 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
131 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
132 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
133 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
134 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
135 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
136 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
137 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
140 content_selection_changed ();
147 TextPanel::setup_visibility ()
149 switch (current_type()) {
150 case TextType::OPEN_SUBTITLE:
151 if (_dcp_track_label) {
152 _dcp_track_label->Destroy ();
153 _dcp_track_label = nullptr;
156 _dcp_track->Destroy ();
157 _dcp_track = nullptr;
159 if (!_outline_subtitles) {
160 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
161 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
162 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
165 _language_label = create_label (this, _("Language"), true);
166 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
167 _language_sizer = new wxBoxSizer (wxHORIZONTAL);
168 _language = new LanguageTagWidget (this, _("Language of these subtitles"), boost::none, wxString("en-US-"));
169 _language->Changed.connect (boost::bind(&TextPanel::language_changed, this));
170 _language_sizer->Add (_language->sizer(), 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
171 _language_type = new wxChoice (this, wxID_ANY);
172 /// TRANSLATORS: Main and Additional here are a choice for whether a set of subtitles is in the "main" language of the
173 /// film or an "additional" language.
174 _language_type->Append (_("Main"));
175 _language_type->Append (_("Additional"));
176 _language_type->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::language_is_additional_changed, this));
177 _language_sizer->Add (_language_type, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_CHOICE_TOP_PAD);
178 _grid->Add (_language_sizer, wxGBPosition(_ccap_track_or_language_row, 1), wxGBSpan(1, 2));
179 film_content_changed (TextContentProperty::LANGUAGE);
180 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
183 case TextType::CLOSED_CAPTION:
184 if (_language_label) {
185 _language_label->Destroy ();
186 _language_label = nullptr;
187 _grid->Remove (_language->sizer());
189 _grid->Remove (_language_sizer);
190 _language_sizer = nullptr;
192 _language_type->Destroy ();
193 _language_type = nullptr;
195 if (!_dcp_track_label) {
196 _dcp_track_label = create_label (this, _("CCAP track"), true);
197 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
200 _dcp_track = new wxChoice (this, wxID_ANY);
201 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
202 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_or_language_row, 1), wxDefaultSpan, wxEXPAND);
203 update_dcp_tracks ();
204 film_content_changed (TextContentProperty::DCP_TRACK);
206 if (_outline_subtitles) {
207 _outline_subtitles->Destroy ();
208 _outline_subtitles = nullptr;
209 clear_outline_subtitles ();
221 TextPanel::add_to_grid ()
225 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
226 reference_sizer->Add (_reference, 0);
227 reference_sizer->Add (_reference_note, 0);
228 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
231 auto use = new wxBoxSizer (wxHORIZONTAL);
232 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
233 use->Add (_type, 1, wxEXPAND, 0);
234 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
237 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
240 _outline_subtitles_row = r;
243 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
244 auto offset = new wxBoxSizer (wxHORIZONTAL);
245 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
246 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
247 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
249 _grid->Add (offset, wxGBPosition(r, 1));
251 offset = new wxBoxSizer (wxHORIZONTAL);
253 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
254 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
255 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
256 _grid->Add (offset, wxGBPosition (r, 1));
259 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
260 auto scale = new wxBoxSizer (wxHORIZONTAL);
261 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
262 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
263 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
265 _grid->Add (scale, wxGBPosition(r, 1));
267 scale = new wxBoxSizer (wxHORIZONTAL);
269 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
270 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
271 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
272 _grid->Add (scale, wxGBPosition (r, 1));
276 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
277 auto s = new wxBoxSizer (wxHORIZONTAL);
278 s->Add (_line_spacing);
279 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
280 _grid->Add (s, wxGBPosition (r, 1));
284 _ccap_track_or_language_row = r;
287 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
288 _grid->Add (_stream, wxGBPosition (r, 1));
292 auto s = new wxBoxSizer (wxHORIZONTAL);
294 s->Add (_text_view_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
295 s->Add (_fonts_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
296 s->Add (_appearance_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
298 _grid->Add (s, wxGBPosition(r, 0), wxGBSpan(1, 2));
307 TextPanel::update_dcp_track_selection ()
309 DCPOMATIC_ASSERT (_dcp_track);
311 optional<DCPTextTrack> selected;
313 for (auto i: _parent->selected_text()) {
314 auto t = i->text_of_original_type(_original_type);
316 auto dt = t->dcp_track();
317 if (dt && selected && *dt != *selected) {
319 } else if (!selected) {
326 for (auto i: _parent->film()->closed_caption_tracks()) {
327 if (!many && selected && *selected == i) {
328 _dcp_track->SetSelection (n);
333 if (!selected || many) {
334 _dcp_track->SetSelection (wxNOT_FOUND);
340 TextPanel::update_dcp_tracks ()
342 DCPOMATIC_ASSERT (_dcp_track);
344 _dcp_track->Clear ();
345 for (auto i: _parent->film()->closed_caption_tracks()) {
346 /* XXX: don't display the "magic" track which has empty name and language;
347 this is a nasty hack (see also Film::closed_caption_tracks)
349 if (!i.name.empty() || i.language) {
350 _dcp_track->Append (std_to_wx(i.summary()));
354 if (_parent->film()->closed_caption_tracks().size() < 6) {
355 _dcp_track->Append (_("Add new..."));
358 update_dcp_track_selection ();
363 TextPanel::dcp_track_changed ()
365 optional<DCPTextTrack> track;
367 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
368 auto d = new DCPTextTrackDialog (this);
369 if (d->ShowModal() == wxID_OK) {
374 /* Find the DCPTextTrack that was selected */
375 for (auto i: _parent->film()->closed_caption_tracks()) {
376 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
383 for (auto i: _parent->selected_text()) {
384 auto t = i->text_of_original_type(_original_type);
385 if (t && t->type() == TextType::CLOSED_CAPTION) {
386 t->set_dcp_track(*track);
391 update_dcp_tracks ();
396 TextPanel::film_changed (Film::Property property)
398 if (property == Film::Property::CONTENT || property == Film::Property::REEL_TYPE || property == Film::Property::INTEROP) {
399 setup_sensitivity ();
405 TextPanel::film_content_changed (int property)
407 auto fc = _parent->selected_ffmpeg ();
408 auto sc = _parent->selected_text ();
410 shared_ptr<FFmpegContent> fcs;
411 if (fc.size() == 1) {
415 shared_ptr<Content> scs;
416 if (sc.size() == 1) {
420 shared_ptr<TextContent> text;
422 text = scs->text_of_original_type(_original_type);
425 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
428 for (auto i: fcs->subtitle_streams()) {
429 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
432 if (fcs->subtitle_stream()) {
433 checked_set (_stream, fcs->subtitle_stream()->identifier ());
435 _stream->SetSelection (wxNOT_FOUND);
438 setup_sensitivity ();
439 clear_outline_subtitles ();
440 } else if (property == TextContentProperty::USE) {
441 checked_set (_use, text ? text->use() : false);
442 setup_sensitivity ();
443 clear_outline_subtitles ();
444 } else if (property == TextContentProperty::TYPE) {
446 switch (text->type()) {
447 case TextType::OPEN_SUBTITLE:
448 _type->SetSelection (0);
450 case TextType::CLOSED_CAPTION:
451 _type->SetSelection (1);
454 DCPOMATIC_ASSERT (false);
457 _type->SetSelection (0);
459 setup_sensitivity ();
461 } else if (property == TextContentProperty::BURN) {
462 checked_set (_burn, text ? text->burn() : false);
463 } else if (property == TextContentProperty::X_OFFSET) {
464 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
465 update_outline_subtitles_in_viewer ();
466 } else if (property == TextContentProperty::Y_OFFSET) {
467 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
468 update_outline_subtitles_in_viewer ();
469 } else if (property == TextContentProperty::X_SCALE) {
470 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
471 clear_outline_subtitles ();
472 } else if (property == TextContentProperty::Y_SCALE) {
473 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
474 clear_outline_subtitles ();
475 } else if (property == TextContentProperty::LINE_SPACING) {
476 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
477 clear_outline_subtitles ();
478 } else if (property == TextContentProperty::DCP_TRACK) {
480 update_dcp_track_selection ();
482 } else if (property == TextContentProperty::LANGUAGE) {
484 _language->set (text ? text->language() : boost::none);
486 } else if (property == TextContentProperty::LANGUAGE_IS_ADDITIONAL) {
487 if (_language_type) {
488 _language_type->SetSelection (text ? (text->language_is_additional() ? 1 : 0) : 0);
490 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
492 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
493 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
495 checked_set (_reference, false);
498 setup_sensitivity ();
499 } else if (property == DCPContentProperty::TEXTS) {
500 setup_sensitivity ();
501 } else if (property == ContentProperty::TRIM_START) {
502 setup_sensitivity ();
508 TextPanel::use_toggled ()
510 for (auto i: _parent->selected_text()) {
511 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
516 /** @return the text type that is currently selected in the drop-down */
518 TextPanel::current_type () const
520 switch (_type->GetSelection()) {
522 return TextType::OPEN_SUBTITLE;
524 return TextType::CLOSED_CAPTION;
527 return TextType::UNKNOWN;
532 TextPanel::type_changed ()
534 for (auto i: _parent->selected_text()) {
535 i->text_of_original_type(_original_type)->set_type (current_type ());
543 TextPanel::burn_toggled ()
545 for (auto i: _parent->selected_text ()) {
546 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
552 TextPanel::setup_sensitivity ()
555 /* We currently assume that FFmpeg subtitles are bitmapped */
557 /* DCP subs can't have their line spacing changed */
559 auto sel = _parent->selected_text ();
561 /* These are the content types that could include subtitles */
562 auto fc = std::dynamic_pointer_cast<const FFmpegContent>(i);
563 auto sc = std::dynamic_pointer_cast<const StringTextFileContent>(i);
564 auto dc = std::dynamic_pointer_cast<const DCPContent>(i);
565 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent>(i);
567 if (!fc->text.empty()) {
571 } else if (dc || dsc) {
575 /* XXX: in the future there could be bitmap subs from DCPs */
580 /* Decide whether we can reference these subs */
582 shared_ptr<DCPContent> dcp;
583 if (sel.size() == 1) {
584 dcp = dynamic_pointer_cast<DCPContent>(sel.front());
588 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
590 if (why_not.empty()) {
591 cannot = _("Cannot reference this DCP's subtitles or captions.");
593 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
595 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
597 bool const reference = _reference->GetValue ();
599 auto const type = current_type ();
603 _type->Append (_("open subtitles"));
604 if (ffmpeg_subs == 0) {
605 _type->Append (_("closed captions"));
609 case TextType::OPEN_SUBTITLE:
610 _type->SetSelection (0);
612 case TextType::CLOSED_CAPTION:
613 if (_type->GetCount() > 1) {
614 _type->SetSelection (1);
621 /* Set up sensitivity */
622 _use->Enable (!reference && any_subs > 0);
623 bool const use = _use->GetValue ();
624 if (_outline_subtitles) {
625 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
627 _type->Enable (!reference && any_subs > 0 && use);
628 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
629 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
630 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
631 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
632 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
633 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
634 _stream->Enable (!reference && ffmpeg_subs == 1);
635 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
636 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
637 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
638 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
643 TextPanel::stream_changed ()
645 auto fc = _parent->selected_ffmpeg ();
646 if (fc.size() != 1) {
650 auto fcs = fc.front ();
652 auto a = fcs->subtitle_streams ();
654 auto const s = string_client_data (_stream->GetClientObject(_stream->GetSelection()));
655 while (i != a.end() && (*i)->identifier () != s) {
660 fcs->set_subtitle_stream (*i);
666 TextPanel::x_offset_changed ()
668 for (auto i: _parent->selected_text ()) {
669 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
675 TextPanel::y_offset_changed ()
677 for (auto i: _parent->selected_text ()) {
678 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
684 TextPanel::x_scale_changed ()
686 for (auto i: _parent->selected_text ()) {
687 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
693 TextPanel::y_scale_changed ()
695 for (auto i: _parent->selected_text ()) {
696 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
702 TextPanel::line_spacing_changed ()
704 for (auto i: _parent->selected_text ()) {
705 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
711 TextPanel::content_selection_changed ()
713 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
714 film_content_changed (TextContentProperty::USE);
715 film_content_changed (TextContentProperty::BURN);
716 film_content_changed (TextContentProperty::X_OFFSET);
717 film_content_changed (TextContentProperty::Y_OFFSET);
718 film_content_changed (TextContentProperty::X_SCALE);
719 film_content_changed (TextContentProperty::Y_SCALE);
720 film_content_changed (TextContentProperty::LINE_SPACING);
721 film_content_changed (TextContentProperty::FONTS);
722 film_content_changed (TextContentProperty::TYPE);
723 film_content_changed (TextContentProperty::DCP_TRACK);
724 film_content_changed (TextContentProperty::LANGUAGE);
725 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
726 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
731 TextPanel::text_view_clicked ()
734 _text_view->Destroy ();
735 _text_view = nullptr;
738 auto c = _parent->selected_text ();
739 DCPOMATIC_ASSERT (c.size() == 1);
741 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
744 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
751 TextPanel::fonts_dialog_clicked ()
754 _fonts_dialog->Destroy ();
755 _fonts_dialog = nullptr;
758 auto c = _parent->selected_text ();
759 DCPOMATIC_ASSERT (c.size() == 1);
761 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
762 _fonts_dialog->Show ();
767 TextPanel::reference_clicked ()
769 auto c = _parent->selected ();
774 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
779 d->set_reference_text (_original_type, _reference->GetValue ());
784 TextPanel::appearance_dialog_clicked ()
786 auto c = _parent->selected_text ();
787 DCPOMATIC_ASSERT (c.size() == 1);
789 auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
790 if (d->ShowModal () == wxID_OK) {
797 /** The user has clicked on the outline subtitles check box */
799 TextPanel::outline_subtitles_changed ()
801 if (_outline_subtitles->GetValue()) {
802 _analysis_content = _parent->selected_text().front();
803 try_to_load_analysis ();
805 clear_outline_subtitles ();
811 TextPanel::try_to_load_analysis ()
813 if (_loading_analysis) {
817 _loading_analysis = true;
818 setup_sensitivity ();
821 auto content = _analysis_content.lock ();
823 _loading_analysis = false;
824 setup_sensitivity ();
828 auto const path = _parent->film()->subtitle_analysis_path(content);
830 if (!boost::filesystem::exists(path)) {
831 for (auto i: JobManager::instance()->get()) {
832 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
837 JobManager::instance()->analyse_subtitles (
838 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
844 _analysis.reset (new SubtitleAnalysis(path));
845 } catch (OldFormatError& e) {
846 /* An old analysis file: recreate it */
847 JobManager::instance()->analyse_subtitles (
848 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
853 update_outline_subtitles_in_viewer ();
854 _loading_analysis = false;
855 setup_sensitivity ();
860 TextPanel::update_outline_subtitles_in_viewer ()
862 auto fv = _parent->film_viewer().lock();
868 auto rect = _analysis->bounding_box ();
870 auto content = _analysis_content.lock ();
871 DCPOMATIC_ASSERT (content);
872 rect->x += content->text.front()->x_offset();
873 rect->y += content->text.front()->y_offset();
875 fv->set_outline_subtitles (rect);
877 fv->set_outline_subtitles ({});
882 /** Remove any current subtitle outline display */
884 TextPanel::clear_outline_subtitles ()
887 update_outline_subtitles_in_viewer ();
888 if (_outline_subtitles) {
889 _outline_subtitles->SetValue (false);
895 TextPanel::analysis_finished ()
897 auto content = _analysis_content.lock ();
899 _loading_analysis = false;
900 setup_sensitivity ();
904 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
905 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
908 error_dialog (_parent->window(), _("Could not analyse subtitles."));
909 clear_outline_subtitles ();
910 _loading_analysis = false;
911 setup_sensitivity ();
915 _loading_analysis = false;
916 try_to_load_analysis ();
921 TextPanel::language_changed ()
923 for (auto i: _parent->selected_text()) {
924 auto t = i->text_of_original_type(_original_type);
926 t->set_language (_language->get());
933 TextPanel::language_is_additional_changed ()
935 for (auto i: _parent->selected_text()) {
936 auto t = i->text_of_original_type(_original_type);
938 t->set_language_is_additional (_language_type->GetSelection() == 1);