/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
files in the program, then also delete it here.
*/
+
+/** @file src/subtitle_string.cc
+ * @brief SubtitleString class
+ */
+
+
#include "subtitle_string.h"
#include "xml.h"
#include <cmath>
-using std::string;
+
+using std::max;
+using std::min;
using std::ostream;
+using std::string;
using boost::optional;
using namespace dcp;
-/** @param v_position Vertical position as a fraction of the screen height (between 0 and 1) from v_align */
+
SubtitleString::SubtitleString (
optional<string> font,
bool italic,
Effect effect,
Colour effect_colour,
Time fade_up_time,
- Time fade_down_time
+ Time fade_down_time,
+ float space_before
)
: Subtitle (in, out, h_position, h_align, v_position, v_align, fade_up_time, fade_down_time)
, _font (font)
, _text (text)
, _effect (effect)
, _effect_colour (effect_colour)
+ , _space_before (space_before)
{
-
+ _aspect_adjust = max(min(_aspect_adjust, 4.0f), 0.25f);
}
+
int
SubtitleString::size_in_pixels (int screen_height) const
{
return _size * screen_height / (11 * 72);
}
+
bool
dcp::operator== (SubtitleString const & a, SubtitleString const & b)
{
a.effect() == b.effect() &&
a.effect_colour() == b.effect_colour() &&
a.fade_up_time() == b.fade_up_time() &&
- a.fade_down_time() == b.fade_down_time()
+ a.fade_down_time() == b.fade_down_time() &&
+ fabs (a.space_before() - b.space_before()) < SPACE_BEFORE_EPSILON
);
}
+
+bool
+dcp::operator!= (SubtitleString const & a, SubtitleString const & b)
+{
+ return !(a == b);
+}
+
+
ostream&
dcp::operator<< (ostream& s, SubtitleString const & sub)
{
s << "underlined, ";
}
- s << "size " << sub.size() << ", aspect " << sub.aspect_adjust() << ", colour " << sub.colour()
+ s << "size " << sub.size() << ", aspect " << sub.aspect_adjust()
+ << ", colour (" << sub.colour().r << ", " << sub.colour().g << ", " << sub.colour().b << ")"
<< ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align())
<< ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
<< ", direction " << ((int) sub.direction())
- << ", effect " << ((int) sub.effect()) << ", effect colour " << sub.effect_colour();
+ << ", effect " << ((int) sub.effect())
+ << ", effect colour (" << sub.effect_colour().r << ", " << sub.effect_colour().g << ", " << sub.effect_colour().b << ")"
+ << ", space before " << sub.space_before();
return s;
}