24a328d088e3c05001f9be31f2f1b614233010da
[dcpomatic.git] / src / lib / text_subtitle_content.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "text_subtitle_content.h"
22 #include "util.h"
23 #include "text_subtitle.h"
24 #include "film.h"
25 #include "font.h"
26 #include "raw_convert.h"
27 #include "subtitle_content.h"
28 #include <libxml++/libxml++.h>
29 #include <iostream>
30
31 #include "i18n.h"
32
33 using std::string;
34 using std::cout;
35 using boost::shared_ptr;
36
37 TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, boost::filesystem::path path)
38         : Content (film, path)
39 {
40         subtitle.reset (new SubtitleContent (this));
41 }
42
43 TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
44         : Content (film, node)
45         , _length (node->number_child<ContentTime::Type> ("Length"))
46 {
47         subtitle = SubtitleContent::from_xml (this, node, version);
48 }
49
50 void
51 TextSubtitleContent::examine (boost::shared_ptr<Job> job)
52 {
53         Content::examine (job);
54         TextSubtitle s (shared_from_this ());
55
56         /* Default to turning these subtitles on */
57         subtitle->set_use (true);
58
59         boost::mutex::scoped_lock lm (_mutex);
60         _length = s.length ();
61         subtitle->add_font (shared_ptr<Font> (new Font (TEXT_FONT_ID)));
62 }
63
64 string
65 TextSubtitleContent::summary () const
66 {
67         return path_summary() + " " + _("[subtitles]");
68 }
69
70 string
71 TextSubtitleContent::technical_summary () const
72 {
73         return Content::technical_summary() + " - " + _("Text subtitles");
74 }
75
76 void
77 TextSubtitleContent::as_xml (xmlpp::Node* node) const
78 {
79         node->add_child("Type")->add_child_text ("TextSubtitle");
80         Content::as_xml (node);
81
82         if (subtitle) {
83                 subtitle->as_xml (node);
84         }
85
86         node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ()));
87 }
88
89 DCPTime
90 TextSubtitleContent::full_length () const
91 {
92         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ());
93         return DCPTime (_length, frc);
94 }