From 5d90b816c9f7578a09038b828f69dc166a75442a Mon Sep 17 00:00:00 2001 From: niksedk Date: Tue, 21 Nov 2023 19:47:01 +0100 Subject: [PATCH] Support an5 alignment for SMPTE-TT 2052 - thx Steve :) --- src/libse/SubtitleFormats/SmpteTt2052.cs | 16 ++++++++++++++-- src/libse/SubtitleFormats/TimedText10.cs | 6 +++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libse/SubtitleFormats/SmpteTt2052.cs b/src/libse/SubtitleFormats/SmpteTt2052.cs index 974c0eaa3..7e0f439b8 100644 --- a/src/libse/SubtitleFormats/SmpteTt2052.cs +++ b/src/libse/SubtitleFormats/SmpteTt2052.cs @@ -120,6 +120,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats + @@ -149,8 +150,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } var div = xml.DocumentElement.SelectSingleNode("//ttml:body", nsmgr).SelectSingleNode("ttml:div", nsmgr); - bool hasBottomCenterRegion = false; - bool hasTopCenterRegion = false; + var hasBottomCenterRegion = false; + var hasTopCenterRegion = false; + var hasMiddleRegion = false; foreach (XmlNode node in xml.DocumentElement.SelectNodes("//ttml:head/ttml:layout/ttml:region", nsmgr)) { string id = null; @@ -172,6 +174,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { hasTopCenterRegion = true; } + + if (id != null && (id == "centerCenter" || id == "center")) + { + hasMiddleRegion = true; + } } foreach (var p in subtitle.Paragraphs) @@ -204,6 +211,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats paragraph.Attributes.Append(regionP); } } + else if (hasMiddleRegion && (text.StartsWith("{\\an5}", StringComparison.Ordinal) || text.StartsWith("{\\an6}", StringComparison.Ordinal) || text.StartsWith("{\\an7}", StringComparison.Ordinal))) + { + regionP.InnerText = "centerCenter"; + paragraph.Attributes.Append(regionP); + } else if (hasBottomCenterRegion) { regionP.InnerText = "bottom"; diff --git a/src/libse/SubtitleFormats/TimedText10.cs b/src/libse/SubtitleFormats/TimedText10.cs index 7c7751013..eec9bcdb6 100644 --- a/src/libse/SubtitleFormats/TimedText10.cs +++ b/src/libse/SubtitleFormats/TimedText10.cs @@ -201,7 +201,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats " " + Environment.NewLine + // Middle column " " + Environment.NewLine + - " " + Environment.NewLine + + " " + Environment.NewLine + " " + Environment.NewLine + // Right column " " + Environment.NewLine + @@ -448,7 +448,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats region = "centerLeft"; } - if (text.StartsWith("{\\an5}", StringComparison.Ordinal) && AddDefaultRegionIfNotExists(xml, "centerСenter")) + if (text.StartsWith("{\\an5}", StringComparison.Ordinal) && AddDefaultRegionIfNotExists(xml, "centerCenter")) { region = "centerСenter"; } @@ -882,7 +882,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats new KeyValuePair("bottomCenter", "{\\an2}"), new KeyValuePair("bottomRight", "{\\an3}"), new KeyValuePair("centerLeft", "{\\an4}"), - new KeyValuePair("centerСenter", "{\\an5}"), + new KeyValuePair("centerCenter", "{\\an5}"), new KeyValuePair("centerRight", "{\\an6}"), new KeyValuePair("topLeft", "{\\an7}"), new KeyValuePair("topCenter", "{\\an8}"),