Pick up effect and effect color.
authorCarl Hetherington <cth@carlh.net>
Tue, 21 Aug 2012 20:38:37 +0000 (21:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 Aug 2012 20:38:37 +0000 (21:38 +0100)
src/dcp_time.cc
src/subtitle_asset.cc
src/subtitle_asset.h
src/xml.cc
src/xml.h
test/tests.cc

index 900d7c6ee1bfbd00b209c5f3242a72ca0a0936e8..0cc6b264894c00be6c11b257ddbe73084c523f17 100644 (file)
@@ -35,7 +35,7 @@ Time::Time (int frame, int frames_per_second)
        , t (0)
 {
        float sec_float = float (frame) / frames_per_second;
-       t = (int (sec_float * 1000) % 1000) / 4;
+       t = (int (floor (sec_float * 1000)) % 1000) / 4;
        s = floor (sec_float);
 
        if (s > 60) {
index a5c94b80cc853d3dee771d678d7b3f5b3c04ed39..2eeceab129eca512c6cdb515479829a3d3f8f944 100644 (file)
@@ -65,7 +65,9 @@ SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_pt
                                                (*j)->in,
                                                (*j)->out,
                                                (*k)->v_position,
-                                               (*k)->text
+                                               (*k)->text,
+                                               effective.effect,
+                                               effective.effect_color.get()
                                                )
                                        )
                                );
@@ -82,10 +84,12 @@ SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_pt
 FontNode::FontNode (xmlpp::Node const * node)
        : XMLNode (node)
 {
-       id = string_attribute ("Id");
+       id = optional_string_attribute ("Id");
        size = optional_int64_attribute ("Size");
        italic = optional_bool_attribute ("Italic");
        color = optional_color_attribute ("Color");
+       effect = optional_string_attribute ("Effect");
+       effect_color = optional_color_attribute ("EffectColor");
        subtitle_nodes = sub_nodes<SubtitleNode> ("Subtitle");
        font_nodes = sub_nodes<FontNode> ("Font");
 }
@@ -108,6 +112,12 @@ FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes)
                if ((*i)->color) {
                        color = (*i)->color.get ();
                }
+               if (!(*i)->effect.empty ()) {
+                       effect = (*i)->effect;
+               }
+               if ((*i)->effect_color) {
+                       effect_color = (*i)->effect_color.get ();
+               }
        }
 }
 
@@ -167,14 +177,16 @@ SubtitleAsset::font_id_to_name (string id) const
 }
 
 Subtitle::Subtitle (
-       std::string font,
+       string font,
        bool italic,
        Color color,
        int size,
        Time in,
        Time out,
        float v_position,
-       std::string text
+       string text,
+       string effect,
+       Color effect_color
        )
        : _font (font)
        , _italic (italic)
@@ -184,6 +196,8 @@ Subtitle::Subtitle (
        , _out (out)
        , _v_position (v_position)
        , _text (text)
+       , _effect (effect)
+       , _effect_color (effect_color)
 {
 
 }
index 02dea865d850c5fcb524d2aab75059b7dd2fdf95..d3f9fa9b6ca95ed9ea1709bdb6434f397d140f02 100644 (file)
@@ -56,6 +56,8 @@ public:
        int size;
        boost::optional<bool> italic;
        boost::optional<Color> color;
+       std::string effect;
+       boost::optional<Color> effect_color;
        
        std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
        std::list<boost::shared_ptr<FontNode> > font_nodes;
@@ -82,7 +84,9 @@ public:
                Time in,
                Time out,
                float v_position,
-               std::string text
+               std::string text,
+               std::string effect,
+               Color effect_color
                );
 
        std::string font () const {
@@ -113,6 +117,14 @@ public:
                return _v_position;
        }
 
+       std::string effect () const {
+               return _effect;
+       }
+
+       Color effect_color () const {
+               return _effect_color;
+       }
+
        int size_in_pixels (int screen_height) const;
 
 private:
@@ -124,6 +136,8 @@ private:
        Time _out;
        float _v_position;
        std::string _text;
+       std::string _effect;
+       Color _effect_color;
 };
 
 class SubtitleAsset : public Asset, public XMLFile
index 1d5247383db78ef048f3fe203b635658588597db..b9ee56a889453528c2c185941d597f8e93c71ed7 100644 (file)
@@ -137,6 +137,22 @@ XMLNode::time_attribute (string name)
 
 string
 XMLNode::string_attribute (string name)
