forked from mia/Aegisub
Fix #759, correctly merge lines with identical text when exporting to simple subtitle formats.
Originally committed to SVN as r2301.
This commit is contained in:
parent
2928449ecc
commit
8129285630
1 changed files with 1 additions and 141 deletions
|
@ -515,7 +515,7 @@ void SubtitleFormat::MergeIdentical() {
|
|||
AssDialogue *curdlg = AssEntry::GetAsDialogue(*cur);
|
||||
AssDialogue *nextdlg = AssEntry::GetAsDialogue(*next);
|
||||
|
||||
if (curdlg && nextdlg && curdlg->Text == nextdlg->Text) {
|
||||
if (curdlg && nextdlg && curdlg->End == nextdlg->Start && curdlg->Text == nextdlg->Text) {
|
||||
// Merge timing
|
||||
nextdlg->Start = (nextdlg->Start < curdlg->Start ? nextdlg->Start : curdlg->Start);
|
||||
nextdlg->End = (nextdlg->End > curdlg->End ? nextdlg->End : curdlg->End);
|
||||
|
@ -527,143 +527,3 @@ void SubtitleFormat::MergeIdentical() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Merge identical and/or overlapping lines
|
||||
/*void SubtitleFormat::Merge(bool identical,bool overlaps,bool stripComments,bool stripNonDialogue) {
|
||||
using std::list;
|
||||
list<AssEntry*>::iterator next;
|
||||
list<AssEntry*>::iterator prev = Line->end();
|
||||
AssDialogue *previous = NULL;
|
||||
|
||||
// Loop through each line
|
||||
for (list<AssEntry*>::iterator cur=Line->begin();cur!=Line->end();cur=next) {
|
||||
next = cur;
|
||||
next++;
|
||||
|
||||
// Dialogue line
|
||||
AssDialogue *current = AssEntry::GetAsDialogue(*cur);
|
||||
if (current) {
|
||||
// Strip comments and empty lines
|
||||
if ((current->Comment && stripComments) || current->Text.IsEmpty()) {
|
||||
delete *cur;
|
||||
Line->erase(cur);
|
||||
}
|
||||
|
||||
// Proper line
|
||||
else {
|
||||
if (previous != NULL) {
|
||||
// Check for duplication
|
||||
if (identical && previous->Text == current->Text) {
|
||||
if (abs(current->Start.GetMS() - previous->End.GetMS()) < 20) {
|
||||
current->Start = (current->Start < previous->Start ? current->Start : previous->Start);
|
||||
current->End = (current->End > previous->End ? current->End : previous->End);
|
||||
delete *prev;
|
||||
Line->erase(prev);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for overlap
|
||||
//
|
||||
if (overlaps && previous->End.GetMS() > current->Start.GetMS()) {
|
||||
// Grab the data
|
||||
int prev_s = previous->Start.GetMS();
|
||||
int prev_e = previous->End.GetMS();
|
||||
int cur_s = current->Start.GetMS();
|
||||
int cur_e = current->End.GetMS();
|
||||
wxString prev_t = previous->Text;
|
||||
wxString cur_t = current->Text;
|
||||
|
||||
// Make sure cur points to the line before those we're working with
|
||||
--cur;
|
||||
// Remove 'cur' and 'prev' from list
|
||||
Line->erase(prev);
|
||||
Line->erase(prev);
|
||||
// Now make sure that 'cur' points to the item after the old 'current'
|
||||
++cur;
|
||||
|
||||
// A-only part
|
||||
if (prev_s < cur_s) {
|
||||
// Actually lines generated from this one never move
|
||||
// So we can assume it can just be inserted at cur
|
||||
AssDialogue *part = AssEntry::GetAsDialogue(previous->Clone());
|
||||
part->End.SetMS(prev_s);
|
||||
// Nothing to do about start-time or text, they are already correct
|
||||
|
||||
// Insert into list
|
||||
Line->insert(cur, part);
|
||||
// 'cur' now points to one past newly inserted item
|
||||
}
|
||||
|
||||
// A+B part
|
||||
{
|
||||
// These lines never move either, so just insert
|
||||
AssDialogue *part = AssEntry::GetAsDialogue(current->Clone());
|
||||
// Fix values
|
||||
part->Start.SetMS(cur_s);
|
||||
part->End.SetMS(prev_e);
|
||||
// Inserting an ASS hard linebreak
|
||||
part->Text = cur_t + _T("\\N") + prev_t;
|
||||
|
||||
// Insert into list
|
||||
Line->insert(cur, part);
|
||||
// 'cur' now points to one past newly inserted item
|
||||
}
|
||||
|
||||
// B-only part
|
||||
if (cur_e > prev_e) {
|
||||
// We need to seek for the right position here
|
||||
AssDialogue *part = AssEntry::GetAsDialogue(current->Clone());
|
||||
// Fix values
|
||||
part->Start.SetMS(prev_e);
|
||||
part->End.SetMS(cur_e);
|
||||
part->Text = cur_t;
|
||||
|
||||
list<AssEntry*>::iterator newpos = cur;
|
||||
|
||||
// Insert into list
|
||||
// Make sure 'cur' never moves during this
|
||||
if (newpos == Line->end()) {
|
||||
Line->push_back(part);
|
||||
}
|
||||
else {
|
||||
while (newpos != Line->end()) {
|
||||
AssDialogue *newline = AssEntry::GetAsDialogue(*newpos);
|
||||
if (newline && part->Start.GetMS() <= newline->Start.GetMS()) {
|
||||
// Suitable position
|
||||
Line->insert(newpos, part);
|
||||
break;
|
||||
}
|
||||
++newpos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now 'cur' has moved around a lot so make sure everything is correct
|
||||
// 'cur' currently points to one past the last inserted item
|
||||
// It should really point to the last inserted item (that wasn't
|
||||
// inserted at a later position) so we need to move it one back.
|
||||
// In fact, 'next' should have that value.
|
||||
next = cur--;
|
||||
// 'prev' should already be correct
|
||||
// And update the rest too
|
||||
previous = AssEntry::GetAsDialogue(*prev);
|
||||
current = AssEntry::GetAsDialogue(*cur);
|
||||
}
|
||||
}
|
||||
|
||||
// Set as previous
|
||||
prev = cur;
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
// Other line, delete it
|
||||
else {
|
||||
if (stripNonDialogue) {
|
||||
delete *cur;
|
||||
Line->erase(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
|
Loading…
Reference in a new issue