Fix for reading of some TTML+Image files - thx snakeLo :)

Fix #1585
This commit is contained in:
Nikolaj Olsson 2016-02-22 09:37:53 +01:00
parent a18eaf9cb8
commit d92662b9e3

View File

@ -76,7 +76,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
XmlNode body = xml.DocumentElement.SelectSingleNode("//tt:body", nsmgr); XmlNode body = xml.DocumentElement.SelectSingleNode("//tt:body", nsmgr);
if (body == null) if (body == null)
body = xml.DocumentElement.SelectSingleNode("//tt:body", nsmgr); body = xml.DocumentElement.SelectSingleNode("//tt:body", nsmgr);
int numberOfParagraphs = body.ChildNodes.Count;
bool couldBeFrames = true; bool couldBeFrames = true;
bool couldBeMillisecondsWithMissingLastDigit = true; bool couldBeMillisecondsWithMissingLastDigit = true;
@ -87,9 +86,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var pText = new StringBuilder(); var pText = new StringBuilder();
foreach (XmlNode innerNode in node.ChildNodes) foreach (XmlNode innerNode in node.ChildNodes)
{ {
switch (innerNode.Name.Replace("tt:", string.Empty)) if (innerNode.Name == "image" || innerNode.Name.EndsWith(":image", StringComparison.Ordinal))
{ {
case "image":
var src = innerNode.Attributes["src"]; var src = innerNode.Attributes["src"];
if (src != null) if (src != null)
pText.Append(src.InnerText); pText.Append(src.InnerText);
@ -97,9 +95,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
} }
} }
string start = null; // = node.Attributes["begin"].InnerText; string start = null;
string end = null; // = node.Attributes["begin"].InnerText; string end = null;
string dur = null; // = node.Attributes["begin"].InnerText; string dur = null;
foreach (XmlAttribute attr in node.Attributes) foreach (XmlAttribute attr in node.Attributes)
{ {
if (attr.Name.EndsWith("begin", StringComparison.Ordinal)) if (attr.Name.EndsWith("begin", StringComparison.Ordinal))
@ -109,7 +107,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
else if (attr.Name.EndsWith("duration", StringComparison.Ordinal)) else if (attr.Name.EndsWith("duration", StringComparison.Ordinal))
dur = attr.InnerText; dur = attr.InnerText;
} }
//string start = node.Attributes["begin"].InnerText;
string text = pText.ToString(); string text = pText.ToString();
text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine); text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
text = text.Replace("<i></i>", string.Empty).Trim(); text = text.Replace("<i></i>", string.Empty).Trim();
@ -126,7 +123,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
couldBeMillisecondsWithMissingLastDigit = false; couldBeMillisecondsWithMissingLastDigit = false;
} }
//string end = node.Attributes["end"].InnerText;
double dBegin, dEnd; double dBegin, dEnd;
if (!start.Contains(':') && Utilities.CountTagInText(start, '.') == 1 && if (!start.Contains(':') && Utilities.CountTagInText(start, '.') == 1 &&
!end.Contains(':') && Utilities.CountTagInText(end, '.') == 1 && !end.Contains(':') && Utilities.CountTagInText(end, '.') == 1 &&
@ -192,8 +188,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
foreach (Paragraph p in subtitle.Paragraphs) foreach (Paragraph p in subtitle.Paragraphs)
{ {
p.StartTime.Milliseconds = SubtitleFormat.FramesToMillisecondsMax999(p.StartTime.Milliseconds); p.StartTime.Milliseconds = FramesToMillisecondsMax999(p.StartTime.Milliseconds);
p.EndTime.Milliseconds = SubtitleFormat.FramesToMillisecondsMax999(p.EndTime.Milliseconds); p.EndTime.Milliseconds = FramesToMillisecondsMax999(p.EndTime.Milliseconds);
} }
} }
} }