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 <dcp/subtitle_string.h>
23 #include <boost/foreach.hpp>
31 using boost::shared_ptr;
32 using boost::optional;
33 using boost::dynamic_pointer_cast;
35 TextSubtitleDecoder::TextSubtitleDecoder (shared_ptr<const TextSubtitleContent> content)
36 : SubtitleDecoder (content)
37 , TextSubtitle (content)
44 TextSubtitleDecoder::seek (ContentTime time, bool accurate)
46 SubtitleDecoder::seek (time, accurate);
49 while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) {
55 TextSubtitleDecoder::pass (PassReason, bool)
57 if (_next >= _subtitles.size ()) {
61 /* XXX: we are ignoring positioning specified in the file */
63 shared_ptr<const TextSubtitleContent> content = dynamic_pointer_cast<const TextSubtitleContent> (_subtitle_content);
64 DCPOMATIC_ASSERT (content);
66 list<dcp::SubtitleString> out;
68 /* Highest line index in this subtitle */
70 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
71 DCPOMATIC_ASSERT (i.vertical_position.reference && i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE);
72 DCPOMATIC_ASSERT (i.vertical_position.line);
73 highest = max (highest, i.vertical_position.line.get());
76 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
77 BOOST_FOREACH (sub::Block j, i.blocks) {
80 TextSubtitleContent::font_id,
82 /* force the colour to whatever is configured */
84 j.font_size.points (72 * 11),
86 dcp::Time (_subtitles[_next].from.all_as_seconds(), 1000),
87 dcp::Time (_subtitles[_next].to.all_as_seconds(), 1000),
90 /* This 1.015 is an arbitrary value to lift the bottom sub off the bottom
91 of the screen a bit to a pleasing degree.
93 1.015 - ((1 + highest - i.vertical_position.line.get()) * 1.5 / 22),
96 content->outline() ? dcp::BORDER : dcp::NONE,
97 content->outline_colour(),
105 text_subtitle (content_time_period (_subtitles[_next]), out);
111 list<ContentTimePeriod>
112 TextSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
114 return list<ContentTimePeriod> ();
117 list<ContentTimePeriod>
118 TextSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
120 /* XXX: inefficient */
122 list<ContentTimePeriod> d;
124 for (vector<sub::Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
125 ContentTimePeriod t = content_time_period (*i);
126 if ((starting && p.contains (t.from)) || (!starting && p.overlaps (t))) {
135 TextSubtitleDecoder::content_time_period (sub::Subtitle s) const
137 return ContentTimePeriod (
138 ContentTime::from_seconds (s.from.all_as_seconds()),
139 ContentTime::from_seconds (s.to.all_as_seconds())