- BOOST_FOREACH (SubtitleString i, subs.text) {
- i.set_in (i.in() - dcp::Time (_period.from.seconds(), i.in().tcr));
- i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr));
- _subtitle_asset->add (i);
+ return asset;
+}
+
+
+void
+ReelWriter::write (PlayerText subs, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period)
+{
+ shared_ptr<dcp::SubtitleAsset> asset;
+
+ switch (type) {
+ case TextType::OPEN_SUBTITLE:
+ asset = _subtitle_asset;
+ break;
+ case TextType::CLOSED_CAPTION:
+ DCPOMATIC_ASSERT (track);
+ asset = _closed_caption_assets[*track];
+ break;
+ default:
+ DCPOMATIC_ASSERT (false);
+ }
+
+ if (!asset) {
+ asset = empty_text_asset (type, track, false);
+ }
+
+ switch (type) {
+ case TextType::OPEN_SUBTITLE:
+ _subtitle_asset = asset;
+ break;
+ case TextType::CLOSED_CAPTION:
+ DCPOMATIC_ASSERT (track);
+ _closed_caption_assets[*track] = asset;
+ break;
+ default:
+ DCPOMATIC_ASSERT (false);
+ }
+
+ /* timecode rate for subtitles we emit; we might as well stick to ms accuracy here, I think */
+ auto const tcr = 1000;
+
+ for (auto i: subs.string) {
+ i.set_in (dcp::Time(period.from.seconds() - _period.from.seconds(), tcr));
+ i.set_out (dcp::Time(period.to.seconds() - _period.from.seconds(), tcr));
+ asset->add (make_shared<dcp::SubtitleString>(i));
+ }
+
+ for (auto i: subs.bitmap) {
+ asset->add (
+ make_shared<dcp::SubtitleImage>(
+ i.image->as_png(),
+ dcp::Time(period.from.seconds() - _period.from.seconds(), tcr),
+ dcp::Time(period.to.seconds() - _period.from.seconds(), tcr),
+ i.rectangle.x, dcp::HAlign::LEFT, i.rectangle.y, dcp::VAlign::TOP,
+ dcp::Time(), dcp::Time()
+ )
+ );