Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cross platform line break #9175

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="SevenZipExtractor" Version="1.0.17" />
<PackageVersion Include="SharpCompress" Version="0.38.0" />
<PackageVersion Include="System.Drawing.Common" Version="9.0.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="UTF.Unknown" Version="2.5.1" />
<PackageVersion Include="zlib.net-mutliplatform" Version="1.0.8" />
<PackageVersion Include="Microsoft.Net.Http" Version="2.2.29" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="NAudio.Core" Version="2.2.1" />
<PackageVersion Include="NAudio.WinMM" Version="2.2.1" />
<PackageVersion Include="ncalc" Version="1.3.8" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NHunspell" Version="1.2.5554.16953" />
<PackageVersion Include="System.Security.AccessControl" Version="6.0.1" />
<PackageVersion Include="System.Security.Principal.Windows" Version="5.0.0" />
<PackageVersion Include="Vosk" Version="0.3.38" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest" Version="3.6.1" />
</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="SevenZipExtractor" Version="1.0.17" />
<PackageVersion Include="SharpCompress" Version="0.38.0" />
<PackageVersion Include="System.Drawing.Common" Version="9.0.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Resources.Extensions" Version="9.0.0" />
<PackageVersion Include="UTF.Unknown" Version="2.5.1" />
<PackageVersion Include="zlib.net-mutliplatform" Version="1.0.8" />
<PackageVersion Include="Microsoft.Net.Http" Version="2.2.29" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="NAudio.Core" Version="2.2.1" />
<PackageVersion Include="NAudio.WinMM" Version="2.2.1" />
<PackageVersion Include="ncalc" Version="1.3.8" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NHunspell" Version="1.2.5554.16953" />
<PackageVersion Include="System.Security.AccessControl" Version="6.0.1" />
<PackageVersion Include="System.Security.Principal.Windows" Version="5.0.0" />
<PackageVersion Include="Vosk" Version="0.3.38" />
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest" Version="3.6.1" />
</ItemGroup>
</Project>
50 changes: 25 additions & 25 deletions src/Tests/FixCommonErrors/FixCommonErrorsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ public void FixOcrErrorsViaHardcodedRules2()
using (var form = new GoToLine())
{
Configuration.Settings.Tools.OcrFixUseHardcodedRules = true;
const string input = "Foobar\r\n<i>-";
string input = $"Foobar{Environment.NewLine}<i>-";
var ofe = new Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine("eng", "us_en", form);
var res = ofe.FixOcrErrorsViaHardcodedRules(input, "Previous line.", null, new HashSet<string>());
Assert.AreEqual(res, "Foobar\r\n<i>-");
Assert.AreEqual(res, $"Foobar{Environment.NewLine}<i>-");
}
}

Expand Down Expand Up @@ -557,9 +557,9 @@ public void FixCommonOcrErrorsFrenchHardCodedRuleNoChange()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "ENCORE UNE VICTIME\r\nDE L'ASSASSIN MYSTERIEUX.");
InitializeFixCommonErrorsLine(target, $"ENCORE UNE VICTIME{Environment.NewLine}DE L'ASSASSIN MYSTERIEUX.");
target.FixOcrErrorsViaReplaceList("fra");
Assert.AreEqual("ENCORE UNE VICTIME\r\nDE L'ASSASSIN MYSTERIEUX.", target.Subtitle.Paragraphs[0].Text);
Assert.AreEqual($"ENCORE UNE VICTIME{Environment.NewLine}DE L'ASSASSIN MYSTERIEUX.", target.Subtitle.Paragraphs[0].Text);
}
}

Expand All @@ -569,9 +569,9 @@ public void FixCommonOcrErrorsFrenchHardCodedRuleChange()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "Encore une victime\r\nde L'assassin mysterieux.");
InitializeFixCommonErrorsLine(target, $"Encore une victime{Environment.NewLine}de L'assassin mysterieux.");
target.FixOcrErrorsViaReplaceList("fra");
Assert.AreEqual("Encore une victime\r\nde l'assassin mysterieux.", target.Subtitle.Paragraphs[0].Text);
Assert.AreEqual($"Encore une victime{Environment.NewLine}de l'assassin mysterieux.", target.Subtitle.Paragraphs[0].Text);
}
}

