+
+shared_ptr<dcp::SubtitleAsset>
+ReelWriter::empty_text_asset (TextType type, optional<DCPTextTrack> track, bool with_dummy) const
+{
+ shared_ptr<dcp::SubtitleAsset> asset;
+
+ auto lang = film()->subtitle_languages();
+ if (film()->interop()) {
+ auto s = make_shared<dcp::InteropSubtitleAsset>();
+ s->set_movie_title (film()->name());
+ if (type == TextType::OPEN_SUBTITLE) {
+ s->set_language (lang.first ? lang.first->to_string() : "Unknown");
+ } else if (track->language) {
+ s->set_language (track->language->to_string());
+ }
+ s->set_reel_number (raw_convert<string> (_reel_index + 1));
+ asset = s;
+ } else {
+ auto s = make_shared<dcp::SMPTESubtitleAsset>();
+ s->set_content_title_text (film()->name());
+ s->set_metadata (mxf_metadata());
+ if (type == TextType::OPEN_SUBTITLE && lang.first) {
+ s->set_language (*lang.first);
+ } else if (track && track->language) {
+ s->set_language (dcp::LanguageTag(track->language->to_string()));
+ }
+ s->set_edit_rate (dcp::Fraction (film()->video_frame_rate(), 1));
+ s->set_reel_number (_reel_index + 1);
+ s->set_time_code_rate (film()->video_frame_rate());
+ s->set_start_time (dcp::Time ());
+ if (film()->encrypted()) {
+ s->set_key (film()->key());
+ }
+ asset = s;
+ }
+
+ if (with_dummy) {
+ asset->add(
+ std::make_shared<dcp::SubtitleString>(
+ optional<std::string>(),
+ false,
+ false,
+ false,
+ dcp::Colour(),
+ 42,
+ 1.0,
+ dcp::Time(0, 0, 0, 0, 24),
+ dcp::Time(0, 0, 1, 0, 24),
+ 0.5,
+ dcp::HAlign::CENTER,
+ 0.5,
+ dcp::VAlign::CENTER,
+ 0,
+ dcp::Direction::LTR,
+ " ",
+ dcp::Effect::NONE,
+ dcp::Colour(),
+ dcp::Time(),
+ dcp::Time(),
+ 0
+ )
+ );
+ }
+
+ return asset;
+}
+
+
+float
+ReelWriter::convert_vertical_position(StringText const& subtitle, dcp::SubtitleStandard to) const
+{
+ if (dcp::uses_baseline(subtitle.valign_standard) == dcp::uses_baseline(to)) {
+ /* The from and to standards use the same alignment reference */
+ return subtitle.v_position();
+ }
+
+ auto const baseline_to_bottom = _font_metrics.baseline_to_bottom(subtitle);
+ auto const height = _font_metrics.height(subtitle);
+
+ float correction = 0;
+ switch (subtitle.v_align()) {
+ case dcp::VAlign::TOP:
+ correction = height - baseline_to_bottom;
+ break;
+ case dcp::VAlign::CENTER:
+ correction = (height / 2) - baseline_to_bottom;
+ break;
+ case dcp::VAlign::BOTTOM:
+ correction = baseline_to_bottom;
+ break;
+ }
+
+ return subtitle.v_position() + (dcp::uses_bounding_box(subtitle.valign_standard) ? correction : -correction);
+}
+
+