Merge pull request #3422 from Flitskikker/fix-3414

Add 'Extend only' option for the 'Recalculate' method in the 'Adjust durations' dialog (#3414)
This commit is contained in:
Nikolaj Olsson 2019-02-27 21:22:09 +01:00 committed by GitHub
commit 1b021d7133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 13 deletions

View File

@ -147,6 +147,7 @@ Note: Do check free disk space.</WaveFileMalformed>
<Note>Note: Display time will not overlap start time of next text</Note>
<Fixed>Fixed</Fixed>
<Milliseconds>Milliseconds</Milliseconds>
<ExtendOnly>Extend only</ExtendOnly>
</AdjustDisplayDuration>
<ApplyDurationLimits>
<Title>Apply duration limits</Title>

View File

@ -277,7 +277,8 @@ namespace Nikse.SubtitleEdit.Core
Seconds = "Seconds",
Note = "Note: Display time will not overlap start time of next text",
Fixed = "Fixed",
Milliseconds = "Milliseconds"
Milliseconds = "Milliseconds",
ExtendOnly = "Extend only"
};
ApplyDurationLimits = new LanguageStructure.ApplyDurationLimits

View File

@ -406,6 +406,9 @@ namespace Nikse.SubtitleEdit.Core
case "AdjustDisplayDuration/Milliseconds":
language.AdjustDisplayDuration.Milliseconds = reader.Value;
break;
case "AdjustDisplayDuration/ExtendOnly":
language.AdjustDisplayDuration.ExtendOnly = reader.Value;
break;
case "ApplyDurationLimits/Title":
language.ApplyDurationLimits.Title = reader.Value;
break;

View File

@ -149,6 +149,7 @@
public string Note { get; set; }
public string Fixed { get; set; }
public string Milliseconds { get; set; }
public string ExtendOnly { get; set; }
}
public class ApplyDurationLimits

View File

