From 4ccce2018e0805f679f960766038af2af4cfe326 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 31 Oct 2024 05:57:41 +0100 Subject: [PATCH] One more italic ocr fix - thx Zoltan :) --- Directory.Packages.props | 4 ++-- .../Ocr/MatchesToItalicStringConverterTest.cs | 23 +++++++++++++++++++ .../Ocr/MatchesToItalicStringConverter.cs | 6 ++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index d231a2cf1..48e9452a8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,8 +3,8 @@ true - - + + diff --git a/src/Test/Logic/Ocr/MatchesToItalicStringConverterTest.cs b/src/Test/Logic/Ocr/MatchesToItalicStringConverterTest.cs index d5e08e697..bddbf07b8 100644 --- a/src/Test/Logic/Ocr/MatchesToItalicStringConverterTest.cs +++ b/src/Test/Logic/Ocr/MatchesToItalicStringConverterTest.cs @@ -284,6 +284,29 @@ namespace Test.Logic.Ocr Assert.AreEqual("Joe:\r\nGodbye!", result); } + public void TestWordInItalicSecondLineAndBrackets() + { + var matches = new List + { + new VobSubOcr.CompareMatch("[J", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("o", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("e", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("]:", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("\r", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("\n", false, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("G", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("o", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("d", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("b", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("y", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("e", true, 0, Guid.NewGuid().ToString()), + new VobSubOcr.CompareMatch("!", true, 0, Guid.NewGuid().ToString()), + }; + + string result = MatchesToItalicStringConverter.GetStringWithItalicTags(matches); + Assert.AreEqual("[Joe]:\r\nGodbye!", result); + } + [TestMethod] public void TestPartInItalic() { diff --git a/src/ui/Logic/Ocr/MatchesToItalicStringConverter.cs b/src/ui/Logic/Ocr/MatchesToItalicStringConverter.cs index 6afd4d0d7..8c616d5a4 100644 --- a/src/ui/Logic/Ocr/MatchesToItalicStringConverter.cs +++ b/src/ui/Logic/Ocr/MatchesToItalicStringConverter.cs @@ -220,7 +220,11 @@ namespace Nikse.SubtitleEdit.Logic.Ocr if (line.Count > 0) { line.Add(t); - if (index < matches.Count - 1 && matches[index + 1].Text == Environment.NewLine) + if (index < matches.Count - 1 && ":)]".Contains(matches[index + 1].ToString())) + { + continue; + } + else if (index < matches.Count - 1 && matches[index + 1].Text == Environment.NewLine) { result.Add(new SplitItem { Matches = line, Separator = Environment.NewLine }); skipNext = true;