summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-07 23:04:15 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-07 23:04:15 +0000
commit74765c0660239f48702ebc6d149d522b85392b63 (patch)
treed548627669b16513d5c2e8c877a7b15eb1879919
parentbe2117b1ea71c535e03c02be962387829806b1da (diff)
Sketchy support for total line counts when describing vertical position as a line number.
-rw-r--r--src/stl_binary_reader.cc1
-rw-r--r--src/stl_binary_writer.cc10
-rw-r--r--src/stl_text_reader.cc2
-rw-r--r--src/subrip_reader.cc2
-rw-r--r--src/vertical_position.cc4
-rw-r--r--src/vertical_position.h3
-rw-r--r--test/stl_binary_writer_test.cc3
-rw-r--r--tools/dumpsubs.cc2
8 files changed, 17 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..fcdc5fe 100644
--- a/src/stl_binary_writer.cc
+++ b/src/stl_binary_writer.cc
@@ -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;
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..cdf0b6c 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 (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;
diff --git a/src/vertical_position.h b/src/vertical_position.h
index 1d0b939..77b0675 100644
--- a/src/vertical_position.h
+++ b/src/vertical_position.h
@@ -35,11 +35,12 @@ 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;
-
};
}
diff --git a/test/stl_binary_writer_test.cc b/test/stl_binary_writer_test.cc
index 90142a7..9bc3ec7 100644
--- a/test/stl_binary_writer_test.cc
+++ b/test/stl_binary_writer_test.cc
@@ -40,6 +40,7 @@ BOOST_AUTO_TEST_CASE (stl_binary_writer_test)
b.font_size.set_points (42);
sub::Line l;
l.vertical_position.line = 0;
+ l.vertical_position.lines = 32;
l.vertical_position.reference = sub::TOP_OF_SCREEN;
l.blocks.push_back (b);
s.lines.push_back (l);
@@ -52,6 +53,7 @@ BOOST_AUTO_TEST_CASE (stl_binary_writer_test)
b.font_size.set_points (42);
sub::Line l;
l.vertical_position.line = 1;
+ l.vertical_position.lines = 32;
l.vertical_position.reference = sub::TOP_OF_SCREEN;
l.blocks.push_back (b);
s.lines.push_back (l);
@@ -67,6 +69,7 @@ BOOST_AUTO_TEST_CASE (stl_binary_writer_test)
sub::Line l;
l.vertical_position.line = 0;
+ l.vertical_position.lines = 32;
l.vertical_position.reference = sub::TOP_OF_SCREEN;
sub::Block b;
diff --git a/tools/dumpsubs.cc b/tools/dumpsubs.cc
index d8fb0c2..fef3885 100644
--- a/tools/dumpsubs.cc
+++ b/tools/dumpsubs.cc
@@ -93,7 +93,7 @@ main (int argc, char* argv[])
if (j->vertical_position.proportional) {
cout << j->vertical_position.proportional.get() << " of screen";
} else if (j->vertical_position.line) {
- cout << j->vertical_position.line.get() << " lines";
+ cout << j->vertical_position.line.get() << " lines of " << j->vertical_position.lines.get();
}
if (j->vertical_position.reference) {
cout << " from ";