Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对在简体中文的Window10在默认的控制台打印包含中文的字符串会出现排版问题的修改 #87

Open
gnbdev opened this issue Mar 7, 2020 · 2 comments

Comments

@gnbdev
Copy link

gnbdev commented Mar 7, 2020

在简体中文的Window10默认的控制台打印包含中文的字符串会出现排版问题,中文字符会叠加在一起,我追踪到在这里做一些修改,实现正常的中文字符排版,可我没有环境去测试日文,韩文、繁体中文等亚洲地区及其他国家的文字。

以下是我修改过的内容:

int waddnstr(WINDOW *win, const char *str, int n)
{
    int i = 0;

    PDC_LOG(("waddnstr() - called: string=\"%s\" n %d \n", str, n));

    if (!win || !str)
        return ERR;

    while (str[i] && (i < n || n < 0))
    {
#ifdef PDC_WIDE
        wchar_t wch;
        int retval = PDC_mbtowc(&wch, str + i, n >= 0 ? n - i : 6);

        if (retval <= 0)
            return OK;

        i += retval;
#else
        chtype wch = (unsigned char)(str[i++]);
#endif

#ifdef PDC_WIDE
	int x = win->_curx;
	int y = win->_cury;

	if (1==retval){
            waddch(win, ' ');
            wmove(win, y, x);
        }

	if (3==retval){
	   if( 0 !=x ){
              wmove(win, y, x-1);
              waddch(win, ' ');
              waddch(win, ' ');
              waddch(win, ' ');
              wmove(win, y, x);
            }
        }
#endif

        if (waddch(win, wch) == ERR)
            return ERR;

#ifdef PDC_WIDE
	if (3==retval){
		win->_curx+=1;
	}
#endif

    }

    return OK;
}

修改的方式比较粗暴,如果原作者能够做官方修改就更好了。

@Bill-Gray
Copy link
Contributor

(G__gle Translate does what appears to me to be a surprisingly good job of translating the above text.)

Thanks for posting this. It's an interesting solution to the fullwidth/halfwidth character problem. It will work only for the Windows console version (I think), but perhaps that's all you need. Also, it assumes all Unicode points above 0x7ff (those encoded as three bytes in UTF8) are fullwidth; it's really more complex than that. Also, points 0x100 to 0x7ff (where retval == 2), including many European languages, are ignored. (Everything in that range is either half- or zero-width.)

You could use this mk_wcwidth() function (Markus Kuhn's version of wcwidth() for Windows) and revise your code to say

if( mk_wcwidth( wch) == 2 && x)
    {
    /* use your fullwidth-character solution */
    }
else
     /* display as a half-width character

You'll still have problems with fullwidth characters. Mainline PDCurses is ill-suited to Asian languages. I had to make a lot of changes before fullwidth characters worked properly; see my fork for details. Among other things, a 'dummy' character has to be stored next to each fullwidth character to make everything line up properly.

Also, mainline PDCurses does not support combining characters or supplemental-plane Unicode (Unicode points past 64K). I don't know if that's a problem for your use.

@GitMensch
Copy link
Contributor

Translation:

Amendments to typographical issues when printing strings containing Chinese in the default console of Window10 in Simplified Chinese

Printing the strings containing Chinese in the default console of Window10 in Simplified Chinese will cause typographical problems and Chinese characters will be superimposed. I traced some modifications here to achieve normal Chinese character layout, but I have no environment to test Japanese , Korean, Traditional Chinese and other Asian languages and other countries.

The following is what I modified: [...]
The method of modification is rough, and it would be better if the original author could make the official modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants