mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Text below video now supports bold and underline - thx Xenophon :)
This commit is contained in:
parent
410374824b
commit
34158d6d83
@ -308,20 +308,27 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
|
|
||||||
// remove styles for display text (except italic)
|
// remove styles for display text (except italic)
|
||||||
string text = RemoveSubStationAlphaFormatting(_subtitleText);
|
string text = RemoveSubStationAlphaFormatting(_subtitleText);
|
||||||
text = HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagBold, HtmlUtil.TagUnderline);
|
text = text.Replace("<b></b>", string.Empty);
|
||||||
text = text.Replace("<i></i>", string.Empty);
|
text = text.Replace("<i></i>", string.Empty);
|
||||||
|
text = text.Replace("<u></u>", string.Empty);
|
||||||
|
|
||||||
// display italic
|
// display italic
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool isItalic = false;
|
bool isItalic = false;
|
||||||
|
bool isBold = false;
|
||||||
|
bool isUnderline = false;
|
||||||
bool isFontColor = false;
|
bool isFontColor = false;
|
||||||
int italicBegin = 0;
|
|
||||||
int fontColorBegin = 0;
|
int fontColorBegin = 0;
|
||||||
_subtitleTextBox.Text = string.Empty;
|
_subtitleTextBox.Text = string.Empty;
|
||||||
int letterCount = 0;
|
int letterCount = 0;
|
||||||
var italicLookups = new System.Collections.Generic.Dictionary<int, int>();
|
|
||||||
var fontColorLookups = new System.Collections.Generic.Dictionary<Point, Color>();
|
var fontColorLookups = new System.Collections.Generic.Dictionary<Point, Color>();
|
||||||
|
var styleLookups = new System.Collections.Generic.Dictionary<int, FontStyle>(text.Length);
|
||||||
|
for (int j = 0; j < text.Length; j++)
|
||||||
|
{
|
||||||
|
styleLookups.Add(j, Configuration.Settings.General.VideoPlayerPreviewFontBold ? FontStyle.Bold : FontStyle.Regular);
|
||||||
|
}
|
||||||
|
|
||||||
Color fontColor = Color.White;
|
Color fontColor = Color.White;
|
||||||
while (i < text.Length)
|
while (i < text.Length)
|
||||||
{
|
{
|
||||||
@ -330,17 +337,49 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
_subtitleTextBox.AppendText(sb.ToString());
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
isItalic = true;
|
isItalic = true;
|
||||||
italicBegin = letterCount;
|
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
else if (text.Substring(i).StartsWith("</i>", StringComparison.OrdinalIgnoreCase) && isItalic)
|
else if (text.Substring(i).StartsWith("</i>", StringComparison.OrdinalIgnoreCase) && isItalic)
|
||||||
{
|
{
|
||||||
italicLookups.Add(italicBegin, _subtitleTextBox.Text.Length + sb.ToString().Length - italicBegin);
|
|
||||||
_subtitleTextBox.AppendText(sb.ToString());
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
isItalic = false;
|
isItalic = false;
|
||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
|
else if (text.Substring(i).StartsWith("<b>", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (!Configuration.Settings.General.VideoPlayerPreviewFontBold)
|
||||||
|
{
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isBold = true;
|
||||||
|
}
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
else if (text.Substring(i).StartsWith("</b>", StringComparison.OrdinalIgnoreCase) && isBold)
|
||||||
|
{
|
||||||
|
if (!Configuration.Settings.General.VideoPlayerPreviewFontBold)
|
||||||
|
{
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isBold = false;
|
||||||
|
}
|
||||||
|
i += 3;
|
||||||
|
}
|
||||||
|
else if (text.Substring(i).StartsWith("<u>", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isUnderline = true;
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
else if (text.Substring(i).StartsWith("</u>", StringComparison.OrdinalIgnoreCase) && isUnderline)
|
||||||
|
{
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isUnderline = false;
|
||||||
|
i += 3;
|
||||||
|
}
|
||||||
else if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
|
else if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
string s = text.Substring(i);
|
string s = text.Substring(i);
|
||||||
@ -412,8 +451,20 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
{
|
{
|
||||||
sb.Append(text[i]);
|
sb.Append(text[i]);
|
||||||
}
|
}
|
||||||
|
else if (text[i] == '\r')
|
||||||
|
{
|
||||||
|
// skip carriage return (0xd / 13)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var idx = _subtitleTextBox.TextLength + sb.Length;
|
||||||
|
if (isBold)
|
||||||
|
styleLookups[idx] = styleLookups[idx] | FontStyle.Bold;
|
||||||
|
if (isItalic)
|
||||||
|
styleLookups[idx] = styleLookups[idx] | FontStyle.Italic;
|
||||||
|
if (isUnderline)
|
||||||
|
styleLookups[idx] = styleLookups[idx] | FontStyle.Underline;
|
||||||
|
|
||||||
sb.Append(text[i]);
|
sb.Append(text[i]);
|
||||||
letterCount++;
|
letterCount++;
|
||||||
}
|
}
|
||||||
@ -430,17 +481,16 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
_subtitleTextBox.SelectionAlignment = HorizontalAlignment.Center;
|
_subtitleTextBox.SelectionAlignment = HorizontalAlignment.Center;
|
||||||
|
|
||||||
_subtitleTextBox.DeselectAll();
|
_subtitleTextBox.DeselectAll();
|
||||||
foreach (var entry in italicLookups)
|
|
||||||
|
Font currentFont = _subtitleTextBox.SelectionFont;
|
||||||
|
for (int k = 0; k < _subtitleTextBox.TextLength; k++)
|
||||||
{
|
{
|
||||||
Font currentFont = _subtitleTextBox.SelectionFont;
|
_subtitleTextBox.SelectionStart = k;
|
||||||
FontStyle newFontStyle = FontStyle.Italic | FontStyle.Bold;
|
_subtitleTextBox.SelectionLength = 1;
|
||||||
if (!Configuration.Settings.General.VideoPlayerPreviewFontBold)
|
_subtitleTextBox.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, styleLookups[k]);
|
||||||
newFontStyle = FontStyle.Italic;
|
|
||||||
_subtitleTextBox.SelectionStart = entry.Key;
|
|
||||||
_subtitleTextBox.SelectionLength = entry.Value;
|
|
||||||
_subtitleTextBox.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
|
|
||||||
_subtitleTextBox.DeselectAll();
|
_subtitleTextBox.DeselectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var entry in fontColorLookups)
|
foreach (var entry in fontColorLookups)
|
||||||
{
|
{
|
||||||
_subtitleTextBox.SelectionStart = entry.Key.X;
|
_subtitleTextBox.SelectionStart = entry.Key.X;
|
||||||
|
Loading…
Reference in New Issue
Block a user