summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-25 14:43:09 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-25 14:43:09 +0100
commitb42066b7d664ac322e6d2c79c5b0fa8bb0eb75c9 (patch)
treef0fd3b7f4bb85e81f0be6a84be3dce54e63df109 /src/lib
parentbb7917d2ea06e6eaa566b00a279e9b5a6a351fc9 (diff)
parent175ec3510439b2184026ee7e8dc75668448f4e21 (diff)
Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/player.cc3
-rw-r--r--src/lib/player_subtitles.h4
-rw-r--r--src/lib/reel_writer.cc2
-rw-r--r--src/lib/render_subtitles.cc15
-rw-r--r--src/lib/render_subtitles.h6
-rw-r--r--src/lib/subtitle_content.cc19
-rw-r--r--src/lib/subtitle_content.h8
-rw-r--r--src/lib/subtitle_string.h46
8 files changed, 87 insertions, 16 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 07bb097c2..10c92c073 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -183,6 +183,7 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
} else if (
property == SubtitleContentProperty::LINE_SPACING ||
+ property == SubtitleContentProperty::OUTLINE_WIDTH ||
property == SubtitleContentProperty::Y_SCALE
) {
@@ -648,7 +649,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt,
}
s.set_in (dcp::Time(content_subtitle_to_dcp (*j, ts.period().from).seconds(), 1000));
s.set_out (dcp::Time(content_subtitle_to_dcp (*j, ts.period().to).seconds(), 1000));
- ps.text.push_back (s);
+ ps.text.push_back (SubtitleString (s, (*j)->content->subtitle->outline_width()));
ps.add_fonts ((*j)->content->subtitle->fonts ());
}
}
diff --git a/src/lib/player_subtitles.h b/src/lib/player_subtitles.h
index 9e50ea777..a202cf4f8 100644
--- a/src/lib/player_subtitles.h
+++ b/src/lib/player_subtitles.h
@@ -23,7 +23,7 @@
#include "image_subtitle.h"
#include "dcpomatic_time.h"
-#include <dcp/subtitle_string.h>
+#include "subtitle_string.h"
class Font;
@@ -41,7 +41,7 @@ public:
/** ImageSubtitles, with their rectangles transformed as specified by their content */
std::list<ImageSubtitle> image;
- std::list<dcp::SubtitleString> text;
+ std::list<SubtitleString> text;
};
#endif
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index 72e10e86b..d742818ae 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -491,7 +491,7 @@ ReelWriter::write (PlayerSubtitles subs)
}
}
- BOOST_FOREACH (dcp::SubtitleString i, subs.text) {
+ BOOST_FOREACH (SubtitleString i, subs.text) {
i.set_in (i.in() - dcp::Time (_period.from.seconds(), i.in().tcr));
i.set_out (i.out() - dcp::Time (_period.from.seconds(), i.out().tcr));
_subtitle_asset->add (i);
diff --git a/src/lib/render_subtitles.cc b/src/lib/render_subtitles.cc
index 6e4dcf46a..c99827d10 100644
--- a/src/lib/render_subtitles.cc
+++ b/src/lib/render_subtitles.cc
@@ -45,13 +45,13 @@ static FcConfig* fc_config = 0;
static list<pair<FontFiles, string> > fc_config_fonts;
string
-marked_up (list<dcp::SubtitleString> subtitles)
+marked_up (list<SubtitleString> subtitles)
{
string out;
bool italic = false;
bool bold = false;
bool underline = false;
- BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
+ BOOST_FOREACH (SubtitleString const & i, subtitles) {
if (i.italic() && !italic) {
out += "<i>";
@@ -96,7 +96,7 @@ marked_up (list<dcp::SubtitleString> subtitles)
* at the same time and with the same fade in/out.
*/
static PositionImage
-render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time)
+render_line (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time)
{
/* XXX: this method can only handle italic / bold changes mid-line,
nothing else yet.
@@ -285,8 +285,7 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts,
/* Border effect; stroke the subtitle with a large (arbitrarily chosen) line width */
dcp::Colour ec = subtitles.front().effect_colour ();
context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor);
- /* This 300.0 is a magic number chosen to make the outline look good */
- context->set_line_width (target.width / 300.0);
+ context->set_line_width (subtitles.front().outline_width * target.width / 2048.0);
context->set_line_join (Cairo::LINE_JOIN_ROUND);
context->move_to (x_offset, 0);
layout->add_to_cairo_context (context);
@@ -350,12 +349,12 @@ render_line (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts,
/** @param time Time of the frame that these subtitles are going on */
list<PositionImage>
-render_subtitles (list<dcp::SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time)
+render_subtitles (list<SubtitleString> subtitles, list<shared_ptr<Font> > fonts, dcp::Size target, DCPTime time)
{
- list<dcp::SubtitleString> pending;
+ list<SubtitleString> pending;
list<PositionImage> images;
- BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) {
+ BOOST_FOREACH (SubtitleString const & i, subtitles) {
if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) {
images.push_back (render_line (pending, fonts, target, time));
pending.clear ();
diff --git a/src/lib/render_subtitles.h b/src/lib/render_subtitles.h
index 79194568a..f81685a28 100644
--- a/src/lib/render_subtitles.h
+++ b/src/lib/render_subtitles.h
@@ -20,12 +20,12 @@
#include "position_image.h"
#include "dcpomatic_time.h"
-#include <dcp/subtitle_string.h>
+#include "subtitle_string.h"
#include <dcp/util.h>
class Font;
-std::string marked_up (std::list<dcp::SubtitleString> subtitles);
+std::string marked_up (std::list<SubtitleString> subtitles);
std::list<PositionImage> render_subtitles (
- std::list<dcp::SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime
+ std::list<SubtitleString>, std::list<boost::shared_ptr<Font> > fonts, dcp::Size, DCPTime
);
diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc
index 34ffa3f4b..37d431e1a 100644
--- a/src/lib/subtitle_content.cc
+++ b/src/lib/subtitle_content.cc
@@ -54,6 +54,7 @@ int const SubtitleContentProperty::EFFECT_COLOUR = 511;
int const SubtitleContentProperty::LINE_SPACING = 512;
int const SubtitleContentProperty::FADE_IN = 513;
int const SubtitleContentProperty::FADE_OUT = 514;
+int const SubtitleContentProperty::OUTLINE_WIDTH = 515;
SubtitleContent::SubtitleContent (Content* parent)
: ContentPart (parent)
@@ -68,6 +69,7 @@ SubtitleContent::SubtitleContent (Content* parent)
, _shadow (false)
, _effect_colour (0, 0, 0)
, _line_spacing (1)
+ , _outline_width (2)
{
}
@@ -111,6 +113,7 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int
, _line_spacing (node->optional_number_child<double>("LineSpacing").get_value_or (1))
, _fade_in (node->optional_number_child<Frame>("SubtitleFadeIn").get_value_or (0))
, _fade_out (node->optional_number_child<Frame>("SubtitleFadeOut").get_value_or (0))
+ , _outline_width (node->optional_number_child<int>("OutlineWidth").get_value_or (2))
{
if (version >= 32) {
_use = node->bool_child ("UseSubtitles");
@@ -196,6 +199,10 @@ SubtitleContent::SubtitleContent (Content* parent, vector<shared_ptr<Content> >
throw JoinError (_("Content to be joined must have the same subtitle fades."));
}
+ if ((c[i]->subtitle->outline_width() != ref->outline_width())) {
+ throw JoinError (_("Content to be joined must have the same outline width."));
+ }
+
list<shared_ptr<Font> > fonts = c[i]->subtitle->fonts ();
if (fonts.size() != ref_fonts.size()) {
throw JoinError (_("Content to be joined must use the same fonts."));
@@ -224,6 +231,7 @@ SubtitleContent::SubtitleContent (Content* parent, vector<shared_ptr<Content> >
_line_spacing = ref->line_spacing ();
_fade_in = ref->fade_in ();
_fade_out = ref->fade_out ();
+ _outline_width = ref->outline_width ();
connect_to_fonts ();
}
@@ -252,6 +260,7 @@ SubtitleContent::as_xml (xmlpp::Node* root) const
root->add_child("LineSpacing")->add_child_text (raw_convert<string> (_line_spacing));
root->add_child("SubtitleFadeIn")->add_child_text (raw_convert<string> (_fade_in.get()));
root->add_child("SubtitleFadeOut")->add_child_text (raw_convert<string> (_fade_out.get()));
+ root->add_child("OutlineWidth")->add_child_text (raw_convert<string> (_outline_width));
for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) {
(*i)->as_xml (root->add_child("Font"));
@@ -267,7 +276,8 @@ SubtitleContent::identifier () const
+ "_" + raw_convert<string> (y_offset())
+ "_" + raw_convert<string> (line_spacing())
+ "_" + raw_convert<string> (fade_in().get())
- + "_" + raw_convert<string> (fade_out().get());
+ + "_" + raw_convert<string> (fade_out().get())
+ + "_" + raw_convert<string> (outline_width());
/* XXX: I suppose really _fonts shouldn't be in here, since not all
types of subtitle content involve fonts.
@@ -397,6 +407,12 @@ SubtitleContent::set_fade_out (ContentTime t)
}
void
+SubtitleContent::set_outline_width (int w)
+{
+ maybe_set (_outline_width, w, SubtitleContentProperty::OUTLINE_WIDTH);
+}
+
+void
SubtitleContent::use_template (shared_ptr<const SubtitleContent> c)
{
_use = c->_use;
@@ -413,4 +429,5 @@ SubtitleContent::use_template (shared_ptr<const SubtitleContent> c)
_line_spacing = c->_line_spacing;
_fade_in = c->_fade_in;
_fade_out = c->_fade_out;
+ _outline_width = c->_outline_width;
}
diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h
index ddc97ce9f..7278b5408 100644
--- a/src/lib/subtitle_content.h
+++ b/src/lib/subtitle_content.h
@@ -46,6 +46,7 @@ public:
static int const LINE_SPACING;
static int const FADE_IN;
static int const FADE_OUT;
+ static int const OUTLINE_WIDTH;
};
/** @class SubtitleContent
@@ -80,6 +81,7 @@ public:
void set_line_spacing (double s);
void set_fade_in (ContentTime);
void set_fade_out (ContentTime);
+ void set_outline_width (int);
bool use () const {
boost::mutex::scoped_lock lm (_mutex);
@@ -156,6 +158,11 @@ public:
return _fade_out;
}
+ int outline_width () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _outline_width;
+ }
+
static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
protected:
@@ -194,6 +201,7 @@ private:
double _line_spacing;
ContentTime _fade_in;
ContentTime _fade_out;
+ int _outline_width;
};
#endif
diff --git a/src/lib/subtitle_string.h b/src/lib/subtitle_string.h
new file mode 100644
index 000000000..c1b0b14a8
--- /dev/null
+++ b/src/lib/subtitle_string.h
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef DCPOMATIC_SUBTITLE_STRING_H
+#define DCPOMATIC_SUBTITLE_STRING_H
+
+#include <dcp/subtitle_string.h>
+
+/** A wrapper for SubtitleString which allows us to include settings that are not
+ * applicable to true DCP subtitles. For example, we can set outline width for burn-in
+ * but this cannot be specified in DCP XML.
+ */
+class SubtitleString : public dcp::SubtitleString
+{
+public:
+ SubtitleString (dcp::SubtitleString dcp_)
+ : dcp::SubtitleString (dcp_)
+ , outline_width (2)
+ {}
+
+ SubtitleString (dcp::SubtitleString dcp_, int outline_width_)
+ : dcp::SubtitleString (dcp_)
+ , outline_width (outline_width_)
+ {}
+
+ int outline_width;
+};
+
+#endif