Minor fix for CJK line length - thx Leon :)

Related to #5711 + https://github.com/SubtitleEdit/subtitleedit/discussions/5711#discussioncomment-2040649
This commit is contained in:
niksedk 2022-01-25 08:15:54 +01:00
parent a65c42e346
commit 3831416791
2 changed files with 19 additions and 20 deletions

View File

@ -46,6 +46,10 @@ namespace Nikse.SubtitleEdit.Core.Common.TextLengthCalculator
{
htmlTagOn = true;
}
else if (JapaneseHalfWidthCharacters.Contains(ch))
{
count += 0.5m;
}
else if (!char.IsControl(ch) &&
ch != zeroWidthSpace &&
ch != zeroWidthNoBreakSpace &&
@ -57,17 +61,10 @@ namespace Nikse.SubtitleEdit.Core.Common.TextLengthCalculator
ch != '\u202D' &&
ch != '\u202E')
{
if (IsChinese(ch))
{
if (JapaneseHalfWidthCharacters.Contains(ch))
{
count += 0.5m;
}
else
if (IsCjk(ch))
{
count++;
}
}
else
{
count += 0.5m;
@ -82,8 +79,13 @@ namespace Nikse.SubtitleEdit.Core.Common.TextLengthCalculator
public const string JapaneseHalfWidthCharacters = "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚";
public static readonly Regex CjkCharRegex = new Regex(@"\p{IsCJKUnifiedIdeographs}", RegexOptions.Compiled);
public static bool IsChinese(char c)
public static bool IsCjk(char c)
{
if (c == '。' || c == '')
{
return true;
}
return CjkCharRegex.IsMatch(c.ToString());
}
}

View File

@ -44,6 +44,10 @@
{
htmlTagOn = true;
}
else if (CalcCjk.JapaneseHalfWidthCharacters.Contains(ch))
{
count += 0.5m;
}
else if (!char.IsControl(ch) &&
ch != ' ' &&
ch != zeroWidthSpace &&
@ -56,17 +60,10 @@
ch != '\u202D' &&
ch != '\u202E')
{
if (CalcCjk.IsChinese(ch))
{
if (CalcCjk.JapaneseHalfWidthCharacters.Contains(ch))
{
count += 0.5m;
}
else
if (CalcCjk.IsCjk(ch))
{
count++;
}
}
else
{
count += 0.5m;