diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-21 16:13:22 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-21 16:13:22 +0100 |
| commit | b56b008e2ad86bd2c29a42390891a32ae658d6c4 (patch) | |
| tree | 1b40a20756da219dd495f1b67ecea37f8cccf8ce /src | |
| parent | f902811342bb9f72bb11e2658aea14cfe8b04c64 (diff) | |
Recurse into font nodes and pick up details of italics.
Diffstat (limited to 'src')
| -rw-r--r-- | src/subtitle_asset.cc | 19 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 8 | ||||
| -rw-r--r-- | src/xml.cc | 15 | ||||
| -rw-r--r-- | src/xml.h | 2 |
4 files changed, 43 insertions, 1 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index be036856..2b200a2f 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -51,13 +51,14 @@ void SubtitleAsset::examine_font_node (shared_ptr<FontNode> font_node, list<shared_ptr<FontNode> >& current_font_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) { _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), (*j)->in, (*j)->out, @@ -101,11 +102,25 @@ SubtitleAsset::size_from_font_nodes (list<shared_ptr<FontNode> > const & font_no } +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 (); + } + } + + 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"); } @@ -167,6 +182,7 @@ SubtitleAsset::font_id_to_name (string id) const Subtitle::Subtitle ( std::string font, + bool italic, int size, Time in, Time out, @@ -174,6 +190,7 @@ Subtitle::Subtitle ( std::string text ) : _font (font) + , _italic (italic) , _size (size) , _in (in) , _out (out) diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 6a04bed3..04154a45 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -53,6 +53,7 @@ public: std::string id; int size; + boost::optional<bool> italic; std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes; std::list<boost::shared_ptr<FontNode> > font_nodes; @@ -73,6 +74,7 @@ class Subtitle public: Subtitle ( std::string font, + bool italic, int size, Time in, Time out, @@ -84,6 +86,10 @@ public: return _font; } + bool italic () const { + return _italic; + } + Time in () const { return _in; } @@ -104,6 +110,7 @@ public: private: std::string _font; + bool _italic; int _size; Time _in; Time _out; @@ -133,6 +140,7 @@ private: 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; @@ -174,6 +174,21 @@ XMLNode::optional_int64_attribute (string name) return lexical_cast<int64_t> (s); } +optional<bool> +XMLNode::optional_bool_attribute (string name) +{ + string const s = string_attribute (name); + if (s.empty ()) { + return optional<bool> (); + } + + if (s == "1" || s == "yes") { + return optional<bool> (true); + } + + return optional<bool> (false); +} + void XMLNode::done () { @@ -6,6 +6,7 @@ #include <stdint.h> #include <glibmm.h> #include <boost/shared_ptr.hpp> +#include <boost/optional.hpp> #include "types.h" #include "exceptions.h" #include "dcp_time.h" @@ -39,6 +40,7 @@ protected: std::string 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); std::string content (); |
