diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-05-30 10:53:53 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-05-30 10:53:53 +0100 |
| commit | 38a5ff713757b9dc0cb67cb09613182c46dc9657 (patch) | |
| tree | ef337ee8bcd315b85f3a50ce37f623f3b1c51d76 /src | |
| parent | 97495d8cce58f0e5d9a43977698c60b8b66a83e3 (diff) | |
Split up into RawSubtitle and Subtitle, with collect(). Hopefully cleaner.
Diffstat (limited to 'src')
| -rw-r--r-- | src/collect.cc | 60 | ||||
| -rw-r--r-- | src/collect.h | 27 | ||||
| -rw-r--r-- | src/colour.h | 5 | ||||
| -rw-r--r-- | src/dcp_reader.cc | 53 | ||||
| -rw-r--r-- | src/effect.h | 5 | ||||
| -rw-r--r-- | src/font_size.cc | 42 | ||||
| -rw-r--r-- | src/font_size.h | 57 | ||||
| -rw-r--r-- | src/raw_subtitle.cc | 36 | ||||
| -rw-r--r-- | src/raw_subtitle.h | 78 | ||||
| -rw-r--r-- | src/reader.h | 6 | ||||
| -rw-r--r-- | src/stl_binary_reader.cc | 7 | ||||
| -rw-r--r-- | src/stl_binary_writer.cc | 38 | ||||
| -rw-r--r-- | src/stl_text_reader.cc | 43 | ||||
| -rw-r--r-- | src/stl_text_reader.h | 6 | ||||
| -rw-r--r-- | src/subtitle.cc | 69 | ||||
| -rw-r--r-- | src/subtitle.h | 74 | ||||
| -rw-r--r-- | src/time_pair.h | 5 | ||||
| -rw-r--r-- | src/vertical_position.cc | 34 | ||||
| -rw-r--r-- | src/vertical_position.h | 45 | ||||
| -rw-r--r-- | src/wscript | 3 |
20 files changed, 509 insertions, 184 deletions
diff --git a/src/collect.cc b/src/collect.cc new file mode 100644 index 0000000..0f592d4 --- /dev/null +++ b/src/collect.cc @@ -0,0 +1,60 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "raw_subtitle.h" +#include "subtitle.h" +#include "collect.h" + +using std::list; +using boost::optional; +using namespace sub; + +list<Subtitle> +sub::collect (list<RawSubtitle> raw) +{ + raw.sort (); + + list<Subtitle> out; + + optional<Subtitle> current; + for (list<RawSubtitle>::const_iterator i = raw.begin (); i != raw.end(); ++i) { + if (current && current->same_metadata (*i)) { + /* This RawSubtitle can be added to current... */ + if (!current->lines.empty() && current->lines.back().same_metadata (*i)) { + /* ... and indeed to its last line */ + current->lines.back().blocks.push_back (Block (*i)); + } else { + /* ... as a new line */ + current->lines.push_back (Line (*i)); + } + } else { + /* We must start a new Subtitle */ + if (current) { + out.push_back (current.get ()); + } + current = Subtitle (*i); + } + } + + if (current) { + out.push_back (current.get ()); + } + + return out; +} diff --git a/src/collect.h b/src/collect.h new file mode 100644 index 0000000..62e872f --- /dev/null +++ b/src/collect.h @@ -0,0 +1,27 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "subtitle.h" +#include "raw_subtitle.h" + +namespace sub { + +std::list<Subtitle> collect (std::list<RawSubtitle>); + +} diff --git a/src/colour.h b/src/colour.h index d6ca267..4989277 100644 --- a/src/colour.h +++ b/src/colour.h @@ -17,6 +17,9 @@ */ +#ifndef LIBSUB_COLOUR_H +#define LIBSUB_COLOUR_H + #include <string> namespace sub { @@ -50,3 +53,5 @@ bool operator== (Colour const & a, Colour const & b); } + +#endif diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc index bd5c183..a5fdd00 100644 --- a/src/dcp_reader.cc +++ b/src/dcp_reader.cc @@ -211,7 +211,6 @@ struct DCPReader::ParseState { list<shared_ptr<DCPFont> > font_nodes; list<shared_ptr<DCPText> > text_nodes; list<shared_ptr<DCPSubtitle> > subtitle_nodes; - boost::optional<Subtitle> subtitle; }; } @@ -269,12 +268,6 @@ DCPReader::DCPReader (istream& in) ParseState parse_state; examine_font_nodes (xml, font_nodes, parse_state); - - if (parse_state.subtitle && !parse_state.subtitle.get().blocks.empty ()) { - _subs.push_back (parse_state.subtitle.get ()); - } - - _subs.sort (); } void @@ -329,38 +322,26 @@ DCPReader::maybe_add_subtitle (string text, ParseState& parse_state) return; } - assert (!parse_state.text_nodes.empty ()); - assert (!parse_state.subtitle_nodes.empty ()); - DCPFont effective_font (parse_state.font_nodes); DCPText effective_text (*parse_state.text_nodes.back ()); DCPSubtitle effective_subtitle (*parse_state.subtitle_nodes.back ()); - Subtitle proposed_subtitle; - proposed_subtitle.vertical_position.proportional = float (effective_text.v_position) / 100; - proposed_subtitle.vertical_position.reference = effective_text.v_align; - proposed_subtitle.from.set_metric (effective_subtitle.in); - proposed_subtitle.to.set_metric (effective_subtitle.out); - proposed_subtitle.fade_up = effective_subtitle.fade_up_time; - proposed_subtitle.fade_down = effective_subtitle.fade_down_time; - - if (!parse_state.subtitle || !parse_state.subtitle.get().same_metadata (proposed_subtitle)) { - /* We need a new Subtitle */ - if (parse_state.subtitle && !parse_state.subtitle.get().blocks.empty ()) { - /* Push the old one */ - _subs.push_back (parse_state.subtitle.get ()); - } - parse_state.subtitle = proposed_subtitle; - } + RawSubtitle sub; + + sub.vertical_position.proportional = float (effective_text.v_position) / 100; + sub.vertical_position.reference = effective_text.v_align; + sub.from.set_metric (effective_subtitle.in); + sub.to.set_metric (effective_subtitle.out); + sub.fade_up = effective_subtitle.fade_up_time; + sub.fade_down = effective_subtitle.fade_down_time; - Block block; - block.text = text; - block.font = font_id_to_name (effective_font.id); - block.font_size.set_proportional (float (effective_font.size) / (72 * 11)); - block.effect = effective_font.effect; - block.effect_colour = effective_font.effect_colour; - block.colour = effective_font.colour.get (); - block.italic = effective_font.italic.get (); - - parse_state.subtitle.get().blocks.push_back (block); + sub.text = text; + sub.font = font_id_to_name (effective_font.id); + sub.font_size.set_proportional (float (effective_font.size) / (72 * 11)); + sub.effect = effective_font.effect; + sub.effect_colour = effective_font.effect_colour; + sub.colour = effective_font.colour.get (); + sub.italic = effective_font.italic.get (); + + _subs.push_back (sub); } diff --git a/src/effect.h b/src/effect.h index 41534a5..7c8c9c7 100644 --- a/src/effect.h +++ b/src/effect.h @@ -17,6 +17,9 @@ */ +#ifndef LIBSUB_EFFECT_H +#define LIBSUB_EFFECT_H + #include <boost/optional.hpp> #include <string> @@ -31,3 +34,5 @@ enum Effect boost::optional<Effect> string_to_effect (std::string s); } + +#endif diff --git a/src/font_size.cc b/src/font_size.cc new file mode 100644 index 0000000..d11ee89 --- /dev/null +++ b/src/font_size.cc @@ -0,0 +1,42 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "font_size.h" + +using namespace sub; + +float +FontSize::proportional (int screen_height_in_points) const +{ + if (_proportional) { + return _proportional.get (); + } + + return float (_points.get ()) / screen_height_in_points; +} + +int +FontSize::points (int screen_height_in_points) const +{ + if (_points) { + return _points.get (); + } + + return _proportional.get() * screen_height_in_points; +} diff --git a/src/font_size.h b/src/font_size.h new file mode 100644 index 0000000..2be2434 --- /dev/null +++ b/src/font_size.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef LIBSUB_FONT_SIZE_H +#define LIBSUB_FONT_SIZE_H + +namespace sub { + +class FontSize +{ +public: + void set_proportional (float p) { + _proportional = p; + } + + void set_points (int p) { + _points = p; + } + + boost::optional<float> proportional () const { + return _proportional; + } + + boost::optional<int> points () const { + return _points; + } + + float proportional (int screen_height_in_points) const; + int points (int screen_height_in_points) const; + +private: + /** as a proportion of screen height */ + boost::optional<float> _proportional; + /** in points */ + boost::optional<int> _points; + +}; + +} + +#endif diff --git a/src/raw_subtitle.cc b/src/raw_subtitle.cc new file mode 100644 index 0000000..24f1a8e --- /dev/null +++ b/src/raw_subtitle.cc @@ -0,0 +1,36 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "raw_subtitle.h" + +using namespace sub; + +bool +sub::operator< (RawSubtitle const & a, RawSubtitle const & b) +{ + if (a.from.frame() && b.from.frame()) { + return a.from.frame().get() < b.from.frame().get(); + } + + if (a.from.metric() && b.from.metric()) { + return a.from.metric().get() < b.from.metric().get(); + } + + assert (false); +} diff --git a/src/raw_subtitle.h b/src/raw_subtitle.h new file mode 100644 index 0000000..ffdc669 --- /dev/null +++ b/src/raw_subtitle.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef LIBSUB_RAW_SUBTITLE_H +#define LIBSUB_RAW_SUBTITLE_H + +#include "frame_time.h" +#include "metric_time.h" +#include "colour.h" +#include "vertical_reference.h" +#include "effect.h" +#include "time_pair.h" +#include "font_size.h" +#include "vertical_position.h" +#include <boost/optional.hpp> +#include <string> +#include <list> + +namespace sub { + +class RawSubtitle +{ +public: + RawSubtitle () + : colour (1, 1, 1) + , bold (false) + , italic (false) + , underline (false) + {} + + /** Subtitle text in UTF-8 */ + std::string text; + std::string font; + + /** font size */ + FontSize font_size; + + boost::optional<Effect> effect; + boost::optional<Colour> effect_colour; + + Colour colour; + bool bold; ///< true to use a bold version of font + bool italic; ///< true to use an italic version of font + bool underline; ///< true to underline + + /** vertical position of the baseline of the text */ + VerticalPosition vertical_position; + + /** from time */ + TimePair from; + /** to time */ + TimePair to; + + boost::optional<MetricTime> fade_up; + boost::optional<MetricTime> fade_down; +}; + +bool operator< (RawSubtitle const &, RawSubtitle const &); + +} + +#endif diff --git a/src/reader.h b/src/reader.h index 8aa9fd8..1237bb5 100644 --- a/src/reader.h +++ b/src/reader.h @@ -20,7 +20,7 @@ #ifndef LIBSUB_READER_H #define LIBSUB_READER_H -#include "subtitle.h" +#include "raw_subtitle.h" #include <list> #include <map> #include <string> @@ -30,7 +30,7 @@ namespace sub { class Reader { public: - std::list<Subtitle> subtitles () const { + std::list<RawSubtitle> subtitles () const { return _subs; } @@ -41,7 +41,7 @@ public: protected: void warn (std::string) const; - std::list<Subtitle> _subs; + std::list<RawSubtitle> _subs; }; } diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index b0701b5..6c02526 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -104,7 +104,7 @@ STLBinaryReader::STLBinaryReader (istream& in) split (lines, whole, is_any_of ("\x8a")); for (size_t i = 0; i < lines.size(); ++i) { - Subtitle sub; + RawSubtitle sub; sub.from.set_frame (get_timecode (5)); sub.to.set_frame (get_timecode (9)); sub.vertical_position.line = get_int (13, 1) + i; @@ -117,10 +117,7 @@ STLBinaryReader::STLBinaryReader (istream& in) lines[i] = lines[i].substr (0, unused); } - Block block; - block.text = utf_to_utf<char> (iso6937_to_utf16 (lines[i].c_str())); - sub.blocks.push_back (block); - + sub.text = utf_to_utf<char> (iso6937_to_utf16 (lines[i].c_str())); _subs.push_back (sub); } } diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index e05215a..e662764 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -113,25 +113,27 @@ sub::write_stl_binary ( for (list<Subtitle>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { int t = 0; - for (list<Block>::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) { - t += j->text.size (); - } - longest = max (longest, t); - - if (i->vertical_position.proportional) { - switch (i->vertical_position.reference.get ()) { - case TOP: - check_top.insert (i->vertical_position.proportional.get ()); - break; - case CENTRE: - check_centre.insert (i->vertical_position.proportional.get ()); - break; - case BOTTOM: - check_bottom.insert (i->vertical_position.proportional.get ()); - break; + for (list<Line>::const_iterator j = i->lines.begin(); j != i->lines.end(); ++j) { + for (list<Block>::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) { + t += k->text.size (); + } + longest = max (longest, t); + + if (j->vertical_position.proportional) { + switch (j->vertical_position.reference.get ()) { + case TOP: + check_top.insert (j->vertical_position.proportional.get ()); + break; + case CENTRE: + check_centre.insert (j->vertical_position.proportional.get ()); + break; + case BOTTOM: + check_bottom.insert (j->vertical_position.proportional.get ()); + break; + } + } else { + check_rows.insert (j->vertical_position.line.get ()); } - } else { - check_rows.insert (i->vertical_position.line.get ()); } } diff --git a/src/stl_text_reader.cc b/src/stl_text_reader.cc index 0b4141c..7eaa24b 100644 --- a/src/stl_text_reader.cc +++ b/src/stl_text_reader.cc @@ -100,30 +100,30 @@ STLTextReader::STLTextReader (istream& in) string text = line.substr (divider[1] + 1); for (size_t i = 0; i < text.length(); ++i) { if (text[i] == '|') { - maybe_push_subtitle (); + maybe_push (); _subtitle.vertical_position.line = _subtitle.vertical_position.line.get() + 1; } else if (text[i] == '^') { - maybe_push_block (); + maybe_push (); if ((i + 1) < text.length()) { switch (text[i + 1]) { case 'B': - _block.bold = !_block.bold; + _subtitle.bold = !_subtitle.bold; break; case 'I': - _block.italic = !_block.italic; + _subtitle.italic = !_subtitle.italic; break; case 'U': - _block.underline = !_block.underline; + _subtitle.underline = !_subtitle.underline; break; } } ++i; } else { - _block.text += text[i]; + _subtitle.text += text[i]; } } - maybe_push_subtitle (); + maybe_push (); } } } @@ -145,37 +145,24 @@ void STLTextReader::set (string name, string value) { if (name == "$FontName") { - _block.font = value; + _subtitle.font = value; } else if (name == "$Bold") { - _block.bold = value == "True"; + _subtitle.bold = value == "True"; } else if (name == "$Italic") { - _block.italic = value == "True"; + _subtitle.italic = value == "True"; } else if (name == "$Underlined") { - _block.underline = value == "True"; + _subtitle.underline = value == "True"; } else if (name == "$FontSize") { - _block.font_size.set_points (lexical_cast<int> (value)); + _subtitle.font_size.set_points (lexical_cast<int> (value)); } } void -STLTextReader::maybe_push_subtitle () +STLTextReader::maybe_push () { - maybe_push_block (); - - if (!_subtitle.blocks.empty ()) { + if (!_subtitle.text.empty ()) { _subs.push_back (_subtitle); - _subtitle.blocks.clear (); + _subtitle.text.clear (); _subtitle.vertical_position.line = 0; } } - -void -STLTextReader::maybe_push_block () -{ - if (!_block.text.empty ()) { - _subtitle.blocks.push_back (_block); - _block.text.clear (); - } -} - - diff --git a/src/stl_text_reader.h b/src/stl_text_reader.h index e6a550a..b84e8b8 100644 --- a/src/stl_text_reader.h +++ b/src/stl_text_reader.h @@ -29,12 +29,10 @@ public: private: void set (std::string name, std::string value); - void maybe_push_subtitle (); - void maybe_push_block (); + void maybe_push (); boost::optional<FrameTime> time (std::string t) const; - Subtitle _subtitle; - Block _block; + RawSubtitle _subtitle; }; } diff --git a/src/subtitle.cc b/src/subtitle.cc index 5eb5784..d828628 100644 --- a/src/subtitle.cc +++ b/src/subtitle.cc @@ -21,62 +21,43 @@ using namespace sub; -bool -sub::operator< (Subtitle const & a, Subtitle const & b) +Subtitle::Subtitle (RawSubtitle s) + : from (s.from) + , to (s.to) + , fade_up (s.fade_up) + , fade_down (s.fade_down) { - if (a.from.frame() && b.from.frame()) { - return a.from.frame().get() < b.from.frame().get(); - } - - if (a.from.metric() && b.from.metric()) { - return a.from.metric().get() < b.from.metric().get(); - } - - assert (false); + lines.push_back (Line (s)); } - -float -Block::FontSize::proportional (int screen_height_in_points) const +bool +Subtitle::same_metadata (RawSubtitle s) const { - if (_proportional) { - return _proportional.get (); - } - - return float (_points.get ()) / screen_height_in_points; + return from == s.from && to == s.to && fade_up == s.fade_up && fade_down == s.fade_down; } -int -Block::FontSize::points (int screen_height_in_points) const +Line::Line (RawSubtitle s) + : vertical_position (s.vertical_position) { - if (_points) { - return _points.get (); - } - - return _proportional.get() * screen_height_in_points; + blocks.push_back (Block (s)); } bool -Subtitle::same_metadata (Subtitle const & other) const +Line::same_metadata (RawSubtitle s) const { - return ( - vertical_position == other.vertical_position && - from == other.from && - to == other.to && - fade_up == other.fade_up && - fade_down == other.fade_down - ); + return vertical_position == s.vertical_position; } -bool -Subtitle::VerticalPosition::operator== (Subtitle::VerticalPosition const & other) const +Block::Block (RawSubtitle s) + : text (s.text) + , font (s.font) + , font_size (s.font_size) + , effect (s.effect) + , effect_colour (s.effect_colour) + , colour (s.colour) + , bold (s.bold) + , italic (s.italic) + , underline (s.underline) { - if (proportional && reference && other.proportional && other.reference) { - return proportional.get() == other.proportional.get() && reference.get() == other.reference.get(); - } else if (line && other.line) { - return line.get() == other.line.get(); - } - - return false; + } - diff --git a/src/subtitle.h b/src/subtitle.h index ca73b4b..795b11e 100644 --- a/src/subtitle.h +++ b/src/subtitle.h @@ -26,6 +26,9 @@ #include "vertical_reference.h" #include "effect.h" #include "time_pair.h" +#include "font_size.h" +#include "vertical_position.h" +#include "raw_subtitle.h" #include <boost/optional.hpp> #include <string> #include <list> @@ -42,40 +45,16 @@ public: , italic (false) , underline (false) {} + + /** Construct a Block taking any relevant information from a RawSubtitle */ + Block (RawSubtitle s); /** Subtitle text in UTF-8 */ std::string text; std::string font; /** font size */ - class FontSize { - public: - void set_proportional (float p) { - _proportional = p; - } - - void set_points (int p) { - _points = p; - } - - boost::optional<float> proportional () const { - return _proportional; - } - - boost::optional<int> points () const { - return _points; - } - - float proportional (int screen_height_in_points) const; - int points (int screen_height_in_points) const; - - private: - /** as a proportion of screen height */ - boost::optional<float> _proportional; - /** in points */ - boost::optional<int> _points; - - } font_size; + FontSize font_size; boost::optional<Effect> effect; boost::optional<Colour> effect_colour; @@ -86,27 +65,32 @@ public: bool underline; ///< true to underline }; -/** A line of text which starts and stops at specific times */ -class Subtitle +/** A line of text */ +class Line { public: - Subtitle () - {} + Line () {} + + /** Construct a Line taking any relevant information from a RawSubtitle */ + Line (RawSubtitle s); /** vertical position of the baseline of the text */ - struct VerticalPosition { + VerticalPosition vertical_position; + + std::list<Block> blocks; - /** as a proportion of screen height offset from some reference point */ - boost::optional<float> proportional; - /** reference position for proportional */ - boost::optional<VerticalReference> reference; - /** line number from the top of the screen */ - boost::optional<int> line; + bool same_metadata (RawSubtitle) const; +}; - bool operator== (VerticalPosition const & other) const; - - } vertical_position; +class Subtitle +{ +public: + Subtitle () + {} + /** Construct a Line taking any relevant information from a RawSubtitle */ + Subtitle (RawSubtitle s); + /** from time */ TimePair from; /** to time */ @@ -115,13 +99,11 @@ public: boost::optional<MetricTime> fade_up; boost::optional<MetricTime> fade_down; - std::list<Block> blocks; + std::list<Line> lines; - bool same_metadata (Subtitle const &) const; + bool same_metadata (RawSubtitle) const; }; -bool operator< (Subtitle const & a, Subtitle const & b); - } #endif diff --git a/src/time_pair.h b/src/time_pair.h index 0ed039d..404c143 100644 --- a/src/time_pair.h +++ b/src/time_pair.h @@ -17,6 +17,9 @@ */ +#ifndef LIBSUB_TIME_PAIR_H +#define LIBSUB_TIME_PAIR_H + #include "frame_time.h" #include "metric_time.h" #include <boost/optional.hpp> @@ -55,3 +58,5 @@ private: }; } + +#endif diff --git a/src/vertical_position.cc b/src/vertical_position.cc new file mode 100644 index 0000000..3984568 --- /dev/null +++ b/src/vertical_position.cc @@ -0,0 +1,34 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "vertical_position.h" + +using namespace sub; + +bool +VerticalPosition::operator== (VerticalPosition const & other) const +{ + if (proportional && reference && other.proportional && other.reference) { + return proportional.get() == other.proportional.get() && reference.get() == other.reference.get(); + } else if (line && other.line) { + return line.get() == other.line.get(); + } + + return false; +} diff --git a/src/vertical_position.h b/src/vertical_position.h new file mode 100644 index 0000000..6885f0e --- /dev/null +++ b/src/vertical_position.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef LIBSUB_VERTICAL_POSITION_H +#define LIBSUB_VERTICAL_POSITION_H + +#include "vertical_reference.h" +#include <boost/optional.hpp> + +namespace sub { + +/** Vertical position of the baseline of some text */ +class VerticalPosition +{ +public: + /** as a proportion of screen height offset from some reference point */ + boost::optional<float> proportional; + /** reference position for proportional */ + boost::optional<VerticalReference> reference; + /** line number from the top of the screen */ + boost::optional<int> line; + + bool operator== (VerticalPosition const & other) const; + +}; + +} + +#endif diff --git a/src/wscript b/src/wscript index dc954c9..41cf6f1 100644 --- a/src/wscript +++ b/src/wscript @@ -11,6 +11,7 @@ def build(bld): obj.uselib = 'CXML BOOST_FILESYSTEM BOOST_LOCALE' obj.export_includes = ['.'] obj.source = """ + collect.cc colour.cc dcp_reader.cc effect.cc @@ -18,6 +19,7 @@ def build(bld): iso6937.cc iso6937_tables.cc metric_time.cc + raw_subtitle.cc reader.cc reader_factory.cc stl_binary_reader.cc @@ -27,6 +29,7 @@ def build(bld): time_pair.cc subtitle.cc vertical_reference.cc + vertical_position.cc """ headers = """ |
