Fix coalesced override codes (\i1\b1 and such).
authorCarl Hetherington <cth@carlh.net>
Sun, 26 Jun 2016 00:00:16 +0000 (01:00 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 26 Jun 2016 00:00:16 +0000 (01:00 +0100)
src/ssa_reader.cc
test/ssa_reader_test.cc

index 93e96f28af7cf4dd7fe6e8dcc0cdd7acf32461f8..05c908e2c86b3c1bbfef35d940116eea57342298 100644 (file)
@@ -230,7 +230,7 @@ SSAReader::parse_line (RawSubtitle base, string line)
                        }
                        break;
                case STYLE:
-                       if (c == '}') {
+                       if (c == '}' || c == '\\') {
                                if (!current.text.empty ()) {
                                        subs.push_back (current);
                                        current.text = "";
@@ -250,7 +250,11 @@ SSAReader::parse_line (RawSubtitle base, string line)
                                } else if (style == "\\an7" || style == "\\an8" || style == "\\an9") {
                                        current.vertical_position.reference = sub::TOP_OF_SCREEN;
                                }
+
                                style = "";
+                       }
+
+                       if (c == '}') {
                                state = TEXT;
                        } else {
                                style += c;
index d0ed8fae95ac55d493a04ca9ab951fdd67aa1bd3..4fb74858bfe7a46c5d87e34e086c921b94b12aa3 100644 (file)
@@ -351,3 +351,84 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test5)
        BLOCK ("4th subtitle, 2nd line", "arial", 26, true, false, false);
        SUB_END ();
 }
+
+/** Test reading of another .ass file */
+BOOST_AUTO_TEST_CASE (ssa_reader_test6)
+{
+       boost::filesystem::path p = private_test / "DCP-o-matic_test_subs_1.ass";
+       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;
+
+       BOOST_REQUIRE (i != subs.end ());
+
+       SUB_START (sub::Time::from_hms (0, 0, 0, 70), sub::Time::from_hms (0, 0, 1, 110));
+       /* The first line should be one line (30 points, 1.2 times
+          spaced, as a proportion of the total screen height 729
+          points) up.
+       */
+       LINE ((30.0 * 1.2 / 792), sub::BOTTOM_OF_SCREEN);
+       BLOCK ("This line is normal", "Arial", 30, false, false, false);
+       LINE (0, sub::BOTTOM_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);
+       BLOCK ("This line is bold", "Arial", 30, true, false, false);
+       LINE (0, sub::BOTTOM_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);
+       BLOCK ("This line is bold", "Arial", 30, true, false, false);
+       LINE (0, sub::BOTTOM_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);
+       BLOCK ("This line is italic", "Arial", 30, false, true, false);
+       LINE (0, sub::BOTTOM_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);
+       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);
+       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);
+       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);
+       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);
+       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);
+       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);
+       BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
+       LINE (0, sub::BOTTOM_OF_SCREEN);
+       BLOCK ("Both lines are bold AND italic", "Arial", 30, true, true, false);
+       SUB_END ();
+}