Add AutoBreakCommaBreakEarly setting

This commit is contained in:
Nikolaj Olsson 2019-01-07 18:17:18 +01:00
parent 42b8582e51
commit 8bf980ac83
2 changed files with 37 additions and 28 deletions

View File

@ -223,6 +223,7 @@ namespace Nikse.SubtitleEdit.Core
public decimal AdjustDurationSeconds { get; set; }
public int AdjustDurationPercent { get; set; }
public string AdjustDurationLast { get; set; }
public bool AutoBreakCommaBreakEarly { get; set; }
public ToolsSettings()
{
@ -314,6 +315,7 @@ namespace Nikse.SubtitleEdit.Core
MoveStartEndMs = 100;
AdjustDurationSeconds = 0.1m;
AdjustDurationPercent = 120;
AutoBreakCommaBreakEarly = true;
}
}
@ -2365,6 +2367,9 @@ $HorzAlign = Center
subNode = node.SelectSingleNode("AdjustDurationLast");
if (subNode != null)
settings.Tools.AdjustDurationLast = subNode.InnerText;
subNode = node.SelectSingleNode("AutoBreakCommaBreakEarly");
if (subNode != null)
settings.Tools.AutoBreakCommaBreakEarly = Convert.ToBoolean(subNode.InnerText);
subNode = node.SelectSingleNode("FindHistory");
if (subNode != null)
{
@ -3859,7 +3864,8 @@ $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("AutoBreakCommaBreakEarly", settings.Tools.AutoBreakCommaBreakEarly.ToString());
if (settings.Tools.FindHistory != null && settings.Tools.FindHistory.Count > 0)
{
const int maximumFindHistoryItems = 10;

View File

@ -553,7 +553,7 @@ namespace Nikse.SubtitleEdit.Core
}
}
}
}
}
if (splitPos > maximumLength) // too long first line
{
@ -566,43 +566,46 @@ namespace Nikse.SubtitleEdit.Core
}
// prefer comma
if (splitPos < 0)
if (Configuration.Settings.Tools.AutoBreakCommaBreakEarly)
{
const string expectedChars1 = ".!?0123456789";
const string expectedChars2 = ",";
for (int j = 0; j < 15; j++)
if (splitPos < 0)
{
if (mid + j + 1 < s.Length && mid + j > 0)
const string expectedChars1 = ".!?0123456789";
const string expectedChars2 = ",";
for (int j = 0; j < 15; j++)
{
if (expectedChars2.Contains(s[mid + j]) && !IsPartOfNumber(s, mid + j) && CanBreak(s, mid + j + 1, language))
if (mid + j + 1 < s.Length && mid + j > 0)
{
splitPos = mid + j + 1;
if (expectedChars1.Contains(s[splitPos]))
{ // do not break double/tripple end lines like "!!!" or "..."
splitPos++;
if (expectedChars1.Contains(s[mid + j + 1]))
if (expectedChars2.Contains(s[mid + j]) && !IsPartOfNumber(s, mid + j) && CanBreak(s, mid + j + 1, language))
{
splitPos = mid + j + 1;
if (expectedChars1.Contains(s[splitPos]))
{ // do not break double/tripple end lines like "!!!" or "..."
splitPos++;
if (expectedChars1.Contains(s[mid + j + 1]))
splitPos++;
}
break;
}
if (expectedChars2.Contains(s[mid - j]) && !IsPartOfNumber(s, mid - j) && CanBreak(s, mid - j + 1, language))
{
splitPos = mid - j;
splitPos++;
break;
}
break;
}
if (expectedChars2.Contains(s[mid - j]) && !IsPartOfNumber(s, mid - j) && CanBreak(s, mid - j + 1, language))
{
splitPos = mid - j;
splitPos++;
break;
}
}
}
}
if (splitPos > maximumLength) // too long first line
{
if (splitPos != maximumLength + 1 || s[maximumLength] != ' ') // allow for maxlength+1 char to be space (does not count)
if (splitPos > maximumLength) // too long first line
{
if (splitPos != maximumLength + 1 || s[maximumLength] != ' ') // allow for maxlength+1 char to be space (does not count)
splitPos = -1;
}
else if (splitPos >= 0 && s.Length - splitPos > maximumLength) // too long second line
{
splitPos = -1;
}
else if (splitPos >= 0 && s.Length - splitPos > maximumLength) // too long second line
{
splitPos = -1;
}
}
if (splitPos < 0)