diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-07-28 16:23:21 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-07-28 16:23:21 +0100 |
| commit | 0c7a195358580f65c9fcfd5342e01a70544c1405 (patch) | |
| tree | bf6dd4e6c984a34723a0cf68ddbe8eb676923dc8 | |
| parent | 6610a686b63c2c65f5f33cdaac5d03fb8874bedf (diff) | |
Support \pos in ssa.
| -rw-r--r-- | src/horizontal_position.h | 7 | ||||
| -rw-r--r-- | src/ssa_reader.cc | 36 | ||||
| -rw-r--r-- | src/ssa_reader.h | 2 | ||||
| -rw-r--r-- | test/ssa_reader_test.cc | 139 |
4 files changed, 127 insertions, 57 deletions
diff --git a/src/horizontal_position.h b/src/horizontal_position.h index 1f4b161..76d09e6 100644 --- a/src/horizontal_position.h +++ b/src/horizontal_position.h @@ -27,7 +27,14 @@ namespace sub { class HorizontalPosition { public: + HorizontalPosition () + : reference(HORIZONTAL_CENTRE_OF_SCREEN) + , proportional(0) + {} + HorizontalReference reference; + /** proportion of screen width offset from reference */ + float proportional; bool operator== (HorizontalPosition const & other) const; }; diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc index 81b6b9d..da36014 100644 --- a/src/ssa_reader.cc +++ b/src/ssa_reader.cc @@ -61,6 +61,7 @@ public: , bold (false) , italic (false) , underline (false) + , horizontal_reference (HORIZONTAL_CENTRE_OF_SCREEN) , vertical_reference (BOTTOM_OF_SCREEN) , vertical_margin (0) {} @@ -71,13 +72,14 @@ public: , bold (false) , italic (false) , underline (false) + , horizontal_reference (HORIZONTAL_CENTRE_OF_SCREEN) , vertical_reference (BOTTOM_OF_SCREEN) , vertical_margin (0) { vector<string> keys; - split (keys, format_line, is_any_of (",")); + split (keys, format_line, boost::is_any_of (",")); vector<string> style; - split (style, style_line, is_any_of (",")); + split (style, style_line, boost::is_any_of (",")); SUB_ASSERT (!keys.empty()); SUB_ASSERT (!style.empty()); @@ -108,6 +110,17 @@ public: } } else if (keys[i] == "Alignment") { /* These values from libass' source code */ + switch ((raw_convert<int> (style[i]) - 1) % 3) { + case 0: + horizontal_reference = LEFT_OF_SCREEN; + break; + case 1: + horizontal_reference = HORIZONTAL_CENTRE_OF_SCREEN; + break; + case 2: + horizontal_reference = RIGHT_OF_SCREEN; + break; + } switch (raw_convert<int> (style[i]) & 12) { case 4: vertical_reference = TOP_OF_SCREEN; @@ -135,6 +148,7 @@ public: bool italic; bool underline; optional<Effect> effect; + HorizontalReference horizontal_reference; VerticalReference vertical_reference; int vertical_margin; @@ -168,7 +182,7 @@ SSAReader::parse_time (string t) const * @return List of RawSubtitles to represent line with vertical reference TOP_OF_SUBTITLE. */ list<RawSubtitle> -SSAReader::parse_line (RawSubtitle base, string line) +SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_res_y) { enum { TEXT, @@ -257,6 +271,14 @@ SSAReader::parse_line (RawSubtitle base, string line) current.vertical_position.reference = sub::VERTICAL_CENTRE_OF_SCREEN; } else if (style == "\\an7" || style == "\\an8" || style == "\\an9") { current.vertical_position.reference = sub::TOP_OF_SCREEN; + } else if (boost::starts_with(style, "\\pos")) { + vector<string> bits; + boost::algorithm::split (bits, style, boost::is_any_of("(,")); + SUB_ASSERT (bits.size() == 3); + current.horizontal_position.reference = sub::LEFT_OF_SCREEN; + current.horizontal_position.proportional = raw_convert<float>(bits[1]) / play_res_x; + current.vertical_position.reference = sub::TOP_OF_SCREEN; + current.vertical_position.proportional = raw_convert<float>(bits[2]) / play_res_y; } style = ""; @@ -302,6 +324,7 @@ SSAReader::read (function<optional<string> ()> get_line) EVENTS } part = INFO; + int play_res_x = 288; int play_res_y = 288; map<string, Style> styles; string style_format_line; @@ -340,7 +363,9 @@ SSAReader::read (function<optional<string> ()> get_line) switch (part) { case INFO: - if (type == "PlayResY") { + if (type == "PlayResX") { + play_res_x = raw_convert<int> (body); + } else if (type == "PlayResY") { play_res_y = raw_convert<int> (body); } break; @@ -399,12 +424,13 @@ SSAReader::read (function<optional<string> ()> get_line) sub.italic = style.italic; sub.underline = style.underline; sub.effect = style.effect; + sub.horizontal_position.reference = style.horizontal_reference; sub.vertical_position.reference = style.vertical_reference; sub.vertical_position.proportional = float(style.vertical_margin) / play_res_y; } else if (event_format[i] == "MarginV") { sub.vertical_position.proportional = raw_convert<float>(event[i]) / play_res_y; } else if (event_format[i] == "Text") { - BOOST_FOREACH (sub::RawSubtitle j, parse_line (sub, event[i])) { + BOOST_FOREACH (sub::RawSubtitle j, parse_line (sub, event[i], play_res_x, play_res_y)) { _subs.push_back (j); } } diff --git a/src/ssa_reader.h b/src/ssa_reader.h index 59c9e86..07a0901 100644 --- a/src/ssa_reader.h +++ b/src/ssa_reader.h @@ -41,7 +41,7 @@ public: SSAReader (FILE* f); SSAReader (std::string const & subs); - static std::list<RawSubtitle> parse_line (RawSubtitle base, std::string line); + static std::list<RawSubtitle> parse_line (RawSubtitle base, std::string line, int play_res_x, int play_res_y); private: void read (boost::function<boost::optional<std::string> ()> get_line); diff --git a/test/ssa_reader_test.cc b/test/ssa_reader_test.cc index bf7b7a8..b127a86 100644 --- a/test/ssa_reader_test.cc +++ b/test/ssa_reader_test.cc @@ -77,7 +77,11 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test) BOOST_AUTO_TEST_CASE (ssa_reader_line_test1) { sub::RawSubtitle base; - list<sub::RawSubtitle> r = sub::SSAReader::parse_line (base, "This is a line with some {\\i1}italics{\\i0} and then\\nthere is a new line."); + list<sub::RawSubtitle> r = sub::SSAReader::parse_line ( + base, + "This is a line with some {\\i1}italics{\\i0} and then\\nthere is a new line.", + 1920, 1080 + ); list<sub::RawSubtitle>::const_iterator i = r.begin (); BOOST_CHECK_EQUAL (i->text, "This is a line with some "); @@ -103,7 +107,11 @@ BOOST_AUTO_TEST_CASE (ssa_reader_line_test1) BOOST_AUTO_TEST_CASE (ssa_reader_line_test2) { sub::RawSubtitle base; - list<sub::RawSubtitle> r = sub::SSAReader::parse_line (base, "{\\i1}It's all just italics{\\i0}"); + list<sub::RawSubtitle> r = sub::SSAReader::parse_line ( + base, + "{\\i1}It's all just italics{\\i0}", + 1920, 1080 + ); list<sub::RawSubtitle>::const_iterator i = r.begin (); BOOST_CHECK_EQUAL (i->text, "It's all just italics"); @@ -111,7 +119,12 @@ BOOST_AUTO_TEST_CASE (ssa_reader_line_test2) ++i; BOOST_REQUIRE (i == r.end ()); - r = sub::SSAReader::parse_line (base, "{\\i1}Italic{\\i0}\\Nand new line"); + r = sub::SSAReader::parse_line ( + base, + "{\\i1}Italic{\\i0}\\Nand new line", + 1920, 1080 + ); + i = r.begin (); BOOST_CHECK_EQUAL (i->text, "Italic"); BOOST_CHECK_EQUAL (i->italic, true); @@ -145,12 +158,14 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test2) BOOST_CHECK_EQUAL (i->to, t); \ j = i->lines.begin (); -#define LINE(p, r) \ +#define LINE(vp, vr, hp, hr) \ BOOST_REQUIRE (j != i->lines.end ()); \ BOOST_CHECK (j->vertical_position.proportional); \ - BOOST_CHECK (fabs (j->vertical_position.proportional.get() - p) < 1e-5); \ + BOOST_CHECK (fabs (j->vertical_position.proportional.get() - vp) < 1e-5); \ BOOST_CHECK (j->vertical_position.reference); \ - BOOST_CHECK_EQUAL (j->vertical_position.reference.get(), r); \ + BOOST_CHECK_EQUAL (j->vertical_position.reference.get(), vr); \ + BOOST_CHECK (fabs (j->horizontal_position.proportional - hp) < 1e-5); \ + BOOST_CHECK_EQUAL (j->horizontal_position.reference, hr); \ k = j->blocks.begin (); \ ++j; @@ -182,7 +197,7 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test3) /* Hello world */ SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550)); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Hello world", "Arial", 20, false, false, false); SUB_END(); @@ -192,15 +207,15 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test3) points, 1.2 times spaced, as a proportion of the total screen height 729 points) up. */ - LINE((900.0 / 1080) - (20.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE((900.0 / 1080) - (20.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("This is vertically moved", "Arial", 20, false, false, false); - LINE((900.0 / 1080), sub::BOTTOM_OF_SCREEN); + LINE((900.0 / 1080), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("and has two lines.", "Arial", 20, false, false, false); SUB_END(); /* Some {\i1}italics{\i} are here. */ SUB_START (sub::Time::from_hms (0, 0, 7, 740), sub::Time::from_hms (0, 0, 9, 0)); - LINE(0, sub::BOTTOM_OF_SCREEN); + LINE(0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("Some ", "Arial", 20, false, false, false); BLOCK("italics", "Arial", 20, false, true, false); BLOCK(" are here.", "Arial", 20, false, false, false); @@ -209,47 +224,47 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test3) /* Alignments */ SUB_START (sub::Time::from_hms (0, 0, 9, 230), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("bottom left", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 240), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("bottom centre", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 250), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("bottom right", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 260), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN); + LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("middle left", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 270), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN); + LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("middle centre", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 280), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN); + LINE (0, sub::VERTICAL_CENTRE_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("middle right", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 290), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::TOP_OF_SCREEN); + LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("top left", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 300), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::TOP_OF_SCREEN); + LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("top centre", "Arial", 20, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 9, 310), sub::Time::from_hms (0, 0, 11, 560)); - LINE (0, sub::TOP_OF_SCREEN); + LINE (0, sub::TOP_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK("top right", "Arial", 20, false, false, false); SUB_END (); @@ -276,30 +291,30 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test4) spaced, as a proportion of the total screen height 729 points) up. */ - LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("1st line: This is normal", "Verdana", 50, false, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2d line: this is bold", "Verdana", 50, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100)); - LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd line: This is normal", "Verdana", 50, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200)); - LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("1st line: this is bold", "Verdana", 50, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd line: this is italics", "Verdana", 50, false, true, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300)); - LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((50.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("1st line: this is italics", "Verdana", 50, false, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd line: this is bold", "Verdana", 50, true, false, false); SUB_END (); } @@ -324,30 +339,30 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test5) spaced, as a proportion of the total screen height 729 points) up. */ - LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("1st subtitle, 1st line", "arial", 26, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 3, 100), sub::Time::from_hms (0, 0, 5, 100)); - LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd subtitle, 1st line", "arial", 26, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("2nd subtitle, 2nd line", "arial", 26, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 5, 200), sub::Time::from_hms (0, 0, 7, 200)); - LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("3rd subtitle, 1st line", "arial", 26, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("3rd subtitle, 2nd line", "arial", 26, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 7, 300), sub::Time::from_hms (0, 0, 9, 300)); - LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((26.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("4th subtitle, 1st line", "arial", 26, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("4th subtitle, 2nd line", "arial", 26, true, false, false); SUB_END (); } @@ -373,63 +388,85 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test6) spaced, as a proportion of the total screen height 729 points) up. */ - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is normal", "Arial", 30, false, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is bold", "Arial", 30, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 1, 200), sub::Time::from_hms (0, 0, 2, 240)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is bold", "Arial", 30, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is normal", "Arial", 30, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 2, 300), sub::Time::from_hms (0, 0, 3, 380)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is bold", "Arial", 30, true, false, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is italic", "Arial", 30, false, true, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 3, 400), sub::Time::from_hms (0, 0, 4, 480)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is italic", "Arial", 30, false, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is bold", "Arial", 30, true, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 4, 510), sub::Time::from_hms (0, 0, 5, 600)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Last three words are ", "Arial", 30, false, false, false); BLOCK ("bold AND italic", "Arial", 30, true, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Last three words are ", "Arial", 30, false, false, false); BLOCK ("italic AND bold", "Arial", 30, true, true, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 5, 620), sub::Time::from_hms (0, 0, 6, 710)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Last three words are ", "Arial", 30, false, false, false); BLOCK ("bold AND italic", "Arial", 30, true, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("First three words", "Arial", 30, true, true, false); BLOCK (" are italic AND bold", "Arial", 30, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 6, 730), sub::Time::from_hms (0, 0, 8, 30)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Last three words are ", "Arial", 30, false, false, false); BLOCK ("bold AND italic", "Arial", 30, true, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("This line is normal", "Arial", 30, false, false, false); SUB_END (); SUB_START (sub::Time::from_hms (0, 0, 8, 90), sub::Time::from_hms (0, 0, 9, 210)); - LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN); + LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false); - LINE (0, sub::BOTTOM_OF_SCREEN); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false); SUB_END (); } + +/** Test \pos */ +BOOST_AUTO_TEST_CASE (ssa_reader_line_pos) +{ + boost::filesystem::path p = "test/data/test2.ssa"; + FILE* f = fopen (p.string().c_str(), "r"); + sub::SSAReader reader (f); + fclose (f); + list<sub::Subtitle> subs = sub::collect<std::list<sub::Subtitle> > (reader.subtitles ()); + + list<sub::Subtitle>::iterator i = subs.begin (); + list<sub::Line>::iterator j; + list<sub::Block>::iterator k; + + /* Hello world */ + SUB_START (sub::Time::from_hms (0, 0, 1, 230), sub::Time::from_hms (0, 0, 4, 550)); + LINE (0, sub::BOTTOM_OF_SCREEN, 0, sub::HORIZONTAL_CENTRE_OF_SCREEN); + BLOCK ("Hello world this is ", "Arial", 20, false, false, false); + LINE (300.0 / 1080, sub::TOP_OF_SCREEN, 400.0 / 1920, sub::LEFT_OF_SCREEN); + BLOCK ("positioning.", "Arial", 20, false, false, false); + SUB_END(); +} |
