diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-09 09:18:23 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-09 09:18:23 +0000 |
| commit | 94399f35aea4e37c699918f06eddfa931e4aaefc (patch) | |
| tree | 3cfedd40361b563cbfeaeede1c362f7c91531cc7 /src | |
| parent | c73bf7010a07aa00dc79d45662b2da1494c8ffb0 (diff) | |
| parent | d65ae002711e5c82ea4e382b577b2314944e1dbd (diff) | |
Merge branch 'master' of git.carlh.net:git/libsub
Diffstat (limited to 'src')
| -rw-r--r-- | src/stl_binary_reader.cc | 1 | ||||
| -rw-r--r-- | src/stl_binary_writer.cc | 14 | ||||
| -rw-r--r-- | src/stl_text_reader.cc | 2 | ||||
| -rw-r--r-- | src/subrip_reader.cc | 2 | ||||
| -rw-r--r-- | src/vertical_position.cc | 35 | ||||
| -rw-r--r-- | src/vertical_position.h | 6 |
6 files changed, 50 insertions, 10 deletions
diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc index ff3d9a0..2246a01 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.lines = maximum_rows; sub.vertical_position.reference = TOP_OF_SCREEN; string text; diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index aa9a032..b9ad86f 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -192,8 +192,8 @@ sub::write_stl_binary ( output.write (buffer, 1024); - int N = 0; for (list<Subtitle>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { + int N = 0; for (list<Line>::const_iterator j = i->lines.begin(); j != i->lines.end(); ++j) { memset (buffer, 0, 1024); @@ -235,18 +235,16 @@ sub::write_stl_binary ( break; } } else if (j->vertical_position.line) { - /* XXX: how many lines are there...? We need to correct for any difference - between the number of lines and our ROWS. - */ + float const prop = float (j->vertical_position.line.get()) / j->vertical_position.lines.get (); switch (j->vertical_position.reference.get_value_or (TOP_OF_SCREEN)) { case TOP_OF_SCREEN: - vp = j->vertical_position.line.get(); + vp = prop * ROWS; break; case CENTRE_OF_SCREEN: - vp = j->vertical_position.line.get() + (ROWS / 2); + vp = (prop + 0.5) * ROWS; break; case BOTTOM_OF_SCREEN: - vp = ROWS - (j->vertical_position.line.get()); + vp = (1 - prop) * ROWS; break; default: break; @@ -295,6 +293,8 @@ sub::write_stl_binary ( put_string (buffer + 16, text); output.write (buffer, 128); + + ++N; } } diff --git a/src/stl_text_reader.cc b/src/stl_text_reader.cc index 3c60e41..b86a656 100644 --- a/src/stl_text_reader.cc +++ b/src/stl_text_reader.cc @@ -39,6 +39,8 @@ using namespace sub; STLTextReader::STLTextReader (istream& in) { _subtitle.vertical_position.line = 0; + /* XXX: no idea what this should be */ + _subtitle.vertical_position.lines = 32; _subtitle.vertical_position.reference = TOP_OF_SCREEN; while (in.good ()) { diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 8bd2005..0aba120 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -132,6 +132,8 @@ SubripReader::convert_line (string t, int line_number, TimePair from, TimePair t p.from = from; p.to = to; p.vertical_position.line = line_number; + /* XXX: arbitrary */ + p.vertical_position.lines = 32; p.vertical_position.reference = TOP_OF_SUBTITLE; /* XXX: missing <font> support */ diff --git a/src/vertical_position.cc b/src/vertical_position.cc index 1fdb1e1..37930d0 100644 --- a/src/vertical_position.cc +++ b/src/vertical_position.cc @@ -21,14 +21,45 @@ using namespace sub; +float +VerticalPosition::fraction_from_screen_top () const +{ + if (!reference || (!proportional && !line)) { + return 0; + } + + float const prop = proportional ? proportional.get() : (float (line.get()) / lines.get ()); + + switch (reference.get ()) { + case TOP_OF_SCREEN: + return prop; + case CENTRE_OF_SCREEN: + return prop + 0.5; + case BOTTOM_OF_SCREEN: + return 1 - prop; + case TOP_OF_SUBTITLE: + return prop; + } + + return 0; +} + 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 (reference && line && other.reference && other.line) { - return line.get() == other.line.get() && reference.get() == other.reference.get(); + } else if (reference && line && lines && other.reference && other.line && other.lines) { + return line.get() == other.line.get() && lines.get() == other.lines.get() && reference.get() == other.reference.get(); } return false; } + +bool +VerticalPosition::operator< (VerticalPosition const & other) const +{ + return fraction_from_screen_top() < other.fraction_from_screen_top(); +} + + diff --git a/src/vertical_position.h b/src/vertical_position.h index 1d0b939..9f04056 100644 --- a/src/vertical_position.h +++ b/src/vertical_position.h @@ -35,11 +35,15 @@ public: boost::optional<float> proportional; /** line number offset from some reference point */ boost::optional<int> line; + /** number of lines on the whole screen (i.e. height of the screen in lines) */ + boost::optional<int> lines; /** reference point */ boost::optional<VerticalReference> reference; bool operator== (VerticalPosition const & other) const; - + bool operator< (VerticalPosition const & other) const; + + float fraction_from_screen_top () const; }; } |
