Skip to content
Draft
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
2 changes: 1 addition & 1 deletion WindowTranslator/Modules/Ocr/OcrBufferFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async IAsyncEnumerable<TextRect> ExecutePreTranslate(IAsyncEnumerable<Tex
Y = pastText.Y,
Width = Math.Max(text.Width, pastText.Width),
Height = pastText.Height,
FontSize = pastText.FontSize
FontSize = (text.FontSize + pastText.FontSize) / 2
};
}
currentTextsList.Add(text);
Expand Down
25 changes: 25 additions & 0 deletions WindowTranslator/Modules/Ocr/WindowsMediaOcr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ public static WordRect CorrectWord(OcrWord word, double angle, double centerX, d
// 矩形の回転補正
var (x, y, width, height) = RotateRect(word.BoundingRect, angle, centerX, centerY);

// CJK文字(日本語・中国語・韓国語等)はem枠をすでに満たしているため位置・高さ補正不要
// ラテン文字が一切含まれない場合もCJK等のフルハイト文字として扱う
if (ContainsCjk(word.Text) || (!isxHeight && !hasAcent && !hasHarfAcent && !hasDecent))
{
return new(word.Text, x, y, width, height);
}

// 文字種類による位置補正
y -= (hasAcent, hasHarfAcent) switch
{
Expand Down Expand Up @@ -457,6 +464,24 @@ private static bool Contains(string text, string target)
return te.ContainsAny(ta);
}

/// <summary>
/// CJK文字(日本語・中国語・韓国語等)が含まれているかを判定する
/// </summary>
private static bool ContainsCjk(string text)
{
foreach (var c in text)
{
// 平仮名・片仮名・CJK統合漢字・ハングル音節・CJK互換漢字
if ((c >= '\u3040' && c <= '\u9FFF') ||
(c >= '\uAC00' && c <= '\uD7AF') ||
(c >= '\uF900' && c <= '\uFAFF'))
{
return true;
}
}
return false;
}

private static bool IsAllSameChar(string text)
{
ReadOnlySpan<char> chars = text;
Expand Down