Skip to content

Commit

Permalink
fixed #100 - loss of color information from the input subtitles file
Browse files Browse the repository at this point in the history
  • Loading branch information
krzemin committed May 15, 2017
1 parent a33b233 commit c9c3ef4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libqnapi/src/subconvert/formats/subrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ QString SubRipSubtitleFormat::encodeToken(const SubToken & entry) const
case STT_ITALIC_END: return "</i>";
case STT_UNDERLINE: return "<u>";
case STT_UNDERLINE_END: return "</u>";
case STT_FONTCOLOR: return QString("<font color=\"%1\">").arg(entry.payload);
case STT_FONTCOLOR: return QString("<font color=\"#%1\">").arg(entry.payload);
case STT_FONTCOLOR_END: return "</font>";
default: return "";
}
Expand Down
18 changes: 13 additions & 5 deletions libqnapi/src/subconvert/subtitleformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,25 @@ QVector<SubToken> SubtitleFormat::decodeTokenStream(QString tokenStream) const

if(!matched)
{
QRegExp colorR1("^\\{c:[$#](.*)\\}");
QRegExp colorR1("^\\{c:(.*)\\}");
colorR1.setPatternSyntax(QRegExp::RegExp2);
colorR1.setCaseSensitivity(Qt::CaseInsensitive);

QRegExp colorR2("^<font color=\"[$#](.*)\">");
QRegExp colorR2("^<font color=(.*)>");
colorR1.setPatternSyntax(QRegExp::RegExp2);
colorR1.setCaseSensitivity(Qt::CaseInsensitive);


if(colorR1.indexIn(tokenStream) == 0)
{
tok.type = STT_FONTCOLOR;
tok.payload = colorR1.cap(2);
tok.payload = parseColor(colorR1.cap(1));
tokenStream.remove(0, colorR1.cap(0).size());
matched = true;
}
else if(colorR2.indexIn(tokenStream) == 0)
{
tok.type = STT_FONTCOLOR;
tok.payload = colorR2.cap(2);
tok.payload = parseColor(colorR2.cap(1));
tokenStream.remove(0, colorR2.cap(0).size());
matched = true;
}
Expand Down Expand Up @@ -125,3 +124,12 @@ QVector<SubToken> SubtitleFormat::decodeTokenStream(QString tokenStream) const

return tokens;
}


QString SubtitleFormat::parseColor(QString colorString) const
{
return colorString
.replace('"', "")
.replace('#', "")
.replace('$', "");
}
2 changes: 2 additions & 0 deletions libqnapi/src/subconvert/subtitleformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class SubtitleFormat
virtual QStringList encode(const SubFile & subFile) const = 0;

QVector<SubToken> decodeTokenStream(QString tokenStream) const;
private:
QString parseColor(QString colorString) const;
};

#endif // SUBTITLEFORMAT_H
Expand Down

0 comments on commit c9c3ef4

Please sign in to comment.