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;
53 using boost::optional;
57 SubtitleString::SubtitleString (
58 optional<string> font,
81 : Subtitle(in, out, h_position, h_align, v_position, v_align, z_position, fade_up_time, fade_down_time)
85 , _underline (underline)
88 , _aspect_adjust (aspect_adjust)
89 , _direction (direction)
92 , _effect_colour (effect_colour)
93 , _space_before (space_before)
96 _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f);
101 SubtitleString::size_in_pixels (int screen_height) const
103 /* Size in the subtitle file is given in points as if the screen
104 height is 11 inches, so a 72pt font would be 1/11th of the screen
108 return _size * static_cast<float>(screen_height) / (11.0f * 72.0f);
113 dcp::operator== (SubtitleString const & a, SubtitleString const & b)
116 a.font() == b.font() &&
117 a.italic() == b.italic() &&
118 a.bold() == b.bold() &&
119 a.underline() == b.underline() &&
120 a.colour() == b.colour() &&
121 a.size() == b.size() &&
122 fabs (a.aspect_adjust() - b.aspect_adjust()) < ASPECT_ADJUST_EPSILON &&
124 a.out() == b.out() &&
125 a.h_position() == b.h_position() &&
126 a.h_align() == b.h_align() &&
127 a.v_position() == b.v_position() &&
128 a.v_align() == b.v_align() &&
129 a.z_position() == b.z_position() &&
130 a.direction() == b.direction() &&
131 a.text() == b.text() &&
132 a.effect() == b.effect() &&
133 a.effect_colour() == b.effect_colour() &&
134 a.fade_up_time() == b.fade_up_time() &&
135 a.fade_down_time() == b.fade_down_time() &&
136 fabs (a.space_before() - b.space_before()) < SPACE_BEFORE_EPSILON &&
137 a.rubies() == b.rubies()
143 dcp::operator!= (SubtitleString const & a, SubtitleString const & b)
150 dcp::operator<< (ostream& s, SubtitleString const & sub)
152 s << "\n`" << sub.text() << "' from " << sub.in() << " to " << sub.out() << ";\n"
153 << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n"
154 << "font " << sub.font().get_value_or ("[default]") << ", ";
168 if (sub.underline()) {
172 s << "size " << sub.size() << ", aspect " << sub.aspect_adjust()
173 << ", colour (" << sub.colour().r << ", " << sub.colour().g << ", " << sub.colour().b << ")"
174 << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align())
175 << ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
176 << ", zpos " << sub.z_position()
177 << ", direction " << ((int) sub.direction())
178 << ", effect " << ((int) sub.effect())
179 << ", effect colour (" << sub.effect_colour().r << ", " << sub.effect_colour().g << ", " << sub.effect_colour().b << ")"
180 << ", space before " << sub.space_before();
182 for (auto ruby: sub.rubies()) {
183 s << ", ruby " << ruby.base << " " << ruby.annotation;
191 SubtitleString::equals(shared_ptr<const Subtitle> other_sub, EqualityOptions const& options, NoteHandler note) const
193 if (!Subtitle::equals(other_sub, options, note)) {
197 auto other = dynamic_pointer_cast<const SubtitleString>(other_sub);
199 note(NoteType::ERROR, "Subtitle types differ: string vs image");
205 if (_font != other->_font) {
206 note(NoteType::ERROR, String::compose("subtitle font differs: %1 vs %2", _font.get_value_or("[none]"), other->_font.get_value_or("[none]")));
210 if (_italic != other->_italic) {
211 note(NoteType::ERROR, String::compose("subtitle italic flag differs: %1 vs %2", _italic ? "true" : "false", other->_italic ? "true" : "false"));
215 if (_bold != other->_bold) {
216 note(NoteType::ERROR, String::compose("subtitle bold flag differs: %1 vs %2", _bold ? "true" : "false", other->_bold ? "true" : "false"));
220 if (_underline != other->_underline) {
221 note(NoteType::ERROR, String::compose("subtitle underline flag differs: %1 vs %2", _underline ? "true" : "false", other->_underline ? "true" : "false"));
225 if (_colour != other->_colour) {
226 note(NoteType::ERROR, String::compose("subtitle colour differs: %1 vs %2", _colour.to_rgb_string(), other->_colour.to_rgb_string()));
230 if (_size != other->_size) {
231 note(NoteType::ERROR, String::compose("subtitle size differs: %1 vs %2", _size, other->_size));
235 if (_aspect_adjust != other->_aspect_adjust) {
236 note(NoteType::ERROR, String::compose("subtitle aspect_adjust differs: %1 vs %2", _aspect_adjust, other->_aspect_adjust));
240 if (_direction != other->_direction) {
241 note(NoteType::ERROR, String::compose("subtitle direction differs: %1 vs %2", direction_to_string(_direction), direction_to_string(other->_direction)));
245 if (_text != other->_text) {
246 note(NoteType::ERROR, String::compose("subtitle text differs: %1 vs %2", _text, other->_text));
250 if (_effect != other->_effect) {
251 note(NoteType::ERROR, String::compose("subtitle effect differs: %1 vs %2", effect_to_string(_effect), effect_to_string(other->_effect)));
255 if (_effect_colour != other->_effect_colour) {
256 note(NoteType::ERROR, String::compose("subtitle effect colour differs: %1 vs %2", _effect_colour.to_rgb_string(), other->_effect_colour.to_rgb_string()));
260 if (_space_before != other->_space_before) {
261 note(NoteType::ERROR, String::compose("subtitle space before differs: %1 vs %2", _space_before, other->_space_before));
265 if (_rubies != other->_rubies) {
266 note(NoteType::ERROR, "rubies differ");