mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2025-02-01 05:21:40 +01:00
Add "Fix short gaps" option to "Fix common errors"
This commit is contained in:
parent
baac6ddf64
commit
255275ab2d
@ -583,6 +583,7 @@ Note: Do check free disk space.</WaveFileMalformed>
|
||||
<FixOverlappingDisplayTimes>Fix overlapping display times</FixOverlappingDisplayTimes>
|
||||
<FixShortDisplayTimes>Fix short display times</FixShortDisplayTimes>
|
||||
<FixLongDisplayTimes>Fix long display times</FixLongDisplayTimes>
|
||||
<FixShortGaps>Fix short gaps</FixShortGaps>
|
||||
<FixInvalidItalicTags>Fix invalid italic tags</FixInvalidItalicTags>
|
||||
<RemoveUnneededSpaces>Remove unneeded spaces</RemoveUnneededSpaces>
|
||||
<RemoveUnneededPeriods>Remove unneeded periods</RemoveUnneededPeriods>
|
||||
@ -648,6 +649,7 @@ Note: Do check free disk space.</WaveFileMalformed>
|
||||
<XDisplayTimesProlonged>{0} display times prolonged</XDisplayTimesProlonged>
|
||||
<XInvalidHtmlTagsFixed>{0} invalid HTML tags fixed</XInvalidHtmlTagsFixed>
|
||||
<XDisplayTimesShortned>{0} display times shortened</XDisplayTimesShortned>
|
||||
<XGapsFixed>{0} short gaps fixed</XGapsFixed>
|
||||
<XLinesUnbreaked>{0} lines unbreaked</XLinesUnbreaked>
|
||||
<UnneededSpace>Unneeded space</UnneededSpace>
|
||||
<XUnneededSpacesRemoved>{0} unneeded spaces removed</XUnneededSpacesRemoved>
|
||||
|
34
libse/Forms/FixCommonErrors/FixShortGaps.cs
Normal file
34
libse/Forms/FixCommonErrors/FixShortGaps.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Nikse.SubtitleEdit.Core.Interfaces;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
{
|
||||
public class FixShortGaps : IFixCommonError
|
||||
{
|
||||
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
|
||||
{
|
||||
var language = Configuration.Settings.Language.FixCommonErrors;
|
||||
string fixAction = language.FixShortGaps;
|
||||
int noOfShortGaps = 0;
|
||||
for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
|
||||
{
|
||||
Paragraph p = subtitle.Paragraphs[i];
|
||||
Paragraph next = subtitle.Paragraphs[i + 1];
|
||||
double minGap = Configuration.Settings.General.MinimumMillisecondsBetweenLines;
|
||||
|
||||
double gap = next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds;
|
||||
|
||||
bool allowFix = callbacks.AllowFix(p, fixAction);
|
||||
if (allowFix && gap < minGap)
|
||||
{
|
||||
string oldCurrent = p.ToString();
|
||||
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - minGap;
|
||||
noOfShortGaps++;
|
||||
callbacks.AddFixToListView(p, fixAction, oldCurrent, p.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
callbacks.UpdateFixStatus(noOfShortGaps, language.FixShortGaps, string.Format(language.XGapsFixed, noOfShortGaps));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -780,6 +780,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
FixOverlappingDisplayTimes = "Fix overlapping display times",
|
||||
FixShortDisplayTimes = "Fix short display times",
|
||||
FixLongDisplayTimes = "Fix long display times",
|
||||
FixShortGaps = "Fix short gaps",
|
||||
FixInvalidItalicTags = "Fix invalid italic tags",
|
||||
RemoveUnneededSpaces = "Remove unneeded spaces",
|
||||
RemoveUnneededPeriods = "Remove unneeded periods",
|
||||
@ -844,6 +845,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
XDisplayTimesProlonged = "{0} display times prolonged",
|
||||
XInvalidHtmlTagsFixed = "{0} invalid HTML tags fixed",
|
||||
XDisplayTimesShortned = "{0} display times shortened",
|
||||
XGapsFixed = "{0} short gaps fixed",
|
||||
XLinesUnbreaked = "{0} lines unbreaked",
|
||||
UnneededSpace = "Unneeded space",
|
||||
XUnneededSpacesRemoved = "{0} unneeded spaces removed",
|
||||
|
@ -1516,6 +1516,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
case "FixCommonErrors/FixLongDisplayTimes":
|
||||
language.FixCommonErrors.FixLongDisplayTimes = reader.Value;
|
||||
break;
|
||||
case "FixCommonErrors/FixShortGaps":
|
||||
language.FixCommonErrors.FixShortGaps = reader.Value;
|
||||
break;
|
||||
case "FixCommonErrors/FixInvalidItalicTags":
|
||||
language.FixCommonErrors.FixInvalidItalicTags = reader.Value;
|
||||
break;
|
||||
@ -1711,6 +1714,9 @@ namespace Nikse.SubtitleEdit.Core
|
||||
case "FixCommonErrors/XDisplayTimesShortned":
|
||||
language.FixCommonErrors.XDisplayTimesShortned = reader.Value;
|
||||
break;
|
||||
case "FixCommonErrors/XGapsFixed":
|
||||
language.FixCommonErrors.XGapsFixed = reader.Value;
|
||||
break;
|
||||
case "FixCommonErrors/XLinesUnbreaked":
|
||||
language.FixCommonErrors.XLinesUnbreaked = reader.Value;
|
||||
break;
|
||||
|
@ -651,6 +651,7 @@
|
||||
public string FixOverlappingDisplayTimes { get; set; }
|
||||
public string FixShortDisplayTimes { get; set; }
|
||||
public string FixLongDisplayTimes { get; set; }
|
||||
public string FixShortGaps { get; set; }
|
||||
public string FixInvalidItalicTags { get; set; }
|
||||
public string RemoveUnneededSpaces { get; set; }
|
||||
public string RemoveUnneededPeriods { get; set; }
|
||||
@ -716,6 +717,7 @@
|
||||
public string XDisplayTimesProlonged { get; set; }
|
||||
public string XInvalidHtmlTagsFixed { get; set; }
|
||||
public string XDisplayTimesShortned { get; set; }
|
||||
public string XGapsFixed { get; set; }
|
||||
public string XLinesUnbreaked { get; set; }
|
||||
public string UnneededSpace { get; set; }
|
||||
public string XUnneededSpacesRemoved { get; set; }
|
||||
|
@ -171,6 +171,7 @@
|
||||
<Compile Include="Forms\FixCommonErrors\FixMusicNotation.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixOverlappingDisplayTimes.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixShortDisplayTimes.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixShortGaps.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixShortLines.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixShortLinesAll.cs" />
|
||||
<Compile Include="Forms\FixCommonErrors\FixSpanishInvertedQuestionAndExclamationMarks.cs" />
|
||||
|
@ -594,6 +594,7 @@ $HorzAlign = Center
|
||||
public bool OverlappingDisplayTimeTicked { get; set; }
|
||||
public bool TooShortDisplayTimeTicked { get; set; }
|
||||
public bool TooLongDisplayTimeTicked { get; set; }
|
||||
public bool TooShortGapTicked { get; set; }
|
||||
public bool InvalidItalicTagsTicked { get; set; }
|
||||
public bool BreakLongLinesTicked { get; set; }
|
||||
public bool MergeShortLinesTicked { get; set; }
|
||||
@ -635,6 +636,7 @@ $HorzAlign = Center
|
||||
OverlappingDisplayTimeTicked = true;
|
||||
TooShortDisplayTimeTicked = true;
|
||||
TooLongDisplayTimeTicked = true;
|
||||
TooShortGapTicked = true;
|
||||
InvalidItalicTagsTicked = true;
|
||||
BreakLongLinesTicked = true;
|
||||
MergeShortLinesTicked = true;
|
||||
@ -3971,6 +3973,12 @@ $HorzAlign = Center
|
||||
settings.CommonErrors.TooLongDisplayTimeTicked = Convert.ToBoolean(subNode.InnerText);
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("TooShortGapTicked");
|
||||
if (subNode != null)
|
||||
{
|
||||
settings.CommonErrors.TooShortGapTicked = Convert.ToBoolean(subNode.InnerText);
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("InvalidItalicTagsTicked");
|
||||
if (subNode != null)
|
||||
{
|
||||
@ -6456,6 +6464,7 @@ $HorzAlign = Center
|
||||
textWriter.WriteElementString("OverlappingDisplayTimeTicked", settings.CommonErrors.OverlappingDisplayTimeTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("TooShortDisplayTimeTicked", settings.CommonErrors.TooShortDisplayTimeTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("TooLongDisplayTimeTicked", settings.CommonErrors.TooLongDisplayTimeTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("TooShortGapTicked", settings.CommonErrors.TooShortGapTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("InvalidItalicTagsTicked", settings.CommonErrors.InvalidItalicTagsTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("BreakLongLinesTicked", settings.CommonErrors.BreakLongLinesTicked.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("MergeShortLinesTicked", settings.CommonErrors.MergeShortLinesTicked.ToString(CultureInfo.InvariantCulture));
|
||||
|
@ -23,31 +23,32 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
private const int IndexOverlappingDisplayTime = 1;
|
||||
private const int IndexTooShortDisplayTime = 2;
|
||||
private const int IndexTooLongDisplayTime = 3;
|
||||
private const int IndexInvalidItalicTags = 4;
|
||||
private const int IndexUnneededSpaces = 5;
|
||||
private const int IndexUnneededPeriods = 6;
|
||||
private const int IndexMissingSpaces = 7;
|
||||
private const int IndexBreakLongLines = 8;
|
||||
private const int IndexMergeShortLines = 9;
|
||||
private const int IndexMergeShortLinesAll = 10;
|
||||
private const int IndexDoubleApostropheToQuote = 11;
|
||||
private const int IndexFixMusicNotation = 12;
|
||||
private const int IndexAddPeriodAfterParagraph = 13;
|
||||
private const int IndexStartWithUppercaseLetterAfterParagraph = 14;
|
||||
private const int IndexStartWithUppercaseLetterAfterPeriodInsideParagraph = 15;
|
||||
private const int IndexStartWithUppercaseLetterAfterColon = 16;
|
||||
private const int IndexAddMissingQuotes = 17;
|
||||
private const int IndexFixHyphensAdd = 18;
|
||||
private const int IndexFixHyphens = 19;
|
||||
private const int IndexFix3PlusLines = 20;
|
||||
private const int IndexFixDoubleDash = 21;
|
||||
private const int IndexFixDoubleGreaterThan = 22;
|
||||
private const int IndexFixEllipsesStart = 23;
|
||||
private const int IndexFixMissingOpenBracket = 24;
|
||||
private const int IndexFixOcrErrorsViaReplaceList = 25;
|
||||
private const int IndexUppercaseIInsideLowercaseWord = 26;
|
||||
private const int IndexRemoveSpaceBetweenNumbers = 27;
|
||||
private const int IndexDialogsOnOneLine = 28;
|
||||
private const int IndexTooShortGap = 4;
|
||||
private const int IndexInvalidItalicTags = 5;
|
||||
private const int IndexUnneededSpaces = 6;
|
||||
private const int IndexUnneededPeriods = 7;
|
||||
private const int IndexMissingSpaces = 8;
|
||||
private const int IndexBreakLongLines = 9;
|
||||
private const int IndexMergeShortLines = 10;
|
||||
private const int IndexMergeShortLinesAll = 11;
|
||||
private const int IndexDoubleApostropheToQuote = 12;
|
||||
private const int IndexFixMusicNotation = 13;
|
||||
private const int IndexAddPeriodAfterParagraph = 14;
|
||||
private const int IndexStartWithUppercaseLetterAfterParagraph = 15;
|
||||
private const int IndexStartWithUppercaseLetterAfterPeriodInsideParagraph = 16;
|
||||
private const int IndexStartWithUppercaseLetterAfterColon = 17;
|
||||
private const int IndexAddMissingQuotes = 18;
|
||||
private const int IndexFixHyphensAdd = 19;
|
||||
private const int IndexFixHyphens = 20;
|
||||
private const int IndexFix3PlusLines = 21;
|
||||
private const int IndexFixDoubleDash = 22;
|
||||
private const int IndexFixDoubleGreaterThan = 23;
|
||||
private const int IndexFixEllipsesStart = 24;
|
||||
private const int IndexFixMissingOpenBracket = 25;
|
||||
private const int IndexFixOcrErrorsViaReplaceList = 26;
|
||||
private const int IndexUppercaseIInsideLowercaseWord = 27;
|
||||
private const int IndexRemoveSpaceBetweenNumbers = 28;
|
||||
private const int IndexDialogsOnOneLine = 29;
|
||||
private int _indexAloneLowercaseIToUppercaseIEnglish = -1;
|
||||
private int _turkishAnsiIndex = -1;
|
||||
private int _danishLetterIIndex = -1;
|
||||
@ -369,6 +370,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
new FixItem(_language.FixOverlappingDisplayTimes, string.Empty, () => new FixOverlappingDisplayTimes().Fix(Subtitle, this), ce.OverlappingDisplayTimeTicked),
|
||||
new FixItem(_language.FixShortDisplayTimes, string.Empty, () => new FixShortDisplayTimes().Fix(Subtitle, this), ce.TooShortDisplayTimeTicked),
|
||||
new FixItem(_language.FixLongDisplayTimes, string.Empty, () => new FixLongDisplayTimes().Fix(Subtitle, this), ce.TooLongDisplayTimeTicked),
|
||||
new FixItem(_language.FixShortGaps, string.Empty, () => new FixShortGaps().Fix(Subtitle, this), ce.TooShortGapTicked),
|
||||
new FixItem(_language.FixInvalidItalicTags, _language.FixInvalidItalicTagsExample, () => new FixInvalidItalicTags().Fix(Subtitle, this), ce.InvalidItalicTagsTicked),
|
||||
new FixItem(_language.RemoveUnneededSpaces, _language.RemoveUnneededSpacesExample, () => new FixUnneededSpaces().Fix(Subtitle, this), ce.UnneededSpacesTicked),
|
||||
new FixItem(_language.RemoveUnneededPeriods, _language.RemoveUnneededPeriodsExample, () => new FixUnneededPeriods().Fix(Subtitle, this), ce.UnneededPeriodsTicked),
|
||||
@ -1012,6 +1014,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
ce.OverlappingDisplayTimeTicked = listView1.Items[IndexOverlappingDisplayTime].Checked;
|
||||
ce.TooShortDisplayTimeTicked = listView1.Items[IndexTooShortDisplayTime].Checked;
|
||||
ce.TooLongDisplayTimeTicked = listView1.Items[IndexTooLongDisplayTime].Checked;
|
||||
ce.TooShortGapTicked = listView1.Items[IndexTooShortGap].Checked;
|
||||
ce.InvalidItalicTagsTicked = listView1.Items[IndexInvalidItalicTags].Checked;
|
||||
ce.UnneededSpacesTicked = listView1.Items[IndexUnneededSpaces].Checked;
|
||||
ce.UnneededPeriodsTicked = listView1.Items[IndexUnneededPeriods].Checked;
|
||||
|
Loading…
x
Reference in New Issue
Block a user