+{
+       xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
+       if (!e) {
+               throw XMLError ("missing attribute");
+       }
+       
+       xmlpp::Attribute* a = e->get_attribute (name);
+       if (!a) {
+               throw XMLError ("missing attribute");
+       }
+
+       return a->get_value ();
+}
+
+string
+XMLNode::optional_string_attribute (string name)
 {
        xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
        if (!e) {
@@ -166,7 +182,7 @@ XMLNode::int64_attribute (string name)
 int64_t
 XMLNode::optional_int64_attribute (string name)
 {
-       string const s = string_attribute (name);
+       string const s = optional_string_attribute (name);
        if (s.empty ()) {
                return 0;
        }
@@ -177,7 +193,7 @@ XMLNode::optional_int64_attribute (string name)
 optional<bool>
 XMLNode::optional_bool_attribute (string name)
 {
-       string const s = string_attribute (name);
+       string const s = optional_string_attribute (name);
        if (s.empty ()) {
                return optional<bool> ();
        }
@@ -192,7 +208,7 @@ XMLNode::optional_bool_attribute (string name)
 optional<Color>
 XMLNode::optional_color_attribute (string name)
 {
-       string const s = string_attribute (name);
+       string const s = optional_string_attribute (name);
        if (s.empty ()) {
                return optional<Color> ();
        }
index 65eb73994b2528a076fa2d835116ba82a8a1006b..9b6000131587b218f09564509d5cc31516be6db2 100644 (file)
--- a/src/xml.h
+++ b/src/xml.h
@@ -38,6 +38,7 @@ protected:
        Time time_attribute (std::string);
        float float_attribute (std::string);
        std::string string_attribute (std::string);
+       std::string optional_string_attribute (std::string);
        int64_t int64_attribute (std::string);
        int64_t optional_int64_attribute (std::string);
        boost::optional<bool> optional_bool_attribute (std::string);
index 6a30a6f192369b87870ce48c2a49cf3ac4e0e683..d503c00d73180f1d0d2821630d13c08a478182c5 100644 (file)
@@ -126,6 +126,8 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (s.front()->italic(), false);
        BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255));
        BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53);
+       BOOST_CHECK_EQUAL (s.front()->effect(), "border");
+       BOOST_CHECK_EQUAL (s.front()->effect_color(), libdcp::Color(0, 0, 0));
 
        s = subs.subtitles_at (libdcp::Time (0, 0, 7, 190));
        BOOST_CHECK_EQUAL (s.size(), 2);
@@ -136,6 +138,8 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (s.front()->font(), "Arial");
        BOOST_CHECK_EQUAL (s.front()->italic(), true);
        BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53);
+       BOOST_CHECK_EQUAL (s.front()->effect(), "border");
+       BOOST_CHECK_EQUAL (s.front()->effect_color(), libdcp::Color(0, 0, 0));
        BOOST_CHECK_EQUAL (s.back()->text(), "My large wonderbra");
        BOOST_CHECK_EQUAL (s.back()->v_position(), 15);
        BOOST_CHECK_EQUAL (s.back()->in(), libdcp::Time (0, 0, 7, 177));
@@ -144,6 +148,8 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (s.back()->italic(), true);
        BOOST_CHECK_EQUAL (s.back()->color(), libdcp::Color(255, 255, 255));
        BOOST_CHECK_EQUAL (s.back()->size_in_pixels(1080), 53);
+       BOOST_CHECK_EQUAL (s.back()->effect(), "border");
+       BOOST_CHECK_EQUAL (s.back()->effect_color(), libdcp::Color(0, 0, 0));
        
        s = subs.subtitles_at (libdcp::Time (0, 0, 11, 95));
        BOOST_CHECK_EQUAL (s.size(), 1);
@@ -155,6 +161,8 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (s.front()->italic(), false);
        BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255));
        BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53);
+       BOOST_CHECK_EQUAL (s.front()->effect(), "border");
+       BOOST_CHECK_EQUAL (s.front()->effect_color(), libdcp::Color(0, 0, 0));
 
        s = subs.subtitles_at (libdcp::Time (0, 0, 14, 42));
        BOOST_CHECK_EQUAL (s.size(), 1);
@@ -166,6 +174,8 @@ BOOST_AUTO_TEST_CASE (subtitles)
        BOOST_CHECK_EQUAL (s.front()->italic(), false);
        BOOST_CHECK_EQUAL (s.front()->color(), libdcp::Color(255, 255, 255));
        BOOST_CHECK_EQUAL (s.front()->size_in_pixels(1080), 53);
+       BOOST_CHECK_EQUAL (s.front()->effect(), "border");
+       BOOST_CHECK_EQUAL (s.front()->effect_color(), libdcp::Color(0, 0, 0));
 }
 
 BOOST_AUTO_TEST_CASE (dcp_time)