Conversation
|
I'm not able to look at it extensievly right now, but pulling in |
src/rtl/cdpapi.c
Outdated
| #include "hbapi.h" | ||
| #include "hbapierr.h" | ||
| #include "hbapicdp.h" | ||
| #include "hbgtcore.h" |
There was a problem hiding this comment.
Calling GT core api from here doesn't look like a good idea, respecting the setting should be done somehow still in terminal code.
8331ff0 to
077d369
Compare
|
Thank you for your patient review and guidance—I’ve revised the code accordingly. I last used Clipper over thirty years ago and then left the IT industry. With the help of AI, I’m now trying to fix UTF-8 character-display issues in CJK terminals, and I hope the solution meets Harbour’s standards. |
|
|
||
| /* Type aliases: preserve original API */ | ||
| #define wchar_t HB_WCHAR | ||
| #define size_t HB_SIZE |
There was a problem hiding this comment.
Considering we need this code to be pulled in, I think the types should be replaced directly in the source, not using a macro. Also proper placing of header file is under include/mk_mcwidth.h plus it should be renamed to something like hbgtwide.h. In it's current form it more likely belongs to a terminal subsystem, but the char tables in final form could be fit in CODEPAGE modules.
All the macro definitions should moved to HB_ namespace, like COMBINING_WIDTH -> HB_COMBINING_WIDTH or even better a reverted scheme like HB_CHARWIDTH_COMBINING that better matches a larger project.
Or HB_WCWIDTH_* if someone else wants to jump what naming scheme fits the best?
Any exported functions also moved to hb_namespace too:
mk_wcwidth -> hb_wcwidth
Still thinking about all implications, but it's not the perfect timing for me to have the possibility to accommodate all the glyph knowledge.
Your original contribution also included support for emojis, where as far i have seen in the wild, width of an emoji character may be individual to the font face used. Therefore the static implementation may not be the best fit for all the needs, finally you will need additional hooks for some kind of dynamic tables.
ede39d4 to
36eb8f2
Compare
|
Summary of Changes Renamed / Refactored Updated Makefiles & References Review Comments Addressed Header placed under include/ and renamed to hbgtwide.h HB_ namespace for all exported symbols Character tables remain inside CODEPAGE modules Deferred for Future Work Dynamic width tables Full glyph knowledge |
When using Harbour with UTF-8 codepage (UTF8EX), the `col()`
function returns incorrect column positions for text containing
wide characters (e.g., CJK characters like 中文, Japanese
characters like 日, Korean characters, etc.).
This fixes cursor mis-alignment in UTF-8 terminals when output contains CJK, Emoji or other multi-column characters.
Key points:
New HB_GTI_WIDECHARWIDTH switch, disabled by default, zero run-time overhead.
Width logic is activated only after hb_gtInfo(HB_GTI_WIDECHARWIDTH, .T.).
Implementation based on public-domain mk_wcwidth; supports narrow(1), wide(2) and zero-width(0) characters.
No binary bloat, no breaking changes—existing applications compile and run unchanged.
Example:
hb_cdpSelect("UTF8EX")
hb_gtInfo(HB_GTI_WIDECHARWIDTH, .T.) && enable wide-char calculation
The cursor now advances by actual display columns, so subsequent prompts are correctly aligned.
The fix add the `hb_cdpUTF8CharWidth` function in `cdpapi.c` to check
the GT driver's `fWideCharWidth` flag. When enabled, it uses the `mk_wcwidth`
function from the public domain implementation for accurate Unicode TR11
width calculation. When disabled, it returns the default width of 1 for
backward compatibility.
- Add HB_GTI_WIDECHARWIDTH switch, disabled by default for zero overhead
- Only activate width calculation when user calls
hb_gtInfo(HB_GTI_WIDECHARWIDTH,.T.)
- Based on public-domain mk_wcwidth; supports narrow(1)/wide(2)/zero(0)
- 100% backward compatible, no binary bloat
- Fixes cursor mis-alignment in UTF-8 terminals with CJK/Emoji
Usage:
hb_cdpSelect("UTF8EX")
hb_gtInfo(HB_GTI_WIDECHARWIDTH,.T.) && enable
36eb8f2 to
01d90eb
Compare
Fixes cursor mis-alignment in UTF-8 terminals with CJK/Emoji
gt: optional Unicode wide-char width calculation (HB_GTI_WIDECHARWIDTH)
hb_gtInfo(HB_GTI_WIDECHARWIDTH,.T.)
Usage:
hb_cdpSelect("UTF8EX")
hb_gtInfo(HB_GTI_WIDECHARWIDTH,.T.) && enable