diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-10-06 13:29:36 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-10-06 13:29:36 +0100 |
| commit | 4ada3e7583dfdc658dbebca3c3603be1e3477c12 (patch) | |
| tree | 0516fdd142b79e7083ed3d455fe45fffce26a9a8 /src | |
| parent | 86440b2afe0a2b83a7e810f37b1f65dbddee90e8 (diff) | |
Template-ize collect so that any container can be used.
Add new vertical reference of TOP_OF_SUBTITLE, and use references
with line numbers as well as proportional specifiers.
Add a couple of methods to MetricTime.
Diffstat (limited to 'src')
| -rw-r--r-- | src/collect.cc | 60 | ||||
| -rw-r--r-- | src/collect.h | 35 | ||||
| -rw-r--r-- | src/dcp_reader.cc | 4 | ||||
| -rw-r--r-- | src/metric_time.h | 8 | ||||
| -rw-r--r-- | src/stl_binary_reader.cc | 1 | ||||
| -rw-r--r-- | src/stl_binary_writer.cc | 10 | ||||
| -rw-r--r-- | src/stl_text_reader.cc | 1 | ||||
| -rw-r--r-- | src/subrip_reader.cc | 4 | ||||
| -rw-r--r-- | src/vertical_position.cc | 4 | ||||
| -rw-r--r-- | src/vertical_position.h | 6 | ||||
| -rw-r--r-- | src/vertical_reference.cc | 6 | ||||
| -rw-r--r-- | src/vertical_reference.h | 7 | ||||
| -rw-r--r-- | src/wscript | 1 |
13 files changed, 67 insertions, 80 deletions
diff --git a/src/collect.cc b/src/collect.cc deleted file mode 100644 index 0f592d4..0000000 --- a/src/collect.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - 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 index 62e872f..ff43ce0 100644 --- a/src/collect.h +++ b/src/collect.h @@ -22,6 +22,39 @@ namespace sub { -std::list<Subtitle> collect (std::list<RawSubtitle>); +template <class T> +T +collect (std::list<RawSubtitle> raw) +{ + raw.sort (); + + T out; + + boost::optional<Subtitle> current; + for (std::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/dcp_reader.cc b/src/dcp_reader.cc index b938b6c..3634d93 100644 --- a/src/dcp_reader.cc +++ b/src/dcp_reader.cc @@ -47,11 +47,11 @@ class DCPText public: DCPText () : v_position (0) - , v_align (TOP) + , v_align (TOP_OF_SCREEN) {} DCPText (shared_ptr<const cxml::Node> node) - : v_align (CENTRE) + : v_align (CENTRE_OF_SCREEN) { text = node->content (); v_position = node->number_attribute<float> ("VPosition"); diff --git a/src/metric_time.h b/src/metric_time.h index 86c1923..404464e 100644 --- a/src/metric_time.h +++ b/src/metric_time.h @@ -42,6 +42,14 @@ public: int seconds () const; int milliseconds () const; + double all_as_seconds () const { + return all_as_milliseconds() / 1000.0; + } + + int64_t all_as_milliseconds () const { + return _ms; + } + void add (MetricTime t); void scale (float f); diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index dd0020f..ff3d9a0 100644 --- a/src/stl_binary_reader.cc +++ b/src/stl_binary_reader.cc @@ -98,6 +98,7 @@ STLBinaryReader::STLBinaryReader (istream& in) sub.from.set_frame (get_timecode (5)); sub.to.set_frame (get_timecode (9)); sub.vertical_position.line = get_int (13, 1) + i; + sub.vertical_position.reference = TOP_OF_SCREEN; string text; for (size_t j = 0; j < lines[i].size(); ++j) { diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index 9b98b84..0ebdc2c 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -135,18 +135,22 @@ sub::write_stl_binary ( if (j->vertical_position.proportional) { switch (j->vertical_position.reference.get ()) { - case TOP: + case TOP_OF_SCREEN: check_top.insert (j->vertical_position.proportional.get ()); break; - case CENTRE: + case CENTRE_OF_SCREEN: check_centre.insert (j->vertical_position.proportional.get ()); break; - case BOTTOM: + case BOTTOM_OF_SCREEN: check_bottom.insert (j->vertical_position.proportional.get ()); break; + case TOP_OF_SUBTITLE: + /* XXX: something needs to be done here */ + break; } } else { check_rows.insert (j->vertical_position.line.get ()); + /* XXX: this needs to take vertical_position.reference into account */ } } } diff --git a/src/stl_text_reader.cc b/src/stl_text_reader.cc index 7eaa24b..3c60e41 100644 --- a/src/stl_text_reader.cc +++ b/src/stl_text_reader.cc @@ -39,6 +39,7 @@ using namespace sub; STLTextReader::STLTextReader (istream& in) { _subtitle.vertical_position.line = 0; + _subtitle.vertical_position.reference = TOP_OF_SCREEN; while (in.good ()) { string line; diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 2728d20..8bd2005 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -131,8 +131,8 @@ SubripReader::convert_line (string t, int line_number, TimePair from, TimePair t p.font_size.set_points (48); p.from = from; p.to = to; - p.vertical_position.proportional = 0.7 + line_number * 0.1; - p.vertical_position.reference = TOP; + p.vertical_position.line = line_number; + p.vertical_position.reference = TOP_OF_SUBTITLE; /* XXX: missing <font> support */ /* XXX: nesting of tags e.g. <b>foo<i>bar<b>baz</b>fred</i>jim</b> might diff --git a/src/vertical_position.cc b/src/vertical_position.cc index 3984568..1fdb1e1 100644 --- a/src/vertical_position.cc +++ b/src/vertical_position.cc @@ -26,8 +26,8 @@ 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(); + } else if (reference && line && other.reference && other.line) { + return line.get() == other.line.get() && reference.get() == other.reference.get(); } return false; diff --git a/src/vertical_position.h b/src/vertical_position.h index 6a0fff4..1d0b939 100644 --- a/src/vertical_position.h +++ b/src/vertical_position.h @@ -33,10 +33,10 @@ 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 */ + /** line number offset from some reference point */ boost::optional<int> line; + /** reference point */ + boost::optional<VerticalReference> reference; bool operator== (VerticalPosition const & other) const; diff --git a/src/vertical_reference.cc b/src/vertical_reference.cc index 69f9d84..3f9219b 100644 --- a/src/vertical_reference.cc +++ b/src/vertical_reference.cc @@ -28,11 +28,11 @@ VerticalReference sub::string_to_vertical_reference (string s) { if (s == "top") { - return TOP; + return TOP_OF_SCREEN; } else if (s == "center") { - return CENTRE; + return CENTRE_OF_SCREEN; } else if (s == "bottom") { - return BOTTOM; + return BOTTOM_OF_SCREEN; } throw XMLError ("unknown subtitle valign type"); diff --git a/src/vertical_reference.h b/src/vertical_reference.h index 52cf840..4bdcde8 100644 --- a/src/vertical_reference.h +++ b/src/vertical_reference.h @@ -26,9 +26,10 @@ namespace sub { enum VerticalReference { - TOP, - CENTRE, - BOTTOM + TOP_OF_SCREEN, + CENTRE_OF_SCREEN, + BOTTOM_OF_SCREEN, + TOP_OF_SUBTITLE }; VerticalReference string_to_vertical_reference (std::string s); diff --git a/src/wscript b/src/wscript index cdc9c3f..58434b2 100644 --- a/src/wscript +++ b/src/wscript @@ -11,7 +11,6 @@ def build(bld): obj.uselib = 'CXML BOOST_FILESYSTEM BOOST_LOCALE' obj.export_includes = ['.'] obj.source = """ - collect.cc colour.cc dcp_reader.cc effect.cc |
