diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-21 21:38:37 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-21 21:38:37 +0100 |
| commit | fd23bf276facab3892a00f010ac7e991bc79af09 (patch) | |
| tree | 2ee3c0e6cfd318bfc14c5fca7c29c9031a570a69 | |
| parent | 3541f4c9bd91169e55a82b9fa46767b46ca06188 (diff) | |
Pick up effect and effect color.
| -rw-r--r-- | src/dcp_time.cc | 2 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 22 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 16 | ||||
| -rw-r--r-- | src/xml.cc | 22 | ||||
| -rw-r--r-- | src/xml.h | 1 | ||||
| -rw-r--r-- | test/tests.cc | 10 |
6 files changed, 64 insertions, 9 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 900d7c6e..0cc6b264 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -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) { diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index a5c94b80..2eeceab1 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -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) { } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 02dea865..d3f9fa9b 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -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 @@ -140,6 +140,22 @@ 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) { return ""; } @@ -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> (); } @@ -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); diff --git a/test/tests.cc b/test/tests.cc index 6a30a6f1..d503c00d 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -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) |
