From fd23bf276facab3892a00f010ac7e991bc79af09 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 21 Aug 2012 21:38:37 +0100 Subject: Pick up effect and effect color. --- src/dcp_time.cc | 2 +- src/subtitle_asset.cc | 22 ++++++++++++++++++---- src/subtitle_asset.h | 16 +++++++++++++++- src/xml.cc | 22 +++++++++++++++++++--- src/xml.h | 1 + 5 files changed, 54 insertions(+), 9 deletions(-) (limited to 'src') 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 font_node, listin, (*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 font_node, list ("Subtitle"); font_nodes = sub_nodes ("Font"); } @@ -108,6 +112,12 @@ FontNode::FontNode (list > 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 italic; boost::optional color; + std::string effect; + boost::optional effect_color; std::list > subtitle_nodes; std::list > 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 diff --git a/src/xml.cc b/src/xml.cc index 1d524738..b9ee56a8 100644 --- a/src/xml.cc +++ b/src/xml.cc @@ -137,6 +137,22 @@ XMLNode::time_attribute (string name) string XMLNode::string_attribute (string name) +{ + xmlpp::Element const * e = dynamic_cast (_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 (_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 XMLNode::optional_bool_attribute (string name) { - string const s = string_attribute (name); + string const s = optional_string_attribute (name); if (s.empty ()) { return optional (); } @@ -192,7 +208,7 @@ XMLNode::optional_bool_attribute (string name) optional XMLNode::optional_color_attribute (string name) { - string const s = string_attribute (name); + string const s = optional_string_attribute (name); if (s.empty ()) { return optional (); } diff --git a/src/xml.h b/src/xml.h index 65eb7399..9b600013 100644 --- 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 optional_bool_attribute (std::string); -- cgit v1.2.3