From 23579be63b69013a9cd27514c38fad3ba2aeb77e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Jul 2019 20:44:01 +0100 Subject: Support rgba() colour specifiers in Subrip files; not sure if they are strictly allowed but part of WebVTT. --- src/subrip_reader.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/subrip_reader.cc') diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index cfeeade..5e41699 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -25,6 +25,7 @@ #include "exceptions.h" #include "util.h" #include "sub_assert.h" +#include "raw_convert.h" #include #include #include @@ -237,13 +238,28 @@ SubripReader::convert_line (string t, RawSubtitle& p) p.underline = false; } else if (boost::starts_with (tag, "font")) { maybe_content (p); - boost::regex re (".*color=\"#([0123456789abcdef]+)\""); + boost::regex re (".*color=\"#([[:xdigit:]]+)\""); 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 { - throw SubripError (tag, "a colour in the format #rrggbb", _context); + re = boost::regex ( + ".*color=\"rgba\\(" + "[[:space:]]*([[:digit:]]+)[[:space:]]*," + "[[:space:]]*([[:digit:]]+)[[:space:]]*," + "[[:space:]]*([[:digit:]]+)[[:space:]]*," + "[[:space:]]*([[:digit:]]+)[[:space:]]*" + "\\)\"" + ); + if (boost::regex_search (tag, match, re) && match.size() == 5) { + p.colour.r = raw_convert(string(match[1])) / 255.0; + p.colour.g = raw_convert(string(match[2])) / 255.0; + p.colour.b = raw_convert(string(match[3])) / 255.0; + colours.push_back (p.colour); + } else { + throw SubripError (tag, "a colour in the format #rrggbb or rgba(rr,gg,bb,aa)", _context); + } } } else if (tag == "/font") { maybe_content (p); -- cgit v1.2.3