|
48 | 48 | #include "hbapi.h" |
49 | 49 | #include "hbapierr.h" |
50 | 50 | #include "hbapicdp.h" |
| 51 | +#include "hbgtcore.h" |
| 52 | +#include "../codepage/mk_wcwidth.h" |
51 | 53 | #include "hbthread.h" |
52 | 54 |
|
53 | 55 |
|
@@ -3558,103 +3560,30 @@ const char ** hb_cdpList( void ) |
3558 | 3560 |
|
3559 | 3561 | /* Calculate Unicode character display width (East Asian Width) |
3560 | 3562 | * Returns: 1 for narrow characters, 2 for wide characters |
| 3563 | + * |
| 3564 | + * This function checks if wide character width calculation is enabled |
| 3565 | + * via the fWideCharWidth flag in the GT driver. If enabled, it uses the |
| 3566 | + * mk_wcwidth() function from the public domain implementation for |
| 3567 | + * accurate Unicode TR11 width calculation. Otherwise, it returns 1 |
| 3568 | + * for backward compatibility. |
3561 | 3569 | */ |
3562 | 3570 | int hb_cdpUTF8CharWidth( HB_WCHAR wc ) |
3563 | 3571 | { |
3564 | | - /* Narrow characters (width 1) */ |
3565 | | - if( wc < 0x1100 ) |
3566 | | - return 1; |
3567 | | - |
3568 | | - /* Hangul Jamo (width 2) */ |
3569 | | - if( wc >= 0x1100 && wc <= 0x115F ) |
3570 | | - return 2; |
3571 | | - |
3572 | | - /* Hangul Compatibility Jamo (width 2) */ |
3573 | | - if( wc >= 0x3130 && wc <= 0x318F ) |
3574 | | - return 2; |
3575 | | - |
3576 | | - /* CJK Radicals Supplement (width 2) */ |
3577 | | - if( wc >= 0x2E80 && wc <= 0x2EFF ) |
3578 | | - return 2; |
3579 | | - |
3580 | | - /* Kangxi Radicals (width 2) */ |
3581 | | - if( wc >= 0x2F00 && wc <= 0x2FDF ) |
3582 | | - return 2; |
3583 | | - |
3584 | | - /* CJK Strokes (width 2) */ |
3585 | | - if( wc >= 0x31C0 && wc <= 0x31EF ) |
3586 | | - return 2; |
3587 | | - |
3588 | | - /* CJK Symbols and Punctuation (width 2) */ |
3589 | | - if( wc >= 0x3000 && wc <= 0x303F ) |
3590 | | - return 2; |
3591 | | - |
3592 | | - /* Hiragana (width 2) */ |
3593 | | - if( wc >= 0x3040 && wc <= 0x309F ) |
3594 | | - return 2; |
3595 | | - |
3596 | | - /* Katakana (width 2) */ |
3597 | | - if( wc >= 0x30A0 && wc <= 0x30FF ) |
3598 | | - return 2; |
3599 | | - |
3600 | | - /* Bopomofo (width 2) */ |
3601 | | - if( wc >= 0x3100 && wc <= 0x312F ) |
3602 | | - return 2; |
3603 | | - |
3604 | | - /* Bopomofo Extended (width 2) */ |
3605 | | - if( wc >= 0x31A0 && wc <= 0x31BF ) |
3606 | | - return 2; |
3607 | | - |
3608 | | - /* Enclosed CJK Letters and Months (width 2) */ |
3609 | | - if( wc >= 0x3200 && wc <= 0x32FF ) |
3610 | | - return 2; |
3611 | | - |
3612 | | - /* CJK Compatibility (width 2) */ |
3613 | | - if( wc >= 0x3300 && wc <= 0x33FF ) |
3614 | | - return 2; |
3615 | | - |
3616 | | - /* CJK Unified Ideographs Extension A (width 2) */ |
3617 | | - if( wc >= 0x3400 && wc <= 0x4DBF ) |
3618 | | - return 2; |
3619 | | - |
3620 | | - /* CJK Unified Ideographs (width 2) */ |
3621 | | - if( wc >= 0x4E00 && wc <= 0x9FFF ) |
3622 | | - return 2; |
3623 | | - |
3624 | | - /* Yi Syllables (width 2) */ |
3625 | | - if( wc >= 0xA000 && wc <= 0xA48F ) |
3626 | | - return 2; |
3627 | | - |
3628 | | - /* Yi Radicals (width 2) */ |
3629 | | - if( wc >= 0xA490 && wc <= 0xA4CF ) |
3630 | | - return 2; |
3631 | | - |
3632 | | - /* Hangul Syllables (width 2) */ |
3633 | | - if( wc >= 0xAC00 && wc <= 0xD7AF ) |
3634 | | - return 2; |
3635 | | - |
3636 | | - /* CJK Compatibility Ideographs (width 2) */ |
3637 | | - if( wc >= 0xF900 && wc <= 0xFAFF ) |
3638 | | - return 2; |
3639 | | - |
3640 | | - /* Halfwidth and Fullwidth Forms (width 1 for halfwidth, 2 for fullwidth) */ |
3641 | | - if( wc >= 0xFF00 && wc <= 0xFFEF ) |
| 3572 | + PHB_GT pGT; |
| 3573 | + |
| 3574 | + /* Check if wide character width calculation is enabled */ |
| 3575 | + pGT = hb_gt_Base(); |
| 3576 | + if( pGT ) |
3642 | 3577 | { |
3643 | | - /* Halfwidth characters (width 1) */ |
3644 | | - if( wc >= 0xFF61 && wc <= 0xFF9F ) |
3645 | | - return 1; |
3646 | | - /* Fullwidth characters (width 2) */ |
3647 | | - return 2; |
| 3578 | + if( pGT->fWideCharWidth ) |
| 3579 | + { |
| 3580 | + hb_gt_BaseFree( pGT ); |
| 3581 | + /* Use mk_wcwidth for accurate width calculation */ |
| 3582 | + return mk_wcwidth( (wchar_t)wc ); |
| 3583 | + } |
| 3584 | + hb_gt_BaseFree( pGT ); |
3648 | 3585 | } |
3649 | | - |
3650 | | - /* Miscellaneous Symbols (width 2) */ |
3651 | | - if( wc >= 0x2600 && wc <= 0x26FF ) |
3652 | | - return 2; |
3653 | | - |
3654 | | - /* Dingbats (width 2) */ |
3655 | | - if( wc >= 0x2700 && wc <= 0x27BF ) |
3656 | | - return 2; |
3657 | | - |
3658 | | - /* Default: narrow character */ |
| 3586 | + |
| 3587 | + /* Default: narrow character (width 1) */ |
3659 | 3588 | return 1; |
3660 | 3589 | } |
0 commit comments