diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-07-02 13:21:16 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-07-02 13:21:16 +0100 |
| commit | 4d406c620b0211a5e27c19187d963241120f8838 (patch) | |
| tree | 4ec7f4a1652ee89fc1b45faccb4d2d72a512a698 /src/subrip_reader.cc | |
| parent | b20c6fd0047a7b8ad63d19c46c3ea0e2185babc2 (diff) | |
Add support for reading <font> tags in SubRip.
Diffstat (limited to 'src/subrip_reader.cc')
| -rw-r--r-- | src/subrip_reader.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index 3f1c23d..134ca3e 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -21,12 +21,17 @@ #include "exceptions.h" #include <boost/algorithm/string.hpp> #include <boost/lexical_cast.hpp> +#include <boost/regex.hpp> #include <cstdio> #include <vector> using std::string; using std::vector; +using std::list; +using std::cout; +using std::hex; using boost::lexical_cast; +using boost::to_upper; using namespace sub; SubripReader::SubripReader (FILE* f) @@ -60,7 +65,7 @@ SubripReader::SubripReader (FILE* f) static_cast<unsigned char> (line[1]) == 0xbb && static_cast<unsigned char> (line[2]) == 0xbf ) { - + /* Skip Unicode byte order mark */ line = line.substr (3); } @@ -88,7 +93,7 @@ SubripReader::SubripReader (FILE* f) to = convert_time (p[2]); /* XXX: should not ignore coordinate specifications */ - + state = CONTENT; break; } @@ -132,7 +137,7 @@ SubripReader::convert_line (string t, int line_number, Time from, Time to) TEXT, TAG } state = TEXT; - + string tag; RawSubtitle p; @@ -144,7 +149,10 @@ SubripReader::convert_line (string t, int line_number, Time from, Time to) /* XXX: arbitrary */ p.vertical_position.lines = 32; p.vertical_position.reference = TOP_OF_SUBTITLE; - + + list<Colour> colours; + colours.push_back (Colour (1, 1, 1)); + /* XXX: missing <font> support */ /* XXX: nesting of tags e.g. <b>foo<i>bar<b>baz</b>fred</i>jim</b> might not work, I think. @@ -179,6 +187,17 @@ SubripReader::convert_line (string t, int line_number, Time from, Time to) } else if (tag == "/u") { maybe_content (p); p.underline = false; + } else if (boost::starts_with (tag, "font")) { + maybe_content (p); + boost::regex re (".*color=\"#([0123456789abcdef]+)\""); + boost::smatch match; + if (boost::regex_search (tag, match, re) && string (match[1]).size() == 6) { + p.colour = Colour::from_rgb_hex (match[1]); + colours.push_back (p.colour); + } + } else if (tag == "/font") { + colours.pop_back (); + p.colour = colours.back (); } tag.clear (); state = TEXT; |
