X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubtitle_content.cc;h=6c0d3af86a6687571d74e3bb576add9494c67567;hb=c33e0fb07be8ffeeff4581aa07621aebd84c638a;hp=c8de9887e66a778e43e3a50c79d6e77ee6a6c2f4;hpb=f0d79f2ee79becbcb7bc9065155eaa0963a6aa99;p=dcpomatic.git diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index c8de9887e..6c0d3af86 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -19,10 +19,16 @@ #include #include "subtitle_content.h" +#include "util.h" +#include "exceptions.h" + +#include "i18n.h" using std::string; +using std::vector; using boost::shared_ptr; using boost::lexical_cast; +using boost::dynamic_pointer_cast; int const SubtitleContentProperty::SUBTITLE_OFFSET = 500; int const SubtitleContentProperty::SUBTITLE_SCALE = 501; @@ -40,19 +46,45 @@ SubtitleContent::SubtitleContent (shared_ptr f, shared_ptrnumber_child ("SubtitleOffset"); _subtitle_scale = node->number_child ("SubtitleScale"); } +SubtitleContent::SubtitleContent (shared_ptr f, vector > c) + : Content (f, c) +{ + shared_ptr ref = dynamic_pointer_cast (c[0]); + assert (ref); + + for (size_t i = 0; i < c.size(); ++i) { + shared_ptr sc = dynamic_pointer_cast (c[i]); + + if (sc->subtitle_offset() != ref->subtitle_offset()) { + throw JoinError (_("Content to be joined must have the same subtitle offset.")); + } + + if (sc->subtitle_scale() != ref->subtitle_scale()) { + throw JoinError (_("Content to be joined must have the same subtitle scale.")); + } + } + + _subtitle_offset = ref->subtitle_offset (); + _subtitle_scale = ref->subtitle_scale (); +} + void SubtitleContent::as_xml (xmlpp::Node* root) const { + LocaleGuard lg; + root->add_child("SubtitleOffset")->add_child_text (lexical_cast (_subtitle_offset)); root->add_child("SubtitleScale")->add_child_text (lexical_cast (_subtitle_scale)); } void -SubtitleContent::set_subtitle_offset (int o) +SubtitleContent::set_subtitle_offset (double o) { { boost::mutex::scoped_lock lm (_mutex); @@ -62,7 +94,7 @@ SubtitleContent::set_subtitle_offset (int o) } void -SubtitleContent::set_subtitle_scale (float s) +SubtitleContent::set_subtitle_scale (double s) { { boost::mutex::scoped_lock lm (_mutex);