@ -233,6 +233,7 @@ namespace Nikse.SubtitleEdit.Core
public decimal AdjustDurationSeconds { get; set; }
public int AdjustDurationPercent { get; set; }
public string AdjustDurationLast { get; set; }
public bool AdjustDurationExtendOnly { get; set; }
public bool AutoBreakCommaBreakEarly { get; set; }
public bool ApplyMinimumDurationLimit { get; set; }
public bool ApplyMaximumDurationLimit { get; set; }
@ -327,6 +328,7 @@ namespace Nikse.SubtitleEdit.Core
MoveStartEndMs = 100;
AdjustDurationSeconds = 0.1m;
AdjustDurationPercent = 120;
AdjustDurationExtendOnly = true;
AutoBreakCommaBreakEarly = true;
ApplyMinimumDurationLimit = true;
ApplyMaximumDurationLimit = true;
@ -3252,6 +3254,12 @@ $HorzAlign = Center
settings.Tools.AdjustDurationLast = subNode.InnerText;
}
subNode = node.SelectSingleNode("AdjustDurationExtendOnly");
if (subNode != null)
{
settings.Tools.AdjustDurationExtendOnly = Convert.ToBoolean(subNode.InnerText);
}
subNode = node.SelectSingleNode("AutoBreakCommaBreakEarly");
if (subNode != null)
{
@ -5889,6 +5897,7 @@ $HorzAlign = Center
textWriter.WriteElementString("AdjustDurationSeconds", settings.Tools.AdjustDurationSeconds.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("AdjustDurationPercent", settings.Tools.AdjustDurationPercent.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("AdjustDurationLast", settings.Tools.AdjustDurationLast);
textWriter.WriteElementString("AdjustDurationExtendOnly", settings.Tools.AdjustDurationExtendOnly.ToString());
textWriter.WriteElementString("AutoBreakCommaBreakEarly", settings.Tools.AutoBreakCommaBreakEarly.ToString());
textWriter.WriteElementString("ApplyMinimumDurationLimit", settings.Tools.ApplyMinimumDurationLimit.ToString());
textWriter.WriteElementString("ApplyMaximumDurationLimit", settings.Tools.ApplyMaximumDurationLimit.ToString());

View File

@ -385,18 +385,18 @@ namespace Nikse.SubtitleEdit.Core
}
}
public void RecalculateDisplayTimes(double maxCharactersPerSecond, List<int> selectedIndexes, double optimalCharactersPerSeconds)
public void RecalculateDisplayTimes(double maxCharactersPerSecond, List<int> selectedIndexes, double optimalCharactersPerSeconds, bool extendOnly = false)
{
for (int i = 0; i < _paragraphs.Count; i++)
{
if (selectedIndexes == null || selectedIndexes.Contains(i))
{
RecalculateDisplayTime(maxCharactersPerSecond, i, optimalCharactersPerSeconds);
RecalculateDisplayTime(maxCharactersPerSecond, i, optimalCharactersPerSeconds, extendOnly);
}
}
}
public void RecalculateDisplayTime(double maxCharactersPerSecond, int index, double optimalCharactersPerSeconds)
public void RecalculateDisplayTime(double maxCharactersPerSecond, int index, double optimalCharactersPerSeconds, bool extendOnly = false)
{
Paragraph p = GetParagraphOrDefault(index);
if (p == null)
@ -404,6 +404,8 @@ namespace Nikse.SubtitleEdit.Core
return;
}
double originalEndTime = p.EndTime.TotalMilliseconds;
double duration = Utilities.GetOptimalDisplayMilliseconds(p.Text, optimalCharactersPerSeconds);
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + duration;
var numberOfCharacters = p.Text.CountCharacters(Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace);
@ -413,6 +415,11 @@ namespace Nikse.SubtitleEdit.Core
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + duration;
}
if (extendOnly && p.EndTime.TotalMilliseconds < originalEndTime)
{
p.EndTime.TotalMilliseconds = originalEndTime;
}
Paragraph next = GetParagraphOrDefault(index + 1);
if (next != null && p.StartTime.TotalMilliseconds + duration + Configuration.Settings.General.MinimumMillisecondsBetweenLines > next.StartTime.TotalMilliseconds)
{

View File

@ -47,6 +47,7 @@
this.numericUpDownFixedMilliseconds = new System.Windows.Forms.NumericUpDown();
this.labelMillisecondsFixed = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.checkBoxExtendOnly = new System.Windows.Forms.CheckBox();
this.groupBoxAdjustVia.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxCharsSec)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSeconds)).BeginInit();
@ -119,7 +120,7 @@
// labelNote
//
this.labelNote.AutoSize = true;
this.labelNote.Location = new System.Drawing.Point(12, 191);
this.labelNote.Location = new System.Drawing.Point(10, 211);
this.labelNote.Name = "labelNote";
this.labelNote.Size = new System.Drawing.Size(279, 13);
this.labelNote.TabIndex = 7;
@ -148,7 +149,7 @@
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(537, 210);
this.buttonCancel.Location = new System.Drawing.Point(537, 231);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 21);
this.buttonCancel.TabIndex = 21;
@ -159,7 +160,7 @@
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(456, 210);
this.buttonOK.Location = new System.Drawing.Point(456, 231);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 21);
this.buttonOK.TabIndex = 20;
@ -194,7 +195,7 @@
// labelMaxCharsPerSecond
//
this.labelMaxCharsPerSecond.AutoSize = true;
this.labelMaxCharsPerSecond.Location = new System.Drawing.Point(357, 70);
this.labelMaxCharsPerSecond.Location = new System.Drawing.Point(354, 70);
this.labelMaxCharsPerSecond.Name = "labelMaxCharsPerSecond";
this.labelMaxCharsPerSecond.Size = new System.Drawing.Size(80, 13);
this.labelMaxCharsPerSecond.TabIndex = 5;
@ -277,7 +278,7 @@
// labelOptimalCharsSec
//
this.labelOptimalCharsSec.AutoSize = true;
this.labelOptimalCharsSec.Location = new System.Drawing.Point(357, 128);
this.labelOptimalCharsSec.Location = new System.Drawing.Point(354, 128);
this.labelOptimalCharsSec.Name = "labelOptimalCharsSec";
this.labelOptimalCharsSec.Size = new System.Drawing.Size(92, 13);
this.labelOptimalCharsSec.TabIndex = 10;
@ -294,7 +295,7 @@
0});
this.numericUpDownFixedMilliseconds.Name = "numericUpDownFixedMilliseconds";
this.numericUpDownFixedMilliseconds.Size = new System.Drawing.Size(80, 21);
this.numericUpDownFixedMilliseconds.TabIndex = 8;
this.numericUpDownFixedMilliseconds.TabIndex = 9;
this.numericUpDownFixedMilliseconds.Value = new decimal(new int[] {
3000,
0,
@ -304,7 +305,7 @@
// labelMillisecondsFixed
//
this.labelMillisecondsFixed.AutoSize = true;
this.labelMillisecondsFixed.Location = new System.Drawing.Point(501, 70);
this.labelMillisecondsFixed.Location = new System.Drawing.Point(498, 70);
this.labelMillisecondsFixed.Name = "labelMillisecondsFixed";
this.labelMillisecondsFixed.Size = new System.Drawing.Size(62, 13);
this.labelMillisecondsFixed.TabIndex = 12;
@ -319,11 +320,22 @@
this.label1.TabIndex = 22;
this.label1.Text = "%";
//
// checkBoxExtendOnly
//
this.checkBoxExtendOnly.AutoSize = true;
this.checkBoxExtendOnly.Location = new System.Drawing.Point(357, 184);
this.checkBoxExtendOnly.Name = "checkBoxExtendOnly";
this.checkBoxExtendOnly.Size = new System.Drawing.Size(83, 17);
this.checkBoxExtendOnly.TabIndex = 8;
this.checkBoxExtendOnly.Text = "Extend only";
this.checkBoxExtendOnly.UseVisualStyleBackColor = true;
//
// AdjustDisplayDuration
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(624, 247);
this.ClientSize = new System.Drawing.Size(624, 268);
this.Controls.Add(this.checkBoxExtendOnly);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDownFixedMilliseconds);
this.Controls.Add(this.labelMillisecondsFixed);
@ -382,5 +394,6 @@
private System.Windows.Forms.NumericUpDown numericUpDownFixedMilliseconds;
private System.Windows.Forms.Label labelMillisecondsFixed;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox checkBoxExtendOnly;
}
}

