* Fix bug in SRT parsing: In some cases a blank line too much is counted.

* Make SRT no longer coalesce line breaks, Aegisub will now write SRT files with blank lines in subtitles.
Updates #1213.

Originally committed to SVN as r4558.
This commit is contained in:
Niels Martin Hansen 2010-06-20 19:42:13 +00:00
parent 2fc8420ee9
commit e5eb91a269
3 changed files with 10 additions and 6 deletions

View File

@ -417,7 +417,7 @@ void SubtitleFormat::SortLines() {
/// @param format
/// @param lineEnd
///
void SubtitleFormat::ConvertTags(int format,wxString lineEnd) {
void SubtitleFormat::ConvertTags(int format,const wxString &lineEnd,bool mergeLineBreaks) {
using std::list;
list<AssEntry*>::iterator next;
for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur++) {
@ -431,10 +431,12 @@ void SubtitleFormat::ConvertTags(int format,wxString lineEnd) {
current->Text.Replace(_T("\\h"),_T(" "),true);
current->Text.Replace(_T("\\n"),lineEnd,true);
current->Text.Replace(_T("\\N"),lineEnd,true);
if (mergeLineBreaks) {
while (current->Text.Replace(lineEnd+lineEnd,lineEnd,true)) {};
}
}
}
}

View File

@ -103,7 +103,7 @@ protected:
void CreateCopy();
void ClearCopy();
void SortLines();
void ConvertTags(int format,wxString lineEnd);
void ConvertTags(int format,const wxString &lineEnd,bool mergeLineBreaks=true);
//void Merge(bool identical,bool overlaps,bool stripComments,bool stripNonDialogue);
void StripComments();
void StripNonDialogue();

View File

@ -184,7 +184,8 @@ found_timestamps:
if (text_line.IsEmpty()) {
// that's not very interesting... blank subtitle?
state = 5;
linebreak_debt = 1;
// no previous line that needs a line break after
linebreak_debt = 0;
break;
}
line->Text.Append(text_line);
@ -197,6 +198,7 @@ found_timestamps:
if (text_line.IsEmpty()) {
// blank line, next may begin a new subtitle
state = 5;
// previous line needs a line break after
linebreak_debt = 1;
break;
}
@ -262,12 +264,12 @@ void SRTSubtitleFormat::WriteFile(wxString _filename,wxString encoding) {
StripComments();
// Tags must be converted in two passes
// First ASS style overrides are converted to SRT but linebreaks are kept
ConvertTags(2,_T("\\N"));
ConvertTags(2,_T("\\N"),false);
// Then we can recombine overlaps, this requires ASS style linebreaks
RecombineOverlaps();
MergeIdentical();
// And finally convert linebreaks
ConvertTags(0,_T("\r\n"));
ConvertTags(0,_T("\r\n"),false);
// Otherwise unclosed overrides might affect lines they shouldn't, see bug #809 for example
// Write lines