Add line-spacing property to SubtitleContent.
authorCarl Hetherington <cth@carlh.net>
Sat, 28 May 2016 17:45:33 +0000 (18:45 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 1 Jul 2016 00:05:06 +0000 (01:05 +0100)
src/lib/subtitle_content.cc
src/lib/subtitle_content.h

index 5b3b453b6eaf12d7614c0a3b6beb2f2b87da3bdb..fcc825026da8d69ebb6ac3829d83f262b27253ac 100644 (file)
@@ -50,6 +50,7 @@ int const SubtitleContentProperty::FONTS = 507;
 int const SubtitleContentProperty::COLOUR = 508;
 int const SubtitleContentProperty::OUTLINE = 509;
 int const SubtitleContentProperty::OUTLINE_COLOUR = 510;
+int const SubtitleContentProperty::LINE_SPACING = 511;
 
 SubtitleContent::SubtitleContent (Content* parent)
        : ContentPart (parent)
@@ -62,6 +63,7 @@ SubtitleContent::SubtitleContent (Content* parent)
        , _colour (255, 255, 255)
        , _outline (false)
        , _outline_colour (0, 0, 0)
+       , _line_spacing (1)
 {
 
 }
@@ -106,6 +108,7 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int
                node->optional_number_child<int>("OutlineGreen").get_value_or(255),
                node->optional_number_child<int>("OutlineBlue").get_value_or(255)
                )
+       , _line_spacing (node->optional_number_child<double>("LineSpacing").get_value_or (1))
 {
        if (version >= 32) {
                _use = node->bool_child ("UseSubtitles");
@@ -169,6 +172,10 @@ SubtitleContent::SubtitleContent (Content* parent, vector<shared_ptr<Content> >
                        throw JoinError (_("Content to be joined must have the same subtitle Y scale."));
                }
 
+               if (c[i]->subtitle->line_spacing() != ref->line_spacing()) {
+                       throw JoinError (_("Content to be joined must have the same subtitle line spacing."));
+               }
+
                list<shared_ptr<Font> > fonts = c[i]->subtitle->fonts ();
                if (fonts.size() != ref_fonts.size()) {
                        throw JoinError (_("Content to be joined must use the same fonts."));
@@ -194,6 +201,7 @@ SubtitleContent::SubtitleContent (Content* parent, vector<shared_ptr<Content> >
        _y_scale = ref->y_scale ();
        _language = ref->language ();
        _fonts = ref_fonts;
+       _line_spacing = ref->line_spacing ();
 
        connect_to_fonts ();
 }
@@ -218,6 +226,7 @@ SubtitleContent::as_xml (xmlpp::Node* root) const
        root->add_child("OutlineRed")->add_child_text (raw_convert<string> (_outline_colour.r));
        root->add_child("OutlineGreen")->add_child_text (raw_convert<string> (_outline_colour.g));
        root->add_child("OutlineBlue")->add_child_text (raw_convert<string> (_outline_colour.b));
+       root->add_child("LineSpacing")->add_child_text (raw_convert<string> (_line_spacing));
 
        for (list<shared_ptr<Font> >::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) {
                (*i)->as_xml (root->add_child("Font"));
@@ -231,7 +240,8 @@ SubtitleContent::identifier () const
        s << raw_convert<string> (x_scale())
          << "_" << raw_convert<string> (y_scale())
          << "_" << raw_convert<string> (x_offset())
-         << "_" << raw_convert<string> (y_offset());
+         << "_" << raw_convert<string> (y_offset())
+         << "_" << raw_convert<string> (line_spacing());
 
        /* XXX: I suppose really _fonts shouldn't be in here, since not all
           types of subtitle content involve fonts.
@@ -335,3 +345,9 @@ SubtitleContent::set_language (string language)
 {
        maybe_set (_language, language, SubtitleContentProperty::LANGUAGE);
 }
+
+void
+SubtitleContent::set_line_spacing (double s)
+{
+       maybe_set (_line_spacing, s, SubtitleContentProperty::LINE_SPACING);
+}
index 2aa33f1727f9ec47c24bee577d34b7c544c1c873..6665f563af4a0496ce9826f17dda7fad80b2b9c5 100644 (file)
@@ -42,6 +42,7 @@ public:
        static int const COLOUR;
        static int const OUTLINE;
        static int const OUTLINE_COLOUR;
+       static int const LINE_SPACING;
 };
 
 /** @class SubtitleContent
@@ -130,6 +131,13 @@ public:
                return _outline_colour;
        }
 
+       void set_line_spacing (double s);
+
+       double line_spacing () const {
+               boost::mutex::scoped_lock lm (_mutex);
+               return _line_spacing;
+       }
+
        static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, cxml::ConstNodePtr, int version);
 
 protected:
@@ -162,6 +170,8 @@ private:
        bool _outline;
        dcp::Colour _outline_colour;
        std::list<boost::signals2::connection> _font_connections;
+       /** scaling factor for line spacing; 1 is "standard", < 1 is closer together, > 1 is further apart */
+       double _line_spacing;
 };
 
 #endif