Add type for text content (CCAP/subtitle).
authorCarl Hetherington <cth@carlh.net>
Thu, 21 Jun 2018 21:33:02 +0000 (22:33 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 19 Jul 2018 22:36:56 +0000 (23:36 +0100)
src/lib/exceptions.h
src/lib/text_content.cc
src/lib/text_content.h
src/lib/types.cc
src/lib/types.h

index 09db968dc949cbf6973dc8345c284d4c591296c8..eceafa10501d656a55ef78961590ecaff72108b7 100644 (file)
@@ -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:
index 9eae63519387056c1cb9176b75edf2f30709f209..96e9cbb8db489c537d574bcd19123586e2565cb8 100644 (file)
@@ -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
@@ -475,6 +482,12 @@ TextContent::unset_fade_out ()
        maybe_set (_fade_out, optional<ContentTime>(), TextContentProperty::FADE_OUT);
 }
 
+void
+TextContent::set_type (TextType type)
+{
+       maybe_set (_type, type, TextContentProperty::TYPE);
+}
+
 void
 TextContent::set_outline_width (int w)
 {
index 941184388850fcb11bd3fd67ae139b285fb1de6c..cb3bb5ee4a8439c6dd6b2bd1cb6149eabbeaa4d6 100644 (file)
@@ -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
index e3bedd667f7a716daee156db5451e2b6b376cc9c..68e00c8d532c55a4fce389721991b9b56a43b6c6 100644 (file)
@@ -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)
 {
index af2171718837ae9ba439dfc529a77e0c4a49734d..5707cf5cef0ca822c21f70895e2713ee06ff6b23 100644 (file)
@@ -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.
  */