Improve vertical alignment for PAC

This commit is contained in:
Nikolaj Olsson 2020-10-20 22:05:32 +02:00
parent d2dfa5d37d
commit 34165be8c8
3 changed files with 43 additions and 19 deletions

View File

@ -516,6 +516,9 @@ namespace Nikse.SubtitleEdit.Core
public int EbuStlMarginTop { get; set; }
public int EbuStlMarginBottom { get; set; }
public int EbuStlNewLineRows { get; set; }
public int PacVerticalTop { get; set; }
public int PacVerticalCenter { get; set; }
public int PacVerticalBottom { get; set; }
public string DvdStudioProHeader { get; set; }
@ -573,6 +576,10 @@ namespace Nikse.SubtitleEdit.Core
EbuStlMarginBottom = 2;
EbuStlNewLineRows = 2;
PacVerticalTop = 1;
PacVerticalCenter = 5;
PacVerticalBottom = 11;
DvdStudioProHeader = @"$VertAlign = Bottom
$Bold = FALSE
$Underlined = FALSE
@ -4857,6 +4864,24 @@ $HorzAlign = Center
settings.SubtitleSettings.EbuStlNewLineRows = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("PacVerticalTop");
if (subNode != null)
{
settings.SubtitleSettings.PacVerticalTop = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("PacVerticalCenter");
if (subNode != null)
{
settings.SubtitleSettings.PacVerticalCenter = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("PacVerticalBottom");
if (subNode != null)
{
settings.SubtitleSettings.PacVerticalBottom = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("DvdStudioProHeader");
if (subNode != null)
{
@ -7946,6 +7971,9 @@ $HorzAlign = Center
textWriter.WriteElementString("EbuStlMarginTop", settings.SubtitleSettings.EbuStlMarginTop.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("EbuStlMarginBottom", settings.SubtitleSettings.EbuStlMarginBottom.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("EbuStlNewLineRows", settings.SubtitleSettings.EbuStlNewLineRows.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("PacVerticalTop", settings.SubtitleSettings.PacVerticalTop.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("PacVerticalCenter", settings.SubtitleSettings.PacVerticalCenter.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("PacVerticalBottom", settings.SubtitleSettings.PacVerticalBottom.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("DvdStudioProHeader", settings.SubtitleSettings.DvdStudioProHeader.TrimEnd() + Environment.NewLine);
textWriter.WriteElementString("TmpegEncXmlFontName", settings.SubtitleSettings.TmpegEncXmlFontName.TrimEnd());
textWriter.WriteElementString("TmpegEncXmlFontHeight", settings.SubtitleSettings.TmpegEncXmlFontHeight.TrimEnd());

View File

@ -1032,7 +1032,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
// paragraphs
int number = 0;
foreach (Paragraph p in subtitle.Paragraphs)
foreach (var p in subtitle.Paragraphs)
{
WriteParagraph(stream, p, number, number + 1 == subtitle.Paragraphs.Count);
number++;
@ -1063,13 +1063,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
}
byte alignment = 2; // center
byte verticalAlignment = 0x0a; // bottom
if (!p.Text.Contains(Environment.NewLine))
{
verticalAlignment = 0x0b;
}
var verticalAlignment = (byte)Math.Max(0, Configuration.Settings.SubtitleSettings.PacVerticalBottom + 1 - Utilities.GetNumberOfLines(p.Text));
string text = p.Text;
var text = p.Text;
if (text.StartsWith("{\\an1}", StringComparison.Ordinal) || text.StartsWith("{\\an4}", StringComparison.Ordinal) || text.StartsWith("{\\an7}", StringComparison.Ordinal))
{
alignment = 1; // left
@ -1078,14 +1074,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
alignment = 0; // right
}
if (text.StartsWith("{\\an7}", StringComparison.Ordinal) || text.StartsWith("{\\an8}", StringComparison.Ordinal) || text.StartsWith("{\\an9}", StringComparison.Ordinal))
{
verticalAlignment = 0; // top
verticalAlignment = (byte)Configuration.Settings.SubtitleSettings.PacVerticalTop; // top
}
else if (text.StartsWith("{\\an4}", StringComparison.Ordinal) || text.StartsWith("{\\an5}", StringComparison.Ordinal) || text.StartsWith("{\\an6}", StringComparison.Ordinal))
{
verticalAlignment = 5; // center
verticalAlignment = (byte)Configuration.Settings.SubtitleSettings.PacVerticalCenter; // center
}
if (text.Length >= 6 && text[0] == '{' && text[5] == '}')
{
text = text.Remove(0, 6);
@ -1093,7 +1091,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
text = MakePacItalicsAndRemoveOtherTags(text);
Encoding encoding = GetEncoding(CodePage);
var encoding = GetEncoding(CodePage);
byte[] textBuffer;
if (CodePage == CodePageArabic)

View File

@ -75,7 +75,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
int index = 0;
while (index < buffer.Length)
{
Paragraph p = GetPacParagraph(ref index, buffer);
var p = GetPacParagraph(ref index, buffer);
if (p != null)
{
subtitle.Paragraphs.Add(p);
@ -266,7 +266,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
sub.Paragraphs.Insert(0, new Paragraph { Text = "-" });
int number = 0;
foreach (Paragraph p in sub.Paragraphs)
foreach (var p in sub.Paragraphs)
{
WriteParagraph(fs, p, number, number + 1 == sub.Paragraphs.Count);
number++;
@ -292,11 +292,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
Pac.WriteTimeCode(fs, p.EndTime);
byte alignment = 2; // center
byte verticalAlignment = 0x0a; // bottom
if (!p.Text.Contains(Environment.NewLine))
{
verticalAlignment = 0x0b;
}
var verticalAlignment = (byte)Math.Max(0, Configuration.Settings.SubtitleSettings.PacVerticalBottom + 1 - Utilities.GetNumberOfLines(p.Text));
string text = p.Text;
if (text.StartsWith("{\\an1}", StringComparison.Ordinal) || text.StartsWith("{\\an4}", StringComparison.Ordinal) || text.StartsWith("{\\an7}", StringComparison.Ordinal))
@ -307,14 +303,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
alignment = 0; // right
}
if (text.StartsWith("{\\an7}", StringComparison.Ordinal) || text.StartsWith("{\\an8}", StringComparison.Ordinal) || text.StartsWith("{\\an9}", StringComparison.Ordinal))
{
verticalAlignment = 0; // top
verticalAlignment = (byte)Configuration.Settings.SubtitleSettings.PacVerticalTop; // top
}
else if (text.StartsWith("{\\an4}", StringComparison.Ordinal) || text.StartsWith("{\\an5}", StringComparison.Ordinal) || text.StartsWith("{\\an6}", StringComparison.Ordinal))
{
verticalAlignment = 5; // center
verticalAlignment = (byte)Configuration.Settings.SubtitleSettings.PacVerticalCenter; // center
}
if (text.Length >= 6 && text[0] == '{' && text[5] == '}')
{
text = text.Remove(0, 6);