+SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int version)
+ : ContentPart (parent)
+ , _use (false)
+ , _burn (false)
+ , _x_offset (0)
+ , _y_offset (0)
+ , _x_scale (1)
+ , _y_scale (1)
+ , _colour (
+ node->optional_number_child<int>("Red").get_value_or(255),
+ node->optional_number_child<int>("Green").get_value_or(255),
+ node->optional_number_child<int>("Blue").get_value_or(255)
+ )
+ , _outline (node->optional_bool_child("Outline").get_value_or(false))
+ , _shadow (node->optional_bool_child("Shadow").get_value_or(false))
+ , _line_spacing (node->optional_number_child<double>("LineSpacing").get_value_or (1))
+{
+ if (version >= 32) {
+ _use = node->bool_child ("UseSubtitles");
+ _burn = node->bool_child ("BurnSubtitles");
+ }
+
+ if (version >= 7) {
+ _x_offset = node->number_child<double> ("SubtitleXOffset");
+ _y_offset = node->number_child<double> ("SubtitleYOffset");
+ } else {
+ _y_offset = node->number_child<double> ("SubtitleOffset");
+ }
+
+ if (version >= 10) {
+ _x_scale = node->number_child<double> ("SubtitleXScale");
+ _y_scale = node->number_child<double> ("SubtitleYScale");
+ } else {
+ _x_scale = _y_scale = node->number_child<double> ("SubtitleScale");
+ }
+
+ if (version >= 36) {
+ _effect_colour = dcp::Colour (
+ node->optional_number_child<int>("EffectRed").get_value_or(255),
+ node->optional_number_child<int>("EffectGreen").get_value_or(255),
+ node->optional_number_child<int>("EffectBlue").get_value_or(255)
+ );
+ } else {
+ _effect_colour = dcp::Colour (
+ node->optional_number_child<int>("OutlineRed").get_value_or(255),
+ node->optional_number_child<int>("OutlineGreen").get_value_or(255),
+ node->optional_number_child<int>("OutlineBlue").get_value_or(255)
+ );
+ }
+
+ _language = node->optional_string_child ("SubtitleLanguage").get_value_or ("");
+
+ list<cxml::NodePtr> fonts = node->node_children ("Font");
+ for (list<cxml::NodePtr>::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
+ _fonts.push_back (shared_ptr<Font> (new Font (*i)));
+ }
+
+ connect_to_fonts ();
+}
+
+SubtitleContent::SubtitleContent (Content* parent, vector<shared_ptr<Content> > c)
+ : ContentPart (parent)
+{
+ shared_ptr<SubtitleContent> ref = c[0]->subtitle;
+ DCPOMATIC_ASSERT (ref);
+ list<shared_ptr<Font> > ref_fonts = ref->fonts ();
+
+ for (size_t i = 1; i < c.size(); ++i) {
+
+ if (c[i]->subtitle->use() != ref->use()) {
+ throw JoinError (_("Content to be joined must have the same 'use subtitles' setting."));
+ }
+
+ if (c[i]->subtitle->burn() != ref->burn()) {
+ throw JoinError (_("Content to be joined must have the same 'burn subtitles' setting."));
+ }
+
+ if (c[i]->subtitle->x_offset() != ref->x_offset()) {
+ throw JoinError (_("Content to be joined must have the same subtitle X offset."));
+ }
+
+ if (c[i]->subtitle->y_offset() != ref->y_offset()) {
+ throw JoinError (_("Content to be joined must have the same subtitle Y offset."));
+ }
+
+ if (c[i]->subtitle->x_scale() != ref->x_scale()) {
+ throw JoinError (_("Content to be joined must have the same subtitle X scale."));
+ }
+
+ if (c[i]->subtitle->y_scale() != ref->y_scale()) {
+ throw JoinError (_("Content to be joined must have the same subtitle Y scale."));
+ }
+
+ if (c[i]->subtitle->line_spacing() != ref->line_spacing()) {
+ throw JoinError (_("Content to be joined must have the same subtitle line spacing."));
+ }
+
+ 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."));
+ }
+
+ list<shared_ptr<Font> >::const_iterator j = ref_fonts.begin ();
+ list<shared_ptr<Font> >::const_iterator k = fonts.begin ();
+
+ while (j != ref_fonts.end ()) {
+ if (**j != **k) {
+ throw JoinError (_("Content to be joined must use the same fonts."));
+ }
+ ++j;
+ ++k;
+ }
+ }
+
+ _use = ref->use ();
+ _burn = ref->burn ();
+ _x_offset = ref->x_offset ();
+ _y_offset = ref->y_offset ();
+ _x_scale = ref->x_scale ();
+ _y_scale = ref->y_scale ();
+ _language = ref->language ();
+ _fonts = ref_fonts;
+ _line_spacing = ref->line_spacing ();
+
+ connect_to_fonts ();
+}
+
+/** _mutex must not be held on entry */