Tweak font handling.
authorCarl Hetherington <cth@carlh.net>
Tue, 21 Aug 2012 17:01:59 +0000 (18:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 Aug 2012 17:01:59 +0000 (18:01 +0100)
src/subtitle_asset.cc
src/subtitle_asset.h

index 2b200a2f319cb58be7d37a3256edfb23039722ed..c27fd2c09575fa36d57290434ee706123defc406 100644 (file)
@@ -54,12 +54,13 @@ SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_pt
 
        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 (id_from_font_nodes (current_font_nodes)),
-                                               italic_from_font_nodes (current_font_nodes),
-                                               size_from_font_nodes (current_font_nodes),
+                                               font_id_to_name (effective.id),
+                                               effective.italic.get(),
+                                               effective.size,
                                                (*j)->in,
                                                (*j)->out,
                                                (*k)->v_position,
@@ -77,52 +78,31 @@ SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_pt
        current_font_nodes.pop_back ();
 }
 
-string
-SubtitleAsset::id_from_font_nodes (list<shared_ptr<FontNode> > const & font_nodes) const
+FontNode::FontNode (xmlpp::Node const * node)
+       : XMLNode (node)
 {
-       for (list<shared_ptr<FontNode> >::const_reverse_iterator i = font_nodes.rbegin(); i != font_nodes.rend(); ++i) {
-               if (!(*i)->id.empty ()) {
-                       return (*i)->id;
-               }
-       }
-
-       return "";
+       id = string_attribute ("Id");
+       size = optional_int64_attribute ("Size");
+       italic = optional_bool_attribute ("Italic");
+       subtitle_nodes = sub_nodes<SubtitleNode> ("Subtitle");
+       font_nodes = sub_nodes<FontNode> ("Font");
 }
 
-int
-SubtitleAsset::size_from_font_nodes (list<shared_ptr<FontNode> > const & font_nodes) const
+FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes)
+       : size (0)
+       , italic (false)
 {
-       for (list<shared_ptr<FontNode> >::const_reverse_iterator i = font_nodes.rbegin(); i != font_nodes.rend(); ++i) {
+       for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
+               if (!(*i)->id.empty ()) {
+                       id = (*i)->id;
+               }
                if ((*i)->size != 0) {
-                       return (*i)->size;
+                       size = (*i)->size;
                }
-       }
-
-       return 0;
-
-}
-
-bool
-SubtitleAsset::italic_from_font_nodes (list<shared_ptr<FontNode> > const & font_nodes) const
-{
-       for (list<shared_ptr<FontNode> >::const_reverse_iterator i = font_nodes.rbegin(); i != font_nodes.rend(); ++i) {
                if ((*i)->italic) {
-                       return (*i)->italic.get ();
+                       italic = (*i)->italic.get ();
                }
        }
-
-       return false;
-
-}
-
-FontNode::FontNode (xmlpp::Node const * node)
-       : XMLNode (node)
-{
-       id = string_attribute ("Id");
-       size = optional_int64_attribute ("Size");
-       italic = optional_bool_attribute ("Italic");
-       subtitle_nodes = sub_nodes<SubtitleNode> ("Subtitle");
-       font_nodes = sub_nodes<FontNode> ("Font");
 }
 
 LoadFontNode::LoadFontNode (xmlpp::Node const * node)
index 04154a450f768c7cd83e7b02d637d3359c06fa0c..3df30e62fcbde24a54f37537941b91482bdd29d4 100644 (file)
@@ -50,6 +50,7 @@ class FontNode : public XMLNode
 public:
        FontNode () {}
        FontNode (xmlpp::Node const * node);
+       FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
 
        std::string id;
        int size;
@@ -138,9 +139,6 @@ 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);
-       std::string id_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
-       int size_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
-       bool italic_from_font_nodes (std::list<boost::shared_ptr<FontNode> > const & font_nodes) const;
        
        std::string _subtitle_id;
        std::string _movie_title;