2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <libcxml/cxml.h>
21 #include <dcp/raw_convert.h>
22 #include "subtitle_content.h"
24 #include "exceptions.h"
31 using boost::shared_ptr;
32 using boost::dynamic_pointer_cast;
33 using dcp::raw_convert;
35 int const SubtitleContentProperty::SUBTITLE_X_OFFSET = 500;
36 int const SubtitleContentProperty::SUBTITLE_Y_OFFSET = 501;
37 int const SubtitleContentProperty::SUBTITLE_SCALE = 502;
38 int const SubtitleContentProperty::SUBTITLE_USE = 503;
40 SubtitleContent::SubtitleContent (shared_ptr<const Film> f, boost::filesystem::path p)
42 , _subtitle_use (false)
43 , _subtitle_x_offset (0)
44 , _subtitle_y_offset (0)
50 SubtitleContent::SubtitleContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
52 , _subtitle_use (false)
53 , _subtitle_x_offset (0)
54 , _subtitle_y_offset (0)
58 _subtitle_use = node->bool_child ("SubtitleUse");
59 _subtitle_x_offset = node->number_child<float> ("SubtitleXOffset");
60 _subtitle_y_offset = node->number_child<float> ("SubtitleYOffset");
62 _subtitle_y_offset = node->number_child<float> ("SubtitleOffset");
65 _subtitle_scale = node->number_child<float> ("SubtitleScale");
68 SubtitleContent::SubtitleContent (shared_ptr<const Film> f, vector<shared_ptr<Content> > c)
71 shared_ptr<SubtitleContent> ref = dynamic_pointer_cast<SubtitleContent> (c[0]);
74 for (size_t i = 0; i < c.size(); ++i) {
75 shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (c[i]);
77 if (sc->subtitle_use() != ref->subtitle_use()) {
78 throw JoinError (_("Content to be joined must have the same 'use subtitles' setting."));
81 if (sc->subtitle_x_offset() != ref->subtitle_x_offset()) {
82 throw JoinError (_("Content to be joined must have the same subtitle X offset."));
85 if (sc->subtitle_y_offset() != ref->subtitle_y_offset()) {
86 throw JoinError (_("Content to be joined must have the same subtitle Y offset."));
89 if (sc->subtitle_scale() != ref->subtitle_scale()) {
90 throw JoinError (_("Content to be joined must have the same subtitle scale."));
94 _subtitle_use = ref->subtitle_use ();
95 _subtitle_x_offset = ref->subtitle_x_offset ();
96 _subtitle_y_offset = ref->subtitle_y_offset ();
97 _subtitle_scale = ref->subtitle_scale ();
101 SubtitleContent::as_xml (xmlpp::Node* root) const
103 root->add_child("SubtitleUse")->add_child_text (raw_convert<string> (_subtitle_use));
104 root->add_child("SubtitleXOffset")->add_child_text (raw_convert<string> (_subtitle_x_offset));
105 root->add_child("SubtitleYOffset")->add_child_text (raw_convert<string> (_subtitle_y_offset));
106 root->add_child("SubtitleScale")->add_child_text (raw_convert<string> (_subtitle_scale));
110 SubtitleContent::set_subtitle_use (bool u)
113 boost::mutex::scoped_lock lm (_mutex);
116 signal_changed (SubtitleContentProperty::SUBTITLE_USE);
120 SubtitleContent::set_subtitle_x_offset (double o)
123 boost::mutex::scoped_lock lm (_mutex);
124 _subtitle_x_offset = o;
126 signal_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET);
130 SubtitleContent::set_subtitle_y_offset (double o)
133 boost::mutex::scoped_lock lm (_mutex);
134 _subtitle_y_offset = o;
136 signal_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET);
140 SubtitleContent::set_subtitle_scale (double s)
143 boost::mutex::scoped_lock lm (_mutex);
146 signal_changed (SubtitleContentProperty::SUBTITLE_SCALE);