1ff66c4904b3f9faa4a48e9e1d0c32b80e52f7df
[dcpomatic.git] / src / lib / text_text_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_text_content.h"
22 #include "util.h"
23 #include "text_subtitle.h"
24 #include "film.h"
25 #include "font.h"
26 #include "text_content.h"
27 #include <dcp/raw_convert.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 using dcp::raw_convert;
37
38 TextTextContent::TextTextContent (shared_ptr<const Film> film, boost::filesystem::path path)
39         : Content (film, path)
40 {
41         subtitle.reset (new TextContent (this));
42 }
43
44 TextTextContent::TextTextContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
45         : Content (film, node)
46         , _length (node->number_child<ContentTime::Type> ("Length"))
47 {
48         subtitle = TextContent::from_xml (this, node, version);
49 }
50
51 void
52 TextTextContent::examine (boost::shared_ptr<Job> job)
53 {
54         Content::examine (job);
55         TextSubtitle s (shared_from_this ());
56
57         /* Default to turning these subtitles on */
58         subtitle->set_use (true);
59
60         boost::mutex::scoped_lock lm (_mutex);
61         _length = s.length ();
62         subtitle->add_font (shared_ptr<Font> (new Font (TEXT_FONT_ID)));
63 }
64
65 string
66 TextTextContent::summary () const
67 {
68         return path_summary() + " " + _("[subtitles]");
69 }
70
71 string
72 TextTextContent::technical_summary () const
73 {
74         return Content::technical_summary() + " - " + _("Text subtitles");
75 }
76
77 void
78 TextTextContent::as_xml (xmlpp::Node* node, bool with_paths) const
79 {
80         node->add_child("Type")->add_child_text ("TextSubtitle");
81         Content::as_xml (node, with_paths);
82
83         if (subtitle) {
84                 subtitle->as_xml (node);
85         }
86
87         node->add_child("Length")->add_child_text (raw_convert<string> (_length.get ()));
88 }
89
90 DCPTime
91 TextTextContent::full_length () const
92 {
93         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate ());
94         return DCPTime (_length, frc);
95 }