Expand Down Expand Up @@ -1373,7 +1373,7 @@ public void FixEmptyLinesTest1()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>\r\nHello world!\r\n</i>");
InitializeFixCommonErrorsLine(target, $"<i>{Environment.NewLine}Hello world!{Environment.NewLine}</i>");
new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Hello world!</i>");
}
Expand All @@ -1384,7 +1384,7 @@ public void FixEmptyLinesTest2()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<font color=\"#000000\">\r\nHello world!\r\n</font>");
InitializeFixCommonErrorsLine(target, $"<font color=\"#000000\">{Environment.NewLine}Hello world!{Environment.NewLine}</font>");
new FixEmptyLines().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<font color=\"#000000\">Hello world!</font>");
}
Expand Down Expand Up @@ -1969,22 +1969,22 @@ public void FixEllipsesAfterAssaTag()
[TestMethod]
public void FixDoubleGreaterThanTest2()
{
const string input1 = "<i>>>Hello world!</i>\r\n<i>>>Hello</i>";
const string input2 = "<b>>>Hello world!</b>\r\n<i>>>Hello</i>";
const string input3 = "<u>>>Hello world!</u>\r\n<b>>>Hello</b>";
const string input4 = "<font color=\"#008040\">>>Hello world!</font>\r\n<font color=\"#008040\">>>Hello</font>";
var input1 = $"<i>>>Hello world!</i>{Environment.NewLine}<i>>>Hello</i>";
var input2 = $"<b>>>Hello world!</b>{Environment.NewLine}<i>>>Hello</i>";
var input3 = $"<u>>>Hello world!</u>{Environment.NewLine}<b>>>Hello</b>";
var input4 = $"<font color=\"#008040\">>>Hello world!</font>{Environment.NewLine}<font color=\"#008040\">>>Hello</font>";

const string expected1 = "<i>Hello world!</i>\r\n<i>Hello</i>";
const string expected2 = "<b>Hello world!</b>\r\n<i>Hello</i>";
const string expected3 = "<u>Hello world!</u>\r\n<b>Hello</b>";
const string expected4 = "<font color=\"#008040\">Hello world!</font>\r\n<font color=\"#008040\">Hello</font>";
var expected1 = $"<i>Hello world!</i>{Environment.NewLine}<i>Hello</i>";
var expected2 = $"<b>Hello world!</b>{Environment.NewLine}<i>Hello</i>";
var expected3 = $"<u>Hello world!</u>{Environment.NewLine}<b>Hello</b>";
var expected4 = $"<font color=\"#008040\">Hello world!</font>{Environment.NewLine}<font color=\"#008040\">Hello</font>";

var lines1 = input1.SplitToLines();
var lines2 = input2.SplitToLines();
var lines3 = input3.SplitToLines();
var lines4 = input4.SplitToLines();

for (int i = 0; i < lines1.Count; i++)
for (var i = 0; i < lines1.Count; i++)
{
lines1[i] = Helper.FixDoubleGreaterThanHelper(lines1[i]);
lines2[i] = Helper.FixDoubleGreaterThanHelper(lines2[i]);
Expand Down Expand Up @@ -2175,9 +2175,9 @@ public void FixDoubleDashTest2()
using (var target = GetFixCommonErrorsLib())
{
// <font color="#000000"> and <font>
InitializeFixCommonErrorsLine(target, "<b>Mm-hmm.</b>\r\n<font color=\"#000000\">-- foobar</font>");
InitializeFixCommonErrorsLine(target, $"<b>Mm-hmm.</b>{Environment.NewLine}<font color=\"#000000\">-- foobar</font>");
new FixDoubleDash().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<b>Mm-hmm.</b>\r\n<font color=\"#000000\">...foobar</font>");
Assert.AreEqual(_subtitle.Paragraphs[0].Text, $"<b>Mm-hmm.</b>{Environment.NewLine}<font color=\"#000000\">...foobar</font>");
}
}

Expand Down Expand Up @@ -3635,7 +3635,7 @@ public void UnbreakShortLinesPixelWidth()
using (var target = GetFixCommonErrorsLib())
{
Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576;
InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\nIt's this...");
InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}It's this...");
new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("It is I this illustrious illiteration. It's this...", _subtitle.Paragraphs[0].Text);
}
Expand All @@ -3648,9 +3648,9 @@ public void UnbreakShortLinesPixelWidthDialog()
{
Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576;
Configuration.Settings.General.DialogStyle = DialogType.DashSecondLineWithoutSpace;
InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\n-It's this...");
InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}-It's this...");
new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("It is I this illustrious illiteration.\r\n-It's this...", _subtitle.Paragraphs[0].Text);
Assert.AreEqual($"It is I this illustrious illiteration.{Environment.NewLine}-It's this...", _subtitle.Paragraphs[0].Text);
}
}

