Support \pos in ssa.
[libsub.git] / test / ssa_reader_test.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "test.h"
21 #include "ssa_reader.h"
22 #include "collect.h"
23 #include "subtitle.h"
24 #include <boost/test/unit_test.hpp>
25 #include <boost/filesystem.hpp>
26 #include <boost/foreach.hpp>
27 #include <cstdio>
28 #include <cmath>
29 #include <iostream>
30
31 using std::list;
32 using std::fabs;
33
34 BOOST_AUTO_TEST_CASE (ssa_reader_test)
35 {
36         boost::filesystem::path p = private_test / "example.ssa";
37         FILE* f = fopen (p.string().c_str(), "r");
38         sub::SSAReader reader (f);
39         fclose (f);
40         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
41
42         list<sub::Subtitle>::iterator i = subs.begin ();
43
44         BOOST_REQUIRE (i != subs.end ());
45         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 40, 650));
46         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 41, 790));
47         list<sub::Line>::iterator j = i->lines.begin();
48         BOOST_REQUIRE (j != i->lines.end ());
49         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
50         sub::Block b = j->blocks.front ();
51         BOOST_CHECK_EQUAL (b.text, "Et les enregistrements de ses ondes delta ?");
52         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
53         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
54         BOOST_CHECK_EQUAL (b.bold, false);
55         BOOST_CHECK_EQUAL (b.italic, false);
56         BOOST_CHECK_EQUAL (b.underline, false);
57         ++i;
58
59         BOOST_REQUIRE (i != subs.end ());
60         BOOST_CHECK_EQUAL (i->from, sub::Time::from_hms (0, 2, 42, 420));
61         BOOST_CHECK_EQUAL (i->to, sub::Time::from_hms (0, 2, 44, 150));
62         j = i->lines.begin();
63         BOOST_REQUIRE (j != i->lines.end ());
64         BOOST_REQUIRE_EQUAL (j->blocks.size(), 1);
65         b = j->blocks.front ();
66         BOOST_CHECK_EQUAL (b.text, "Toujours rien.");
67         BOOST_CHECK_EQUAL (b.font.get(), "Wolf_Rain");
68         BOOST_CHECK_EQUAL (b.font_size.points().get(), 56);
69         BOOST_CHECK_EQUAL (b.bold, false);
70         BOOST_CHECK_EQUAL (b.italic, false);
71         BOOST_CHECK_EQUAL (b.underline, false);
72         ++i;
73
74         BOOST_CHECK (i == subs.end());
75 }
76
77 BOOST_AUTO_TEST_CASE (ssa_reader_line_test1)
78 {
79         sub::RawSubtitle base;
80         list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
81                 base,
82                 "This is a line with some {\\i1}italics{\\i0} and then\\nthere is a new line.",
83                 1920, 1080
84                 );
85
86         list<sub::RawSubtitle>::const_iterator i = r.begin ();
87         BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
88         BOOST_CHECK_EQUAL (i->italic, false);
89         ++i;
90         BOOST_REQUIRE (i != r.end ());
91
92         BOOST_CHECK_EQUAL (i->text, "italics");
93         BOOST_CHECK_EQUAL (i->italic, true);
94         ++i;
95         BOOST_REQUIRE (i != r.end ());
96
97         BOOST_CHECK_EQUAL (i->text, " and then");
98         BOOST_CHECK_EQUAL (i->italic, false);
99         ++i;
100         BOOST_REQUIRE (i != r.end ());
101
102         BOOST_CHECK_EQUAL (i->text, "there is a new line.");
103         ++i;
104         BOOST_REQUIRE (i == r.end ());
105 }
106
107 BOOST_AUTO_TEST_CASE (ssa_reader_line_test2)
108 {
109         sub::RawSubtitle base;
110         list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
111                 base,
112                 "{\\i1}It's all just italics{\\i0}",
113                 1920, 1080
114                 );
115
116         list<sub::RawSubtitle>::const_iterator i = r.begin ();
117         BOOST_CHECK_EQUAL (i->text, "It's all just italics");
118         BOOST_CHECK_EQUAL (i->italic, true);
119         ++i;
120         BOOST_REQUIRE (i == r.end ());
121
122         r = sub::SSAReader::parse_line (
123                 base,
124                 "{\\i1}Italic{\\i0}\\Nand new line",
125                 1920, 1080
126                 );
127
128         i = r.begin ();
129         BOOST_CHECK_EQUAL (i->text, "Italic");
130         BOOST_CHECK_EQUAL (i->italic, true);
131         BOOST_CHECK (fabs ((72.0 * 1.2 / 792) - i->vertical_position.proportional.get()) < 1e-5);
132         ++i;
133         BOOST_CHECK_EQUAL (i->text, "and new line");
134         BOOST_CHECK_EQUAL (i->italic, false);
135         BOOST_CHECK (i->vertical_position.proportional.get() < 1e-5);
136 }
137
138 static void
139 test (boost::filesystem::path p)
140 {
141         p = private_test / p;
142         FILE* f = fopen (p.string().c_str(), "r");
143         BOOST_REQUIRE (f);
144         sub::SSAReader r (f);
145         fclose (f);
146 }
147
148 /** Test of reading some typical .ssa files */
149 BOOST_AUTO_TEST_CASE (ssa_reader_test2)
150 {
151         test ("DKH_UT_EN20160601def.ssa");
152         test ("dcpsubtest-en.ssa");
153 }
154
155 #define SUB_START(f, t) \
156         BOOST_REQUIRE (i != subs.end ()); \
157         BOOST_CHECK_EQUAL (i->from, f); \
158         BOOST_CHECK_EQUAL (i->to, t); \
159         j = i->lines.begin ();
160
161 #define LINE(vp, vr, hp, hr)                  \
162         BOOST_REQUIRE (j != i->lines.end ()); \
163         BOOST_CHECK (j->vertical_position.proportional); \
164         BOOST_CHECK (fabs (j->vertical_position.proportional.get() - vp) < 1e-5); \
165         BOOST_CHECK (j->vertical_position.reference); \
166         BOOST_CHECK_EQUAL (j->vertical_position.reference.get(), vr); \
167         BOOST_CHECK (fabs (j->horizontal_position.proportional - hp) < 1e-5); \
168         BOOST_CHECK_EQUAL (j->horizontal_position.reference, hr); \
169         k = j->blocks.begin (); \
170         ++j;
171
172 #define BLOCK(t, f, s, b, i, u) \
173         BOOST_REQUIRE (k != j->blocks.end ()); \
174         BOOST_CHECK_EQUAL (k->text, t); \
175         BOOST_CHECK_EQUAL (k->font.get(), f); \
176         BOOST_CHECK_EQUAL (k->font_size.points().get(), s); \
177         BOOST_CHECK_EQUAL (k->bold, b); \
178         BOOST_CHECK_EQUAL (k->italic, i); \
179         BOOST_CHECK_EQUAL (k->underline, u); \
180         ++k;
181
182 #define SUB_END() \
183         ++i;
184
185 /** Test reading of a file within the libsub tree which exercises the parser */
186 BOOST_AUTO_TEST_CASE (ssa_reader_test3)
187 {
188         boost::filesystem::path p = "test/data/test.ssa";
189         FILE* f = fopen (p.string().c_str(), "r");
190         sub::SSAReader reader (f);
191         fclose (f);
192         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
193
194         list<sub::Subtitle>::iterator i = subs.begin ();
195         list<sub::Line>::iterator j;
196         list<sub::Block>::iterator k;
197
198         /* Hello world */
199         SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550));
200         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
201         BLOCK ("Hello world", "Arial", 20, false, false, false);
202         SUB_END();
203
204         /* This is vertically moved\nand has two lines. */
205         SUB_START (sub::Time::from_hms (0, 0, 5, 740), sub::Time::from_hms (0, 0, 11, 0));
206         /* The first line should be 900 pixels and one line (20
207            points, 1.2 times spaced, as a proportion of the total
208            screen height 729 points) up.
209         */
210         LINE((900.0 / 1080) - (20.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
211         BLOCK("This is vertically moved", "Arial", 20, false, false, false);
212         LINE((900.0 / 1080), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
213         BLOCK("and has two lines.", "Arial", 20, false, false, false);
214         SUB_END();
215
216         /* Some {\i1}italics{\i} are here. */
217         SUB_START (sub::Time::from_hms (0, 0, 7, 740), sub::Time::from_hms (0, 0, 9, 0));
218         LINE(0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
219         BLOCK("Some ", "Arial", 20, false, false, false);
220         BLOCK("italics", "Arial", 20, false, true, false);
221         BLOCK(" are here.", "Arial", 20, false, false, false);
222         SUB_END();
223
224         /* Alignments */
225
226         SUB_START (sub::Time::from_hms (0, 0, 9, 230), sub::Time::from_hms (0, 0, 11, 560));
227         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
228         BLOCK("bottom left", "Arial", 20, false, false, false);
229         SUB_END ();
230
231         SUB_START (sub::Time::from_hms (0, 0, 9, 240), sub::Time::from_hms (0, 0, 11, 560));
232         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
233         BLOCK("bottom centre", "Arial", 20, false, false, false);
234         SUB_END ();
235
236         SUB_START (sub::Time::from_hms (0, 0, 9, 250), sub::Time::from_hms (0, 0, 11, 560));
237         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
238         BLOCK("bottom right", "Arial", 20, false, false, false);
239         SUB_END ();
240
241         SUB_START (sub::Time::from_hms (0, 0, 9, 260), sub::Time::from_hms (0, 0, 11, 560));
242         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
243         BLOCK("middle left", "Arial", 20, false, false, false);
244         SUB_END ();
245
246         SUB_START (sub::Time::from_hms (0, 0, 9, 270), sub::Time::from_hms (0, 0, 11, 560));
247         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
248         BLOCK("middle centre", "Arial", 20, false, false, false);
249         SUB_END ();
250
251         SUB_START (sub::Time::from_hms (0, 0, 9, 280), sub::Time::from_hms (0, 0, 11, 560));
252         LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
253         BLOCK("middle right", "Arial", 20, false, false, false);
254         SUB_END ();
255
256         SUB_START (sub::Time::from_hms (0, 0, 9, 290), sub::Time::from_hms (0, 0, 11, 560));
257         LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
258         BLOCK("top left", "Arial", 20, false, false, false);
259         SUB_END ();
260
261         SUB_START (sub::Time::from_hms (0, 0, 9, 300), sub::Time::from_hms (0, 0, 11, 560));
262         LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
263         BLOCK("top centre", "Arial", 20, false, false, false);
264         SUB_END ();
265
266         SUB_START (sub::Time::from_hms (0, 0, 9, 310), sub::Time::from_hms (0, 0, 11, 560));
267         LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
268         BLOCK("top right", "Arial", 20, false, false, false);
269         SUB_END ();
270
271         BOOST_REQUIRE (i == subs.end ());
272 }
273
274 /** Test reading of a file within the libsub-test-private tree which exercises the parser */
275 BOOST_AUTO_TEST_CASE (ssa_reader_test4)
276 {
277         boost::filesystem::path p = private_test / "dcpsubtest2-en.ssa";
278         FILE* f = fopen (p.string().c_str(), "r");
279         sub::SSAReader reader (f);
280         fclose (f);
281         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
282
283         list<sub::Subtitle>::iterator i = subs.begin ();
284         list<sub::Line>::iterator j;
285         list<sub::Block>::iterator k;
286
287         BOOST_REQUIRE (i != subs.end ());
288
289         SUB_START (sub::Time::from_hms (0, 0, 1, 0), sub::Time::from_hms (0, 0, 3, 0));
290         /* The first line should be one line (50 points, 1.2 times
291            spaced, as a proportion of the total screen height 729
292            points) up.
293         */
294         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
295         BLOCK ("1st line: This is normal", "Verdana", 50, false, false, false);
296         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
297         BLOCK ("2d line: this is bold", "Verdana", 50, true, false, false);
298         SUB_END ();
299
300         SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100));
301         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
302         BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false);
303         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
304         BLOCK ("2nd line: This is normal", "Verdana", 50, false, false, false);
305         SUB_END ();
306
307         SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200));
308         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
309         BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false);
310         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
311         BLOCK ("2nd line: this is italics", "Verdana", 50, false, true, false);
312         SUB_END ();
313
314         SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300));
315         LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
316         BLOCK ("1st line: this is italics", "Verdana", 50, false, true, false);
317         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
318         BLOCK ("2nd line: this is bold", "Verdana", 50, true, false, false);
319         SUB_END ();
320 }
321
322 /** Test reading of a .ass file */
323 BOOST_AUTO_TEST_CASE (ssa_reader_test5)
324 {
325         boost::filesystem::path p = private_test / "dcpsubtest-en.ass";
326         FILE* f = fopen (p.string().c_str(), "r");
327         sub::SSAReader reader (f);
328         fclose (f);
329         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
330
331         list<sub::Subtitle>::iterator i = subs.begin ();
332         list<sub::Line>::iterator j;
333         list<sub::Block>::iterator k;
334
335         BOOST_REQUIRE (i != subs.end ());
336
337         SUB_START (sub::Time::from_hms (0, 0, 1, 0), sub::Time::from_hms (0, 0, 3, 0));
338         /* The first line should be one line (26 points, 1.2 times
339            spaced, as a proportion of the total screen height 729
340            points) up.
341         */
342         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
343         BLOCK ("1st subtitle, 1st line", "arial", 26, true, false, false);
344         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
345         BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false);
346         SUB_END ();
347
348         SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100));
349         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
350         BLOCK ("2nd subtitle, 1st line", "arial", 26, true, false, false);
351         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
352         BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false);
353         SUB_END ();
354
355         SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200));
356         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
357         BLOCK ("3rd subtitle, 1st line", "arial", 26, true, false, false);
358         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
359         BLOCK ("3rd subtitle, 2nd line", "arial", 26, true, false, false);
360         SUB_END ();
361
362         SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300));
363         LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
364         BLOCK ("4th subtitle, 1st line", "arial", 26, true, false, false);
365         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
366         BLOCK ("4th subtitle, 2nd line", "arial", 26, true, false, false);
367         SUB_END ();
368 }
369
370 /** Test reading of another .ass file */
371 BOOST_AUTO_TEST_CASE (ssa_reader_test6)
372 {
373         boost::filesystem::path p = private_test / "DCP-o-matic_test_subs_1.ass";
374         FILE* f = fopen (p.string().c_str(), "r");
375         BOOST_REQUIRE (f);
376         sub::SSAReader reader (f);
377         fclose (f);
378         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
379
380         list<sub::Subtitle>::iterator i = subs.begin ();
381         list<sub::Line>::iterator j;
382         list<sub::Block>::iterator k;
383
384         BOOST_REQUIRE (i != subs.end ());
385
386         SUB_START (sub::Time::from_hms (0, 0, 0, 70), sub::Time::from_hms (0, 0, 1, 110));
387         /* The first line should be one line (30 points, 1.2 times
388            spaced, as a proportion of the total screen height 729
389            points) up.
390         */
391         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
392         BLOCK ("This line is normal", "Arial", 30, false, false, false);
393         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
394         BLOCK ("This line is bold", "Arial", 30, true, false, false);
395         SUB_END ();
396
397         SUB_START (sub::Time::from_hms (0, 0, 1, 200), sub::Time::from_hms (0, 0, 2, 240));
398         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
399         BLOCK ("This line is bold", "Arial", 30, true, false, false);
400         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
401         BLOCK ("This line is normal", "Arial", 30, false, false, false);
402         SUB_END ();
403
404         SUB_START (sub::Time::from_hms (0, 0, 2, 300), sub::Time::from_hms (0, 0, 3, 380));
405         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
406         BLOCK ("This line is bold", "Arial", 30, true, false, false);
407         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
408         BLOCK ("This line is italic", "Arial", 30, false, true, false);
409         SUB_END ();
410
411         SUB_START (sub::Time::from_hms (0, 0, 3, 400), sub::Time::from_hms (0, 0, 4, 480));
412         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
413         BLOCK ("This line is italic", "Arial", 30, false, true, false);
414         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
415         BLOCK ("This line is bold", "Arial", 30, true, false, false);
416         SUB_END ();
417
418         SUB_START (sub::Time::from_hms (0, 0, 4, 510), sub::Time::from_hms (0, 0, 5, 600));
419         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
420         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
421         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
422         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
423         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
424         BLOCK ("italic AND bold", "Arial", 30, true, true, false);
425         SUB_END ();
426
427         SUB_START (sub::Time::from_hms (0, 0, 5, 620), sub::Time::from_hms (0, 0, 6, 710));
428         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
429         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
430         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
431         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
432         BLOCK ("First three words", "Arial", 30, true, true, false);
433         BLOCK (" are italic AND bold", "Arial", 30, false, false, false);
434         SUB_END ();
435
436         SUB_START (sub::Time::from_hms (0, 0, 6, 730), sub::Time::from_hms (0, 0, 8, 30));
437         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
438         BLOCK ("Last three words are ", "Arial", 30, false, false, false);
439         BLOCK ("bold AND italic", "Arial", 30, true, true, false);
440         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
441         BLOCK ("This line is normal", "Arial", 30, false, false, false);
442         SUB_END ();
443
444         SUB_START (sub::Time::from_hms (0, 0, 8, 90), sub::Time::from_hms (0, 0, 9, 210));
445         LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
446         BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
447         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
448         BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
449         SUB_END ();
450 }
451
452 /** Test \pos */
453 BOOST_AUTO_TEST_CASE (ssa_reader_line_pos)
454 {
455         boost::filesystem::path p = "test/data/test2.ssa";
456         FILE* f = fopen (p.string().c_str(), "r");
457         sub::SSAReader reader (f);
458         fclose (f);
459         list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ());
460
461         list<sub::Subtitle>::iterator i = subs.begin ();
462         list<sub::Line>::iterator j;
463         list<sub::Block>::iterator k;
464
465         /* Hello world */
466         SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550));
467         LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN);
468         BLOCK ("Hello world this is ", "Arial", 20, false, false, false);
469         LINE (300.0 / 1080, sub::TOP_OF_SCREEN, 400.0 / 1920, sub::LEFT_OF_SCREEN);
470         BLOCK ("positioning.", "Arial", 20, false, false, false);
471         SUB_END();
472 }