summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-29 15:15:37 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-29 15:15:37 +0100
commit97495d8cce58f0e5d9a43977698c60b8b66a83e3 (patch)
treeb2b13eb769002b6e0e0134ed98320cb507705e78
parentf6fb2090f4180f8cd507d694f7eb663b3f25d2f0 (diff)
Various tinkering with STL write.
-rw-r--r--src/stl_binary_writer.cc49
-rw-r--r--test/stl_binary_writer_test.cc60
2 files changed, 105 insertions, 4 deletions
diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc
index 8ec8c67..e05215a 100644
--- a/src/stl_binary_writer.cc
+++ b/src/stl_binary_writer.cc
@@ -18,17 +18,21 @@
*/
#include "stl_binary_writer.h"
+#include "subtitle.h"
#include "compose.hpp"
#include <list>
#include <cmath>
#include <fstream>
#include <iomanip>
+#include <set>
using std::list;
+using std::set;
using std::ofstream;
using std::string;
using std::setw;
using std::setfill;
+using std::max;
using namespace sub;
static void
@@ -97,6 +101,41 @@ sub::write_stl_binary (
char* buffer = new char[1024];
ofstream output (file_name.string().c_str ());
STLBinaryTables tables;
+
+ /* Find the longest subtitle in characters and the number of rows */
+
+ int longest = 0;
+
+ set<float> check_top;
+ set<float> check_centre;
+ set<float> check_bottom;
+ set<int> check_rows;
+
+ for (list<Subtitle>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) {
+ int t = 0;
+ for (list<Block>::const_iterator j = i->blocks.begin(); j != i->blocks.end(); ++j) {
+ t += j->text.size ();
+ }
+ longest = max (longest, t);
+
+ if (i->vertical_position.proportional) {
+ switch (i->vertical_position.reference.get ()) {
+ case TOP:
+ check_top.insert (i->vertical_position.proportional.get ());
+ break;
+ case CENTRE:
+ check_centre.insert (i->vertical_position.proportional.get ());
+ break;
+ case BOTTOM:
+ check_bottom.insert (i->vertical_position.proportional.get ());
+ break;
+ }
+ } else {
+ check_rows.insert (i->vertical_position.line.get ());
+ }
+ }
+
+ int const rows = check_top.size() + check_centre.size() + check_bottom.size() + check_rows.size();
/* Code page: 850 */
put_string (buffer + 0, "850");
@@ -125,11 +164,9 @@ sub::write_stl_binary (
/* Total number of subtitle groups */
put_string (buffer + 248, "000");
/* Maximum number of displayable characters in any text row */
- /* XXX */
- put_string (buffer + 251, "99");
+ put_int (buffer + 251, 2, longest);
/* Maximum number of displayable rows */
- /* XXX */
- put_string (buffer + 253, "99");
+ put_int (buffer + 253, 2, rows);
/* Time code status */
put_string (buffer + 255, "1");
/* Start-of-programme time code */
@@ -147,5 +184,9 @@ sub::write_stl_binary (
output.write (buffer, 1024);
+ for (list<Subtitle>::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) {
+
+ }
+
delete[] buffer;
}
diff --git a/test/stl_binary_writer_test.cc b/test/stl_binary_writer_test.cc
index 3960ea2..fafa14f 100644
--- a/test/stl_binary_writer_test.cc
+++ b/test/stl_binary_writer_test.cc
@@ -27,7 +27,67 @@ using std::list;
BOOST_AUTO_TEST_CASE (stl_binary_writer_test)
{
list<sub::Subtitle> subs;
+
+ {
+ sub::Subtitle s;
+ s.vertical_position.line = 0;
+ s.from.set_frame (sub::FrameTime (0, 0, 41, 9));
+ s.to.set_frame (sub::FrameTime (0, 0, 42, 21));
+
+ sub::Block b;
+ b.text = "This is a subtitle ";
+ b.font = "Arial";
+ b.font_size.set_points (42);
+ s.blocks.push_back (b);
+ }
+ {
+ sub::Subtitle s;
+ s.vertical_position.line = 1;
+ s.from.set_frame (sub::FrameTime (0, 0, 41, 9));
+ s.to.set_frame (sub::FrameTime (0, 0, 42, 21));
+
+ sub::Block b;
+ b.text = " and that's a line break";
+ b.font = "Arial";
+ b.font_size.set_points (42);
+ s.blocks.push_back (b);
+ }
+
+ {
+ sub::Subtitle s;
+ s.vertical_position.line = 0;
+ s.from.set_frame (sub::FrameTime (0, 1, 1, 1));
+ s.to.set_frame (sub::FrameTime (0, 1, 2, 10));
+
+ sub::Block b;
+ b.text = "This is some ";
+ b.font = "Arial";
+ b.font_size.set_points (42);
+ s.blocks.push_back (b);
+
+ b.text = "bold";
+ b.bold = true;
+ s.blocks.push_back (b);
+
+ b.text = " and some ";
+ b.bold = false;
+ s.blocks.push_back (b);
+
+ b.text = "bold italic";
+ b.bold = true;
+ b.italic = true;
+ s.blocks.push_back (b);
+
+ b.text = " and some ";
+ b.bold = false;
+ b.italic = false;
+ b.underline = true;
+ s.blocks.push_back (b);
+
+ subs.push_back (s);
+ }
+
sub::write_stl_binary (
subs,
25,