mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Work on pns format - thx Milenko :)
This commit is contained in:
parent
ac10a35bd3
commit
ee87529ffa
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user