From b02d08547dd5739ede56cf73190b23f0bcd990a8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 2 Sep 2022 23:37:33 +0200 Subject: [PATCH] Correctly parse \c tags in SSA (with no specified colour) to return to PrimaryColour. This seems to be what libssa does. --- src/ssa_reader.cc | 40 ++++++++++++++++++++++------------------ src/ssa_reader.h | 4 ++-- src/subrip_reader.cc | 2 +- test/ssa_reader_test.cc | 17 ++++++++++++----- 4 files changed, 37 insertions(+), 26 deletions(-) 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