mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Some work on split long lines
This commit is contained in:
parent
87f7eeb2af
commit
eb23bd20e2
@ -52,7 +52,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
comboBoxLineContinuationBegin.Text = continuationProfile.Prefix;
|
||||
comboBoxLineContinuationEnd.Text = continuationProfile.Suffix;
|
||||
|
||||
checkBoxSplitAtLineBreaks.Text= LanguageSettings.Current.SplitLongLines.SplitAtLineBreaks;;
|
||||
checkBoxSplitAtLineBreaks.Text = LanguageSettings.Current.SplitLongLines.SplitAtLineBreaks; ;
|
||||
toolStripMenuItemInverseSelection.Text = LanguageSettings.Current.Main.Menu.Edit.InverseSelection;
|
||||
toolStripMenuItemSelectAll.Text = LanguageSettings.Current.Main.Menu.ContextMenu.SelectAll;
|
||||
buttonOK.Text = LanguageSettings.Current.General.Ok;
|
||||
@ -511,6 +511,126 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
numberOfSplits++;
|
||||
}
|
||||
}
|
||||
else if ((language == "ja" || language == "zh") && !p.Text.Contains(Environment.NewLine))
|
||||
{
|
||||
var splitChars = ".!?:;。、;·!…";
|
||||
var splitPos = (int)Math.Round(p.Text.Length / 2.0 + 0.5);
|
||||
if (p.Text.Length > 12)
|
||||
{
|
||||
for (var j = 0; j < 5; j++)
|
||||
{
|
||||
if (splitChars.Contains(p.Text[splitPos - j]))
|
||||
{
|
||||
splitPos = splitPos - j;
|
||||
break;
|
||||
}
|
||||
|
||||
if (splitChars.Contains(p.Text[splitPos + j]))
|
||||
{
|
||||
splitPos = splitPos + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var spacing1 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
|
||||
var spacing2 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
|
||||
if (Configuration.Settings.General.MinimumMillisecondsBetweenLines % 2 == 1)
|
||||
{
|
||||
spacing2++;
|
||||
}
|
||||
|
||||
var newParagraph1 = new Paragraph(p);
|
||||
var newParagraph2 = new Paragraph(p);
|
||||
|
||||
newParagraph1.Text = Utilities.AutoBreakLine(p.Text.Substring(0, splitPos + 1), language);
|
||||
|
||||
var middle = p.StartTime.TotalMilliseconds + p.DurationTotalMilliseconds / 2;
|
||||
if (!string.IsNullOrWhiteSpace(oldText))
|
||||
{
|
||||
var startFactor = (double)HtmlUtil.RemoveHtmlTags(newParagraph1.Text).Length / oldText.Length;
|
||||
if (startFactor < 0.25)
|
||||
{
|
||||
startFactor = 0.25;
|
||||
}
|
||||
|
||||
if (startFactor > 0.75)
|
||||
{
|
||||
startFactor = 0.75;
|
||||
}
|
||||
|
||||
middle = p.StartTime.TotalMilliseconds + p.DurationTotalMilliseconds * startFactor;
|
||||
}
|
||||
|
||||
newParagraph1.EndTime.TotalMilliseconds = middle - spacing1;
|
||||
newParagraph2.Text = Utilities.AutoBreakLine(p.Text.Substring(splitPos + 1), language);
|
||||
newParagraph2.StartTime.TotalMilliseconds = newParagraph1.EndTime.TotalMilliseconds + spacing2;
|
||||
|
||||
if (Configuration.Settings.General.SplitRemovesDashes && isDialog)
|
||||
{
|
||||
newParagraph1.Text = DialogSplitMerge.RemoveStartDash(newParagraph1.Text);
|
||||
newParagraph2.Text = DialogSplitMerge.RemoveStartDash(newParagraph2.Text);
|
||||
}
|
||||
|
||||
if (clearFixes)
|
||||
{
|
||||
AddToListView(p, (splitSubtitle.Paragraphs.Count + 1).ToString(CultureInfo.InvariantCulture), oldText);
|
||||
}
|
||||
|
||||
splitIndexes.Add(splitSubtitle.Paragraphs.Count);
|
||||
splitIndexes.Add(splitSubtitle.Paragraphs.Count + 1);
|
||||
|
||||
var p1 = HtmlUtil.RemoveHtmlTags(newParagraph1.Text).TrimEnd();
|
||||
if (!p1.EndsWith('.') && !p1.EndsWith('!') && !p1.EndsWith('?') && !p1.EndsWith(':') && !p1.EndsWith(')') && !p1.EndsWith(']') && !p1.EndsWith('♪'))
|
||||
{
|
||||
var endsWithComma = newParagraph1.Text.EndsWith(',') || newParagraph1.Text.EndsWith(",</i>", StringComparison.Ordinal);
|
||||
|
||||
var post = string.Empty;
|
||||
if (newParagraph1.Text.EndsWith("</i>", StringComparison.Ordinal))
|
||||
{
|
||||
post = "</i>";
|
||||
newParagraph1.Text = newParagraph1.Text.Remove(newParagraph1.Text.Length - post.Length);
|
||||
}
|
||||
|
||||
if (endsWithComma)
|
||||
{
|
||||
newParagraph1.Text += post;
|
||||
}
|
||||
else
|
||||
{
|
||||
newParagraph1.Text += comboBoxLineContinuationEnd.Text.TrimEnd() + post;
|
||||
}
|
||||
|
||||
var pre = string.Empty;
|
||||
if (newParagraph2.Text.StartsWith("<i>", StringComparison.Ordinal))
|
||||
{
|
||||
pre = "<i>";
|
||||
newParagraph2.Text = newParagraph2.Text.Remove(0, pre.Length);
|
||||
}
|
||||
|
||||
if (endsWithComma)
|
||||
{
|
||||
newParagraph2.Text = pre + newParagraph2.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
newParagraph2.Text = pre + comboBoxLineContinuationBegin.Text + newParagraph2.Text;
|
||||
}
|
||||
}
|
||||
|
||||
var italicStart1 = newParagraph1.Text.IndexOf("<i>", StringComparison.Ordinal);
|
||||
if (italicStart1 >= 0 && italicStart1 < 10 && newParagraph1.Text.IndexOf("</i>", StringComparison.Ordinal) < 0 &&
|
||||
newParagraph2.Text.Contains("</i>") && newParagraph2.Text.IndexOf("<i>", StringComparison.Ordinal) < 0)
|
||||
{
|
||||
newParagraph1.Text += "</i>";
|
||||
newParagraph2.Text = "<i>" + newParagraph2.Text;
|
||||
}
|
||||
|
||||
splitSubtitle.Paragraphs.Add(newParagraph1);
|
||||
splitSubtitle.Paragraphs.Add(newParagraph2);
|
||||
added = true;
|
||||
numberOfSplits++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user