fee2d84176248cbc31c2ac022ade79873104fe38
[libdcp.git] / test / write_subtitle_test.cc
1 /*
2     Copyright (C) 2015-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #include "interop_subtitle_asset.h"
35 #include "smpte_subtitle_asset.h"
36 #include "subtitle_string.h"
37 #include "subtitle_image.h"
38 #include "subtitle_asset_internal.h"
39 #include "reel_subtitle_asset.h"
40 #include "reel.h"
41 #include "cpl.h"
42 #include "dcp.h"
43 #include "test.h"
44 #include "util.h"
45 #include <boost/test/unit_test.hpp>
46
47 using std::string;
48 using std::shared_ptr;
49 using std::vector;
50 using boost::optional;
51
52 /** Test dcp::order::Font::take_intersection */
53 BOOST_AUTO_TEST_CASE (take_intersection_test)
54 {
55         dcp::order::Font A;
56         A._values["foo"] = "bar";
57         A._values["fred"] = "jim";
58
59         dcp::order::Font B;
60         B._values["foo"] = "bar";
61         B._values["sheila"] = "baz";
62
63         A.take_intersection (B);
64         BOOST_REQUIRE_EQUAL (A._values.size(), 1);
65         BOOST_CHECK_EQUAL (A._values["foo"], "bar");
66
67         A._values.clear ();
68         B._values.clear ();
69
70         A._values["foo"] = "bar";
71         A._values["fred"] = "jim";
72
73         B._values["foo"] = "hello";
74         B._values["sheila"] = "baz";
75
76         A.take_intersection (B);
77         BOOST_CHECK_EQUAL (A._values.size(), 0);
78 }
79
80 /** Test dcp::order::Font::take_difference */
81 BOOST_AUTO_TEST_CASE (take_difference_test)
82 {
83         dcp::order::Font A;
84         A._values["foo"] = "bar";
85         A._values["fred"] = "jim";
86
87         dcp::order::Font B;
88         B._values["foo"] = "bar";
89         B._values["sheila"] = "baz";
90
91         A.take_difference (B);
92         BOOST_REQUIRE_EQUAL (A._values.size(), 1);
93         BOOST_CHECK_EQUAL (A._values["fred"], "jim");
94 }
95
96 /** Test dcp::order::Subtitle::pull_fonts */
97 BOOST_AUTO_TEST_CASE (pull_fonts_test1)
98 {
99         shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
100         shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
101         root->children.push_back (sub1);
102         shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
103         sub1->children.push_back (text1);
104         text1->font._values["font"] = "Inconsolata";
105         text1->font._values["size"] = "42";
106
107         dcp::SubtitleAsset::pull_fonts (root);
108
109         BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
110         BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
111         BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");
112         BOOST_CHECK_EQUAL (text1->font._values.size(), 0);
113 }
114
115 /** Test dcp::order::Subtitle::pull_fonts */
116 BOOST_AUTO_TEST_CASE (pull_fonts_test2)
117 {
118         shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
119         shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
120         root->children.push_back (sub1);
121         shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
122         sub1->children.push_back (text1);
123         text1->font._values["font"] = "Inconsolata";
124         text1->font._values["size"] = "42";
125         shared_ptr<dcp::order::Text> text2 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
126         sub1->children.push_back (text2);
127         text2->font._values["font"] = "Inconsolata";
128         text2->font._values["size"] = "48";
129
130         dcp::SubtitleAsset::pull_fonts (root);
131
132         BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 1);
133         BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
134         BOOST_REQUIRE_EQUAL (text1->font._values.size(), 1);
135         BOOST_CHECK_EQUAL (text1->font._values["size"], "42");
136         BOOST_REQUIRE_EQUAL (text2->font._values.size(), 1);
137         BOOST_CHECK_EQUAL (text2->font._values["size"], "48");
138 }
139
140 /** Test dcp::order::Subtitle::pull_fonts */
141 BOOST_AUTO_TEST_CASE (pull_fonts_test3)
142 {
143         shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
144         shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
145         root->children.push_back (sub1);
146         shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
147         sub1->children.push_back (text1);
148         dcp::order::Font font;
149         font._values["font"] = "Inconsolata";
150         font._values["size"] = "42";
151         shared_ptr<dcp::order::String> string1 (new dcp::order::String (text1, font, "Hello world"));
152         text1->children.push_back (string1);
153
154         dcp::SubtitleAsset::pull_fonts (root);
155
156         BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
157         BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
158         BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");
159 }
160
161 /** Write some subtitle content as Interop XML and check that it is right */
162 BOOST_AUTO_TEST_CASE (write_interop_subtitle_test)
163 {
164         dcp::InteropSubtitleAsset c;
165         c.set_reel_number ("1");
166         c.set_language ("EN");
167         c.set_movie_title ("Test");
168
169         c.add (
170                 shared_ptr<dcp::Subtitle> (
171                         new dcp::SubtitleString (
172                                 string ("Frutiger"),
173                                 false,
174                                 false,
175                                 false,
176                                 dcp::Colour (255, 255, 255),
177                                 48,
178                                 1.0,
179                                 dcp::Time (0, 4,  9, 22, 24),
180                                 dcp::Time (0, 4, 11, 22, 24),
181                                 0,
182                                 dcp::HALIGN_CENTER,
183                                 0.8,
184                                 dcp::VALIGN_TOP,
185                                 dcp::DIRECTION_LTR,
186                                 "Hello world",
187                                 dcp::NONE,
188                                 dcp::Colour (0, 0, 0),
189                                 dcp::Time (0, 0, 0, 0, 24),
190                                 dcp::Time (0, 0, 0, 0, 24)
191                                 )
192                         )
193                 );
194
195         c.add (
196                 shared_ptr<dcp::Subtitle> (
197                         new dcp::SubtitleString (
198                                 boost::optional<string> (),
199                                 true,
200                                 true,
201                                 true,
202                                 dcp::Colour (128, 0, 64),
203                                 91,
204                                 1.0,
205                                 dcp::Time (5, 41,  0, 21, 24),
206                                 dcp::Time (6, 12, 15, 21, 24),
207                                 0,
208                                 dcp::HALIGN_CENTER,
209                                 0.4,
210                                 dcp::VALIGN_BOTTOM,
211                                 dcp::DIRECTION_LTR,
212                                 "What's going on",
213                                 dcp::BORDER,
214                                 dcp::Colour (1, 2, 3),
215                                 dcp::Time (1, 2, 3, 4, 24),
216                                 dcp::Time (5, 6, 7, 8, 24)
217                                 )
218                         )
219                 );
220
221         c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
222
223         check_xml (
224                 "<DCSubtitle Version=\"1.0\">"
225                   "<SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>"
226                   "<MovieTitle>Test</MovieTitle>"
227                   "<ReelNumber>1</ReelNumber>"
228                   "<Language>EN</Language>"
229                   "<Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" Id=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underlined=\"no\" Weight=\"normal\">"
230                     "<Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:229\" TimeOut=\"00:04:11:229\" FadeUpTime=\"0\" FadeDownTime=\"0\">"
231                       "<Text VAlign=\"top\" VPosition=\"80\">Hello world</Text>"
232                     "</Subtitle>"
233                   "</Font>"
234                   "<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
235                     "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
236                       "<Text VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
237                     "</Subtitle>"
238                   "</Font>"
239                 "</DCSubtitle>",
240                 c.xml_as_string (),
241                 vector<string>()
242                 );
243 }
244
245 /** Write some subtitle content as Interop XML and check that it is right.
246  *  This test includes some horizontal alignment.
247  */
248 BOOST_AUTO_TEST_CASE (write_interop_subtitle_test2)
249 {
250         dcp::InteropSubtitleAsset c;
251         c.set_reel_number ("1");
252         c.set_language ("EN");
253         c.set_movie_title ("Test");
254
255         c.add (
256                 shared_ptr<dcp::Subtitle> (
257                         new dcp::SubtitleString (
258                                 string ("Frutiger"),
259                                 false,
260                                 false,
261                                 false,
262                                 dcp::Colour (255, 255, 255),
263                                 48,
264                                 1.0,
265                                 dcp::Time (0, 4,  9, 22, 24),
266                                 dcp::Time (0, 4, 11, 22, 24),
267                                 -0.2,
268                                 dcp::HALIGN_CENTER,
269                                 0.8,
270                                 dcp::VALIGN_TOP,
271                                 dcp::DIRECTION_LTR,
272                                 "Hello world",
273                                 dcp::NONE,
274                                 dcp::Colour (0, 0, 0),
275                                 dcp::Time (0, 0, 0, 0, 24),
276                                 dcp::Time (0, 0, 0, 0, 24)
277                                 )
278                         )
279                 );
280
281         c.add (
282                 shared_ptr<dcp::Subtitle> (
283                         new dcp::SubtitleString (
284                                 boost::optional<string> (),
285                                 true,
286                                 true,
287                                 true,
288                                 dcp::Colour (128, 0, 64),
289                                 91,
290                                 1.0,
291                                 dcp::Time (5, 41,  0, 21, 24),
292                                 dcp::Time (6, 12, 15, 21, 24),
293                                 -0.2,
294                                 dcp::HALIGN_CENTER,
295                                 0.4,
296                                 dcp::VALIGN_BOTTOM,
297                                 dcp::DIRECTION_LTR,
298                                 "What's going on",
299                                 dcp::BORDER,
300                                 dcp::Colour (1, 2, 3),
301                                 dcp::Time (1, 2, 3, 4, 24),
302                                 dcp::Time (5, 6, 7, 8, 24)
303                                 )
304                         )
305                 );
306
307         c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
308
309         check_xml (
310                 "<DCSubtitle Version=\"1.0\">"
311                   "<SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>"
312                   "<MovieTitle>Test</MovieTitle>"
313                   "<ReelNumber>1</ReelNumber>"
314                   "<Language>EN</Language>"
315                   "<Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" Id=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underlined=\"no\" Weight=\"normal\">"
316                     "<Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:229\" TimeOut=\"00:04:11:229\" FadeUpTime=\"0\" FadeDownTime=\"0\">"
317                       "<Text HPosition=\"-20\" VAlign=\"top\" VPosition=\"80\">Hello world</Text>"
318                     "</Subtitle>"
319                   "</Font>"
320                   "<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
321                     "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:219\" TimeOut=\"06:12:15:219\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
322                       "<Text HPosition=\"-20\" VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
323                     "</Subtitle>"
324                   "</Font>"
325                 "</DCSubtitle>",
326                 c.xml_as_string (),
327                 vector<string>()
328                 );
329 }
330
331 /* Write some subtitle content as Interop XML using bitmaps and check that it is right */
332 BOOST_AUTO_TEST_CASE (write_interop_subtitle_test3)
333 {
334         RNGFixer fix;
335
336         shared_ptr<dcp::InteropSubtitleAsset> c (new dcp::InteropSubtitleAsset());
337         c->set_reel_number ("1");
338         c->set_language ("EN");
339         c->set_movie_title ("Test");
340
341         c->add (
342                 shared_ptr<dcp::Subtitle> (
343                         new dcp::SubtitleImage (
344                                 dcp::ArrayData ("test/data/sub.png"),
345                                 dcp::Time (0, 4,  9, 22, 24),
346                                 dcp::Time (0, 4, 11, 22, 24),
347                                 0,
348                                 dcp::HALIGN_CENTER,
349                                 0.8,
350                                 dcp::VALIGN_TOP,
351                                 dcp::Time (0, 0, 0, 0, 24),
352                                 dcp::Time (0, 0, 0, 0, 24)
353                                 )
354                         )
355                 );
356
357         c->_id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
358         boost::filesystem::remove_all ("build/test/write_interop_subtitle_test3");
359         boost::filesystem::create_directories ("build/test/write_interop_subtitle_test3");
360         c->write ("build/test/write_interop_subtitle_test3/subs.xml");
361
362         shared_ptr<dcp::Reel> reel (new dcp::Reel());
363         reel->add(shared_ptr<dcp::ReelSubtitleAsset>(new dcp::ReelSubtitleAsset(c, dcp::Fraction(24, 1), 6046, 0)));
364
365         string const issue_date = "2018-09-02T04:45:18+00:00";
366         string const issuer = "libdcp";
367         string const creator = "libdcp";
368         string const annotation_text = "Created by libdcp";
369
370         shared_ptr<dcp::CPL> cpl (new dcp::CPL ("My film", dcp::FEATURE));
371         cpl->add (reel);
372         cpl->set_issuer (issuer);
373         cpl->set_creator (creator);
374         cpl->set_issue_date (issue_date);
375         cpl->set_annotation_text (annotation_text);
376         optional<dcp::ContentVersion> cv = cpl->content_version();
377         BOOST_REQUIRE (cv);
378         cv->label_text = "foo";
379         cpl->set_content_version (*cv);
380
381         dcp::DCP dcp ("build/test/write_interop_subtitle_test3");
382         dcp.add (cpl);
383         dcp.write_xml (dcp::INTEROP, issuer, creator, issue_date, annotation_text);
384
385         check_xml (
386                 dcp::file_to_string("test/ref/write_interop_subtitle_test3/subs.xml"),
387                 dcp::file_to_string("build/test/write_interop_subtitle_test3/subs.xml"),
388                 vector<string>()
389                 );
390         check_file ("build/test/write_interop_subtitle_test3/d36f4bb3-c4fa-4a95-9915-6fec3110cd71.png", "test/data/sub.png");
391
392         check_xml (
393                 dcp::file_to_string("test/ref/write_interop_subtitle_test3/ASSETMAP"),
394                 dcp::file_to_string("build/test/write_interop_subtitle_test3/ASSETMAP"),
395                 vector<string>()
396                 );
397
398         check_xml (
399                 dcp::file_to_string("test/ref/write_interop_subtitle_test3/pkl.xml"),
400                 dcp::file_to_string("build/test/write_interop_subtitle_test3/pkl_6a9e31a6-50a4-4ecb-8683-fa667848470a.xml"),
401                 vector<string>()
402                 );
403 }
404
405 /* Write some subtitle content as SMPTE XML and check that it is right */
406 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test)
407 {
408         dcp::SMPTESubtitleAsset c;
409         c.set_reel_number (1);
410         c.set_language (dcp::LanguageTag("en"));
411         c.set_content_title_text ("Test");
412         c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
413
414         c.add (
415                 shared_ptr<dcp::Subtitle> (
416                         new dcp::SubtitleString (
417                                 string ("Frutiger"),
418                                 false,
419                                 false,
420                                 false,
421                                 dcp::Colour (255, 255, 255),
422                                 48,
423                                 1.0,
424                                 dcp::Time (0, 4,  9, 22, 24),
425                                 dcp::Time (0, 4, 11, 22, 24),
426                                 0,
427                                 dcp::HALIGN_CENTER,
428                                 0.8,
429                                 dcp::VALIGN_TOP,
430                                 dcp::DIRECTION_LTR,
431                                 "Hello world",
432                                 dcp::NONE,
433                                 dcp::Colour (0, 0, 0),
434                                 dcp::Time (0, 0, 0, 0, 24),
435                                 dcp::Time (0, 0, 0, 0, 24)
436                                 )
437                         )
438                 );
439
440         c.add (
441                 shared_ptr<dcp::Subtitle> (
442                         new dcp::SubtitleString (
443                                 boost::optional<string> (),
444                                 true,
445                                 true,
446                                 true,
447                                 dcp::Colour (128, 0, 64),
448                                 91,
449                                 1.0,
450                                 dcp::Time (5, 41,  0, 21, 24),
451                                 dcp::Time (6, 12, 15, 21, 24),
452                                 0,
453                                 dcp::HALIGN_CENTER,
454                                 0.4,
455                                 dcp::VALIGN_BOTTOM,
456                                 dcp::DIRECTION_RTL,
457                                 "What's going on",
458                                 dcp::BORDER,
459                                 dcp::Colour (1, 2, 3),
460                                 dcp::Time (1, 2, 3, 4, 24),
461                                 dcp::Time (5, 6, 7, 8, 24)
462                                 )
463                         )
464                 );
465
466         c._xml_id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
467
468         check_xml (
469                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
470                 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
471                   "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
472                   "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
473                   "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
474                   "<dcst:ReelNumber>1</dcst:ReelNumber>"
475                   "<dcst:Language>en</dcst:Language>"
476                   "<dcst:EditRate>24 1</dcst:EditRate>"
477                   "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
478                   "<dcst:SubtitleList>"
479                     "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
480                       "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:22\" TimeOut=\"00:04:11:22\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
481                         "<dcst:Text Valign=\"top\" Vposition=\"80\">Hello world</dcst:Text>"
482                       "</dcst:Subtitle>"
483                     "</dcst:Font>"
484                     "<dcst:Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underline=\"yes\" Weight=\"bold\">"
485                       "<dcst:Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:21\" TimeOut=\"06:12:15:21\" FadeUpTime=\"01:02:03:04\" FadeDownTime=\"05:06:07:08\">"
486                         "<dcst:Text Valign=\"bottom\" Vposition=\"40\" Direction=\"rtl\">What's going on</dcst:Text>"
487                       "</dcst:Subtitle>"
488                     "</dcst:Font>"
489                   "</dcst:SubtitleList>"
490                 "</dcst:SubtitleReel>",
491                 c.xml_as_string (),
492                 vector<string>()
493                 );
494 }
495
496 /* Write some subtitle content as SMPTE XML and check that it is right.
497    This includes in-line font changes.
498 */
499 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test2)
500 {
501         dcp::SMPTESubtitleAsset c;
502         c.set_reel_number (1);
503         c.set_language (dcp::LanguageTag("en"));
504         c.set_content_title_text ("Test");
505         c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
506
507         c.add (
508                 shared_ptr<dcp::Subtitle> (
509                         new dcp::SubtitleString (
510                                 string ("Arial"),
511                                 false,
512                                 false,
513                                 false,
514                                 dcp::Colour (255, 255, 255),
515                                 48,
516                                 1.0,
517                                 dcp::Time (0, 0, 1, 0, 24),
518                                 dcp::Time (0, 0, 9, 0, 24),
519                                 0,
520                                 dcp::HALIGN_CENTER,
521                                 0.8,
522                                 dcp::VALIGN_TOP,
523                                 dcp::DIRECTION_LTR,
524                                 "Testing is ",
525                                 dcp::NONE,
526                                 dcp::Colour (0, 0, 0),
527                                 dcp::Time (0, 0, 0, 0, 24),
528                                 dcp::Time (0, 0, 0, 0, 24)
529                                 )
530                         )
531                 );
532
533         c.add (
534                 shared_ptr<dcp::Subtitle> (
535                         new dcp::SubtitleString (
536                                 string ("Arial"),
537                                 true,
538                                 false,
539                                 false,
540                                 dcp::Colour (255, 255, 255),
541                                 48,
542                                 1.0,
543                                 dcp::Time (0, 0, 1, 0, 24),
544                                 dcp::Time (0, 0, 9, 0, 24),
545                                 0,
546                                 dcp::HALIGN_CENTER,
547                                 0.8,
548                                 dcp::VALIGN_TOP,
549                                 dcp::DIRECTION_LTR,
550                                 "really",
551                                 dcp::NONE,
552                                 dcp::Colour (0, 0, 0),
553                                 dcp::Time (0, 0, 0, 0, 24),
554                                 dcp::Time (0, 0, 0, 0, 24)
555                                 )
556                         )
557                 );
558
559         c.add (
560                 shared_ptr<dcp::Subtitle> (
561                         new dcp::SubtitleString (
562                                 string ("Arial"),
563                                 false,
564                                 false,
565                                 false,
566                                 dcp::Colour (255, 255, 255),
567                                 48,
568                                 1.0,
569                                 dcp::Time (0, 0, 1, 0, 24),
570                                 dcp::Time (0, 0, 9, 0, 24),
571                                 0,
572                                 dcp::HALIGN_CENTER,
573                                 0.8,
574                                 dcp::VALIGN_TOP,
575                                 dcp::DIRECTION_LTR,
576                                 " fun",
577                                 dcp::NONE,
578                                 dcp::Colour (0, 0, 0),
579                                 dcp::Time (0, 0, 0, 0, 24),
580                                 dcp::Time (0, 0, 0, 0, 24)
581                                 )
582                         )
583                 );
584
585         c.add (
586                 shared_ptr<dcp::Subtitle> (
587                         new dcp::SubtitleString (
588                                 string ("Arial"),
589                                 false,
590                                 false,
591                                 false,
592                                 dcp::Colour (255, 255, 255),
593                                 48,
594                                 1.0,
595                                 dcp::Time (0, 0, 1, 0, 24),
596                                 dcp::Time (0, 0, 9, 0, 24),
597                                 0,
598                                 dcp::HALIGN_CENTER,
599                                 0.9,
600                                 dcp::VALIGN_TOP,
601                                 dcp::DIRECTION_LTR,
602                                 "This is the ",
603                                 dcp::NONE,
604                                 dcp::Colour (0, 0, 0),
605                                 dcp::Time (0, 0, 0, 0, 24),
606                                 dcp::Time (0, 0, 0, 0, 24)
607                                 )
608                         )
609                 );
610
611         c.add (
612                 shared_ptr<dcp::Subtitle> (
613                         new dcp::SubtitleString (
614                                 string ("Arial"),
615                                 true,
616                                 false,
617                                 false,
618                                 dcp::Colour (255, 255, 255),
619                                 48,
620                                 1.0,
621                                 dcp::Time (0, 0, 1, 0, 24),
622                                 dcp::Time (0, 0, 9, 0, 24),
623                                 0,
624                                 dcp::HALIGN_CENTER,
625                                 0.9,
626                                 dcp::VALIGN_TOP,
627                                 dcp::DIRECTION_LTR,
628                                 "second",
629                                 dcp::NONE,
630                                 dcp::Colour (0, 0, 0),
631                                 dcp::Time (0, 0, 0, 0, 24),
632                                 dcp::Time (0, 0, 0, 0, 24)
633                                 )
634                         )
635                 );
636
637         c.add (
638                 shared_ptr<dcp::Subtitle> (
639                         new dcp::SubtitleString (
640                                 string ("Arial"),
641                                 false,
642                                 false,
643                                 false,
644                                 dcp::Colour (255, 255, 255),
645                                 48,
646                                 1.0,
647                                 dcp::Time (0, 0, 1, 0, 24),
648                                 dcp::Time (0, 0, 9, 0, 24),
649                                 0,
650                                 dcp::HALIGN_CENTER,
651                                 0.9,
652                                 dcp::VALIGN_TOP,
653                                 dcp::DIRECTION_LTR,
654                                 " line",
655                                 dcp::NONE,
656                                 dcp::Colour (0, 0, 0),
657                                 dcp::Time (0, 0, 0, 0, 24),
658                                 dcp::Time (0, 0, 0, 0, 24)
659                                 )
660                         )
661                 );
662
663         c._xml_id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
664
665         check_xml (
666                 c.xml_as_string (),
667                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
668                 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
669                   "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
670                   "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
671                   "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
672                   "<dcst:ReelNumber>1</dcst:ReelNumber>"
673                   "<dcst:Language>en</dcst:Language>"
674                   "<dcst:EditRate>24 1</dcst:EditRate>"
675                   "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
676                   "<dcst:SubtitleList>"
677                     "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Arial\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
678                       "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:00:01:00\" TimeOut=\"00:00:09:00\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
679                         "<dcst:Text Valign=\"top\" Vposition=\"80\">"
680                           "<dcst:Font Italic=\"no\">Testing is </dcst:Font>"
681                           "<dcst:Font Italic=\"yes\">really</dcst:Font>"
682                           "<dcst:Font Italic=\"no\"> fun</dcst:Font>"
683                         "</dcst:Text>"
684                         "<dcst:Text Valign=\"top\" Vposition=\"90\">"
685                           "<dcst:Font Italic=\"no\">This is the </dcst:Font>"
686                           "<dcst:Font Italic=\"yes\">second</dcst:Font>"
687                           "<dcst:Font Italic=\"no\"> line</dcst:Font>"
688                         "</dcst:Text>"
689                       "</dcst:Subtitle>"
690                     "</dcst:Font>"
691                   "</dcst:SubtitleList>"
692                 "</dcst:SubtitleReel>",
693                 vector<string>()
694                 );
695 }
696
697 /* Write some subtitle content as SMPTE using bitmaps and check that it is right */
698 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test3)
699 {
700         dcp::SMPTESubtitleAsset c;
701         c.set_reel_number (1);
702         c.set_language (dcp::LanguageTag("en"));
703         c.set_content_title_text ("Test");
704
705         c.add (
706                 shared_ptr<dcp::Subtitle> (
707                         new dcp::SubtitleImage (
708                                 dcp::ArrayData ("test/data/sub.png"),
709                                 dcp::Time (0, 4,  9, 22, 24),
710                                 dcp::Time (0, 4, 11, 22, 24),
711                                 0,
712                                 dcp::HALIGN_CENTER,
713                                 0.8,
714                                 dcp::VALIGN_TOP,
715                                 dcp::Time (0, 0, 0, 0, 24),
716                                 dcp::Time (0, 0, 0, 0, 24)
717                                 )
718                         )
719                 );
720
721         c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
722
723         boost::filesystem::create_directories ("build/test/write_smpte_subtitle_test3");
724         c.write ("build/test/write_smpte_subtitle_test3/subs.mxf");
725
726         /* XXX: check this result when we can read them back in again */
727 }