/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2016 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
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
+#include <iostream>
using std::list;
using std::ostream;
STLTextReader::STLTextReader (istream& in)
{
+ /* This reader extracts no information about where the subtitle
+ should be on screen, so its reference is TOP_OF_SUBTITLE.
+ */
_subtitle.vertical_position.line = 0;
-
+ _subtitle.vertical_position.reference = TOP_OF_SUBTITLE;
+
while (in.good ()) {
string line;
getline (in, line);
if (divider[0] != string::npos) {
divider[1] = line.find_first_of (",", divider[0] + 1);
}
-
+
if (divider[0] == string::npos || divider[1] == string::npos || divider[0] <= 1 || divider[1] >= line.length() - 1) {
warn (String::compose ("Unrecognised line %1", line));
continue;
string to_string = line.substr (divider[0] + 1, divider[1] - divider[0] - 1);
trim (to_string);
- optional<FrameTime> from = time (from_string);
- optional<FrameTime> to = time (to_string);
+ optional<Time> from = time (from_string);
+ optional<Time> to = time (to_string);
if (!from || !to) {
warn (String::compose ("Unrecognised line %1", line));
continue;
}
- _subtitle.from.set_frame (from.get ());
- _subtitle.to.set_frame (to.get ());
+ _subtitle.from = from.get ();
+ _subtitle.to = to.get ();
/* Parse ^B/^I/^U */
string text = line.substr (divider[1] + 1);
}
}
-optional<FrameTime>
+optional<Time>
STLTextReader::time (string t) const
{
vector<string> b;
split (b, t, is_any_of (":"));
if (b.size() != 4) {
warn (String::compose ("Unrecognised time %1", t));
- return optional<FrameTime> ();
+ return optional<Time> ();
}
- return FrameTime (lexical_cast<int> (b[0]), lexical_cast<int> (b[1]), lexical_cast<int> (b[2]), lexical_cast<int> (b[3]));
+ return sub::Time::from_hmsf (lexical_cast<int> (b[0]), lexical_cast<int> (b[1]), lexical_cast<int> (b[2]), lexical_cast<int> (b[3]));
}
void