X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcaption_content.cc;h=bbb1bacf3d7a3eb6acb7efd7224890839db6b506;hb=ded71cffd18962ebb6b9611a5eb6dfafe9e8e4ec;hp=33e21bc4a212631224990ee32a40ba2777065814;hpb=27b83475435dda4e84a90cf59a52f150905c4ab1;p=dcpomatic.git diff --git a/src/lib/caption_content.cc b/src/lib/caption_content.cc index 33e21bc4a..bbb1bacf3 100644 --- a/src/lib/caption_content.cc +++ b/src/lib/caption_content.cc @@ -57,7 +57,7 @@ int const CaptionContentProperty::FADE_OUT = 513; int const CaptionContentProperty::OUTLINE_WIDTH = 514; int const CaptionContentProperty::TYPE = 515; -CaptionContent::CaptionContent (Content* parent) +CaptionContent::CaptionContent (Content* parent, CaptionType original_type) : ContentPart (parent) , _use (false) , _burn (false) @@ -67,12 +67,16 @@ CaptionContent::CaptionContent (Content* parent) , _y_scale (1) , _line_spacing (1) , _outline_width (2) - , _type (CAPTION_OPEN) + , _type (original_type) + , _original_type (original_type) { } -shared_ptr +/** @return CaptionContents from node or nodes under node (according to version). + * The list could be empty if no CaptionContents are found. + */ +list > CaptionContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) { if (version < 34) { @@ -80,17 +84,30 @@ CaptionContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) subtitle streams, so check for that. */ if (node->string_child("Type") == "FFmpeg" && node->node_children("SubtitleStream").empty()) { - return shared_ptr (); + return list >(); } /* Otherwise we can drop through to the newer logic */ } - if (!node->optional_number_child("SubtitleXOffset") && !node->optional_number_child("SubtitleOffset")) { - return shared_ptr (); + if (version < 37) { + if (!node->optional_number_child("SubtitleXOffset") && !node->optional_number_child("SubtitleOffset")) { + return list >(); + } + list > c; + c.push_back (shared_ptr (new CaptionContent (parent, node, version))); + return c; + } + + if (!node->optional_node_child("Caption")) { + return list >(); } - return shared_ptr (new CaptionContent (parent, node, version)); + list > c; + BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children("Caption")) { + c.push_back (shared_ptr (new CaptionContent (parent, i, version))); + } + return c; } CaptionContent::CaptionContent (Content* parent, cxml::ConstNodePtr node, int version) @@ -105,12 +122,18 @@ CaptionContent::CaptionContent (Content* parent, cxml::ConstNodePtr node, int ve , _outline_width (node->optional_number_child("OutlineWidth").get_value_or (2)) , _type (CAPTION_OPEN) { - if (version >= 32) { + if (version >= 37) { + _use = node->bool_child ("Use"); + _burn = node->bool_child ("Burn"); + } else if (version >= 32) { _use = node->bool_child ("UseSubtitles"); _burn = node->bool_child ("BurnSubtitles"); } - if (version >= 7) { + if (version >= 37) { + _x_offset = node->number_child ("XOffset"); + _y_offset = node->number_child ("YOffset"); + } else if (version >= 7) { _x_offset = node->number_child ("SubtitleXOffset"); _y_offset = node->number_child ("SubtitleYOffset"); } else { @@ -136,7 +159,10 @@ CaptionContent::CaptionContent (Content* parent, cxml::ConstNodePtr node, int ve } } - if (version >= 10) { + if (version >= 37) { + _x_scale = node->number_child ("XScale"); + _y_scale = node->number_child ("YScale"); + } else if (version >= 10) { _x_scale = node->number_child ("SubtitleXScale"); _y_scale = node->number_child ("SubtitleYScale"); } else { @@ -165,16 +191,31 @@ CaptionContent::CaptionContent (Content* parent, cxml::ConstNodePtr node, int ve ); } - optional fi = node->optional_number_child("SubtitleFadeIn"); + optional fi; + if (version >= 37) { + fi = node->optional_number_child("FadeIn"); + } else { + fi = node->optional_number_child("SubtitleFadeIn"); + } if (fi) { _fade_in = ContentTime (*fi); } - optional fo = node->optional_number_child("SubtitleFadeOut"); + + optional fo; + if (version >= 37) { + fo = node->optional_number_child("FadeOut"); + } else { + fo = node->optional_number_child("SubtitleFadeOut"); + } if (fo) { _fade_out = ContentTime (*fo); } - _language = node->optional_string_child ("SubtitleLanguage").get_value_or (""); + if (version >= 37) { + _language = node->optional_string_child ("Language").get_value_or (""); + } else { + _language = node->optional_string_child ("SubtitleLanguage").get_value_or (""); + } list fonts = node->node_children ("Font"); for (list::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { @@ -183,55 +224,59 @@ CaptionContent::CaptionContent (Content* parent, cxml::ConstNodePtr node, int ve connect_to_fonts (); - _type = string_to_caption_type (node->optional_string_child("CaptionType").get_value_or("open")); + _type = string_to_caption_type (node->optional_string_child("Type").get_value_or("open")); + _original_type = string_to_caption_type (node->optional_string_child("Type").get_value_or("open")); } CaptionContent::CaptionContent (Content* parent, vector > c) : ContentPart (parent) { - shared_ptr ref = c[0]->caption; + /* This constructor is for join which is only supported for content types + that have a single caption, so we can use only_caption() here. + */ + shared_ptr ref = c[0]->only_caption(); DCPOMATIC_ASSERT (ref); list > ref_fonts = ref->fonts (); for (size_t i = 1; i < c.size(); ++i) { - if (c[i]->caption->use() != ref->use()) { + if (c[i]->only_caption()->use() != ref->use()) { throw JoinError (_("Content to be joined must have the same 'use subtitles' setting.")); } - if (c[i]->caption->burn() != ref->burn()) { + if (c[i]->only_caption()->burn() != ref->burn()) { throw JoinError (_("Content to be joined must have the same 'burn subtitles' setting.")); } - if (c[i]->caption->x_offset() != ref->x_offset()) { + if (c[i]->only_caption()->x_offset() != ref->x_offset()) { throw JoinError (_("Content to be joined must have the same subtitle X offset.")); } - if (c[i]->caption->y_offset() != ref->y_offset()) { + if (c[i]->only_caption()->y_offset() != ref->y_offset()) { throw JoinError (_("Content to be joined must have the same subtitle Y offset.")); } - if (c[i]->caption->x_scale() != ref->x_scale()) { + if (c[i]->only_caption()->x_scale() != ref->x_scale()) { throw JoinError (_("Content to be joined must have the same subtitle X scale.")); } - if (c[i]->caption->y_scale() != ref->y_scale()) { + if (c[i]->only_caption()->y_scale() != ref->y_scale()) { throw JoinError (_("Content to be joined must have the same subtitle Y scale.")); } - if (c[i]->caption->line_spacing() != ref->line_spacing()) { + if (c[i]->only_caption()->line_spacing() != ref->line_spacing()) { throw JoinError (_("Content to be joined must have the same subtitle line spacing.")); } - if ((c[i]->caption->fade_in() != ref->fade_in()) || (c[i]->caption->fade_out() != ref->fade_out())) { + if ((c[i]->only_caption()->fade_in() != ref->fade_in()) || (c[i]->only_caption()->fade_out() != ref->fade_out())) { throw JoinError (_("Content to be joined must have the same subtitle fades.")); } - if ((c[i]->caption->outline_width() != ref->outline_width())) { + if ((c[i]->only_caption()->outline_width() != ref->outline_width())) { throw JoinError (_("Content to be joined must have the same outline width.")); } - list > fonts = c[i]->caption->fonts (); + list > fonts = c[i]->only_caption()->fonts (); if (fonts.size() != ref_fonts.size()) { throw JoinError (_("Content to be joined must use the same fonts.")); } @@ -270,50 +315,53 @@ CaptionContent::as_xml (xmlpp::Node* root) const { boost::mutex::scoped_lock lm (_mutex); - root->add_child("UseSubtitles")->add_child_text (_use ? "1" : "0"); - root->add_child("BurnSubtitles")->add_child_text (_burn ? "1" : "0"); - root->add_child("SubtitleXOffset")->add_child_text (raw_convert (_x_offset)); - root->add_child("SubtitleYOffset")->add_child_text (raw_convert (_y_offset)); - root->add_child("SubtitleXScale")->add_child_text (raw_convert (_x_scale)); - root->add_child("SubtitleYScale")->add_child_text (raw_convert (_y_scale)); - root->add_child("SubtitleLanguage")->add_child_text (_language); + xmlpp::Element* caption = root->add_child ("Caption"); + + caption->add_child("Use")->add_child_text (_use ? "1" : "0"); + caption->add_child("Burn")->add_child_text (_burn ? "1" : "0"); + caption->add_child("XOffset")->add_child_text (raw_convert (_x_offset)); + caption->add_child("YOffset")->add_child_text (raw_convert (_y_offset)); + caption->add_child("XScale")->add_child_text (raw_convert (_x_scale)); + caption->add_child("YScale")->add_child_text (raw_convert (_y_scale)); + caption->add_child("Language")->add_child_text (_language); if (_colour) { - root->add_child("Red")->add_child_text (raw_convert (_colour->r)); - root->add_child("Green")->add_child_text (raw_convert (_colour->g)); - root->add_child("Blue")->add_child_text (raw_convert (_colour->b)); + caption->add_child("Red")->add_child_text (raw_convert (_colour->r)); + caption->add_child("Green")->add_child_text (raw_convert (_colour->g)); + caption->add_child("Blue")->add_child_text (raw_convert (_colour->b)); } if (_effect) { switch (*_effect) { case dcp::NONE: - root->add_child("Effect")->add_child_text("none"); + caption->add_child("Effect")->add_child_text("none"); break; case dcp::BORDER: - root->add_child("Effect")->add_child_text("outline"); + caption->add_child("Effect")->add_child_text("outline"); break; case dcp::SHADOW: - root->add_child("Effect")->add_child_text("shadow"); + caption->add_child("Effect")->add_child_text("shadow"); break; } } if (_effect_colour) { - root->add_child("EffectRed")->add_child_text (raw_convert (_effect_colour->r)); - root->add_child("EffectGreen")->add_child_text (raw_convert (_effect_colour->g)); - root->add_child("EffectBlue")->add_child_text (raw_convert (_effect_colour->b)); + caption->add_child("EffectRed")->add_child_text (raw_convert (_effect_colour->r)); + caption->add_child("EffectGreen")->add_child_text (raw_convert (_effect_colour->g)); + caption->add_child("EffectBlue")->add_child_text (raw_convert (_effect_colour->b)); } - root->add_child("LineSpacing")->add_child_text (raw_convert (_line_spacing)); + caption->add_child("LineSpacing")->add_child_text (raw_convert (_line_spacing)); if (_fade_in) { - root->add_child("SubtitleFadeIn")->add_child_text (raw_convert (_fade_in->get())); + caption->add_child("FadeIn")->add_child_text (raw_convert (_fade_in->get())); } if (_fade_out) { - root->add_child("SubtitleFadeOut")->add_child_text (raw_convert (_fade_out->get())); + caption->add_child("FadeOut")->add_child_text (raw_convert (_fade_out->get())); } - root->add_child("OutlineWidth")->add_child_text (raw_convert (_outline_width)); + caption->add_child("OutlineWidth")->add_child_text (raw_convert (_outline_width)); for (list >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { - (*i)->as_xml (root->add_child("Font")); + (*i)->as_xml (caption->add_child("Font")); } - root->add_child("CaptionType")->add_child_text (caption_type_to_string(_type)); + caption->add_child("Type")->add_child_text (caption_type_to_string(_type)); + caption->add_child("OriginalType")->add_child_text (caption_type_to_string(_original_type)); } string