40 #include "compose.hpp"
46 using std::dynamic_pointer_cast;
50 using std::shared_ptr;
53 using boost::optional;
58 optional<string> font,
81 :
Text(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 TextString::size_in_pixels(
int screen_height)
const
108 return _size *
static_cast<float>(screen_height) / (11.0f * 72.0f);
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() &&
125 a.h_position() == b.h_position() &&
126 a.h_align() == b.h_align() &&
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() &&
137 a.rubies() == b.rubies()
150 dcp::operator<<(ostream& s,
TextString 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 TextString::equals(shared_ptr<const Text> other_sub,
EqualityOptions const& options, NoteHandler note)
const
193 if (!Text::equals(other_sub, options, note)) {
197 auto other = dynamic_pointer_cast<const TextString>(other_sub);
199 note(NoteType::ERROR,
"Text types differ: string vs image");
205 if (
_font != other->_font) {
206 note(NoteType::ERROR, String::compose(
"text 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(
"text italic flag differs: %1 vs %2",
_italic ?
"true" :
"false", other->_italic ?
"true" :
"false"));
215 if (
_bold != other->_bold) {
216 note(NoteType::ERROR, String::compose(
"text bold flag differs: %1 vs %2",
_bold ?
"true" :
"false", other->_bold ?
"true" :
"false"));
221 note(NoteType::ERROR, String::compose(
"text underline flag differs: %1 vs %2",
_underline ?
"true" :
"false", other->_underline ?
"true" :
"false"));
225 if (
_colour != other->_colour) {
226 note(NoteType::ERROR, String::compose(
"text 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(
"text size differs: %1 vs %2",
_size, other->_size));
235 if (_aspect_adjust != other->_aspect_adjust) {
236 note(NoteType::ERROR, String::compose(
"text aspect_adjust differs: %1 vs %2", _aspect_adjust, other->_aspect_adjust));
240 if (_direction != other->_direction) {
241 note(NoteType::ERROR, String::compose(
"text 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(
"text text differs: %1 vs %2", _text, other->_text));
250 if (_effect != other->_effect) {
251 note(NoteType::ERROR, String::compose(
"text 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(
"text 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(
"text space before differs: %1 vs %2", _space_before, other->_space_before));
265 if (_rubies != other->_rubies) {
266 note(NoteType::ERROR,
"rubies differ");
int g
green component, from 0 to 255
int b
blue component, from 0 to 255
int r
red component, from 0 to 255
std::string to_rgb_string() const
A class to describe what "equality" means for a particular test.
A single line of subtitle text with all the associated attributes.
TextString(boost::optional< std::string > font, bool italic, bool bold, bool underline, Colour colour, int size, float aspect_adjust, Time in, Time out, float h_position, HAlign h_align, float v_position, VAlign v_align, float z_position, Direction direction, std::string text, Effect effect, Colour effect_colour, Time fade_up_time, Time fade_down_time, float space_before, std::vector< Ruby > rubies)
boost::optional< std::string > _font
float aspect_adjust() const
boost::optional< std::string > font() const
A representation of time within a DCP.
Namespace for everything in libdcp.
constexpr float SPACE_BEFORE_EPSILON
constexpr float ASPECT_ADJUST_EPSILON
Helpers for XML reading with libcxml.