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"));
85 _offset_label = create_label (this, _("Offset"), true);
86 _x_offset_label = create_label (this, _("X"), true);
87 _x_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
88 _x_offset_pc_label = new StaticText (this, _("%"));
89 _y_offset_label = create_label (this, _("Y"), true);
90 _y_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
91 _y_offset_pc_label = new StaticText (this, _("%"));
93 _scale_label = create_label (this, _("Scale"), true);
94 _x_scale_label = create_label (this, _("X"), true);
95 _x_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
96 _x_scale_pc_label = new StaticText (this, _("%"));
97 _y_scale_label = create_label (this, S_("Coord|Y"), true);
98 _y_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
99 _y_scale_pc_label = new StaticText (this, _("%"));
101 _line_spacing_label = create_label (this, _("Line spacing"), true);
102 _line_spacing = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
103 _line_spacing_pc_label = new StaticText (this, _("%"));
105 _stream_label = create_label (this, _("Stream"), true);
106 _stream = new wxChoice (this, wxID_ANY);
108 _text_view_button = new Button (this, _("View..."));
109 _fonts_dialog_button = new Button (this, _("Fonts..."));
110 _appearance_dialog_button = new Button (this, _("Appearance..."));
112 _x_offset->SetRange (-100, 100);
113 _y_offset->SetRange (-100, 100);
114 _x_scale->SetRange (0, 1000);
115 _y_scale->SetRange (0, 1000);
116 _line_spacing->SetRange (0, 1000);
118 _reference->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
119 _use->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
120 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
121 _burn->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
122 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
123 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
124 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
125 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
126 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
127 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
128 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
129 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
130 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
133 content_selection_changed ();
138 TextPanel::setup_visibility ()
140 switch (current_type()) {
141 case TextType::OPEN_SUBTITLE:
142 if (_dcp_track_label) {
143 _dcp_track_label->Destroy ();
144 _dcp_track_label = nullptr;
147 _dcp_track->Destroy ();
148 _dcp_track = nullptr;
150 if (!_outline_subtitles) {
151 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
152 _outline_subtitles->Bind (wxEVT_CHECKBOX, boost::bind (&TextPanel::outline_subtitles_changed, this));
153 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
156 _language_label = create_label (this, _("Language"), true);
157 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
158 _language_sizer = new wxBoxSizer (wxHORIZONTAL);
159 _language = new LanguageTagWidget (this, _("Language of these subtitles"), boost::none, wxString("en-US-"));
160 _language->Changed.connect (boost::bind(&TextPanel::language_changed, this));
161 _language_sizer->Add (_language->sizer(), 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
162 _language_type = new wxChoice (this, wxID_ANY);
163 /// TRANSLATORS: Main and Additional here are a choice for whether a set of subtitles is in the "main" language of the
164 /// film or an "additional" language.
165 _language_type->Append (_("Main"));
166 _language_type->Append (_("Additional"));
167 _language_type->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::language_is_additional_changed, this));
168 _language_sizer->Add (_language_type, 0);
169 _grid->Add (_language_sizer, wxGBPosition(_ccap_track_or_language_row, 1), wxGBSpan(1, 2));
170 film_content_changed (TextContentProperty::LANGUAGE);
171 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
174 case TextType::CLOSED_CAPTION:
175 if (_language_label) {
176 _language_label->Destroy ();
177 _language_label = nullptr;
178 _grid->Remove (_language->sizer());
180 _grid->Remove (_language_sizer);
181 _language_sizer = nullptr;
183 _language_type->Destroy ();
184 _language_type = nullptr;
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(_ccap_track_or_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(_ccap_track_or_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 = nullptr;
200 clear_outline_subtitles ();
212 TextPanel::add_to_grid ()
216 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
217 reference_sizer->Add (_reference, 0);
218 reference_sizer->Add (_reference_note, 0);
219 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
222 auto 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 auto offset = new wxBoxSizer (wxHORIZONTAL);
236 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
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);
240 _grid->Add (offset, wxGBPosition(r, 1));
242 offset = new wxBoxSizer (wxHORIZONTAL);
244 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
245 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
246 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
247 _grid->Add (offset, wxGBPosition (r, 1));
250 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
251 auto scale = new wxBoxSizer (wxHORIZONTAL);
252 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
253 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
254 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
256 _grid->Add (scale, wxGBPosition(r, 1));
258 scale = new wxBoxSizer (wxHORIZONTAL);
260 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
261 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
262 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
263 _grid->Add (scale, wxGBPosition (r, 1));
267 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
268 auto s = new wxBoxSizer (wxHORIZONTAL);
269 s->Add (_line_spacing);
270 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
271 _grid->Add (s, wxGBPosition (r, 1));
275 _ccap_track_or_language_row = r;
278 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
279 _grid->Add (_stream, wxGBPosition (r, 1));
283 auto s = new wxBoxSizer (wxHORIZONTAL);
285 s->Add (_text_view_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
286 s->Add (_fonts_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
287 s->Add (_appearance_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
289 _grid->Add (s, wxGBPosition(r, 0), wxGBSpan(1, 2));
298 TextPanel::update_dcp_track_selection ()
300 DCPOMATIC_ASSERT (_dcp_track);
302 optional<DCPTextTrack> selected;
304 for (auto i: _parent->selected_text()) {
305 auto t = i->text_of_original_type(_original_type);
307 auto dt = t->dcp_track();
308 if (dt && selected && *dt != *selected) {
310 } else if (!selected) {
317 for (auto i: _parent->film()->closed_caption_tracks()) {
318 if (!many && selected && *selected == i) {
319 _dcp_track->SetSelection (n);
324 if (!selected || many) {
325 _dcp_track->SetSelection (wxNOT_FOUND);
331 TextPanel::update_dcp_tracks ()
333 DCPOMATIC_ASSERT (_dcp_track);
335 _dcp_track->Clear ();
336 for (auto i: _parent->film()->closed_caption_tracks()) {
337 /* XXX: don't display the "magic" track which has empty name and language;
338 this is a nasty hack (see also Film::closed_caption_tracks)
340 if (!i.name.empty() || i.language) {
341 _dcp_track->Append (std_to_wx(i.summary()));
345 if (_parent->film()->closed_caption_tracks().size() < 6) {
346 _dcp_track->Append (_("Add new..."));
349 update_dcp_track_selection ();
354 TextPanel::dcp_track_changed ()
356 optional<DCPTextTrack> track;
358 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
359 auto d = new DCPTextTrackDialog (this);
360 if (d->ShowModal() == wxID_OK) {
365 /* Find the DCPTextTrack that was selected */
366 for (auto i: _parent->film()->closed_caption_tracks()) {
367 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
374 for (auto i: _parent->selected_text()) {
375 auto t = i->text_of_original_type(_original_type);
376 if (t && t->type() == TextType::CLOSED_CAPTION) {
377 t->set_dcp_track(*track);
382 update_dcp_tracks ();
387 TextPanel::film_changed (Film::Property property)
389 if (property == Film::Property::CONTENT || property == Film::Property::REEL_TYPE || property == Film::Property::INTEROP) {
390 setup_sensitivity ();
396 TextPanel::film_content_changed (int property)
398 auto fc = _parent->selected_ffmpeg ();
399 auto sc = _parent->selected_text ();
401 shared_ptr<FFmpegContent> fcs;
402 if (fc.size() == 1) {
406 shared_ptr<Content> scs;
407 if (sc.size() == 1) {
411 shared_ptr<TextContent> text;
413 text = scs->text_of_original_type(_original_type);
416 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
419 for (auto i: fcs->subtitle_streams()) {
420 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
423 if (fcs->subtitle_stream()) {
424 checked_set (_stream, fcs->subtitle_stream()->identifier ());
426 _stream->SetSelection (wxNOT_FOUND);
429 setup_sensitivity ();
430 clear_outline_subtitles ();
431 } else if (property == TextContentProperty::USE) {
432 checked_set (_use, text ? text->use() : false);
433 setup_sensitivity ();
434 clear_outline_subtitles ();
435 } else if (property == TextContentProperty::TYPE) {
437 switch (text->type()) {
438 case TextType::OPEN_SUBTITLE:
439 _type->SetSelection (0);
441 case TextType::CLOSED_CAPTION:
442 _type->SetSelection (1);
445 DCPOMATIC_ASSERT (false);
448 _type->SetSelection (0);
450 setup_sensitivity ();
452 } else if (property == TextContentProperty::BURN) {
453 checked_set (_burn, text ? text->burn() : false);
454 } else if (property == TextContentProperty::X_OFFSET) {
455 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
456 update_outline_subtitles_in_viewer ();
457 } else if (property == TextContentProperty::Y_OFFSET) {
458 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
459 update_outline_subtitles_in_viewer ();
460 } else if (property == TextContentProperty::X_SCALE) {
461 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
462 clear_outline_subtitles ();
463 } else if (property == TextContentProperty::Y_SCALE) {
464 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
465 clear_outline_subtitles ();
466 } else if (property == TextContentProperty::LINE_SPACING) {
467 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
468 clear_outline_subtitles ();
469 } else if (property == TextContentProperty::DCP_TRACK) {
471 update_dcp_track_selection ();
473 } else if (property == TextContentProperty::LANGUAGE) {
475 _language->set (text ? text->language() : boost::none);
477 } else if (property == TextContentProperty::LANGUAGE_IS_ADDITIONAL) {
478 if (_language_type) {
479 _language_type->SetSelection (text ? (text->language_is_additional() ? 1 : 0) : 0);
481 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
483 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
484 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
486 checked_set (_reference, false);
489 setup_sensitivity ();
490 } else if (property == DCPContentProperty::TEXTS) {
491 setup_sensitivity ();
492 } else if (property == ContentProperty::TRIM_START) {
493 setup_sensitivity ();
499 TextPanel::use_toggled ()
501 for (auto i: _parent->selected_text()) {
502 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
507 /** @return the text type that is currently selected in the drop-down */
509 TextPanel::current_type () const
511 switch (_type->GetSelection()) {
513 return TextType::OPEN_SUBTITLE;
515 return TextType::CLOSED_CAPTION;
518 return TextType::UNKNOWN;
523 TextPanel::type_changed ()
525 for (auto i: _parent->selected_text()) {
526 i->text_of_original_type(_original_type)->set_type (current_type ());
534 TextPanel::burn_toggled ()
536 for (auto i: _parent->selected_text ()) {
537 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
543 TextPanel::setup_sensitivity ()
546 /* We currently assume that FFmpeg subtitles are bitmapped */
548 /* DCP subs can't have their line spacing changed */
550 auto sel = _parent->selected_text ();
552 /* These are the content types that could include subtitles */
553 auto fc = std::dynamic_pointer_cast<const FFmpegContent>(i);
554 auto sc = std::dynamic_pointer_cast<const StringTextFileContent>(i);
555 auto dc = std::dynamic_pointer_cast<const DCPContent>(i);
556 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent>(i);
558 if (!fc->text.empty()) {
562 } else if (dc || dsc) {
566 /* XXX: in the future there could be bitmap subs from DCPs */
571 /* Decide whether we can reference these subs */
573 shared_ptr<DCPContent> dcp;
574 if (sel.size() == 1) {
575 dcp = dynamic_pointer_cast<DCPContent>(sel.front());
579 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
581 if (why_not.empty()) {
582 cannot = _("Cannot reference this DCP's subtitles or captions.");
584 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
586 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
588 bool const reference = _reference->GetValue ();
590 auto const type = current_type ();
594 _type->Append (_("open subtitles"));
595 if (ffmpeg_subs == 0) {
596 _type->Append (_("closed captions"));
600 case TextType::OPEN_SUBTITLE:
601 _type->SetSelection (0);
603 case TextType::CLOSED_CAPTION:
604 if (_type->GetCount() > 1) {
605 _type->SetSelection (1);
612 /* Set up sensitivity */
613 _use->Enable (!reference && any_subs > 0);
614 bool const use = _use->GetValue ();
615 if (_outline_subtitles) {
616 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
618 _type->Enable (!reference && any_subs > 0 && use);
619 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
620 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
621 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
622 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
623 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
624 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
625 _stream->Enable (!reference && ffmpeg_subs == 1);
626 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
627 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
628 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
629 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
634 TextPanel::stream_changed ()
636 auto fc = _parent->selected_ffmpeg ();
637 if (fc.size() != 1) {
641 auto fcs = fc.front ();
643 auto a = fcs->subtitle_streams ();
645 auto const s = string_client_data (_stream->GetClientObject(_stream->GetSelection()));
646 while (i != a.end() && (*i)->identifier () != s) {
651 fcs->set_subtitle_stream (*i);
657 TextPanel::x_offset_changed ()
659 for (auto i: _parent->selected_text ()) {
660 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
666 TextPanel::y_offset_changed ()
668 for (auto i: _parent->selected_text ()) {
669 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
675 TextPanel::x_scale_changed ()
677 for (auto i: _parent->selected_text ()) {
678 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
684 TextPanel::y_scale_changed ()
686 for (auto i: _parent->selected_text ()) {
687 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
693 TextPanel::line_spacing_changed ()
695 for (auto i: _parent->selected_text ()) {
696 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
702 TextPanel::content_selection_changed ()
704 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
705 film_content_changed (TextContentProperty::USE);
706 film_content_changed (TextContentProperty::BURN);
707 film_content_changed (TextContentProperty::X_OFFSET);
708 film_content_changed (TextContentProperty::Y_OFFSET);
709 film_content_changed (TextContentProperty::X_SCALE);
710 film_content_changed (TextContentProperty::Y_SCALE);
711 film_content_changed (TextContentProperty::LINE_SPACING);
712 film_content_changed (TextContentProperty::FONTS);
713 film_content_changed (TextContentProperty::TYPE);
714 film_content_changed (TextContentProperty::DCP_TRACK);
715 film_content_changed (TextContentProperty::LANGUAGE);
716 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
717 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
722 TextPanel::text_view_clicked ()
725 _text_view->Destroy ();
726 _text_view = nullptr;
729 auto c = _parent->selected_text ();
730 DCPOMATIC_ASSERT (c.size() == 1);
732 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
735 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
742 TextPanel::fonts_dialog_clicked ()
745 _fonts_dialog->Destroy ();
746 _fonts_dialog = nullptr;
749 auto c = _parent->selected_text ();
750 DCPOMATIC_ASSERT (c.size() == 1);
752 _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
753 _fonts_dialog->Show ();
758 TextPanel::reference_clicked ()
760 auto c = _parent->selected ();
765 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
770 d->set_reference_text (_original_type, _reference->GetValue ());
775 TextPanel::appearance_dialog_clicked ()
777 auto c = _parent->selected_text ();
778 DCPOMATIC_ASSERT (c.size() == 1);
780 auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
781 if (d->ShowModal () == wxID_OK) {
788 /** The user has clicked on the outline subtitles check box */
790 TextPanel::outline_subtitles_changed ()
792 if (_outline_subtitles->GetValue()) {
793 _analysis_content = _parent->selected_text().front();
794 try_to_load_analysis ();
796 clear_outline_subtitles ();
802 TextPanel::try_to_load_analysis ()
804 if (_loading_analysis) {
808 _loading_analysis = true;
809 setup_sensitivity ();
812 auto content = _analysis_content.lock ();
814 _loading_analysis = false;
815 setup_sensitivity ();
819 auto const path = _parent->film()->subtitle_analysis_path(content);
821 if (!boost::filesystem::exists(path)) {
822 for (auto i: JobManager::instance()->get()) {
823 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i)) {
828 JobManager::instance()->analyse_subtitles (
829 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
835 _analysis.reset (new SubtitleAnalysis(path));
836 } catch (OldFormatError& e) {
837 /* An old analysis file: recreate it */
838 JobManager::instance()->analyse_subtitles (
839 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this)
844 update_outline_subtitles_in_viewer ();
845 _loading_analysis = false;
846 setup_sensitivity ();
851 TextPanel::update_outline_subtitles_in_viewer ()
853 auto fv = _parent->film_viewer().lock();
859 auto rect = _analysis->bounding_box ();
861 auto content = _analysis_content.lock ();
862 DCPOMATIC_ASSERT (content);
863 rect->x += content->text.front()->x_offset();
864 rect->y += content->text.front()->y_offset();
866 fv->set_outline_subtitles (rect);
868 fv->set_outline_subtitles (optional<dcpomatic::Rect<double> >());
873 /** Remove any current subtitle outline display */
875 TextPanel::clear_outline_subtitles ()
878 update_outline_subtitles_in_viewer ();
879 if (_outline_subtitles) {
880 _outline_subtitles->SetValue (false);
886 TextPanel::analysis_finished ()
888 auto content = _analysis_content.lock ();
890 _loading_analysis = false;
891 setup_sensitivity ();
895 if (!boost::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
896 /* We analysed and still nothing showed up, so maybe it was cancelled or it failed.
899 error_dialog (_parent->window(), _("Could not analyse subtitles."));
900 clear_outline_subtitles ();
901 _loading_analysis = false;
902 setup_sensitivity ();
906 _loading_analysis = false;
907 try_to_load_analysis ();
912 TextPanel::language_changed ()
914 for (auto i: _parent->selected_text()) {
915 auto t = i->text_of_original_type(_original_type);
917 t->set_language (_language->get());
924 TextPanel::language_is_additional_changed ()
926 for (auto i: _parent->selected_text()) {
927 auto t = i->text_of_original_type(_original_type);
929 t->set_language_is_additional (_language_type->GetSelection() == 1);