Expand All @@ -3660,9 +3660,9 @@ public void UnbreakShortLinesPixelWidthTooLong()
using (var target = GetFixCommonErrorsLib())
{
Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576;
InitializeFixCommonErrorsLine(target, "It is I this illustrious illiteration.\r\nIt's super...");
InitializeFixCommonErrorsLine(target, $"It is I this illustrious illiteration.{Environment.NewLine}It's super...");
new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("It is I this illustrious illiteration.\r\nIt's super...", _subtitle.Paragraphs[0].Text);
Assert.AreEqual($"It is I this illustrious illiteration.{Environment.NewLine}It's super...", _subtitle.Paragraphs[0].Text);
}
}

Expand All @@ -3672,7 +3672,7 @@ public void UnbreakShortLinesPixelWidthTags()
using (var target = GetFixCommonErrorsLib())
{
Configuration.Settings.General.SubtitleLineMaximumPixelWidth = 576;
InitializeFixCommonErrorsLine(target, "<i>It is I this illustrious illiteration.</i>\r\n<i>It's this...</i>");
InitializeFixCommonErrorsLine(target, $"<i>It is I this illustrious illiteration.</i>{Environment.NewLine}<i>It's this...</i>");
new FixShortLinesPixelWidth(TextWidth.CalcPixelWidth).Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("<i>It is I this illustrious illiteration. It's this...</i>", _subtitle.Paragraphs[0].Text);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nikse.SubtitleEdit.Core.Common;
using System;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.VobSub.Ocr.Service;

namespace Tests.GoogleCloudVision
Expand All @@ -15,7 +16,7 @@ public void JsonToLines1()
Configuration.Settings.Tools.OcrGoogleCloudVisionSeHandlesTextMerge = true;
var lines = GoogleCloudVisionApi.JsonToStringList("nl", JsonInput1);
Assert.AreEqual(1, lines.Count);
Assert.AreEqual("Wat ben jij aan het doen?\r\n-Ik bouw een marshmallow-hotel.", lines[0]);
Assert.AreEqual($"Wat ben jij aan het doen?{Environment.NewLine}-Ik bouw een marshmallow-hotel.", lines[0]);
}

[TestMethod]
Expand All @@ -24,7 +25,7 @@ public void JsonToLines2()
Configuration.Settings.Tools.OcrGoogleCloudVisionSeHandlesTextMerge = true;
var lines = GoogleCloudVisionApi.JsonToStringList("en", JsonInput2);
Assert.AreEqual(1, lines.Count);
Assert.AreEqual("I've already said what's\r\nnecessary to be said.", lines[0]);
Assert.AreEqual($"I've already said what's{Environment.NewLine}necessary to be said.", lines[0]);
}
}
}
16 changes: 8 additions & 8 deletions src/Tests/Logic/Forms/RemoveTextForHearImpairedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public void RemoveColonTest3()
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.ColonSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
const string text = "Barry, remember: She cannot\r\nteleport if she cannot see.";
const string expected = text;
string text = $"Barry, remember: She cannot{Environment.NewLine}teleport if she cannot see.";
string expected = text;
string actual = target.RemoveColon(text);
Assert.AreEqual(expected, actual);
}
Expand All @@ -161,8 +161,8 @@ public void RemoveColonTest4()
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.ColonSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
const string text = "http://subscene.com/u/659433\r\nImproved by: @Ivandrofly";
const string expected = text;
string text = $"http://subscene.com/u/659433{Environment.NewLine}Improved by: @Ivandrofly";
string expected = text;
string actual = target.RemoveColon(text);
Assert.AreEqual(expected, actual);
}
Expand Down Expand Up @@ -329,8 +329,8 @@ public void RemoveHI1()
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
const string text = "- Aw, save it. Storm?\r\n- [Storm]\r\nWe're outta here.";
const string expected = "- Aw, save it. Storm?\r\n- We're outta here.";
string text = $"- Aw, save it. Storm?{Environment.NewLine}- [Storm]\r\nWe're outta here.";
string expected = $"- Aw, save it. Storm?{Environment.NewLine}- We're outta here.";
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode);
Assert.AreEqual(expected, actual);
}
Expand Down Expand Up @@ -364,8 +364,8 @@ public void RemoveHINot()
target.Settings.OnlyIfInSeparateLine = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.ColonSeparateLine = false;
const string text = "is the body of a mutant kid\r\non the 6:00 news.";
const string expected = "is the body of a mutant kid\r\non the 6:00 news.";
string text = $"is the body of a mutant kid{Environment.NewLine}on the 6:00 news.";
string expected = $"is the body of a mutant kid{Environment.NewLine}on the 6:00 news.";
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsLanguageCode);
Assert.AreEqual(expected, actual);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Tests/Logic/SplitLongLinesHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void SplitLongLinesInSubtitleTest()
Configuration.Settings.Tools.AutoBreakUsePixelWidth = false;
var procSubtitle = SplitLongLinesHelper.SplitLongLinesInSubtitle(_subtitle, _maxLineLength * 2, _maxLineLength);

