diff --git a/src/libse/SubtitleFormats/Pns.cs b/src/libse/SubtitleFormats/Pns.cs index c3991ec86..c2b41a559 100644 --- a/src/libse/SubtitleFormats/Pns.cs +++ b/src/libse/SubtitleFormats/Pns.cs @@ -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(""); + italicOn = true; } - else if (buffer[j] == 15) + else if (v == 15) { sb.Append(""); + 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("")) + { + text = text.Remove(0, "".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("", StringComparison.Ordinal) && !text.Contains("")) + { + return "" + text.Replace("", string.Empty) + ""; + } + + return text; + } } } diff --git a/src/ui/Logic/UiUtil.cs b/src/ui/Logic/UiUtil.cs index c6712222b..06321c315 100644 --- a/src/ui/Logic/UiUtil.cs +++ b/src/ui/Logic/UiUtil.cs @@ -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)) {