2 Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "text_subtitle_decoder.h"
21 #include "text_subtitle_content.h"
22 #include "subtitle_content.h"
23 #include <dcp/subtitle_string.h>
24 #include <boost/foreach.hpp>
32 using boost::shared_ptr;
33 using boost::optional;
34 using boost::dynamic_pointer_cast;
36 TextSubtitleDecoder::TextSubtitleDecoder (shared_ptr<const TextSubtitleContent> content)
37 : TextSubtitle (content)
44 bind (&TextSubtitleDecoder::image_subtitles_during, this, _1, _2),
45 bind (&TextSubtitleDecoder::text_subtitles_during, this, _1, _2)
51 TextSubtitleDecoder::seek (ContentTime time, bool accurate)
53 subtitle->seek (time, accurate);
56 while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) {
62 TextSubtitleDecoder::pass (PassReason, bool)
64 if (_next >= _subtitles.size ()) {
68 /* XXX: we are ignoring positioning specified in the file */
70 list<dcp::SubtitleString> out;
72 /* Highest line index in this subtitle */
74 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
75 DCPOMATIC_ASSERT (i.vertical_position.reference && i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE);
76 DCPOMATIC_ASSERT (i.vertical_position.line);
77 highest = max (highest, i.vertical_position.line.get());
80 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
81 BOOST_FOREACH (sub::Block j, i.blocks) {
84 TextSubtitleContent::font_id,
87 /* force the colour to whatever is configured */
88 subtitle->content()->colour(),
89 j.font_size.points (72 * 11),
91 dcp::Time (_subtitles[_next].from.all_as_seconds(), 1000),
92 dcp::Time (_subtitles[_next].to.all_as_seconds(), 1000),
95 /* This 1.015 is an arbitrary value to lift the bottom sub off the bottom
96 of the screen a bit to a pleasing degree.
98 1.015 - ((1 + highest - i.vertical_position.line.get()) * 1.5 / 22),
102 subtitle->content()->outline() ? dcp::BORDER : dcp::NONE,
103 subtitle->content()->outline_colour(),
111 subtitle->give_text (content_time_period (_subtitles[_next]), out);
117 list<ContentTimePeriod>
118 TextSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
120 return list<ContentTimePeriod> ();
123 list<ContentTimePeriod>
124 TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
126 /* XXX: inefficient */
128 list<ContentTimePeriod> d;
130 for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
131 ContentTimePeriod t = content_time_period (*i);
132 if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) {
141 TextSubtitleDecoder::content_time_period (sub::Subtitle s) const
143 return ContentTimePeriod (
144 ContentTime::from_seconds (s.from.all_as_seconds()),
145 ContentTime::from_seconds (s.to.all_as_seconds())