From: Carl Hetherington Date: Fri, 2 Sep 2022 21:37:33 +0000 (+0200) Subject: Correctly parse \c tags in SSA (with no specified colour) to return to PrimaryColour. X-Git-Tag: v1.6.29~1 X-Git-Url: https://git.carlh.net/gitweb/?p=libsub.git;a=commitdiff_plain;h=b02d08547dd5739ede56cf73190b23f0bcd990a8 Correctly parse \c tags in SSA (with no specified colour) to return to PrimaryColour. This seems to be what libssa does. --- diff --git a/src/ssa_reader.cc b/src/ssa_reader.cc index 07d592a..dad0f26 100644 --- a/src/ssa_reader.cc +++ b/src/ssa_reader.cc @@ -200,7 +200,7 @@ SSAReader::parse_time (string t) const } void -SSAReader::parse_style (RawSubtitle& sub, string style, int play_res_x, int play_res_y) +SSAReader::parse_style(RawSubtitle& sub, string style, int play_res_x, int play_res_y, Colour primary_colour) { if (style == "\\i1") { sub.italic = true; @@ -254,10 +254,13 @@ SSAReader::parse_style (RawSubtitle& sub, string style, int play_res_x, int play sub.font_size.set_proportional(raw_convert(style.substr(3)) / play_res_y); } else if (boost::starts_with(style, "\\c")) { /* \c&Hbbggrr& */ - if (style.length() <= 2) { + if (style.length() > 2) { + sub.colour = h_colour(style.substr(2, style.length() - 3)); + } else if (style.length() == 2) { + sub.colour = primary_colour; + } else { throw SSAError(String::compose("Badly formatted colour tag %1", style)); } - sub.colour = h_colour (style.substr(2, style.length() - 3)); } } @@ -266,7 +269,7 @@ SSAReader::parse_style (RawSubtitle& sub, string style, int play_res_x, int play * @return List of RawSubtitles to represent line with vertical reference TOP_OF_SUBTITLE. */ vector -SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_res_y) +SSAReader::parse_line(RawSubtitle base, string line, int play_res_x, int play_res_y, Colour primary_colour) { enum { TEXT, @@ -328,7 +331,7 @@ SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_r subs.push_back (current); current.text = ""; } - parse_style (current, style, play_res_x, play_res_y); + parse_style(current, style, play_res_x, play_res_y, primary_colour); style = ""; } @@ -472,6 +475,7 @@ SSAReader::read (function ()> get_line) SUB_ASSERT (event_format.size() == event.size()); RawSubtitle sub; + optional