#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)
static_cast<unsigned char> (line[1]) == 0xbb &&
static_cast<unsigned char> (line[2]) == 0xbf
) {
-
+
/* Skip Unicode byte order mark */
line = line.substr (3);
}
to = convert_time (p[2]);
/* XXX: should not ignore coordinate specifications */
-
+
state = CONTENT;
break;
}
TEXT,
TAG
} state = TEXT;
-
+
string tag;
RawSubtitle p;
/* 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.
} 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;