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