summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-03 16:09:24 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-03 16:09:24 +0100
commit4b0ece8d964961598ce4734ce25bb0aed66dbf7a (patch)
treee13cc114733d155353e8e20c73d96627a5ceb1a0
parent5e4c87ae58f1ed73b9ef19cd75210963599fa546 (diff)
Add AspectAdjust to subtitles.
-rwxr-xr-xrun/tests2
-rw-r--r--src/font_node.cc4
-rw-r--r--src/font_node.h1
-rw-r--r--src/interop_subtitle_content.cc15
-rw-r--r--src/subtitle_content.cc9
-rw-r--r--src/subtitle_string.cc9
-rw-r--r--src/subtitle_string.h14
-rw-r--r--src/types.h4
-rw-r--r--test/read_subtitle_test.cc23
-rw-r--r--test/write_subtitle_test.cc2
10 files changed, 70 insertions, 13 deletions
diff --git a/run/tests b/run/tests
index 243eee96..e8357d73 100755
--- a/run/tests
+++ b/run/tests
@@ -10,7 +10,7 @@ private=../libdcp1-test-private
work=build/test
dcpinfo=build/tools/dcpinfo
-export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:build/src:build/asdcplib/src
+export LD_LIBRARY_PATH=build/src:build/asdcplib/src:$LD_LIBRARY_PATH
for c in xmlsec1 xmldiff; do
hash $c 2>/dev/null || { echo >&2 "$c required but not found; aborting"; exit 1; }
diff --git a/src/font_node.cc b/src/font_node.cc
index 257a6b51..963eb0d8 100644
--- a/src/font_node.cc
+++ b/src/font_node.cc
@@ -37,6 +37,7 @@ FontNode::FontNode (cxml::ConstNodePtr node, int tcr)
id = node->optional_string_attribute ("Id");
size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
+ aspect_adjust = node->optional_number_attribute<float> ("AspectAdjust");
italic = node->optional_bool_attribute ("Italic");
optional<string> c = node->optional_string_attribute ("Color");
if (c) {
@@ -80,6 +81,9 @@ FontNode::FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes)
if ((*i)->size != 0) {
size = (*i)->size;
}
+ if ((*i)->aspect_adjust) {
+ aspect_adjust = (*i)->aspect_adjust.get ();
+ }
if ((*i)->italic) {
italic = (*i)->italic.get ();
}
diff --git a/src/font_node.h b/src/font_node.h
index 97efde73..2149e883 100644
--- a/src/font_node.h
+++ b/src/font_node.h
@@ -46,6 +46,7 @@ public:
std::string text;
boost::optional<std::string> id;
int size;
+ boost::optional<float> aspect_adjust;
boost::optional<bool> italic;
boost::optional<Colour> colour;
boost::optional<Effect> effect;
diff --git a/src/interop_subtitle_content.cc b/src/interop_subtitle_content.cc
index 305c3666..4829f077 100644
--- a/src/interop_subtitle_content.cc
+++ b/src/interop_subtitle_content.cc
@@ -23,6 +23,7 @@
#include "raw_convert.h"
#include "font_node.h"
#include <boost/foreach.hpp>
+#include <cmath>
using std::list;
using std::string;
@@ -93,6 +94,7 @@ InteropSubtitleContent::xml_as_string () const
bool italic = false;
Colour colour;
int size = 0;
+ float aspect_adjust = 1.0;
Effect effect = NONE;
Colour effect_colour;
int spot_number = 1;
@@ -112,11 +114,12 @@ InteropSubtitleContent::xml_as_string () const
*/
bool const font_changed =
- font != i->font() ||
- italic != i->italic() ||
+ font != i->font() ||
+ italic != i->italic() ||
colour != i->colour() ||
- size != i->size() ||
- effect != i->effect() ||
+ size != i->size() ||
+ fabs (aspect_adjust - i->aspect_adjust()) > ASPECT_ADJUST_EPSILON ||
+ effect != i->effect() ||
effect_colour != i->effect_colour();
if (font_changed) {
@@ -124,6 +127,7 @@ InteropSubtitleContent::xml_as_string () const
italic = i->italic ();
colour = i->colour ();
size = i->size ();
+ aspect_adjust = i->aspect_adjust ();
effect = i->effect ();
effect_colour = i->effect_colour ();
}
@@ -136,6 +140,9 @@ InteropSubtitleContent::xml_as_string () const
font_element->set_attribute ("Italic", italic ? "yes" : "no");
font_element->set_attribute ("Color", colour.to_argb_string());
font_element->set_attribute ("Size", raw_convert<string> (size));
+ if (fabs (aspect_adjust - 1.0) > ASPECT_ADJUST_EPSILON) {
+ font_element->set_attribute ("AspectAdjust", raw_convert<string> (aspect_adjust));
+ }
font_element->set_attribute ("Effect", effect_to_string (effect));
font_element->set_attribute ("EffectColor", effect_colour.to_argb_string());
font_element->set_attribute ("Script", "normal");
diff --git a/src/subtitle_content.cc b/src/subtitle_content.cc
index f8321273..1977861e 100644
--- a/src/subtitle_content.cc
+++ b/src/subtitle_content.cc
@@ -131,16 +131,17 @@ SubtitleContent::maybe_add_subtitle (string text, ParseState const & parse_state
_subtitles.push_back (
SubtitleString (
effective_font.id,
- effective_font.italic.get(),
- effective_font.colour.get(),
+ effective_font.italic.get_value_or (false),
+ effective_font.colour.get_value_or (dcp::Colour (255, 255, 255)),
effective_font.size,
+ effective_font.aspect_adjust.get_value_or (1.0),
effective_subtitle.in,
effective_subtitle.out,
effective_text.v_position,
effective_text.v_align,
text,
- effective_font.effect ? effective_font.effect.get() : NONE,
- effective_font.effect_colour.get(),
+ effective_font.effect.get_value_or (NONE),
+ effective_font.effect_colour.get_value_or (dcp::Colour (0, 0, 0)),
effective_subtitle.fade_up_time,
effective_subtitle.fade_down_time
)
diff --git a/src/subtitle_string.cc b/src/subtitle_string.cc
index 15131873..c4358381 100644
--- a/src/subtitle_string.cc
+++ b/src/subtitle_string.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-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
@@ -19,6 +19,7 @@
#include "subtitle_string.h"
#include "xml.h"
+#include <cmath>
using std::string;
using std::ostream;
@@ -31,6 +32,7 @@ SubtitleString::SubtitleString (
bool italic,
Colour colour,
int size,
+ float aspect_adjust,
Time in,
Time out,
float v_position,
@@ -45,6 +47,7 @@ SubtitleString::SubtitleString (
, _italic (italic)
, _colour (colour)
, _size (size)
+ , _aspect_adjust (aspect_adjust)
, _in (in)
, _out (out)
, _v_position (v_position)
@@ -77,6 +80,7 @@ dcp::operator== (SubtitleString const & a, SubtitleString const & b)
a.italic() == b.italic() &&
a.colour() == b.colour() &&
a.size() == b.size() &&
+ fabs (a.aspect_adjust() - b.aspect_adjust()) < ASPECT_ADJUST_EPSILON &&
a.in() == b.in() &&
a.out() == b.out() &&
a.v_position() == b.v_position() &&
@@ -102,7 +106,8 @@ dcp::operator<< (ostream& s, SubtitleString const & sub)
s << "non-italic";
}
- s << ", size " << sub.size() << ", colour " << sub.colour() << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align()) << ";\n"
+ s << ", size " << sub.size() << ", aspect " << sub.aspect_adjust() << ", colour " << sub.colour()
+ << ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align()) << ";\n"
<< "effect " << ((int) sub.effect()) << ", effect colour " << sub.effect_colour();
return s;
diff --git a/src/subtitle_string.h b/src/subtitle_string.h
index 966ae8cb..ba975778 100644
--- a/src/subtitle_string.h
+++ b/src/subtitle_string.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-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
@@ -42,6 +42,7 @@ public:
bool italic,
Colour colour,
int size,
+ float aspect_adjust,
Time in,
Time out,
float v_position,
@@ -108,9 +109,17 @@ public:
int size () const {
return _size;
}
-
+
int size_in_pixels (int screen_height) const;
+ /** @return Aspect ratio `adjustment' of the font size.
+ * Values greater than 1 widen each character, values less than 1 narrow each character,
+ * and the value must be between 0.25 and 4.
+ */
+ float aspect_adjust () const {
+ return _aspect_adjust;
+ }
+
/** @param p New vertical position as a proportion of the screen height
* from the top (between 0 and 1)
*/
@@ -133,6 +142,7 @@ private:
* would be 1/11th of the screen height.
*/
int _size;
+ float _aspect_adjust;
Time _in;
Time _out;
/** Vertical position as a proportion of the screen height from the _v_align
diff --git a/src/types.h b/src/types.h
index 3c74c45c..52b831f7 100644
--- a/src/types.h
+++ b/src/types.h
@@ -214,6 +214,10 @@ extern std::ostream & operator<< (std::ostream & s, Colour const & c);
typedef boost::function<void (NoteType, std::string)> NoteHandler;
+/** Maximum absolute difference between dcp::SubtitleString::aspect_adjust values that
+ * are considered equal.
+ */
+#define ASPECT_ADJUST_EPSILON (1e-3)
}
diff --git a/test/read_subtitle_test.cc b/test/read_subtitle_test.cc
index eed8488e..6ee59612 100644
--- a/test/read_subtitle_test.cc
+++ b/test/read_subtitle_test.cc
@@ -39,6 +39,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test1)
false,
dcp::Colour (255, 255, 255),
39,
+ 1.0,
dcp::Time (0, 0, 5, 198, 250),
dcp::Time (0, 0, 7, 115, 250),
0.15,
@@ -57,6 +58,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test1)
true,
dcp::Colour (255, 255, 255),
39,
+ 1.0,
dcp::Time (0, 0, 7, 177, 250),
dcp::Time (0, 0, 11, 31, 250),
0.21,
@@ -72,6 +74,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test1)
false,
dcp::Colour (255, 255, 255),
39,
+ 1.0,
dcp::Time (0, 0, 7, 177, 250),
dcp::Time (0, 0, 11, 31, 250),
0.15,
@@ -90,6 +93,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test1)
false,
dcp::Colour (255, 255, 255),
39,
+ 1.0,
dcp::Time (0, 0, 11, 94, 250),
dcp::Time (0, 0, 13, 63, 250),
0.15,
@@ -108,6 +112,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test1)
false,
dcp::Colour (255, 255, 255),
39,
+ 1.0,
dcp::Time (0, 0, 13, 104, 250),
dcp::Time (0, 0, 15, 177, 250),
0.15,
@@ -132,6 +137,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 0, 41, 62, 250),
dcp::Time (0, 0, 43, 52, 250),
0.89,
@@ -147,6 +153,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 0, 41, 62, 250),
dcp::Time (0, 0, 43, 52, 250),
0.95,
@@ -165,6 +172,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 0, 50, 42, 250),
dcp::Time (0, 0, 52, 21, 250),
0.89,
@@ -180,6 +188,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 0, 50, 42, 250),
dcp::Time (0, 0, 52, 21, 250),
0.95,
@@ -198,6 +207,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 2, 208, 250),
dcp::Time (0, 1, 4, 10, 250),
0.89,
@@ -213,6 +223,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 2, 208, 250),
dcp::Time (0, 1, 4, 10, 250),
0.95,
@@ -231,6 +242,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 15, 42, 250),
dcp::Time (0, 1, 16, 42, 250),
0.89,
@@ -246,6 +258,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 15, 42, 250),
dcp::Time (0, 1, 16, 42, 250),
0.95,
@@ -264,6 +277,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 27, 115, 250),
dcp::Time (0, 1, 28, 208, 250),
0.89,
@@ -279,6 +293,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 27, 115, 250),
dcp::Time (0, 1, 28, 208, 250),
0.95,
@@ -297,6 +312,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 42, 229, 250),
dcp::Time (0, 1, 45, 62, 250),
0.89,
@@ -312,6 +328,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 42, 229, 250),
dcp::Time (0, 1, 45, 62, 250),
0.95,
@@ -330,6 +347,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 45, 146, 250),
dcp::Time (0, 1, 47, 94, 250),
0.89,
@@ -345,6 +363,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 45, 146, 250),
dcp::Time (0, 1, 47, 94, 250),
0.95,
@@ -363,6 +382,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 47, 146, 250),
dcp::Time (0, 1, 48, 167, 250),
0.89,
@@ -378,6 +398,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
false,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 1, 47, 146, 250),
dcp::Time (0, 1, 48, 167, 250),
0.95,
@@ -396,6 +417,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 2, 5, 208, 250),
dcp::Time (0, 2, 7, 31, 250),
0.89,
@@ -411,6 +433,7 @@ BOOST_AUTO_TEST_CASE (read_subtitle_test2)
true,
dcp::Colour (255, 255, 255),
42,
+ 1.0,
dcp::Time (0, 2, 5, 208, 250),
dcp::Time (0, 2, 7, 31, 250),
0.95,
diff --git a/test/write_subtitle_test.cc b/test/write_subtitle_test.cc
index b5daa2b1..a017547b 100644
--- a/test/write_subtitle_test.cc
+++ b/test/write_subtitle_test.cc
@@ -37,6 +37,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
false,
dcp::Colour (255, 255, 255),
48,
+ 1.0,
dcp::Time (0, 4, 9, 22, 24),
dcp::Time (0, 4, 11, 22, 24),
0.8,
@@ -55,6 +56,7 @@ BOOST_AUTO_TEST_CASE (write_subtitle_test)
true,
dcp::Colour (128, 0, 64),
91,
+ 1.0,
dcp::Time (5, 41, 0, 21, 24),
dcp::Time (6, 12, 15, 21, 24),
0.4,