/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2015 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/lexical_cast.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/locale.hpp>
#include "stl_binary_reader.h"
#include "exceptions.h"
#include "iso6937.h"
+#include "stl_util.h"
#include "compose.hpp"
+#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/locale.hpp>
+#include <iostream>
using std::map;
using std::vector;
}
code_page_number = atoi (get_string (0, 3).c_str ());
-
- string const dfc = get_string (3, 8);
- if (dfc == "STL24.01") {
- frame_rate = 24;
- } else if (dfc == "STL25.01") {
- frame_rate = 25;
- } else if (dfc == "STL30.01") {
- frame_rate = 30;
- } else {
- throw STLError (String::compose ("Unknown disk format code %1 in binary STL file", dfc));
- }
-
+ frame_rate = stl_dfc_to_frame_rate (get_string (3, 8));
display_standard = _tables.display_standard_file_to_enum (get_string (11, 1));
language_group = _tables.language_group_file_to_enum (get_string (12, 2));
language = _tables.language_file_to_enum (get_string (14, 2));
editor_contact_details = get_string (341, 32);
for (int i = 0; i < tti_blocks; ++i) {
-
+
in.read ((char *) _buffer, 128);
if (in.gcount() != 128) {
throw STLError ("Could not read TTI block from binary STL file");
vector<string> lines;
split (lines, whole, is_any_of ("\x8a"));
+ /* Italic / underline specifications can span lines, so we need to track them
+ outside the lines loop.
+ */
+ bool italic = false;
+ bool underline = false;
+
for (size_t i = 0; i < lines.size(); ++i) {
RawSubtitle sub;
- sub.from.set_frame (get_timecode (5));
- sub.to.set_frame (get_timecode (9));
+ sub.from = get_timecode (5);
+ sub.to = 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;
+ sub.italic = italic;
+ sub.underline = underline;
+
+ /* XXX: not sure what to do with JC = 0, "unchanged presentation" */
+ int const h = get_int (14, 1);
+ switch (h) {
+ case 0:
+ case 2:
+ sub.horizontal_position.reference = HORIZONTAL_CENTRE_OF_SCREEN;
+ break;
+ case 1:
+ sub.horizontal_position.reference = LEFT_OF_SCREEN;
+ break;
+ case 3:
+ sub.horizontal_position.reference = RIGHT_OF_SCREEN;
+ break;
+ }
+ /* Loop over characters */
string text;
for (size_t j = 0; j < lines[i].size(); ++j) {
switch (c) {
case 0x80:
- sub.italic = true;
+ italic = true;
break;
case 0x81:
- sub.italic = false;
+ italic = false;
break;
case 0x82:
- sub.underline = true;
+ underline = true;
break;
case 0x83:
- sub.underline = false;
+ underline = false;
break;
default:
text += lines[i][j];
break;
}
+
+ sub.italic = italic;
+ sub.underline = underline;
}
if (!text.empty ()) {
sub.text = utf_to_utf<char> (iso6937_to_utf16 (text.c_str()));
_subs.push_back (sub);
}
-
+
/* XXX: justification */
}
}
return v;
}
-FrameTime
+Time
STLBinaryReader::get_timecode (int offset) const
{
- return FrameTime (_buffer[offset], _buffer[offset + 1], _buffer[offset + 2], _buffer[offset + 3]);
+ return Time::from_hmsf (_buffer[offset], _buffer[offset + 1], _buffer[offset + 2], _buffer[offset + 3], Rational (frame_rate, 1));
}
map<string, string>