2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 /** @file src/subtitle_string.cc
36 * @brief SubtitleString class
40 #include "compose.hpp"
41 #include "subtitle_string.h"
46 using std::dynamic_pointer_cast;
50 using std::shared_ptr;
52 using boost::optional;
56 SubtitleString::SubtitleString (
57 optional<string> font,
79 : Subtitle(in, out, h_position, h_align, v_position, v_align, z_position, fade_up_time, fade_down_time)
83 , _underline (underline)
86 , _aspect_adjust (aspect_adjust)
87 , _direction (direction)
90 , _effect_colour (effect_colour)
91 , _space_before (space_before)
93 _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f);
98 SubtitleString::size_in_pixels (int screen_height) const
100 /* Size in the subtitle file is given in points as if the screen
101 height is 11 inches, so a 72pt font would be 1/11th of the screen
105 return _size * static_cast<float>(screen_height) / (11.0f * 72.0f);
110 dcp::operator== (SubtitleString const & a, SubtitleString const & b)
113 a.font() == b.font() &&
114 a.italic() == b.italic() &&
115 a.bold() == b.bold() &&
116 a.underline() == b.underline() &&
117 a.colour() == b.colour() &&
118 a.size() == b.size() &&
119 fabs (a.aspect_adjust() - b.aspect_adjust()) < ASPECT_ADJUST_EPSILON &&
121 a.out() == b.out() &&
122 a.h_position() == b.h_position() &&
123 a.h_align() == b.h_align() &&
124 a.v_position() == b.v_position() &&
125 a.v_align() == b.v_align() &&
126 a.z_position() == b.z_position() &&
127 a.direction() == b.direction() &&
128 a.text() == b.text() &&
129 a.effect() == b.effect() &&
130 a.effect_colour() == b.effect_colour() &&
131 a.fade_up_time() == b.fade_up_time() &&
132 a.fade_down_time() == b.fade_down_time() &&
133 fabs (a.space_before() - b.space_before()) < SPACE_BEFORE_EPSILON
139 dcp::operator!= (SubtitleString const & a, SubtitleString const & b)
146 dcp::operator<< (ostream& s, SubtitleString const & sub)
148 s << "\n`" << sub.text() << "' from " << sub.in() << " to " << sub.out() << ";\n"
149 << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n"
150 << "font " << sub.font().get_value_or ("[default]") << ", ";
164 if (sub.underline()) {
168 s << "size " << sub.size() << ", aspect " << sub.aspect_adjust()
169 << ", colour (" << sub.colour().r << ", " << sub.colour().g << ", " << sub.colour().b << ")"
170 << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align())
171 << ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
172 << ", zpos " << sub.z_position()
173 << ", direction " << ((int) sub.direction())
174 << ", effect " << ((int) sub.effect())
175 << ", effect colour (" << sub.effect_colour().r << ", " << sub.effect_colour().g << ", " << sub.effect_colour().b << ")"
176 << ", space before " << sub.space_before();
183 SubtitleString::equals(shared_ptr<const Subtitle> other_sub, EqualityOptions const& options, NoteHandler note) const
185 if (!Subtitle::equals(other_sub, options, note)) {
189 auto other = dynamic_pointer_cast<const SubtitleString>(other_sub);
191 note(NoteType::ERROR, "Subtitle types differ: string vs image");
197 if (_font != other->_font) {
198 note(NoteType::ERROR, String::compose("subtitle font differs: %1 vs %2", _font.get_value_or("[none]"), other->_font.get_value_or("[none]")));
202 if (_italic != other->_italic) {
203 note(NoteType::ERROR, String::compose("subtitle italic flag differs: %1 vs %2", _italic ? "true" : "false", other->_italic ? "true" : "false"));
207 if (_bold != other->_bold) {
208 note(NoteType::ERROR, String::compose("subtitle bold flag differs: %1 vs %2", _bold ? "true" : "false", other->_bold ? "true" : "false"));
212 if (_underline != other->_underline) {
213 note(NoteType::ERROR, String::compose("subtitle underline flag differs: %1 vs %2", _underline ? "true" : "false", other->_underline ? "true" : "false"));
217 if (_colour != other->_colour) {
218 note(NoteType::ERROR, String::compose("subtitle colour differs: %1 vs %2", _colour.to_rgb_string(), other->_colour.to_rgb_string()));
222 if (_size != other->_size) {
223 note(NoteType::ERROR, String::compose("subtitle size differs: %1 vs %2", _size, other->_size));
227 if (_aspect_adjust != other->_aspect_adjust) {
228 note(NoteType::ERROR, String::compose("subtitle aspect_adjust differs: %1 vs %2", _aspect_adjust, other->_aspect_adjust));
232 if (_direction != other->_direction) {
233 note(NoteType::ERROR, String::compose("subtitle direction differs: %1 vs %2", direction_to_string(_direction), direction_to_string(other->_direction)));
237 if (_text != other->_text) {
238 note(NoteType::ERROR, String::compose("subtitle text differs: %1 vs %2", _text, other->_text));
242 if (_effect != other->_effect) {
243 note(NoteType::ERROR, String::compose("subtitle effect differs: %1 vs %2", effect_to_string(_effect), effect_to_string(other->_effect)));
247 if (_effect_colour != other->_effect_colour) {
248 note(NoteType::ERROR, String::compose("subtitle effect colour differs: %1 vs %2", _effect_colour.to_rgb_string(), other->_effect_colour.to_rgb_string()));
252 if (_space_before != other->_space_before) {
253 note(NoteType::ERROR, String::compose("subtitle space before differs: %1 vs %2", _space_before, other->_space_before));