In-line run of subs_in_out so that it gets the environment more easily.
[libdcp.git] / src / subtitle.cc
1 /*
2     Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
18
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
23     including the two.
24
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.
32 */
33
34
35 /** @file  src/subtitle.cc
36  *  @brief Subtitle class
37  */
38
39
40 #include "compose.hpp"
41 #include "dcp_time.h"
42 #include "equality_options.h"
43 #include "subtitle.h"
44
45
46 using std::shared_ptr;
47 using namespace dcp;
48
49
50 /** @param v_position Vertical position as a fraction of the screen height (between 0 and 1) from v_align */
51 Subtitle::Subtitle (
52         Time in,
53         Time out,
54         float h_position,
55         HAlign h_align,
56         float v_position,
57         VAlign v_align,
58         float z_position,
59         Time fade_up_time,
60         Time fade_down_time
61         )
62         : _in (in)
63         , _out (out)
64         , _h_position (h_position)
65         , _h_align (h_align)
66         , _v_position (v_position)
67         , _v_align (v_align)
68         , _z_position(z_position)
69         , _fade_up_time (fade_up_time)
70         , _fade_down_time (fade_down_time)
71 {
72
73 }
74
75
76 bool
77 Subtitle::equals(shared_ptr<const Subtitle> other, EqualityOptions const& options, NoteHandler note) const
78 {
79         bool same = true;
80
81         if (in() != other->in()) {
82                 note(NoteType::ERROR, "subtitle in times differ");
83                 same = false;
84         }
85
86         if (out() != other->out()) {
87                 note(NoteType::ERROR, "subtitle out times differ");
88                 same = false;
89         }
90
91         if (h_position() != other->h_position()) {
92                 note(NoteType::ERROR, "subtitle horizontal positions differ");
93                 same = false;
94         }
95
96         if (h_align() != other->h_align()) {
97                 note(NoteType::ERROR, "subtitle horizontal alignments differ");
98                 same = false;
99         }
100
101         auto const vpos = std::abs(v_position() - other->v_position());
102         if (vpos > options.max_subtitle_vertical_position_error)  {
103                 note(
104                         NoteType::ERROR,
105                         String::compose("subtitle vertical positions differ by %1 (more than the allowed difference of %2)", vpos, options.max_subtitle_vertical_position_error)
106                     );
107                 same = false;
108         }
109
110         if (v_align() != other->v_align()) {
111                 note(NoteType::ERROR, "subtitle vertical alignments differ");
112                 same = false;
113         }
114
115         if (z_position() != other->z_position()) {
116                 note(NoteType::ERROR, "subtitle Z positions differ");
117                 same = false;
118         }
119
120         if (fade_up_time() != other->fade_up_time()) {
121                 note(NoteType::ERROR, "subtitle fade-up times differ");
122                 same = false;
123         }
124
125         if (fade_down_time() != other->fade_down_time()) {
126                 note(NoteType::ERROR, "subtitle fade-down times differ");
127                 same = false;
128         }
129
130         return same;
131 }