From cea67f840c135dc9ffd6fa45bf4ff09b95f456ab Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sat, 16 Jul 2016 19:44:20 +0200 Subject: [PATCH] Fixed issue with loosing concatenated tags in ass - thx Johan :) --- .../AdvancedSubStationAlpha.cs | 41 +++++++++++++------ .../SubtitleFormats/SubtitleFormatsTest.cs | 13 ++++++ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libse/SubtitleFormats/AdvancedSubStationAlpha.cs b/libse/SubtitleFormats/AdvancedSubStationAlpha.cs index 2eb4c7512..5cb483a79 100644 --- a/libse/SubtitleFormats/AdvancedSubStationAlpha.cs +++ b/libse/SubtitleFormats/AdvancedSubStationAlpha.cs @@ -529,12 +529,13 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text { string fontName = text.Substring(start + 4, end - (start + 4)); string extraTags = string.Empty; - CheckAndAddSubTags(ref fontName, ref extraTags, out italic); + string unknownTags; + CheckAndAddSubTags(ref fontName, ref extraTags, out unknownTags, out italic); text = text.Remove(start, end - start + 1); if (italic) - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags + ""); else - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags); int indexOfEndTag = text.IndexOf("{\\fn}", start, StringComparison.Ordinal); if (indexOfEndTag > 0) @@ -569,14 +570,15 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text { string fontSize = text.Substring(start + 4, end - (start + 4)); string extraTags = string.Empty; - CheckAndAddSubTags(ref fontSize, ref extraTags, out italic); + string unknownTags; + CheckAndAddSubTags(ref fontSize, ref extraTags, out unknownTags, out italic); if (Utilities.IsInteger(fontSize)) { text = text.Remove(start, end - start + 1); if (italic) - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags + ""); else - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags); int indexOfEndTag = text.IndexOf("{\\fs}", start, StringComparison.Ordinal); if (indexOfEndTag > 0) @@ -612,7 +614,8 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text { string color = text.Substring(start + 4, end - (start + 4)); string extraTags = string.Empty; - CheckAndAddSubTags(ref color, ref extraTags, out italic); + string unknownTags; + CheckAndAddSubTags(ref color, ref extraTags, out unknownTags, out italic); color = color.Replace("&", string.Empty).TrimStart('H'); color = color.PadLeft(6, '0'); @@ -623,9 +626,9 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text text = text.Remove(start, end - start + 1); if (italic) - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags + ""); else - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags); int indexOfEndTag = text.IndexOf("{\\c}", start, StringComparison.Ordinal); int indexOfNextColorTag = text.IndexOf("{\\c&", start, StringComparison.Ordinal); if (indexOfNextColorTag > 0 && (indexOfNextColorTag < indexOfEndTag || indexOfEndTag == -1)) @@ -645,7 +648,8 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text { string color = text.Substring(start + 5, end - (start + 5)); string extraTags = string.Empty; - CheckAndAddSubTags(ref color, ref extraTags, out italic); + string unknownTags; + CheckAndAddSubTags(ref color, ref extraTags, out unknownTags, out italic); color = color.Replace("&", string.Empty).TrimStart('H'); color = color.PadLeft(6, '0'); @@ -656,9 +660,9 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text text = text.Remove(start, end - start + 1); if (italic) - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags + ""); else - text = text.Insert(start, ""); + text = text.Insert(start, "" + unknownTags); text += ""; } } @@ -685,9 +689,10 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text return text; } - private static void CheckAndAddSubTags(ref string tagName, ref string extraTags, out bool italic) + private static void CheckAndAddSubTags(ref string tagName, ref string extraTags, out string unknownTags, out bool italic) { italic = false; + unknownTags = string.Empty; int indexOfSPlit = tagName.IndexOf('\\'); if (indexOfSPlit > 0) { @@ -765,10 +770,20 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text else if (rest.Length > 0 && rest.Contains("\\")) { indexOfSPlit = rest.IndexOf('\\'); + var unknowntag = rest.Substring(0, indexOfSPlit); + unknownTags += "\\" + unknowntag; rest = rest.Substring(indexOfSPlit).TrimStart('\\'); } + else if (!string.IsNullOrEmpty(rest)) + { + + unknownTags += "\\" + rest; + rest = string.Empty; + } } } + if (!string.IsNullOrEmpty(unknownTags)) + unknownTags = "{" + unknownTags + "}"; } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) diff --git a/src/Test/Logic/SubtitleFormats/SubtitleFormatsTest.cs b/src/Test/Logic/SubtitleFormats/SubtitleFormatsTest.cs index 6519c2be0..e55d24b74 100644 --- a/src/Test/Logic/SubtitleFormats/SubtitleFormatsTest.cs +++ b/src/Test/Logic/SubtitleFormats/SubtitleFormatsTest.cs @@ -347,6 +347,19 @@ Dialogue: 0,0:00:16.84,0:00:18.16,rechts,,0000,0000,0000,," + lineOneText; Assert.AreEqual(expected, actual); } + [TestMethod] + public void AssSizeAndOtherTags() + { + var target = new AdvancedSubStationAlpha(); + var subtitle = new Subtitle(); + target.LoadSubtitle(subtitle, GetAssLines(@"{\fs20\pos(1,1)\blur5}Bla-bla-bla"), null); + string actual = subtitle.Paragraphs[0].Text; + const string expected = "{\\pos(1,1)\\blur5}Bla-bla-bla"; + Assert.AreEqual(expected, actual); + } + + + #endregion Advanced Sub Station alpha (.ass) #region Sub Station Alpha (.ssa)