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/>.
22 #include "check_box.h"
23 #include "content_panel.h"
24 #include "dcp_text_track_dialog.h"
25 #include "dcpomatic_button.h"
26 #include "dcpomatic_spin_ctrl.h"
27 #include "film_editor.h"
28 #include "film_viewer.h"
29 #include "fonts_dialog.h"
30 #include "language_tag_widget.h"
31 #include "static_text.h"
32 #include "subtitle_appearance_dialog.h"
33 #include "text_panel.h"
34 #include "text_view.h"
36 #include "lib/analyse_subtitles_job.h"
37 #include "lib/dcp_content.h"
38 #include "lib/dcp_subtitle_content.h"
39 #include "lib/dcp_subtitle_decoder.h"
40 #include "lib/decoder_factory.h"
41 #include "lib/ffmpeg_content.h"
42 #include "lib/ffmpeg_subtitle_stream.h"
44 #include "lib/job_manager.h"
45 #include "lib/scope_guard.h"
46 #include "lib/string_text_file_content.h"
47 #include "lib/string_text_file_decoder.h"
48 #include "lib/subtitle_analysis.h"
49 #include "lib/text_content.h"
50 #include <dcp/filesystem.h>
51 #include <dcp/warnings.h>
52 LIBDCP_DISABLE_WARNINGS
53 #include <wx/spinctrl.h>
54 LIBDCP_ENABLE_WARNINGS
58 using std::dynamic_pointer_cast;
60 using std::shared_ptr;
64 using boost::optional;
65 #if BOOST_VERSION >= 106100
66 using namespace boost::placeholders;
70 /** @param t Original text type of the content, if known */
71 TextPanel::TextPanel (ContentPanel* p, TextType t)
72 : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
82 wxString refer = _("Use this DCP's subtitle as OV and make VF");
83 if (_original_type == TextType::CLOSED_CAPTION) {
84 refer = _("Use this DCP's closed caption as OV and make VF");
87 _reference = new CheckBox (this, refer);
88 _reference_note = new StaticText (this, wxT(""));
89 _reference_note->Wrap (200);
90 auto font = _reference_note->GetFont();
91 font.SetStyle(wxFONTSTYLE_ITALIC);
92 font.SetPointSize(font.GetPointSize() - 1);
93 _reference_note->SetFont(font);
95 _use = new CheckBox (this, _("Use as"));
96 _type = new wxChoice (this, wxID_ANY);
97 _type->Append (_("open subtitles"));
98 _type->Append (_("closed captions"));
100 _burn = new CheckBox (this, _("Burn subtitles into image"));
102 _offset_label = create_label (this, _("Offset"), true);
103 _x_offset_label = create_label (this, _("X"), true);
104 _x_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
105 _x_offset_pc_label = new StaticText (this, _("%"));
106 _y_offset_label = create_label (this, _("Y"), true);
107 _y_offset = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
108 _y_offset_pc_label = new StaticText (this, _("%"));
110 _scale_label = create_label (this, _("Scale"), true);
111 _x_scale_label = create_label (this, _("X"), true);
112 _x_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
113 _x_scale_pc_label = new StaticText (this, _("%"));
114 _y_scale_label = create_label (this, S_("Coord|Y"), true);
115 _y_scale = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
116 _y_scale_pc_label = new StaticText (this, _("%"));
118 _line_spacing_label = create_label (this, _("Line spacing"), true);
119 _line_spacing = new SpinCtrl (this, DCPOMATIC_SPIN_CTRL_WIDTH);
120 _line_spacing_pc_label = new StaticText (this, _("%"));
122 _stream_label = create_label (this, _("Stream"), true);
123 _stream = new wxChoice (this, wxID_ANY);
125 _text_view_button = new Button (this, _("View..."));
126 _fonts_dialog_button = new Button (this, _("Fonts..."));
127 _appearance_dialog_button = new Button (this, _("Appearance..."));
129 _x_offset->SetRange (-100, 100);
130 _y_offset->SetRange (-100, 100);
131 _x_scale->SetRange (0, 1000);
132 _y_scale->SetRange (0, 1000);
133 _line_spacing->SetRange (0, 1000);
135 _reference->bind(&TextPanel::reference_clicked, this);
136 _use->bind(&TextPanel::use_toggled, this);
137 _type->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::type_changed, this));
138 _burn->bind(&TextPanel::burn_toggled, this);
139 _x_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
140 _y_offset->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
141 _x_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
142 _y_scale->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
143 _line_spacing->Bind (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
144 _stream->Bind (wxEVT_CHOICE, boost::bind (&TextPanel::stream_changed, this));
145 _text_view_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::text_view_clicked, this));
146 _fonts_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::fonts_dialog_clicked, this));
147 _appearance_dialog_button->Bind (wxEVT_BUTTON, boost::bind (&TextPanel::appearance_dialog_clicked, this));
150 content_selection_changed ();
157 TextPanel::setup_visibility ()
159 switch (current_type()) {
160 case TextType::OPEN_SUBTITLE:
161 if (_dcp_track_label) {
162 _dcp_track_label->Destroy ();
163 _dcp_track_label = nullptr;
166 _dcp_track->Destroy ();
167 _dcp_track = nullptr;
169 if (!_outline_subtitles) {
170 _outline_subtitles = new CheckBox (this, _("Show subtitle area"));
171 _outline_subtitles->bind(&TextPanel::outline_subtitles_changed, this);
172 _grid->Add (_outline_subtitles, wxGBPosition(_outline_subtitles_row, 0), wxGBSpan(1, 2));
175 _language_label = create_label (this, _("Language"), true);
176 add_label_to_sizer (_grid, _language_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
177 _language_sizer = new wxBoxSizer (wxHORIZONTAL);
178 _language = new LanguageTagWidget (this, _("Language of these subtitles"), boost::none, wxString("en-US-"));
179 _language->Changed.connect (boost::bind(&TextPanel::language_changed, this));
180 _language_sizer->Add (_language->sizer(), 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
181 _language_type = new wxChoice (this, wxID_ANY);
182 /// TRANSLATORS: Main and Additional here are a choice for whether a set of subtitles is in the "main" language of the
183 /// film or an "additional" language.
184 _language_type->Append (_("Main"));
185 _language_type->Append (_("Additional"));
186 _language_type->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::language_is_additional_changed, this));
187 _language_sizer->Add (_language_type, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_CHOICE_TOP_PAD);
188 _grid->Add (_language_sizer, wxGBPosition(_ccap_track_or_language_row, 1), wxGBSpan(1, 2));
189 film_content_changed (TextContentProperty::LANGUAGE);
190 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
193 case TextType::CLOSED_CAPTION:
194 if (_language_label) {
195 _language_label->Destroy ();
196 _language_label = nullptr;
197 _grid->Remove (_language->sizer());
199 _grid->Remove (_language_sizer);
200 _language_sizer = nullptr;
202 _language_type->Destroy ();
203 _language_type = nullptr;
205 if (!_dcp_track_label) {
206 _dcp_track_label = create_label (this, _("CCAP track"), true);
207 add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(_ccap_track_or_language_row, 0));
210 _dcp_track = new wxChoice (this, wxID_ANY);
211 _dcp_track->Bind (wxEVT_CHOICE, boost::bind(&TextPanel::dcp_track_changed, this));
212 _grid->Add (_dcp_track, wxGBPosition(_ccap_track_or_language_row, 1), wxDefaultSpan, wxEXPAND);
213 update_dcp_tracks ();
214 film_content_changed (TextContentProperty::DCP_TRACK);
216 if (_outline_subtitles) {
217 _outline_subtitles->Destroy ();
218 _outline_subtitles = nullptr;
219 clear_outline_subtitles ();
231 TextPanel::add_to_grid ()
235 auto reference_sizer = new wxBoxSizer (wxVERTICAL);
236 reference_sizer->Add (_reference, 0);
237 reference_sizer->Add (_reference_note, 0);
238 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
241 auto use = new wxBoxSizer (wxHORIZONTAL);
242 use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
243 use->Add (_type, 1, wxEXPAND, 0);
244 _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
247 _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
250 _outline_subtitles_row = r;
253 add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
254 auto offset = new wxBoxSizer (wxHORIZONTAL);
255 add_label_to_sizer (offset, _x_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
256 offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
257 offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
259 _grid->Add (offset, wxGBPosition(r, 1));
261 offset = new wxBoxSizer (wxHORIZONTAL);
263 add_label_to_sizer (offset, _y_offset_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
264 offset->Add (_y_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
265 add_label_to_sizer (offset, _y_offset_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
266 _grid->Add (offset, wxGBPosition (r, 1));
269 add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
270 auto scale = new wxBoxSizer (wxHORIZONTAL);
271 add_label_to_sizer (scale, _x_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
272 scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
273 scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
275 _grid->Add (scale, wxGBPosition(r, 1));
277 scale = new wxBoxSizer (wxHORIZONTAL);
279 add_label_to_sizer (scale, _y_scale_label, true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
280 scale->Add (_y_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
281 add_label_to_sizer (scale, _y_scale_pc_label, false, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL);
282 _grid->Add (scale, wxGBPosition (r, 1));
286 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
287 auto s = new wxBoxSizer (wxHORIZONTAL);
288 s->Add (_line_spacing);
289 add_label_to_sizer (s, _line_spacing_pc_label, false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL);
290 _grid->Add (s, wxGBPosition (r, 1));
294 _ccap_track_or_language_row = r;
297 add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
298 _grid->Add (_stream, wxGBPosition (r, 1));
302 auto s = new wxBoxSizer (wxHORIZONTAL);
304 s->Add (_text_view_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
305 s->Add (_fonts_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
306 s->Add (_appearance_dialog_button, 0, wxALL, DCPOMATIC_SIZER_GAP);
308 _grid->Add (s, wxGBPosition(r, 0), wxGBSpan(1, 2));
317 TextPanel::update_dcp_track_selection ()
319 DCPOMATIC_ASSERT (_dcp_track);
321 optional<DCPTextTrack> selected;
323 for (auto i: _parent->selected_text()) {
324 auto t = i->text_of_original_type(_original_type);
326 auto dt = t->dcp_track();
327 if (dt && selected && *dt != *selected) {
329 } else if (!selected) {
336 for (auto i: _parent->film()->closed_caption_tracks()) {
337 if (!many && selected && *selected == i) {
338 _dcp_track->SetSelection (n);
343 if (!selected || many) {
344 _dcp_track->SetSelection (wxNOT_FOUND);
350 TextPanel::update_dcp_tracks ()
352 DCPOMATIC_ASSERT (_dcp_track);
354 _dcp_track->Clear ();
355 for (auto i: _parent->film()->closed_caption_tracks()) {
356 /* XXX: don't display the "magic" track which has empty name and language;
357 this is a nasty hack (see also Film::closed_caption_tracks)
359 if (!i.name.empty() || i.language) {
360 _dcp_track->Append (std_to_wx(i.summary()));
364 if (_parent->film()->closed_caption_tracks().size() < 6) {
365 _dcp_track->Append (_("Add new..."));
368 update_dcp_track_selection ();
373 TextPanel::dcp_track_changed ()
375 optional<DCPTextTrack> track;
377 if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
378 auto d = make_wx<DCPTextTrackDialog>(this);
379 if (d->ShowModal() == wxID_OK) {
383 /* Find the DCPTextTrack that was selected */
384 for (auto i: _parent->film()->closed_caption_tracks()) {
385 if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
392 for (auto i: _parent->selected_text()) {
393 auto t = i->text_of_original_type(_original_type);
394 if (t && t->type() == TextType::CLOSED_CAPTION) {
395 t->set_dcp_track(*track);
400 update_dcp_tracks ();
405 TextPanel::film_changed(FilmProperty property)
407 if (property == FilmProperty::CONTENT || property == FilmProperty::REEL_TYPE || property == FilmProperty::INTEROP) {
408 setup_sensitivity ();
414 TextPanel::film_content_changed (int property)
416 auto fc = _parent->selected_ffmpeg ();
417 auto sc = _parent->selected_text ();
419 shared_ptr<FFmpegContent> fcs;
420 if (fc.size() == 1) {
424 shared_ptr<Content> scs;
425 if (sc.size() == 1) {
429 shared_ptr<TextContent> text;
431 text = scs->text_of_original_type(_original_type);
434 if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
437 for (auto i: fcs->subtitle_streams()) {
438 _stream->Append (std_to_wx(i->name), new wxStringClientData(std_to_wx(i->identifier())));
441 if (fcs->subtitle_stream()) {
442 checked_set (_stream, fcs->subtitle_stream()->identifier ());
444 _stream->SetSelection (wxNOT_FOUND);
447 setup_sensitivity ();
448 clear_outline_subtitles ();
449 } else if (property == TextContentProperty::USE) {
450 checked_set (_use, text ? text->use() : false);
451 setup_sensitivity ();
452 clear_outline_subtitles ();
453 } else if (property == TextContentProperty::TYPE) {
455 switch (text->type()) {
456 case TextType::OPEN_SUBTITLE:
457 _type->SetSelection (0);
459 case TextType::CLOSED_CAPTION:
460 _type->SetSelection (1);
463 DCPOMATIC_ASSERT (false);
466 _type->SetSelection (0);
468 setup_sensitivity ();
470 } else if (property == TextContentProperty::BURN) {
471 checked_set (_burn, text ? text->burn() : false);
472 } else if (property == TextContentProperty::X_OFFSET) {
473 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
474 update_outline_subtitles_in_viewer ();
475 } else if (property == TextContentProperty::Y_OFFSET) {
476 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
477 update_outline_subtitles_in_viewer ();
478 } else if (property == TextContentProperty::X_SCALE) {
479 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
480 clear_outline_subtitles ();
481 } else if (property == TextContentProperty::Y_SCALE) {
482 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
483 clear_outline_subtitles ();
484 } else if (property == TextContentProperty::LINE_SPACING) {
485 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
486 clear_outline_subtitles ();
487 } else if (property == TextContentProperty::DCP_TRACK) {
489 update_dcp_track_selection ();
491 } else if (property == TextContentProperty::LANGUAGE) {
493 _language->set (text ? text->language() : boost::none);
495 } else if (property == TextContentProperty::LANGUAGE_IS_ADDITIONAL) {
496 if (_language_type) {
497 _language_type->SetSelection (text ? (text->language_is_additional() ? 1 : 0) : 0);
499 } else if (property == DCPContentProperty::REFERENCE_TEXT) {
501 auto dcp = dynamic_pointer_cast<DCPContent> (scs);
502 checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
504 checked_set (_reference, false);
507 setup_sensitivity ();
508 } else if (property == DCPContentProperty::TEXTS) {
509 setup_sensitivity ();
510 } else if (property == ContentProperty::TRIM_START) {
511 setup_sensitivity ();
517 TextPanel::use_toggled ()
519 for (auto i: _parent->selected_text()) {
520 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
525 /** @return the text type that is currently selected in the drop-down */
527 TextPanel::current_type () const
529 switch (_type->GetSelection()) {
531 return TextType::OPEN_SUBTITLE;
533 return TextType::CLOSED_CAPTION;
536 return TextType::UNKNOWN;
541 TextPanel::type_changed ()
543 for (auto i: _parent->selected_text()) {
544 i->text_of_original_type(_original_type)->set_type (current_type ());
552 TextPanel::burn_toggled ()
554 for (auto i: _parent->selected_text ()) {
555 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
561 TextPanel::setup_sensitivity ()
564 /* We currently assume that FFmpeg subtitles are bitmapped */
566 /* DCP subs can't have their line spacing changed */
568 auto sel = _parent->selected_text ();
570 /* These are the content types that could include subtitles */
571 auto fc = std::dynamic_pointer_cast<const FFmpegContent>(i);
572 auto sc = std::dynamic_pointer_cast<const StringTextFileContent>(i);
573 auto dc = std::dynamic_pointer_cast<const DCPContent>(i);
574 auto dsc = std::dynamic_pointer_cast<const DCPSubtitleContent>(i);
576 if (!fc->text.empty()) {
580 } else if (dc || dsc) {
584 /* XXX: in the future there could be bitmap subs from DCPs */
589 /* Decide whether we can reference these subs */
591 shared_ptr<DCPContent> dcp;
592 if (sel.size() == 1) {
593 dcp = dynamic_pointer_cast<DCPContent>(sel.front());
597 bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
599 if (why_not.empty()) {
600 cannot = _("Cannot reference this DCP's subtitles or captions.");
602 cannot = _("Cannot reference this DCP's subtitles or captions: ") + std_to_wx(why_not);
604 setup_refer_button (_reference, _reference_note, dcp, can_reference, cannot);
606 bool const reference = _reference->GetValue ();
608 auto const type = current_type ();
612 _type->Append (_("open subtitles"));
613 if (ffmpeg_subs == 0) {
614 _type->Append (_("closed captions"));
618 case TextType::OPEN_SUBTITLE:
619 _type->SetSelection (0);
621 case TextType::CLOSED_CAPTION:
622 if (_type->GetCount() > 1) {
623 _type->SetSelection (1);
630 /* Set up sensitivity */
631 _use->Enable (!reference && any_subs > 0);
632 bool const use = _use->GetValue ();
633 if (_outline_subtitles) {
634 _outline_subtitles->Enable (!_loading_analysis && any_subs && use && type == TextType::OPEN_SUBTITLE);
636 _type->Enable (!reference && any_subs > 0 && use);
637 _burn->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
638 _x_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
639 _y_offset->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
640 _x_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
641 _y_scale->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
642 _line_spacing->Enable (!reference && use && type == TextType::OPEN_SUBTITLE && dcp_subs < any_subs);
643 _stream->Enable (!reference && ffmpeg_subs == 1);
644 /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
645 _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
646 _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TextType::OPEN_SUBTITLE);
647 _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TextType::OPEN_SUBTITLE);
652 TextPanel::stream_changed ()
654 auto fc = _parent->selected_ffmpeg ();
655 if (fc.size() != 1) {
659 auto fcs = fc.front ();
661 auto a = fcs->subtitle_streams ();
663 auto const s = string_client_data (_stream->GetClientObject(_stream->GetSelection()));
664 while (i != a.end() && (*i)->identifier () != s) {
669 fcs->set_subtitle_stream (*i);
675 TextPanel::x_offset_changed ()
677 for (auto i: _parent->selected_text ()) {
678 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
684 TextPanel::y_offset_changed ()
686 for (auto i: _parent->selected_text ()) {
687 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
693 TextPanel::x_scale_changed ()
695 for (auto i: _parent->selected_text ()) {
696 i->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
702 TextPanel::y_scale_changed ()
704 for (auto i: _parent->selected_text ()) {
705 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
711 TextPanel::line_spacing_changed ()
713 for (auto i: _parent->selected_text ()) {
714 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
720 TextPanel::content_selection_changed ()
722 film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
723 film_content_changed (TextContentProperty::USE);
724 film_content_changed (TextContentProperty::BURN);
725 film_content_changed (TextContentProperty::X_OFFSET);
726 film_content_changed (TextContentProperty::Y_OFFSET);
727 film_content_changed (TextContentProperty::X_SCALE);
728 film_content_changed (TextContentProperty::Y_SCALE);
729 film_content_changed (TextContentProperty::LINE_SPACING);
730 film_content_changed (TextContentProperty::FONTS);
731 film_content_changed (TextContentProperty::TYPE);
732 film_content_changed (TextContentProperty::DCP_TRACK);
733 film_content_changed (TextContentProperty::LANGUAGE);
734 film_content_changed (TextContentProperty::LANGUAGE_IS_ADDITIONAL);
735 film_content_changed (DCPContentProperty::REFERENCE_TEXT);
740 TextPanel::text_view_clicked ()
742 auto c = _parent->selected_text ();
743 DCPOMATIC_ASSERT (c.size() == 1);
745 auto decoder = decoder_factory (_parent->film(), c.front(), false, false, shared_ptr<Decoder>());
748 _text_view.reset(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
755 TextPanel::fonts_dialog_clicked ()
757 auto c = _parent->selected_text ();
758 DCPOMATIC_ASSERT (c.size() == 1);
760 _fonts_dialog.reset(this, c.front(), c.front()->text_of_original_type(_original_type));
761 _fonts_dialog->Show ();
766 TextPanel::reference_clicked ()
768 auto c = _parent->selected ();
773 auto d = dynamic_pointer_cast<DCPContent> (c.front ());
778 d->set_reference_text (_original_type, _reference->GetValue ());
783 TextPanel::appearance_dialog_clicked ()
785 auto c = _parent->selected_text ();
786 DCPOMATIC_ASSERT (c.size() == 1);
788 SubtitleAppearanceDialog dialog(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
789 if (dialog.ShowModal() == wxID_OK) {
795 /** The user has clicked on the outline subtitles check box */
797 TextPanel::outline_subtitles_changed ()
799 if (_outline_subtitles->GetValue()) {
800 _analysis_content = _parent->selected_text().front();
801 try_to_load_analysis ();
803 clear_outline_subtitles ();
809 TextPanel::try_to_load_analysis ()
811 if (_loading_analysis) {
815 _loading_analysis = true;
816 ScopeGuard sg = [this]() {
817 _loading_analysis = false;
821 setup_sensitivity ();
824 auto content = _analysis_content.lock ();
829 auto const path = _parent->film()->subtitle_analysis_path(content);
831 if (!dcp::filesystem::exists(path)) {
832 for (auto i: JobManager::instance()->get()) {
833 if (dynamic_pointer_cast<AnalyseSubtitlesJob>(i) && !i->finished()) {
838 JobManager::instance()->analyse_subtitles (
839 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this, _1)
845 _analysis.reset (new SubtitleAnalysis(path));
846 } catch (OldFormatError& e) {
847 /* An old analysis file: recreate it */
848 JobManager::instance()->analyse_subtitles (
849 _parent->film(), content, _analysis_finished_connection, bind(&TextPanel::analysis_finished, this, _1)
854 update_outline_subtitles_in_viewer ();
859 TextPanel::update_outline_subtitles_in_viewer ()
861 auto& fv = _parent->film_viewer();
864 auto rect = _analysis->bounding_box ();
866 auto content = _analysis_content.lock ();
867 DCPOMATIC_ASSERT (content);
868 rect->x += content->text.front()->x_offset() - _analysis->analysis_x_offset();
869 rect->y += content->text.front()->y_offset() - _analysis->analysis_y_offset();
871 fv.set_outline_subtitles(rect);
873 fv.set_outline_subtitles({});
878 /** Remove any current subtitle outline display */
880 TextPanel::clear_outline_subtitles ()
883 update_outline_subtitles_in_viewer ();
884 if (_outline_subtitles) {
885 _outline_subtitles->SetValue (false);
891 TextPanel::analysis_finished(Job::Result result)
893 _loading_analysis = false;
895 auto content = _analysis_content.lock ();
896 if (!content || result == Job::Result::RESULT_CANCELLED) {
897 clear_outline_subtitles();
902 if (!dcp::filesystem::exists(_parent->film()->subtitle_analysis_path(content))) {
903 /* We analysed and still nothing showed up, so maybe it failed. Give up. */
904 error_dialog (_parent->window(), _("Could not analyse subtitles."));
905 clear_outline_subtitles ();
906 setup_sensitivity ();
910 try_to_load_analysis ();
915 TextPanel::language_changed ()
917 for (auto i: _parent->selected_text()) {
918 auto t = i->text_of_original_type(_original_type);
920 t->set_language (_language->get());
927 TextPanel::language_is_additional_changed ()
929 for (auto i: _parent->selected_text()) {
930 auto t = i->text_of_original_type(_original_type);
932 t->set_language_is_additional (_language_type->GetSelection() == 1);