Assert.AreEqual("We have never been to Asia,\r\nnor have we visited Africa.", procSubtitle.Paragraphs[0].Text);
Assert.AreEqual("We have never\r\nbeen to Asia, nor\r\nhave we visited Africa.", procSubtitle.Paragraphs[1].Text);
Assert.AreEqual($"We have never been to Asia,{Environment.NewLine}nor have we visited Africa.", procSubtitle.Paragraphs[0].Text);
Assert.AreEqual($"We have never{Environment.NewLine}been to Asia, nor{Environment.NewLine}have we visited Africa.", procSubtitle.Paragraphs[1].Text);
Assert.AreEqual(_subtitle.Paragraphs[2].Text, procSubtitle.Paragraphs[2].Text);

Assert.AreNotEqual(_subtitle.Paragraphs.Count, procSubtitle.Paragraphs.Count);
Expand All @@ -60,8 +60,8 @@ public void SplitLongLinesInSubtitleTest()
Assert.AreEqual(Utilities.AutoBreakLine("Of yourself and laugh it off to realise that life isn’t so bad after all.", "en"), procSubtitle.Paragraphs[4].Text);

// too long
Assert.AreEqual("Sometimes, all you need to do is\r\ncompletely make an ass of yourself", procSubtitle.Paragraphs[5].Text);
Assert.AreEqual("and laugh it off to realise that\r\nlife isn’t so bad after all.", procSubtitle.Paragraphs[6].Text);
Assert.AreEqual($"Sometimes, all you need to do is{Environment.NewLine}completely make an ass of yourself", procSubtitle.Paragraphs[5].Text);
Assert.AreEqual($"and laugh it off to realise that{Environment.NewLine}life isn’t so bad after all.", procSubtitle.Paragraphs[6].Text);

// timing test
if (procSubtitle.Paragraphs[5].DurationTotalMilliseconds > procSubtitle.Paragraphs[6].DurationTotalMilliseconds)
Expand All @@ -88,7 +88,7 @@ public void SplitLongLinesInSubtitleTest2()
[TestMethod]
public void MillisecondsPerCharTest()
{
string text = Utilities.AutoBreakLine("The waves were crashing on the\r\nshore; it was a lovely sight.");
string text = Utilities.AutoBreakLine($"The waves were crashing on the{Environment.NewLine}shore; it was a lovely sight.");
double optimalDuration = Utilities.GetOptimalDisplayMilliseconds(text);
double displayCharLen = HtmlUtil.RemoveHtmlTags(text, true).Length - (Utilities.GetNumberOfLines(text) - 1) * Environment.NewLine.Length;
double msPerChar = optimalDuration / displayCharLen;
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Logic/SubtitleFormats/SubtitleFormatsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ public void PhoenixSubtitleTest()
// Test text.
phxSub.LoadSubtitle(subtitle, new List<string>(text.SplitToLines()), null);
Assert.AreEqual("You should come to the Drama Club, too.", subtitle.Paragraphs[0].Text);
Assert.AreEqual("Yeah. The Drama Club is worried\r\nthat you haven't been coming.", subtitle.Paragraphs[1].Text);
Assert.AreEqual($"Yeah. The Drama Club is worried{Environment.NewLine}that you haven't been coming.", subtitle.Paragraphs[1].Text);

// Test frames.
Assert.AreEqual(SubtitleFormat.FramesToMilliseconds(2447), subtitle.Paragraphs[0].StartTime.TotalMilliseconds);
Expand Down
Loading