using std::cout;
using std::string;
using std::min;
+using std::max;
using boost::shared_ptr;
using boost::optional;
using boost::function;
+using namespace dcpomatic;
TextDecoder::TextDecoder (
Decoder* parent,
shared_ptr<const TextContent> c,
- shared_ptr<Log> log,
ContentTime first
)
- : DecoderPart (parent, log)
+ : DecoderPart (parent)
, _content (c)
, _position (first)
{
* of the video frame)
*/
void
-TextDecoder::emit_image_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
+TextDecoder::emit_bitmap_start (ContentTime from, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
{
- ImageStart (ContentImageSubtitle (from, image, rect));
+ BitmapStart (ContentBitmapText (from, image, rect));
_position = from;
}
void
-TextDecoder::emit_text_start (ContentTime from, list<dcp::SubtitleString> s)
+TextDecoder::emit_plain_start (ContentTime from, list<dcp::SubtitleString> s)
{
BOOST_FOREACH (dcp::SubtitleString& i, s) {
/* We must escape < and > in strings, otherwise they might confuse our subtitle
}
}
- TextStart (ContentTextSubtitle (from, s));
+ PlainStart (ContentStringText (from, s));
_position = from;
}
void
-TextDecoder::emit_text_start (ContentTime from, sub::Subtitle const & subtitle)
+TextDecoder::emit_plain_start (ContentTime from, sub::Subtitle const & subtitle)
{
/* See if our next subtitle needs to be vertically placed on screen by us */
bool needs_placement = false;
optional<int> bottom_line;
BOOST_FOREACH (sub::Line i, subtitle.lines) {
- if (!i.vertical_position.reference || i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE) {
+ if (!i.vertical_position.reference || (i.vertical_position.line && !i.vertical_position.lines) || i.vertical_position.reference.get() == sub::TOP_OF_SUBTITLE) {
needs_placement = true;
- DCPOMATIC_ASSERT (i.vertical_position.line);
if (!bottom_line || bottom_line.get() < i.vertical_position.line.get()) {
bottom_line = i.vertical_position.line.get();
}
v_align = dcp::VALIGN_TOP;
} else {
- DCPOMATIC_ASSERT (i.vertical_position.proportional);
DCPOMATIC_ASSERT (i.vertical_position.reference);
- v_position = i.vertical_position.proportional.get();
+ if (i.vertical_position.proportional) {
+ v_position = i.vertical_position.proportional.get();
+ } else {
+ DCPOMATIC_ASSERT (i.vertical_position.line);
+ DCPOMATIC_ASSERT (i.vertical_position.lines);
+ v_position = float(*i.vertical_position.line) / *i.vertical_position.lines;
+ }
if (lowest_proportional) {
/* Adjust line spacing */
}
dcp::HAlign h_align;
+ float h_position = i.horizontal_position.proportional;
switch (i.horizontal_position.reference) {
case sub::LEFT_OF_SCREEN:
h_align = dcp::HALIGN_LEFT;
+ h_position = max(h_position, 0.05f);
break;
case sub::HORIZONTAL_CENTRE_OF_SCREEN:
h_align = dcp::HALIGN_CENTER;
break;
case sub::RIGHT_OF_SCREEN:
h_align = dcp::HALIGN_RIGHT;
+ h_position = max(h_position, 0.05f);
break;
default:
h_align = dcp::HALIGN_CENTER;
/* The idea here (rightly or wrongly) is that we set the appearance based on the
values in the libsub objects, and these are overridden with values from the
- content by the other emit_text_start() above.
+ content by the other emit_plain_start() above.
*/
out.push_back (
dcp::Time (from.seconds(), 1000),
/* XXX: hmm; this is a bit ugly (we don't know the to time yet) */
dcp::Time (),
- i.horizontal_position.proportional,
+ h_position,
h_align,
v_position,
v_align,
}
}
- emit_text_start (from, out);
+ emit_plain_start (from, out);
}
void
}
void
-TextDecoder::emit_text (ContentTimePeriod period, list<dcp::SubtitleString> s)
+TextDecoder::emit_plain (ContentTimePeriod period, list<dcp::SubtitleString> s)
{
- emit_text_start (period.from, s);
+ emit_plain_start (period.from, s);
emit_stop (period.to);
}
void
-TextDecoder::emit_text (ContentTimePeriod period, sub::Subtitle const & s)
+TextDecoder::emit_plain (ContentTimePeriod period, sub::Subtitle const & s)
+{
+ emit_plain_start (period.from, s);
+ emit_stop (period.to);
+}
+
+/* @param rect Area expressed as a fraction of the video frame that this subtitle
+ * is for (e.g. a width of 0.5 means the width of the subtitle is half the width
+ * of the video frame)
+ */
+void
+TextDecoder::emit_bitmap (ContentTimePeriod period, shared_ptr<Image> image, dcpomatic::Rect<double> rect)
{
- emit_text_start (period.from, s);
+ emit_bitmap_start (period.from, image, rect);
emit_stop (period.to);
}