Add some handling of font tags in split - thx Peter :)

This commit is contained in:
Nikolaj Olsson 2020-10-12 20:29:14 +02:00
parent cd819f2a21
commit b5a31a7f72

View File

@ -9870,6 +9870,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
FixSplitFontTag(currentParagraph, newParagraph);
SetSplitTime(splitSeconds, currentParagraph, newParagraph, oldText);
if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
@ -10050,6 +10051,7 @@ namespace Nikse.SubtitleEdit.Forms
_subtitleAlternate.InsertParagraphInCorrectTimeOrder(originalNew);
_subtitleAlternate.Renumber();
FixSplitFontTag(originalCurrent, originalNew);
}
}
@ -10075,6 +10077,36 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void FixSplitFontTag(Paragraph currentParagraph, Paragraph nextParagraph)
{
if (currentParagraph == null || nextParagraph == null)
{
return;
}
var startIdx = currentParagraph.Text.LastIndexOf("<font ", StringComparison.OrdinalIgnoreCase);
if (startIdx >= 0 &&
!currentParagraph.Text.Contains("</font>", StringComparison.OrdinalIgnoreCase) &&
nextParagraph.Text.Contains("</font>", StringComparison.OrdinalIgnoreCase))
{
var endIdx = currentParagraph.Text.IndexOf('>', startIdx);
if (endIdx >= 0)
{
var fontTag = currentParagraph.Text.Substring(startIdx, endIdx - startIdx + 1);
var pre = string.Empty;
if (currentParagraph.Text.StartsWith('{') && currentParagraph.Text.IndexOf('}') > 0)
{
var i = currentParagraph.Text.IndexOf('}');
pre = currentParagraph.Text.Substring(0, i + 1);
currentParagraph.Text = currentParagraph.Text.Remove(0, i + 1);
}
currentParagraph.Text = pre + currentParagraph.Text + "</font>";
nextParagraph.Text = pre + fontTag + nextParagraph.Text;
}
}
}
private void SetSplitTime(double? splitSeconds, Paragraph currentParagraph, Paragraph newParagraph, string oldText)
{
double middle = currentParagraph.StartTime.TotalMilliseconds + (currentParagraph.Duration.TotalMilliseconds / 2);