Work on pns format - thx Milenko :)

This commit is contained in:
niksedk 2021-09-30 23:36:09 +02:00
parent ac10a35bd3
commit ee87529ffa
2 changed files with 48 additions and 23 deletions

View File

@ -46,25 +46,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
byte[] buffer = FileUtil.ReadAllBytesShared(fileName);
if (buffer[00] != 0 &&
buffer[01] == 0 &&
buffer[02] == 0 &&
buffer[03] == 0 &&
buffer[04] == 0 &&
buffer[05] == 0 &&
buffer[06] == 0 &&
buffer[07] == 0 &&
buffer[08] == 0 &&
buffer[09] == 0 &&
buffer[10] == 0 &&
buffer[11] == 0 &&
buffer[12] == 0 &&
buffer[13] == 0 &&
buffer[14] == 0 &&
buffer[15] == 0 &&
buffer[16] == 0 &&
buffer[17] == 0 &&
buffer[18] == 0 &&
buffer[19] == 0)
buffer[01] == 0)
{
var sub = new Subtitle();
LoadSubtitle(sub, null, fileName);
@ -137,17 +119,38 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (buffer.Length > index + 15 + textLength)
{
var sb = new StringBuilder();
var skipNext = false;
bool italicOn = false;
for (int j = index + 16; j < index + 16 + textLength; j++)
{
if (buffer[j] < 32 && buffer[j] != 0xd)
if (skipNext)
{
if (buffer[j] == 5)
skipNext = false;
continue;
}
var v = buffer[j];
if (v < 32 && v != 0xd && v != 0xa)
{
if (v == 1)
{
skipNext = true;
continue;
}
if (v == 5)
{
sb.Append("<i>");
italicOn = true;
}
else if (buffer[j] == 15)
else if (v == 15)
{
sb.Append("</i>");
italicOn = false;
}
else
{
// sb.Append("(" + v + ")");
}
}
else
@ -158,9 +161,20 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var text = sb.ToString();
text = text.Replace("\0", string.Empty);
text = text.Replace("\n", Environment.NewLine);
text = text.Replace("\n", "\r");
text = text.Replace("\r", Environment.NewLine);
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
text = string.Join(Environment.NewLine, text.SplitToLines());
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
if (text.StartsWith("</i>"))
{
text = text.Remove(0, "</i>".Length);
}
text = text.Trim();
text = FixItalics(text);
index += 15 + textLength;
var p = new Paragraph(text, startSeconds * 1000 + FramesToMillisecondsMax999(startFrame), endSeconds * 1000 + FramesToMillisecondsMax999(endFrame));
return p;
@ -173,5 +187,15 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
index++;
return null;
}
private string FixItalics(string text)
{
if (text.StartsWith("<i>", StringComparison.Ordinal) && !text.Contains("</i>"))
{
return "<i>" + text.Replace("<i>", string.Empty) + "</i>";
}
return text;
}
}
}

View File

@ -1117,6 +1117,7 @@ namespace Nikse.SubtitleEdit.Logic
AddExtension(sb, new IsmtDfxp().Extension);
AddExtension(sb, new PlayCaptionsFreeEditor().Extension);
AddExtension(sb, ".cdg"); // karaoke
AddExtension(sb, ".pns"); // karaoke
if (!string.IsNullOrEmpty(Configuration.Settings.General.OpenSubtitleExtraExtensions))
{