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 : SubtitleDecoder (content->subtitle)
38 , TextSubtitle (content)
45 TextSubtitleDecoder::seek (ContentTime time, bool accurate)
47 SubtitleDecoder::seek (time, accurate);
50 while (_next < _subtitles.size() && ContentTime::from_seconds (_subtitles[_next].from.all_as_seconds ()) < time) {
56 TextSubtitleDecoder::pass (PassReason, bool)
58 if (_next >= _subtitles.size ()) {
62 /* XXX: we are ignoring positioning specified in the file */
64 list<dcp::SubtitleString> out;
66 /* Highest line index in this subtitle */
68 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
69 DCPOMATIC_ASSERT (i.vertical_position.reference && i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE);
70 DCPOMATIC_ASSERT (i.vertical_position.line);
71 highest = max (highest, i.vertical_position.line.get());
74 BOOST_FOREACH (sub::Line i, _subtitles[_next].lines) {
75 BOOST_FOREACH (sub::Block j, i.blocks) {
78 TextSubtitleContent::font_id,
81 /* force the colour to whatever is configured */
82 _subtitle_content->colour(),
83 j.font_size.points (72 * 11),
85 dcp::Time (_subtitles[_next].from.all_as_seconds(), 1000),
86 dcp::Time (_subtitles[_next].to.all_as_seconds(), 1000),
89 /* This 1.015 is an arbitrary value to lift the bottom sub off the bottom
90 of the screen a bit to a pleasing degree.
92 1.015 - ((1 + highest - i.vertical_position.line.get()) * 1.5 / 22),
96 _subtitle_content->outline() ? dcp::BORDER : dcp::NONE,
97 _subtitle_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())