summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-16 10:35:00 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-16 10:35:00 +0000
commitf9c43d87b62653c2d37d4a7b470ca7d4c30b6af0 (patch)
tree1cba96c7bd5a80fec7969aae16af3da4adadd54b
parent6a90762b8d103d256aa3851e55574154881a4612 (diff)
Support horizontal positioning in STL binary reader/writer and DCP reader.
-rw-r--r--src/dcp_reader.cc18
-rw-r--r--src/horizontal_position.h34
-rw-r--r--src/raw_subtitle.h4
-rw-r--r--src/stl_binary_reader.cc15
-rw-r--r--src/stl_binary_writer.cc15
-rw-r--r--src/subtitle.cc3
-rw-r--r--src/subtitle.h6
-rw-r--r--src/wscript1
-rw-r--r--tools/dumpsubs.cc12
9 files changed, 101 insertions, 7 deletions
diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc
index 3376e36..b3b9bda 100644
--- a/src/dcp_reader.cc
+++ b/src/dcp_reader.cc
@@ -53,16 +53,28 @@ DCPReader::DCPReader (boost::filesystem::path file)
sub.vertical_position.proportional = float ((*i)->v_position ()) / 100;
switch ((*i)->v_align ()) {
- case libdcp::TOP:
+ case libdcp::VERTICAL_TOP:
sub.vertical_position.reference = TOP_OF_SCREEN;
break;
- case libdcp::CENTER:
+ case libdcp::VERTICAL_CENTER:
sub.vertical_position.reference = CENTRE_OF_SCREEN;
break;
- case libdcp::BOTTOM:
+ case libdcp::VERTICAL_BOTTOM:
sub.vertical_position.reference = BOTTOM_OF_SCREEN;
break;
}
+
+ switch ((*i)->h_align ()) {
+ case libdcp::HORIZONTAL_LEFT:
+ sub.horizontal_position = LEFT;
+ break;
+ case libdcp::HORIZONTAL_CENTER:
+ sub.horizontal_position = CENTRE;
+ break;
+ case libdcp::HORIZONTAL_RIGHT:
+ sub.horizontal_position = RIGHT;
+ break;
+ }
sub.from.set_metric (dcp_to_metric ((*i)->in ()));
sub.to.set_metric (dcp_to_metric ((*i)->out ()));
diff --git a/src/horizontal_position.h b/src/horizontal_position.h
new file mode 100644
index 0000000..df592d9
--- /dev/null
+++ b/src/horizontal_position.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef LIBSUB_HORIZONTAL_POSITION_H
+#define LIBSUB_HORIZONTAL_POSITION_H
+
+namespace sub {
+
+enum HorizontalPosition
+{
+ LEFT,
+ CENTRE,
+ RIGHT
+};
+
+}
+
+#endif
diff --git a/src/raw_subtitle.h b/src/raw_subtitle.h
index 8a8ac7f..f3cf93c 100644
--- a/src/raw_subtitle.h
+++ b/src/raw_subtitle.h
@@ -24,6 +24,7 @@
#include "metric_time.h"
#include "colour.h"
#include "vertical_reference.h"
+#include "horizontal_position.h"
#include "effect.h"
#include "time_pair.h"
#include "font_size.h"
@@ -45,6 +46,7 @@ public:
, bold (false)
, italic (false)
, underline (false)
+ , horizontal_position (CENTRE)
{}
/** Subtitle text in UTF-8 */
@@ -62,6 +64,8 @@ public:
bool italic; ///< true to use an italic version of font
bool underline; ///< true to underline
+ HorizontalPosition horizontal_position;
+
/** vertical position of the baseline of the text */
VerticalPosition vertical_position;
diff --git a/src/stl_binary_reader.cc b/src/stl_binary_reader.cc
index 2246a01..9a2fc11 100644
--- a/src/stl_binary_reader.cc
+++ b/src/stl_binary_reader.cc
@@ -101,6 +101,21 @@ STLBinaryReader::STLBinaryReader (istream& in)
sub.vertical_position.lines = maximum_rows;
sub.vertical_position.reference = TOP_OF_SCREEN;
+ /* 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 = CENTRE;
+ break;
+ case 1:
+ sub.horizontal_position = LEFT;
+ break;
+ case 3:
+ sub.horizontal_position = RIGHT;
+ break;
+ }
+
string text;
for (size_t j = 0; j < lines[i].size(); ++j) {
diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc
index b9ad86f..89bf36f 100644
--- a/src/stl_binary_writer.cc
+++ b/src/stl_binary_writer.cc
@@ -251,9 +251,20 @@ sub::write_stl_binary (
}
}
put_int_as_int (buffer + 13, vp, 1);
+
/* Justification code */
- /* XXX */
- put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_NONE), 1);
+ switch (j->horizontal_position) {
+ case LEFT:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_LEFT), 1);
+ break;
+ case CENTRE:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_CENTRE), 1);
+ break;
+ case RIGHT:
+ put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_RIGHT), 1);
+ break;
+ }
+
/* Comment flag */
put_int_as_int (buffer + 15, tables.comment_enum_to_file (COMMENT_NO), 1);
diff --git a/src/subtitle.cc b/src/subtitle.cc
index d828628..4f4c474 100644
--- a/src/subtitle.cc
+++ b/src/subtitle.cc
@@ -37,7 +37,8 @@ Subtitle::same_metadata (RawSubtitle s) const
}
Line::Line (RawSubtitle s)
- : vertical_position (s.vertical_position)
+ : horizontal_position (s.horizontal_position)
+ , vertical_position (s.vertical_position)
{
blocks.push_back (Block (s));
}
diff --git a/src/subtitle.h b/src/subtitle.h
index 6afdc51..0a9eb9d 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -77,11 +77,15 @@ public:
class Line
{
public:
- Line () {}
+ Line ()
+ : horizontal_position (CENTRE)
+ {}
/** Construct a Line taking any relevant information from a RawSubtitle */
Line (RawSubtitle s);
+ HorizontalPosition horizontal_position;
+
/** vertical position of the baseline of the text */
VerticalPosition vertical_position;
diff --git a/src/wscript b/src/wscript
index 599e2af..92535f7 100644
--- a/src/wscript
+++ b/src/wscript
@@ -40,6 +40,7 @@ def build(bld):
effect.h
font_size.h
frame_time.h
+ horizontal_position.h
metric_time.h
raw_subtitle.h
reader.h
diff --git a/tools/dumpsubs.cc b/tools/dumpsubs.cc
index fef3885..6cd1255 100644
--- a/tools/dumpsubs.cc
+++ b/tools/dumpsubs.cc
@@ -113,6 +113,18 @@ main (int argc, char* argv[])
}
}
+ switch (j->horizontal_position) {
+ case LEFT:
+ cout << "; left aligned";
+ break;
+ case CENTRE:
+ cout << "; horizontally centered";
+ break;
+ case RIGHT:
+ cout << "; right-aligned";
+ break;
+ }
+
cout << "\t";
bool italic = false;
bool underline = false;