mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Improved splitting - thx dr. Jackson
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@270 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
9064caa33e
commit
a2d212dd95
@ -3764,23 +3764,16 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
Paragraph currentParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex);
|
||||
var newParagraph = new Paragraph();
|
||||
|
||||
double middle = currentParagraph.StartTime.TotalMilliseconds + (currentParagraph.Duration.TotalMilliseconds / 2.0);
|
||||
if (splitSeconds.HasValue && splitSeconds.Value > (currentParagraph.StartTime.TotalSeconds + 0.2) && splitSeconds.Value < (currentParagraph.EndTime.TotalSeconds - 0.2))
|
||||
middle = splitSeconds.Value * 1000.0;
|
||||
newParagraph.EndTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds;
|
||||
currentParagraph.EndTime.TotalMilliseconds = middle;
|
||||
newParagraph.StartTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds + 1;
|
||||
|
||||
|
||||
string oldText = currentParagraph.Text;
|
||||
string[] lines = currentParagraph.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
if (lines.Length == 2)
|
||||
if (lines.Length == 2 && (lines[0].EndsWith(".") || lines[0].EndsWith("!") || lines[0].EndsWith("?")))
|
||||
{
|
||||
currentParagraph.Text = Utilities.AutoBreakLine(lines[0]);
|
||||
newParagraph.Text = Utilities.AutoBreakLine(lines[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
string s = Utilities.AutoBreakLine(currentParagraph.Text);
|
||||
string s = Utilities.AutoBreakLine(currentParagraph.Text, 5, Configuration.Settings.General.SubtitleLineMaximumLength * 2);
|
||||
lines = s.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
if (lines.Length == 2)
|
||||
{
|
||||
@ -3789,6 +3782,19 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
double startFactor = (double)Utilities.RemoveHtmlTags(currentParagraph.Text).Length / Utilities.RemoveHtmlTags(oldText).Length;
|
||||
if (startFactor < 0.20)
|
||||
startFactor = 0.20;
|
||||
if (startFactor > 0.80)
|
||||
startFactor = 0.80;
|
||||
|
||||
double middle = currentParagraph.StartTime.TotalMilliseconds + (currentParagraph.Duration.TotalMilliseconds * startFactor);
|
||||
if (splitSeconds.HasValue && splitSeconds.Value > (currentParagraph.StartTime.TotalSeconds + 0.2) && splitSeconds.Value < (currentParagraph.EndTime.TotalSeconds - 0.2))
|
||||
middle = splitSeconds.Value * 1000.0;
|
||||
newParagraph.EndTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds;
|
||||
currentParagraph.EndTime.TotalMilliseconds = middle;
|
||||
newParagraph.StartTime.TotalMilliseconds = currentParagraph.EndTime.TotalMilliseconds + 1;
|
||||
|
||||
if (_networkSession != null)
|
||||
{
|
||||
_networkSession.TimerStop();
|
||||
|
@ -266,10 +266,10 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
|
||||
public static string AutoBreakLine(string text)
|
||||
{
|
||||
return AutoBreakLine(text, 5);
|
||||
return AutoBreakLine(text, 5, Configuration.Settings.General.SubtitleLineMaximumLength);
|
||||
}
|
||||
|
||||
public static string AutoBreakLine(string text, int mininumLength)
|
||||
public static string AutoBreakLine(string text, int mininumLength, int maximumLength)
|
||||
{
|
||||
if (text.Length < mininumLength)
|
||||
return text;
|
||||
@ -293,7 +293,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
// try to find " - " with uppercase letter after (dialogue)
|
||||
if (splitPos == -1 && s.Contains(" - "))
|
||||
{
|
||||
for (int j = 0; j < 40; j++)
|
||||
for (int j = 0; j < (maximumLength / 2)+5; j++)
|
||||
{
|
||||
if (mid + j + 4 < s.Length)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user