Fix missing HAlign/VAlign attributes in subtitles when their value is negative.
authorCarl Hetherington <cth@carlh.net>
Sat, 13 Jan 2018 21:18:24 +0000 (21:18 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 13 Jan 2018 21:18:24 +0000 (21:18 +0000)
src/object.h
src/subtitle_asset_internal.cc
test/write_subtitle_test.cc

index 0804f4cfa1f8e8b3458d0dde40d3fdb9e507d2c5..8364efff8efb26b5fe8504ce0da8e1d56d786fba 100644 (file)
@@ -42,6 +42,7 @@
 #include <string>
 
 class write_interop_subtitle_test;
+class write_interop_subtitle_test2;
 class write_smpte_subtitle_test;
 class write_smpte_subtitle_test2;
 
@@ -64,6 +65,7 @@ public:
 
 protected:
        friend class ::write_interop_subtitle_test;
+       friend class ::write_interop_subtitle_test2;
        friend class ::write_smpte_subtitle_test;
        friend class ::write_smpte_subtitle_test2;
 
index bd28cdcb1414eec08a6e033d34b019e5bb12b666..4ae90461c1cabb084112dd25258edc747773c33d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -33,6 +33,7 @@
 
 #include "subtitle_asset_internal.h"
 #include "subtitle_string.h"
+#include <cmath>
 
 using std::string;
 using std::map;
@@ -156,7 +157,7 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const
                }
        }
 
-       if (_h_position > ALIGN_EPSILON) {
+       if (fabs(_h_position) > ALIGN_EPSILON) {
                if (context.standard == SMPTE) {
                        e->set_attribute ("Hposition", raw_convert<string> (_h_position * 100, 6));
                } else {
@@ -170,7 +171,7 @@ order::Text::as_xml (xmlpp::Element* parent, Context& context) const
                e->set_attribute ("VAlign", valign_to_string (_v_align));
        }
 
-       if (_v_position > ALIGN_EPSILON) {
+       if (fabs(_v_position) > ALIGN_EPSILON) {
                if (context.standard == SMPTE) {
                        e->set_attribute ("Vposition", raw_convert<string> (_v_position * 100, 6));
                } else {
index b27f8e0e1718f6886a383a3cebb226baebcddc46..bb5a77c4163c8a7e572f9117dc3ed538a8a45206 100644 (file)
@@ -217,6 +217,88 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test)
                );
 }
 
+/** Write some subtitle content as Interop XML and check that it is right.
+ *  This test includes some horizontal alignment.
+ */
+BOOST_AUTO_TEST_CASE (write_interop_subtitle_test2)
+{
+       dcp::InteropSubtitleAsset c;
+       c.set_reel_number ("1");
+       c.set_language ("EN");
+       c.set_movie_title ("Test");
+
+       c.add (
+               dcp::SubtitleString (
+                       string ("Frutiger"),
+                       false,
+                       false,
+                       false,
+                       dcp::Colour (255, 255, 255),
+                       48,
+                       1.0,
+                       dcp::Time (0, 4,  9, 22, 24),
+                       dcp::Time (0, 4, 11, 22, 24),
+                       -0.2,
+                       dcp::HALIGN_CENTER,
+                       0.8,
+                       dcp::VALIGN_TOP,
+                       dcp::DIRECTION_LTR,
+                       "Hello world",
+                       dcp::NONE,
+                       dcp::Colour (0, 0, 0),
+                       dcp::Time (0, 0, 0, 0, 24),
+                       dcp::Time (0, 0, 0, 0, 24)
+                       )
+               );
+
+       c.add (
+               dcp::SubtitleString (
+                       boost::optional<string> (),
+                       true,
+                       true,
+                       true,
+                       dcp::Colour (128, 0, 64),
+                       91,
+                       1.0,
+                       dcp::Time (5, 41,  0, 21, 24),
+                       dcp::Time (6, 12, 15, 21, 24),
+                       -0.2,
+                       dcp::HALIGN_CENTER,
+                       0.4,
+                       dcp::VALIGN_BOTTOM,
+                       dcp::DIRECTION_LTR,
+                       "What's going on",
+                       dcp::BORDER,
+                       dcp::Colour (1, 2, 3),
+                       dcp::Time (1, 2, 3, 4, 24),
+                       dcp::Time (5, 6, 7, 8, 24)
+                       )
+               );
+
+       c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
+
+       check_xml (
+               "<DCSubtitle Version=\"1.0\">"
+                 "<SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>"
+                 "<MovieTitle>Test</MovieTitle>"
+                 "<ReelNumber>1</ReelNumber>"
+                 "<Language>EN</Language>"
+                 "<Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" Id=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underlined=\"no\" Weight=\"normal\">"
+                   "<Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:229\" TimeOut=\"00:04:11:229\" FadeUpTime=\"0\" FadeDownTime=\"0\">"
+                     "<Text HPosition=\"-20\" VAlign=\"top\" VPosition=\"80\">Hello world</Text>"
+                   "</Subtitle>"
+                 "</Font>"
+                 "<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
+                   "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:218\" TimeOut=\"06:12:15:218\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
+                     "<Text HPosition=\"-20\" VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
+                   "</Subtitle>"
+                 "</Font>"
+               "</DCSubtitle>",
+               c.xml_as_string (),
+               list<string> ()
+               );
+}
+
 /* Write some subtitle content as SMPTE XML and check that it is right */
 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test)
 {