diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-22 15:00:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-22 15:00:33 +0100 |
| commit | 8b8bce8d2a83739f96e02a48b77d352414361c43 (patch) | |
| tree | 08abcadb9fa0ba92a6e75d6f6a21383341ba656f | |
| parent | a3bbf59dd06dda14f070e99aaee32bb29a13f51a (diff) | |
Allow <Font> nodes inside <Subtitle> nodes.
| -rw-r--r-- | src/subtitle_asset.cc | 85 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 17 | ||||
| -rw-r--r-- | test/ref/subs.xml | 4 | ||||
| -rw-r--r-- | test/tests.cc | 2 |
4 files changed, 73 insertions, 35 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index a80fdec2..ee74e5eb 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -43,46 +43,65 @@ SubtitleAsset::SubtitleAsset (string directory, string xml) */ list<shared_ptr<FontNode> > current_font_nodes; - for (list<shared_ptr<FontNode> >::iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { - examine_font_node (*i, current_font_nodes); - } + list<shared_ptr<SubtitleNode> > current_subtitle_nodes; + current_subtitle_nodes.push_back (shared_ptr<SubtitleNode> ()); + examine_font_nodes (font_nodes, current_font_nodes, current_subtitle_nodes); } void -SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_ptr<FontNode> >& current_font_nodes) +SubtitleAsset::examine_font_nodes ( + list<shared_ptr<FontNode> > const & font_nodes, + list<shared_ptr<FontNode> >& current_font_nodes, + list<shared_ptr<SubtitleNode> >& current_subtitle_nodes + ) { - current_font_nodes.push_back (font_node); - - for (list<shared_ptr<SubtitleNode> >::iterator j = font_node->subtitle_nodes.begin(); j != font_node->subtitle_nodes.end(); ++j) { - for (list<shared_ptr<TextNode> >::iterator k = (*j)->text_nodes.begin(); k != (*j)->text_nodes.end(); ++k) { - FontNode effective (current_font_nodes); - _subtitles.push_back ( - shared_ptr<Subtitle> ( - new Subtitle ( - font_id_to_name (effective.id), - effective.italic.get(), - effective.color.get(), - effective.size, - (*j)->in, - (*j)->out, - (*k)->v_position, - (*k)->v_align, - (*k)->text, - effective.effect.get(), - effective.effect_color.get(), - (*k)->fade_up_time, - (*k)->fade_down_time - ) - ) - ); + for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { + + current_font_nodes.push_back (*i); + + for (list<shared_ptr<SubtitleNode> >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) { + current_subtitle_nodes.push_back (*j); + examine_text_nodes (*j, (*j)->text_nodes, current_font_nodes); + examine_font_nodes ((*j)->font_nodes, current_font_nodes, current_subtitle_nodes); + current_subtitle_nodes.pop_back (); } + + examine_font_nodes ((*i)->font_nodes, current_font_nodes, current_subtitle_nodes); + examine_text_nodes (current_subtitle_nodes.back (), (*i)->text_nodes, current_font_nodes); + + current_font_nodes.pop_back (); } +} - for (list<shared_ptr<FontNode> >::iterator j = font_node->font_nodes.begin(); j != font_node->font_nodes.end(); ++j) { - examine_font_node (*j, current_font_nodes); +void +SubtitleAsset::examine_text_nodes ( + shared_ptr<SubtitleNode> subtitle_node, + list<shared_ptr<TextNode> > const & text_nodes, + list<shared_ptr<FontNode> >& current_font_nodes + ) +{ + for (list<shared_ptr<TextNode> >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) { + FontNode effective (current_font_nodes); + _subtitles.push_back ( + shared_ptr<Subtitle> ( + new Subtitle ( + font_id_to_name (effective.id), + effective.italic.get(), + effective.color.get(), + effective.size, + subtitle_node->in, + subtitle_node->out, + (*i)->v_position, + (*i)->v_align, + (*i)->text, + effective.effect.get(), + effective.effect_color.get(), + (*i)->fade_up_time, + (*i)->fade_down_time + ) + ) + ); } - - current_font_nodes.pop_back (); } FontNode::FontNode (xmlpp::Node const * node) @@ -105,6 +124,7 @@ FontNode::FontNode (xmlpp::Node const * node) effect_color = optional_color_attribute ("EffectColor"); subtitle_nodes = sub_nodes<SubtitleNode> ("Subtitle"); font_nodes = sub_nodes<FontNode> ("Font"); + text_nodes = sub_nodes<TextNode> ("Text"); } FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes) @@ -148,6 +168,7 @@ SubtitleNode::SubtitleNode (xmlpp::Node const * node) { in = time_attribute ("TimeIn"); out = time_attribute ("TimeOut"); + font_nodes = sub_nodes<FontNode> ("Font"); text_nodes = sub_nodes<TextNode> ("Text"); } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 607b054d..662f85f1 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -24,6 +24,8 @@ namespace libdcp { +class FontNode; + class TextNode : public XMLNode { public: @@ -49,6 +51,7 @@ public: Time in; Time out; + std::list<boost::shared_ptr<FontNode> > font_nodes; std::list<boost::shared_ptr<TextNode> > text_nodes; }; @@ -68,6 +71,7 @@ public: std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes; std::list<boost::shared_ptr<FontNode> > font_nodes; + std::list<boost::shared_ptr<TextNode> > text_nodes; }; class LoadFontNode : public XMLNode @@ -184,7 +188,18 @@ public: private: std::string font_id_to_name (std::string id) const; - void examine_font_node (boost::shared_ptr<FontNode> font_node, std::list<boost::shared_ptr<FontNode> >& current_font_nodes); + + void examine_font_nodes ( + std::list<boost::shared_ptr<FontNode> > const & font_nodes, + std::list<boost::shared_ptr<FontNode> >& current_font_nodes, + std::list<boost::shared_ptr<SubtitleNode> >& current_subtitle_nodes + ); + + void examine_text_nodes ( + boost::shared_ptr<SubtitleNode> subtitle_node, + std::list<boost::shared_ptr<TextNode> > const & text_nodes, + std::list<boost::shared_ptr<FontNode> >& current_font_nodes + ); std::string _subtitle_id; std::string _movie_title; diff --git a/test/ref/subs.xml b/test/ref/subs.xml index 399c2a57..515dd9f7 100644 --- a/test/ref/subs.xml +++ b/test/ref/subs.xml @@ -12,7 +12,9 @@ <Font Italic="yes"> <Subtitle SpotNumber="2" TimeIn="00:00:07:177" TimeOut="00:00:11:031" FadeUpTime="1" FadeDownTime="1"> <Text VAlign="bottom" VPosition="21.0">My corset was H.M. The Queen's</Text> - <Text VAlign="bottom" VPosition="15.0">My large wonderbra</Text> + <Font Italic="no"> + <Text VAlign="bottom" VPosition="15.0">My large wonderbra</Text> + </Font> </Subtitle> </Font> <Subtitle SpotNumber="3" TimeIn="00:00:11:094" TimeOut="00:00:13:063" FadeUpTime="1" FadeDownTime="1"> diff --git a/test/tests.cc b/test/tests.cc index d434429a..3264f07d 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE (subtitles) BOOST_CHECK_EQUAL (s.back()->in(), libdcp::Time (0, 0, 7, 177)); BOOST_CHECK_EQUAL (s.back()->out(), libdcp::Time (0, 0, 11, 31)); BOOST_CHECK_EQUAL (s.back()->font(), "Arial"); - BOOST_CHECK_EQUAL (s.back()->italic(), true); + BOOST_CHECK_EQUAL (s.back()->italic(), false); 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(), libdcp::BORDER); |
