Merge pull request #61 from rtw1x1/main

fix: BiDi logic & broken cursor & auto-detect LTR/RTL input
This commit is contained in:
rtw1x1
2025-12-31 21:08:00 +00:00
committed by GitHub
3 changed files with 221 additions and 692 deletions

16
extern/include/utf8.h vendored
View File

@@ -337,6 +337,12 @@ static inline ECharDir GetCharDirSmart(const wchar_t* s, int n, int i)
if (ch == L'(' || ch == L')')
return ECharDir::LTR;
// Common punctuation: treat as strong LTR to prevent jumping around in mixed text
// This makes "Hello + اختبار" and "اختبار + Hello" both keep punctuation in place
if (ch == L'+' || ch == L'-' || ch == L'=' || ch == L'*' || ch == L'/' ||
ch == L'<' || ch == L'>' || ch == L'&' || ch == L'|' || ch == L'@' || ch == L'#')
return ECharDir::LTR;
// Percentage sign: attach to numbers (scan nearby for digits/minus/plus)
// Handles: "%20", "20%", "-6%", "%d%%", etc.
if (ch == L'%')
@@ -755,8 +761,9 @@ static inline std::vector<wchar_t> BuildVisualChatMessage(
}
else
{
// Apply BiDi to message based on its content
std::vector<wchar_t> msgVisual = BuildVisualBidiText_Tagless(msg, msgLen, msgHasRTL);
// Apply BiDi to message with auto-detection (don't force RTL)
// Let the BiDi algorithm detect base direction from first strong character
std::vector<wchar_t> msgVisual = BuildVisualBidiText_Tagless(msg, msgLen, false);
visual.insert(visual.end(), msgVisual.begin(), msgVisual.end());
}
visual.push_back(L' ');
@@ -778,8 +785,9 @@ static inline std::vector<wchar_t> BuildVisualChatMessage(
}
else
{
// Apply BiDi to message based on its content
std::vector<wchar_t> msgVisual = BuildVisualBidiText_Tagless(msg, msgLen, msgHasRTL);
// Apply BiDi to message with auto-detection (don't force RTL)
// Let the BiDi algorithm detect base direction from first strong character
std::vector<wchar_t> msgVisual = BuildVisualBidiText_Tagless(msg, msgLen, false);
visual.insert(visual.end(), msgVisual.begin(), msgVisual.end());
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,7 @@
#include "MarkManager.h"
#include <utf8.h>
// EPlaceDir and TextTailBiDi() template are defined in utf8.h
const D3DXCOLOR c_TextTail_Player_Color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
const D3DXCOLOR c_TextTail_Monster_Color = D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f);