summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-06-21 22:33:02 +0100
committerCarl Hetherington <cth@carlh.net>2018-07-19 23:36:56 +0100
commit491edba4e79656a045103a284c65b846a167d2ff (patch)
treec11e2a9f7b7f097a2320f2b6a21e69a1aab9b581
parent26acd1ec8426d8be48c37ca20b3af26b4bc73fa7 (diff)
Add type for text content (CCAP/subtitle).
-rw-r--r--src/lib/exceptions.h8
-rw-r--r--src/lib/text_content.cc13
-rw-r--r--src/lib/text_content.h8
-rw-r--r--src/lib/types.cc26
-rw-r--r--src/lib/types.h9
5 files changed, 64 insertions, 0 deletions
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index 09db968dc..eceafa105 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -255,6 +255,14 @@ public:
{}
};
+class MetadataError : public std::runtime_error
+{
+public:
+ explicit MetadataError (std::string s)
+ : std::runtime_error (s)
+ {}
+};
+
class OldFormatError : public std::runtime_error
{
public:
diff --git a/src/lib/text_content.cc b/src/lib/text_content.cc
index 9eae63519..96e9cbb8d 100644
--- a/src/lib/text_content.cc
+++ b/src/lib/text_content.cc
@@ -55,6 +55,7 @@ int const TextContentProperty::LINE_SPACING = 511;
int const TextContentProperty::FADE_IN = 512;
int const TextContentProperty::FADE_OUT = 513;
int const TextContentProperty::OUTLINE_WIDTH = 514;
+int const TextContentProperty::TYPE = 515;
TextContent::TextContent (Content* parent)
: ContentPart (parent)
@@ -66,6 +67,7 @@ TextContent::TextContent (Content* parent)
, _y_scale (1)
, _line_spacing (1)
, _outline_width (2)
+ , _type (TEXT_SUBTITLE)
{
}
@@ -101,6 +103,7 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version)
, _y_scale (1)
, _line_spacing (node->optional_number_child<double>("LineSpacing").get_value_or (1))
, _outline_width (node->optional_number_child<int>("OutlineWidth").get_value_or (2))
+ , _type (TEXT_SUBTITLE)
{
if (version >= 32) {
_use = node->bool_child ("UseSubtitles");
@@ -179,6 +182,8 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version)
}
connect_to_fonts ();
+
+ _type = string_to_text_type (node->optional_string_child("TextType").get_value_or("subtitle"));
}
TextContent::TextContent (Content* parent, vector<shared_ptr<Content> > c)
@@ -307,6 +312,8 @@ TextContent::as_xml (xmlpp::Node* root) const
for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) {
(*i)->as_xml (root->add_child("Font"));
}
+
+ root->add_child("TextType", text_type_to_string(_type));
}
string
@@ -476,6 +483,12 @@ TextContent::unset_fade_out ()
}
void
+TextContent::set_type (TextType type)
+{
+ maybe_set (_type, type, TextContentProperty::TYPE);
+}
+
+void
TextContent::set_outline_width (int w)
{
maybe_set (_outline_width, w, TextContentProperty::OUTLINE_WIDTH);
diff --git a/src/lib/text_content.h b/src/lib/text_content.h
index 941184388..cb3bb5ee4 100644
--- a/src/lib/text_content.h
+++ b/src/lib/text_content.h
@@ -46,6 +46,7 @@ public:
static int const FADE_IN;
static int const FADE_OUT;
static int const OUTLINE_WIDTH;
+ static int const TYPE;
};
/** @class TextContent
@@ -85,6 +86,7 @@ public:
void set_fade_out (ContentTime);
void set_outline_width (int);
void unset_fade_out ();
+ void set_type (TextType type);
bool use () const {
boost::mutex::scoped_lock lm (_mutex);
@@ -161,6 +163,11 @@ public:
return _outline_width;
}
+ TextType type () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _type;
+ }
+
static boost::shared_ptr<TextContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
protected:
@@ -199,6 +206,7 @@ private:
boost::optional<ContentTime> _fade_in;
boost::optional<ContentTime> _fade_out;
int _outline_width;
+ TextType _type;
};
#endif
diff --git a/src/lib/types.cc b/src/lib/types.cc
index e3bedd667..68e00c8d5 100644
--- a/src/lib/types.cc
+++ b/src/lib/types.cc
@@ -19,6 +19,7 @@
*/
#include "types.h"
+#include "compose.hpp"
#include "dcpomatic_assert.h"
#include <dcp/raw_convert.h>
#include <libxml++/libxml++.h>
@@ -90,6 +91,31 @@ Crop::as_xml (xmlpp::Node* node) const
node->add_child("BottomCrop")->add_child_text (raw_convert<string> (bottom));
}
+TextType
+string_to_text_type (string s)
+{
+ if (s == "subtitle") {
+ return TEXT_SUBTITLE;
+ } else if (s == "ccap") {
+ return TEXT_CLOSED_CAPTION;
+ } else {
+ throw MetadataError (String::compose ("Unknown text type %1", s));
+ }
+}
+
+string
+text_type_to_string (TextType t)
+{
+ switch (t) {
+ case TEXT_SUBTITLE:
+ return "subtitle";
+ case TEXT_CLOSED_CAPTION:
+ return "ccap";
+ default:
+ DCPOMATIC_ASSERT (false);
+ }
+}
+
string
video_frame_type_to_string (VideoFrameType t)
{
diff --git a/src/lib/types.h b/src/lib/types.h
index af2171718..5707cf5ce 100644
--- a/src/lib/types.h
+++ b/src/lib/types.h
@@ -129,6 +129,15 @@ enum ReelType
REELTYPE_BY_LENGTH
};
+enum TextType
+{
+ TEXT_SUBTITLE,
+ TEXT_CLOSED_CAPTION
+};
+
+extern std::string text_type_to_string (TextType t);
+extern TextType string_to_text_type (std::string s);
+
/** @struct Crop
* @brief A description of the crop of an image or video.
*/