Fixed bugs in ASS/SSA loading - thx kotuwa :)

This commit is contained in:
niksedk 2015-02-18 20:50:33 +01:00
parent 595103e5bc
commit cd1ba45595
2 changed files with 21 additions and 41 deletions

View File

@ -5,7 +5,6 @@ using System.Drawing;
using System.Globalization;
using System.Text;
using System.Xml;
using Nikse.SubtitleEdit.Forms;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
@ -511,7 +510,7 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
{
int start = text.IndexOf(@"{\c", StringComparison.Ordinal);
int end = text.IndexOf('}', start);
if (end > 0 && !text.Substring(start).StartsWith("{\\c}", StringComparison.Ordinal))
if (end > 0 && !text.Substring(start).StartsWith("{\\c}", StringComparison.Ordinal) && !text.Substring(start).StartsWith("{\\clip", StringComparison.Ordinal))
{
string color = text.Substring(start + 4, end - (start + 4));
string extraTags = string.Empty;
@ -706,7 +705,7 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
{
// skip empty and comment lines
}
else if (line.TrimStart().StartsWith("dialog:", StringComparison.OrdinalIgnoreCase)) // fix faulty font tags...
else if (line.TrimStart().StartsWith("dialog:", StringComparison.OrdinalIgnoreCase) || line.TrimStart().StartsWith("dialogue:", StringComparison.OrdinalIgnoreCase)) // fix faulty font tags...
{
eventsStarted = true;
fontsStarted = false;
@ -780,10 +779,11 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
string effect = string.Empty;
var layer = 0;
string[] splittedLine;
string[] splittedLine;
if (s.StartsWith("dialog:", StringComparison.Ordinal))
splittedLine = line.Substring(10).Split(',');
splittedLine = line.Remove(0, 7).Split(',');
else if (s.StartsWith("dialogue:", StringComparison.Ordinal))
splittedLine = line.Remove(0, 9).Split(',');
else
splittedLine = line.Split(',');
@ -809,11 +809,13 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
try
{
var p = new Paragraph();
var p = new Paragraph
{
StartTime = GetTimeCodeFromString(start),
EndTime = GetTimeCodeFromString(end),
Text = GetFormattedText(text)
};
p.StartTime = GetTimeCodeFromString(start);
p.EndTime = GetTimeCodeFromString(end);
p.Text = GetFormattedText(text);
if (!string.IsNullOrEmpty(style))
p.Extra = style;
if (!string.IsNullOrEmpty(actor))

View File

@ -293,31 +293,6 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
}
}
private static string FormatTag(ref string text, int start, string fontTag, string tag, string endSign, string ssaTagName, string endSsaTag)
{
if (fontTag.Contains(tag))
{
int fontStart = fontTag.IndexOf(tag, StringComparison.Ordinal);
int fontEnd = fontTag.IndexOf(endSign, fontStart + tag.Length, StringComparison.Ordinal);
if (fontEnd > 0)
{
string subTag = fontTag.Substring(fontStart + tag.Length, fontEnd - (fontStart + tag.Length));
if (tag.Contains("color"))
{
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);
if (start < text.Length)
text = text.Insert(start, @"{\" + ssaTagName + subTag + endSsaTag);
}
}
return fontTag;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
@ -386,9 +361,10 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
string name = string.Empty;
string[] splittedLine;
if (s.StartsWith("dialog:", StringComparison.Ordinal))
splittedLine = line.Substring(10).Split(',');
splittedLine = line.Remove(0, 7).Split(',');
else if (s.StartsWith("dialogue:", StringComparison.Ordinal))
splittedLine = line.Remove(0, 9).Split(',');
else
splittedLine = line.Split(',');
@ -414,11 +390,13 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
try
{
var p = new Paragraph();
var p = new Paragraph
{
StartTime = GetTimeCodeFromString(start),
EndTime = GetTimeCodeFromString(end),
Text = AdvancedSubStationAlpha.GetFormattedText(text)
};
p.StartTime = GetTimeCodeFromString(start);
p.EndTime = GetTimeCodeFromString(end);
p.Text = AdvancedSubStationAlpha.GetFormattedText(text);
if (!string.IsNullOrEmpty(style))
p.Extra = style;
if (!string.IsNullOrEmpty(effect))