diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-13 23:04:11 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-13 23:04:11 +0000 |
| commit | f1ba458a19a9b998ecdb1db726106876953abcc0 (patch) | |
| tree | 1e414103fec758275f92dff3b7973cc02dbf39a3 /src/subtitle.cc | |
| parent | d15ef17dccf87b633d1971c38032a2049abe3db0 (diff) | |
Various development / fixes.rework
Diffstat (limited to 'src/subtitle.cc')
| -rw-r--r-- | src/subtitle.cc | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/subtitle.cc b/src/subtitle.cc index dc316c3..231abc6 100644 --- a/src/subtitle.cc +++ b/src/subtitle.cc @@ -19,6 +19,8 @@ #include "subtitle.h" +using std::ostream; +using std::list; using namespace sub; Subtitle::Subtitle (RawSubtitle s) @@ -56,6 +58,18 @@ Subtitle::same_metadata (RawSubtitle s) const return true; } +bool +sub::operator== (Subtitle const & a, Subtitle const & b) +{ + return ( + a.from == b.from && + a.to == b.to && + a.fade_up == b.fade_up && + a.fade_down == b.fade_down && + a.lines == b.lines + ); +} + Line::Line (RawSubtitle s) : vertical_position (s.vertical_position) { @@ -68,6 +82,15 @@ Line::same_metadata (RawSubtitle s) const return vertical_position == s.vertical_position; } +bool +sub::operator== (Line const & a, Line const & b) +{ + return ( + a.vertical_position == b.vertical_position && + a.blocks == b.blocks + ); +} + Block::Block (RawSubtitle s) : text (s.text) , font (s.font) @@ -81,3 +104,87 @@ Block::Block (RawSubtitle s) { } + +bool +sub::operator== (Block const & a, Block const & b) +{ + return ( + a.text == b.text && + a.font == b.font && + a.font_size == b.font_size && + a.effect == b.effect && + a.effect_colour == b.effect_colour && + a.colour == b.colour && + a.bold == b.bold && + a.italic == b.italic && + a.underline == b.underline + ); +} + +/* The output of this method should not be relied upon + as part of the API. +*/ +ostream & +sub::operator<< (ostream& s, Subtitle const & sub) +{ + s << "Subtitle at " << sub.from << " -> " << sub.to << "\n"; + for (list<sub::Line>::const_iterator i = sub.lines.begin(); i != sub.lines.end(); ++i) { + + s << "\t"; + + /* XXX: should be in VerticalPosition operator<< */ + if (i->vertical_position.proportional) { + s << i->vertical_position.proportional.get() << " of screen"; + } else if (i->vertical_position.line) { + s << i->vertical_position.line.get() << " lines of " << i->vertical_position.lines.get(); + } + if (i->vertical_position.reference) { + s << " from "; + switch (i->vertical_position.reference.get()) { + case TOP_OF_SCREEN: + s << "top"; + break; + case CENTRE_OF_SCREEN: + s << "centre"; + break; + case BOTTOM_OF_SCREEN: + s << "bottom"; + break; + case TOP_OF_SUBTITLE: + s << "top of subtitle"; + break; + } + } + + s << "\t"; + bool italic = false; + bool underline = false; + for (list<sub::Block>::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) { + if (j->italic && !italic) { + s << "<i>"; + } else if (italic && !j->italic) { + s << "</i>"; + } + if (j->underline && !underline) { + s << "<u>"; + } else if (underline && !j->underline) { + s << "</u>"; + } + + italic = j->italic; + underline = j->underline; + + s << j->text; + } + + if (italic) { + s << "</i>"; + } + if (underline) { + s << "</u>"; + } + s << "\n"; + } + + return s; +} |
