From 491edba4e79656a045103a284c65b846a167d2ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 21 Jun 2018 22:33:02 +0100 Subject: [PATCH] Add type for text content (CCAP/subtitle). --- src/lib/exceptions.h | 8 ++++++++ src/lib/text_content.cc | 13 +++++++++++++ src/lib/text_content.h | 8 ++++++++ src/lib/types.cc | 26 ++++++++++++++++++++++++++ src/lib/types.h | 9 +++++++++ 5 files changed, 64 insertions(+) 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("LineSpacing").get_value_or (1)) , _outline_width (node->optional_number_child("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 > c) @@ -307,6 +312,8 @@ TextContent::as_xml (xmlpp::Node* root) const for (list >::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 @@ -475,6 +482,12 @@ TextContent::unset_fade_out () maybe_set (_fade_out, optional(), TextContentProperty::FADE_OUT); } +void +TextContent::set_type (TextType type) +{ + maybe_set (_type, type, TextContentProperty::TYPE); +} + void TextContent::set_outline_width (int w) { 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 from_xml (Content* parent, cxml::ConstNodePtr, int version); protected: @@ -199,6 +206,7 @@ private: boost::optional _fade_in; boost::optional _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 #include @@ -90,6 +91,31 @@ Crop::as_xml (xmlpp::Node* node) const node->add_child("BottomCrop")->add_child_text (raw_convert (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. */ -- 2.30.2