Fix for crash due to color in karoke/typewriter effect - thx PM :)

This commit is contained in:
Nikolaj Olsson 2021-04-24 09:53:22 +02:00
parent ae249cbf14
commit a3963cc60c
5 changed files with 31 additions and 60 deletions

View File

@ -37,7 +37,7 @@
* Make "load second subtitle" work with more subtitle formats - thx PM
* Improve compare colors for dark theme - thx OmrSi
* Minor UI improvements for nOCR character inspect
* Add "Clear" to File - Recent files - thx Dominiquini/OmrSi
* Add "Clear" to "File - Recent files" - thx Dominiquini/OmrSi
* Make bd sup edit work better with full frame images - thx peter-qgd
* Point sync now also works on original subtitle - thx Rene
* FIXED:
@ -52,6 +52,7 @@
* Some fixes for editing source view - thx PreetM07
* Fix bug converting vtt two line color text to srt
* Fix FCE issue w missing spaces/French language - thx kyrpasto/OmrSi
* Fix crash in karoke/typewriter effect due to invalid color - thx PM
3.6.0 (18th February 2021)

View File

@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@ -909,5 +910,28 @@ namespace Nikse.SubtitleEdit.Core.Common
return text;
}
public static Color GetColorFromString(string color)
{
Color c = Color.White;
try
{
if (color.StartsWith("rgb(", StringComparison.Ordinal))
{
string[] arr = color.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(color);
}
}
catch
{
// ignored
}
return c;
}
}
}

View File

@ -442,23 +442,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
color = node.Attributes["tts:color"].Value.Trim();
}
Color c = Color.White;
try
{
if (color.StartsWith("rgb(", StringComparison.Ordinal))
{
string[] arr = color.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(color);
}
}
catch
{
// ignored
}
var c = HtmlUtil.GetColorFromString(color);
string fontSize = "20";
if (node.Attributes["tts:fontSize"] != null)
@ -589,23 +573,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
color = node.Attributes["tts:color"].Value.Trim();
}
Color c = Color.White;
try
{
if (color.StartsWith("rgb(", StringComparison.Ordinal))
{
string[] arr = color.Remove(0, 4).TrimEnd(')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
c = Color.FromArgb(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]));
}
else
{
c = ColorTranslator.FromHtml(color);
}
}
catch
{
// ignored
}
var c = HtmlUtil.GetColorFromString(color);
string fontSize = "20";
if (node.Attributes["tts:fontSize"] != null)
@ -802,15 +770,7 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
if (tag.Contains("color"))
{
Color c;
try
{
c = ColorTranslator.FromHtml(subTag);
}
catch
{
c = Color.White;
}
var c = HtmlUtil.GetColorFromString(subTag);
subTag = (c.B.ToString("X2") + c.G.ToString("X2") + c.R.ToString("X2")).ToLowerInvariant(); // use bbggrr
}
fontTag = fontTag.Remove(fontStart, fontEnd - fontStart + 1);

View File

@ -194,7 +194,7 @@ namespace Nikse.SubtitleEdit.Forms
{
int length = rtb.Text.Length;
richTextBoxPreview.Text += text;
_colorList.Add(new ColorEntry { Start = length, Length = text.Length, Color = string.IsNullOrWhiteSpace(color) ? Color.White : ColorTranslator.FromHtml(color) });
_colorList.Add(new ColorEntry { Start = length, Length = text.Length, Color = HtmlUtil.GetColorFromString(color) });
var fontStyle = new FontStyle();
if (underline)

View File

@ -176,21 +176,7 @@ namespace Nikse.SubtitleEdit.Forms
var c = Color.White;
if (!string.IsNullOrWhiteSpace(color))
{
try
{
c = ColorTranslator.FromHtml(color);
}
catch
{
try
{
c = ColorTranslator.FromHtml("#" + color.Trim('#', ' ', '"', '\''));
}
catch
{
c = Color.White;
}
}
c = HtmlUtil.GetColorFromString(color);
}
_colorList.Add(new EffectKaraoke.ColorEntry { Start = length, Length = text.Length, Color = c });