diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-07-02 00:17:24 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-07-02 00:17:24 +0100 |
| commit | bd491319f52ba7f37ef5763960b4c0c00434b5f9 (patch) | |
| tree | c8578912077611e7fcbd5ba804abea97adce7b32 /src | |
| parent | d87f979ea98a19614f164a0d49fccc1be926e789 (diff) | |
Tweaks: don't use shared_ptr for dcp::SubtitleString; SubtitleContent::write_xml takes a path.
Diffstat (limited to 'src')
| -rw-r--r-- | src/subtitle_content.cc | 108 | ||||
| -rw-r--r-- | src/subtitle_content.h | 11 | ||||
| -rw-r--r-- | src/wscript | 1 |
3 files changed, 60 insertions, 60 deletions
diff --git a/src/subtitle_content.cc b/src/subtitle_content.cc index a622e7b0..7e11dea4 100644 --- a/src/subtitle_content.cc +++ b/src/subtitle_content.cc @@ -169,32 +169,30 @@ SubtitleContent::maybe_add_subtitle (string text, ParseState const & parse_state dcp::Subtitle effective_subtitle (*parse_state.subtitle_nodes.back ()); _subtitles.push_back ( - shared_ptr<SubtitleString> ( - new SubtitleString ( - font_id_to_name (effective_font.id), - effective_font.italic.get(), - effective_font.color.get(), - effective_font.size, - effective_subtitle.in, - effective_subtitle.out, - effective_text.v_position, - effective_text.v_align, - text, - effective_font.effect ? effective_font.effect.get() : NONE, - effective_font.effect_color.get(), - effective_subtitle.fade_up_time, - effective_subtitle.fade_down_time - ) + SubtitleString ( + font_id_to_name (effective_font.id), + effective_font.italic.get(), + effective_font.color.get(), + effective_font.size, + effective_subtitle.in, + effective_subtitle.out, + effective_text.v_position, + effective_text.v_align, + text, + effective_font.effect ? effective_font.effect.get() : NONE, + effective_font.effect_color.get(), + effective_subtitle.fade_up_time, + effective_subtitle.fade_down_time ) ); } -list<shared_ptr<SubtitleString> > +list<SubtitleString> SubtitleContent::subtitles_at (Time t) const { - list<shared_ptr<SubtitleString> > s; - for (list<shared_ptr<SubtitleString> >::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { - if ((*i)->in() <= t && t <= (*i)->out ()) { + list<SubtitleString> s; + for (list<SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) { + if (i->in() <= t && t <= i->out ()) { s.push_back (*i); } } @@ -222,25 +220,25 @@ SubtitleContent::font_id_to_name (string id) const } void -SubtitleContent::add (shared_ptr<SubtitleString> s) +SubtitleContent::add (SubtitleString s) { _subtitles.push_back (s); _need_sort = true; } struct SubtitleSorter { - bool operator() (shared_ptr<SubtitleString> a, shared_ptr<SubtitleString> b) { - if (a->in() != b->in()) { - return a->in() < b->in(); + bool operator() (SubtitleString const & a, SubtitleString const & b) { + if (a.in() != b.in()) { + return a.in() < b.in(); } - return a->v_position() < b->v_position(); + return a.v_position() < b.v_position(); } }; void -SubtitleContent::write_xml () const +SubtitleContent::write_xml (boost::filesystem::path p) const { - FILE* f = fopen_boost (file (), "r"); + FILE* f = fopen_boost (p, "r"); Glib::ustring const s = xml_as_string (); fwrite (s.c_str(), 1, s.length(), f); fclose (f); @@ -272,7 +270,7 @@ SubtitleContent::xml_as_string () const } } - list<shared_ptr<SubtitleString> > sorted = _subtitles; + list<SubtitleString> sorted = _subtitles; if (_need_sort) { sorted.sort (SubtitleSorter ()); } @@ -294,7 +292,7 @@ SubtitleContent::xml_as_string () const xmlpp::Element* font = 0; xmlpp::Element* subtitle = 0; - for (list<shared_ptr<SubtitleString> >::iterator i = sorted.begin(); i != sorted.end(); ++i) { + for (list<SubtitleString>::iterator i = sorted.begin(); i != sorted.end(); ++i) { /* We will start a new <Font>...</Font> whenever some font property changes. I suppose we should really make an optimal hierarchy of <Font> tags, but @@ -302,18 +300,18 @@ SubtitleContent::xml_as_string () const */ bool const font_changed = - italic != (*i)->italic() || - color != (*i)->color() || - size != (*i)->size() || - effect != (*i)->effect() || - effect_color != (*i)->effect_color(); + italic != i->italic() || + color != i->color() || + size != i->size() || + effect != i->effect() || + effect_color != i->effect_color(); if (font_changed) { - italic = (*i)->italic (); - color = (*i)->color (); - size = (*i)->size (); - effect = (*i)->effect (); - effect_color = (*i)->effect_color (); + italic = i->italic (); + color = i->color (); + size = i->size (); + effect = i->effect (); + effect_color = i->effect_color (); } if (!font || font_changed) { @@ -334,29 +332,29 @@ SubtitleContent::xml_as_string () const } if (!subtitle || font_changed || - (last_in != (*i)->in() || - last_out != (*i)->out() || - last_fade_up_time != (*i)->fade_up_time() || - last_fade_down_time != (*i)->fade_down_time() + (last_in != i->in() || + last_out != i->out() || + last_fade_up_time != i->fade_up_time() || + last_fade_down_time != i->fade_down_time() )) { subtitle = font->add_child ("Subtitle"); subtitle->set_attribute ("SpotNumber", raw_convert<string> (spot_number++)); - subtitle->set_attribute ("TimeIn", (*i)->in().to_string()); - subtitle->set_attribute ("TimeOut", (*i)->out().to_string()); - subtitle->set_attribute ("FadeUpTime", raw_convert<string> ((*i)->fade_up_time().to_ticks())); - subtitle->set_attribute ("FadeDownTime", raw_convert<string> ((*i)->fade_down_time().to_ticks())); - - last_in = (*i)->in (); - last_out = (*i)->out (); - last_fade_up_time = (*i)->fade_up_time (); - last_fade_down_time = (*i)->fade_down_time (); + subtitle->set_attribute ("TimeIn", i->in().to_string()); + subtitle->set_attribute ("TimeOut", i->out().to_string()); + subtitle->set_attribute ("FadeUpTime", raw_convert<string> (i->fade_up_time().to_ticks())); + subtitle->set_attribute ("FadeDownTime", raw_convert<string> (i->fade_down_time().to_ticks())); + + last_in = i->in (); + last_out = i->out (); + last_fade_up_time = i->fade_up_time (); + last_fade_down_time = i->fade_down_time (); } xmlpp::Element* text = subtitle->add_child ("Text"); - text->set_attribute ("VAlign", valign_to_string ((*i)->v_align())); - text->set_attribute ("VPosition", raw_convert<string> ((*i)->v_position())); - text->add_child_text ((*i)->text()); + text->set_attribute ("VAlign", valign_to_string (i->v_align())); + text->set_attribute ("VPosition", raw_convert<string> (i->v_position())); + text->add_child_text (i->text()); } return doc.write_to_string_formatted ("UTF-8"); diff --git a/src/subtitle_content.h b/src/subtitle_content.h index 1ddb9122..c00c3f31 100644 --- a/src/subtitle_content.h +++ b/src/subtitle_content.h @@ -22,6 +22,7 @@ #include "content.h" #include "dcp_time.h" +#include "subtitle_string.h" #include <libcxml/cxml.h> namespace dcp @@ -63,14 +64,14 @@ public: return _language; } - std::list<boost::shared_ptr<SubtitleString> > subtitles_at (Time t) const; - std::list<boost::shared_ptr<SubtitleString> > const & subtitles () const { + std::list<SubtitleString> subtitles_at (Time t) const; + std::list<SubtitleString> const & subtitles () const { return _subtitles; } - void add (boost::shared_ptr<SubtitleString>); + void add (SubtitleString); - void write_xml () const; + void write_xml (boost::filesystem::path) const; Glib::ustring xml_as_string () const; protected: @@ -111,7 +112,7 @@ private: std::string _language; std::list<boost::shared_ptr<LoadFont> > _load_font_nodes; - std::list<boost::shared_ptr<SubtitleString> > _subtitles; + std::list<SubtitleString> _subtitles; bool _need_sort; }; diff --git a/src/wscript b/src/wscript index e5f0c2a5..e9b3c955 100644 --- a/src/wscript +++ b/src/wscript @@ -99,6 +99,7 @@ def build(bld): reel_picture_asset.h reel_sound_asset.h reel_stereo_picture_asset.h + reel_subtitle_asset.h ref.h argb_frame.h signer.h |
