mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Fixed a bug regarding colors in ssa/ass (did not convert to/from BGR - just kept RGB)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1237 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
0c8d746adb
commit
ee1a42ca29
@ -254,16 +254,21 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
text = text.Replace("</u>", string.Empty);
|
text = text.Replace("</u>", string.Empty);
|
||||||
text = text.Replace("<U>", string.Empty);
|
text = text.Replace("<U>", string.Empty);
|
||||||
text = text.Replace("</U>", string.Empty);
|
text = text.Replace("</U>", string.Empty);
|
||||||
text = Utilities.RemoveHtmlFontTag(text);
|
// text = Utilities.RemoveHtmlFontTag(text);
|
||||||
|
|
||||||
// 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 isFontColor = false;
|
||||||
int italicBegin = 0;
|
int italicBegin = 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 italicLookups = new System.Collections.Generic.Dictionary<int, int>();
|
||||||
|
var fontColorLookups = new System.Collections.Generic.Dictionary<Point, Color>();
|
||||||
|
System.Collections.Generic.Stack<Color> colorStack = new System.Collections.Generic.Stack<Color>();
|
||||||
|
Color fontColor = Color.White;
|
||||||
while (i < text.Length)
|
while (i < text.Length)
|
||||||
{
|
{
|
||||||
if (text.Substring(i).ToLower().StartsWith("<i>"))
|
if (text.Substring(i).ToLower().StartsWith("<i>"))
|
||||||
@ -282,6 +287,57 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
isItalic = false;
|
isItalic = false;
|
||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
|
else if (text.Substring(i).ToLower().StartsWith("<font "))
|
||||||
|
{
|
||||||
|
string s = text.Substring(i);
|
||||||
|
bool fontFound = false;
|
||||||
|
int start = s.IndexOf("<font ");
|
||||||
|
if (start >= 0)
|
||||||
|
{
|
||||||
|
int end = s.IndexOf(">", start);
|
||||||
|
if (end > 0)
|
||||||
|
{
|
||||||
|
string f = s.Substring(start, end - start);
|
||||||
|
int colorStart = f.IndexOf(" color=");
|
||||||
|
if (colorStart > 0)
|
||||||
|
{
|
||||||
|
int colorEnd = f.IndexOf("\"", colorStart + " color=".Length + 1);
|
||||||
|
if (colorEnd > 0)
|
||||||
|
{
|
||||||
|
s = f.Substring(colorStart, colorEnd - colorStart);
|
||||||
|
s = s.Remove(0, " color=".Length);
|
||||||
|
s = s.Trim('"');
|
||||||
|
s = s.Trim('\'');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fontColor = System.Drawing.ColorTranslator.FromHtml(s);
|
||||||
|
fontFound = true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
fontFound = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i+=end;
|
||||||
|
}
|
||||||
|
if (fontFound)
|
||||||
|
{
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isFontColor = true;
|
||||||
|
fontColorBegin = letterCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (text.Substring(i).ToLower().StartsWith("</font>") && isFontColor)
|
||||||
|
{
|
||||||
|
fontColorLookups.Add(new Point(fontColorBegin, sb.Length), fontColor);
|
||||||
|
_subtitleTextBox.AppendText(sb.ToString());
|
||||||
|
sb = new StringBuilder();
|
||||||
|
isFontColor = false;
|
||||||
|
i += 6;
|
||||||
|
}
|
||||||
else if (text.Substring(i, 1) == "\n") // RichTextBox only count NewLine as one character!
|
else if (text.Substring(i, 1) == "\n") // RichTextBox only count NewLine as one character!
|
||||||
{
|
{
|
||||||
sb.Append(text.Substring(i, 1));
|
sb.Append(text.Substring(i, 1));
|
||||||
@ -313,6 +369,13 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
_subtitleTextBox.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
|
_subtitleTextBox.SelectionFont = new Font(currentFont.FontFamily, currentFont.Size, newFontStyle);
|
||||||
_subtitleTextBox.DeselectAll();
|
_subtitleTextBox.DeselectAll();
|
||||||
}
|
}
|
||||||
|
foreach (var entry in fontColorLookups)
|
||||||
|
{
|
||||||
|
_subtitleTextBox.SelectionStart = entry.Key.X;
|
||||||
|
_subtitleTextBox.SelectionLength = entry.Key.Y;
|
||||||
|
_subtitleTextBox.SelectionColor = entry.Value;
|
||||||
|
_subtitleTextBox.DeselectAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,13 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
|
|||||||
{
|
{
|
||||||
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
|
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
|
||||||
if (tag.Contains("color"))
|
if (tag.Contains("color"))
|
||||||
|
{
|
||||||
subTag = subTag.Replace("#", string.Empty);
|
subTag = subTag.Replace("#", string.Empty);
|
||||||
|
|
||||||
|
// switch from rrggbb to bbggrr
|
||||||
|
if (subTag.Length >= 6)
|
||||||
|
subTag = subTag.Remove(subTag.Length - 6) + subTag.Substring(subTag.Length - 2, 2) + subTag.Substring(subTag.Length - 4, 2) + subTag.Substring(subTag.Length - 6, 2);
|
||||||
|
}
|
||||||
fontTag = fontTag.Remove(fontStart, fontEnd - fontStart + 1);
|
fontTag = fontTag.Remove(fontStart, fontEnd - fontStart + 1);
|
||||||
text = text.Insert(start, @"{\" + ssaTagName + subTag + endSsaTag);
|
text = text.Insert(start, @"{\" + ssaTagName + subTag + endSsaTag);
|
||||||
}
|
}
|
||||||
@ -235,6 +241,11 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
|
|||||||
{
|
{
|
||||||
string color = text.Substring(start + 4, end - (start + 4));
|
string color = text.Substring(start + 4, end - (start + 4));
|
||||||
color = color.Replace("&", string.Empty).TrimStart('H');
|
color = color.Replace("&", string.Empty).TrimStart('H');
|
||||||
|
color = color.PadLeft(6, '0');
|
||||||
|
|
||||||
|
// switch to rrggbb from bbggrr
|
||||||
|
color = "#" + color.Remove(color.Length - 6) + color.Substring(color.Length - 2, 2) + color.Substring(color.Length - 4, 2) + color.Substring(color.Length - 6, 2);
|
||||||
|
|
||||||
text = text.Remove(start, end - start + 1);
|
text = text.Remove(start, end - start + 1);
|
||||||
text = text.Insert(start, "<font color=\"" + color + "\">");
|
text = text.Insert(start, "<font color=\"" + color + "\">");
|
||||||
text += "</font>";
|
text += "</font>";
|
||||||
|
@ -125,7 +125,13 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
|||||||
{
|
{
|
||||||
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
|
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
|
||||||
if (tag.Contains("color"))
|
if (tag.Contains("color"))
|
||||||
|
{
|
||||||
subTag = subTag.Replace("#", string.Empty);
|
subTag = subTag.Replace("#", string.Empty);
|
||||||
|
|
||||||
|
// switch from rrggbb to bbggrr
|
||||||
|
if (subTag.Length >= 6)
|
||||||
|
subTag = subTag.Remove(subTag.Length - 6) + subTag.Substring(subTag.Length - 2, 2) + subTag.Substring(subTag.Length - 4, 2) + subTag.Substring(subTag.Length - 6, 2);
|
||||||
|
}
|
||||||
fontTag = fontTag.Remove(fontStart, fontEnd - fontStart + 1);
|
fontTag = fontTag.Remove(fontStart, fontEnd - fontStart + 1);
|
||||||
text = text.Insert(start, @"{\" + ssaTagName + subTag + endSsaTag);
|
text = text.Insert(start, @"{\" + ssaTagName + subTag + endSsaTag);
|
||||||
}
|
}
|
||||||
@ -191,6 +197,11 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
|||||||
{
|
{
|
||||||
string color = text.Substring(start + 4, end - (start + 4));
|
string color = text.Substring(start + 4, end - (start + 4));
|
||||||
color = color.Replace("&", string.Empty).TrimStart('H');
|
color = color.Replace("&", string.Empty).TrimStart('H');
|
||||||
|
color = color.PadLeft(6, '0');
|
||||||
|
|
||||||
|
// switch to rrggbb from bbggrr
|
||||||
|
color = "#" + color.Remove(color.Length-6) + color.Substring(color.Length-2,2) + color.Substring(color.Length-4,2) + color.Substring(color.Length-6,2);
|
||||||
|
|
||||||
text = text.Remove(start, end - start + 1);
|
text = text.Remove(start, end - start + 1);
|
||||||
text = text.Insert(start, "<font color=\"" + color + "\">");
|
text = text.Insert(start, "<font color=\"" + color + "\">");
|
||||||
text += "</font>";
|
text += "</font>";
|
||||||
@ -319,14 +330,5 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<string> AlternateExtensions
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new List<string>() { ".ass" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user