summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-14 15:13:48 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-14 15:13:48 +0000
commit972d33c500c9de02aa007440f665637e455610c1 (patch)
tree5956c54b3b97ab10b61fd1383cfd12de15959214 /src
parent65244fb9190e6d0aefc83c9cc4de83b1df18001d (diff)
Forward-port some stuff from 0.x.
Diffstat (limited to 'src')
-rw-r--r--src/stl_binary_reader.cc1
-rw-r--r--src/stl_binary_writer.cc14
-rw-r--r--src/stl_text_reader.cc2
-rw-r--r--src/subrip_reader.cc5
-rw-r--r--src/vertical_position.cc34
-rw-r--r--src/vertical_position.h6
6 files changed, 49 insertions, 13 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 557a250..0aba120 100644
--- a/src/subrip_reader.cc
+++ b/src/subrip_reader.cc
@@ -83,9 +83,6 @@ SubripReader::SubripReader (FILE* f)
}
case CONTENT:
if (line.empty ()) {
- /* XXX: I think this line_number should be set to some sensible value and TOP_OF_SUBTITLE
- should not be used.
- */
state = COUNTER;
line_number = 0;
} else {
@@ -135,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..5f7d0d0 100644
--- a/src/vertical_position.cc
+++ b/src/vertical_position.cc
@@ -21,14 +21,44 @@
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;
};
}