View File

@ -43,6 +43,8 @@ namespace Nikse.SubtitleEdit.Forms
public int FixedMilliseconds => (int)numericUpDownFixedMilliseconds.Value;
public bool ExtendOnly => checkBoxExtendOnly.Checked;
public AdjustDisplayDuration()
{
UiUtil.PreInitialize(this);
@ -68,6 +70,8 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownOptimalCharsSec.Value = (decimal)Configuration.Settings.General.SubtitleOptimalCharactersPerSeconds;
numericUpDownMaxCharsSec.Value = (decimal)Configuration.Settings.General.SubtitleMaximumCharactersPerSeconds;
checkBoxExtendOnly.Checked = Configuration.Settings.Tools.AdjustDurationExtendOnly;
LanguageStructure.AdjustDisplayDuration language = Configuration.Settings.Language.AdjustDisplayDuration;
Text = language.Title;
groupBoxAdjustVia.Text = language.AdjustVia;
@ -80,6 +84,7 @@ namespace Nikse.SubtitleEdit.Forms
labelNote.Text = language.Note;
radioButtonFixed.Text = language.Fixed;
labelMillisecondsFixed.Text = language.Milliseconds;
checkBoxExtendOnly.Text = language.ExtendOnly;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
FixLargeFonts();
@ -131,6 +136,7 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownSeconds.Enabled = radioButtonSeconds.Checked;
numericUpDownMaxCharsSec.Enabled = radioButtonAutoRecalculate.Checked;
numericUpDownOptimalCharsSec.Enabled = radioButtonAutoRecalculate.Checked;
checkBoxExtendOnly.Enabled = radioButtonAutoRecalculate.Checked;
numericUpDownFixedMilliseconds.Enabled = radioButtonFixed.Checked;
}
@ -143,6 +149,7 @@ namespace Nikse.SubtitleEdit.Forms
{
Configuration.Settings.Tools.AdjustDurationSeconds = numericUpDownSeconds.Value;
Configuration.Settings.Tools.AdjustDurationPercent = (int)numericUpDownPercent.Value;
Configuration.Settings.Tools.AdjustDurationExtendOnly = checkBoxExtendOnly.Checked;
if (radioButtonSeconds.Checked)
{

View File

@ -6289,7 +6289,7 @@ namespace Nikse.SubtitleEdit.Forms
else if (adjustDisplayTime.AdjustUsingRecalc)
{
double maxCharSeconds = (double)(adjustDisplayTime.MaxCharactersPerSecond);
_subtitle.RecalculateDisplayTimes(maxCharSeconds, selectedIndices, (double)adjustDisplayTime.OptimalCharactersPerSecond);
_subtitle.RecalculateDisplayTimes(maxCharSeconds, selectedIndices, (double)adjustDisplayTime.OptimalCharactersPerSecond, adjustDisplayTime.ExtendOnly);
ShowStatus(string.Format(_language.DisplayTimesAdjustedX, adjustDisplayTime.AdjustValue));
}
else