From: jacob Date: Tue, 22 Mar 2005 23:20:23 +0000 (+0000) Subject: Add an option to use wcwidth_cjk() instead of wcwidth(), as several people X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/commitdiff_plain/74790953a734d6e745c1e412cb9824743348ec3c Add an option to use wcwidth_cjk() instead of wcwidth(), as several people have asked for it. git-svn-id: svn://svn.tartarus.org/sgt/putty@5542 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/config.c b/config.c index 5922e041..73ed703f 100644 --- a/config.c +++ b/config.c @@ -1282,6 +1282,11 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist, 'r', 100, HELPCTX(translation_codepage), codepage_handler, P(NULL), P(NULL)); + s = ctrl_getset(b, "Window/Translation", "tweaks", NULL); + ctrl_checkbox(s, "Treat CJK ambiguous characters as wide", 'w', + HELPCTX(translation_cjk_ambig_wide), + dlg_stdcheckbox_handler, I(offsetof(Config,cjk_ambig_wide))); + str = dupprintf("Adjust how %s handles line drawing characters", appname); s = ctrl_getset(b, "Window/Translation", "linedraw", str); sfree(str); diff --git a/doc/config.but b/doc/config.but index 0b506898..e01eb2ac 100644 --- a/doc/config.but +++ b/doc/config.but @@ -1213,6 +1213,24 @@ its name manually (\c{CP866} for example) in the list box. If the underlying version of Windows has the appropriate translation table installed, PuTTY will use it. +\S{config-cjk-ambig-wide} \q{Treat CJK ambiguous characters as wide} + +\cfg{winhelp-topic}{translation.cjkambigwide} + +There are \I{East Asian Ambiguous characters}some Unicode characters +whose width is not well-defined. In most contexts, such characters +should be treated as single-width for the purposes of wrapping and so +on; however, in some CJK contexts, they are better treated as +double-width for historical reasons, and some server-side applications +may expect them to be displayed as such. Setting this option will +cause PuTTY to take the double-width interpretation. + +If you use legacy CJK applications, and you find your lines are +wrapping in the wrong places, or you are having other display +problems, you might want to play with this setting. + +This option only has any effect in UTF-8 mode (see \k{config-charset}). + \S{config-cyr} \q{Caps Lock acts as Cyrillic switch} \cfg{winhelp-topic}{translation.cyrillic} diff --git a/putty.h b/putty.h index 430fd96e..43a66e62 100644 --- a/putty.h +++ b/putty.h @@ -525,6 +525,7 @@ struct config_tag { /* translations */ int vtmode; char line_codepage[128]; + int cjk_ambig_wide; int utf8_override; int xlat_capslockcyr; /* X11 forwarding */ @@ -869,6 +870,8 @@ void get_unitab(int codepage, wchar_t * unitab, int ftype); */ int wcwidth(wchar_t ucs); int wcswidth(const wchar_t *pwcs, size_t n); +int wcwidth_cjk(wchar_t ucs); +int wcswidth_cjk(const wchar_t *pwcs, size_t n); /* * Exports from mscrypto.c diff --git a/settings.c b/settings.c index c4804864..8b9caa0b 100644 --- a/settings.c +++ b/settings.c @@ -339,6 +339,7 @@ void save_open_settings(void *sesskey, int do_host, Config *cfg) write_setting_s(sesskey, buf, buf2); } write_setting_s(sesskey, "LineCodePage", cfg->line_codepage); + write_setting_i(sesskey, "CJKAmbigWide", cfg->cjk_ambig_wide); write_setting_i(sesskey, "UTF8Override", cfg->utf8_override); write_setting_s(sesskey, "Printer", cfg->printer); write_setting_i(sesskey, "CapsLockCyr", cfg->xlat_capslockcyr); @@ -666,6 +667,7 @@ void load_open_settings(void *sesskey, int do_host, Config *cfg) */ gpps(sesskey, "LineCodePage", "", cfg->line_codepage, sizeof(cfg->line_codepage)); + gppi(sesskey, "CJKAmbigWide", 0, &cfg->cjk_ambig_wide); gppi(sesskey, "UTF8Override", 1, &cfg->utf8_override); gpps(sesskey, "Printer", "", cfg->printer, sizeof(cfg->printer)); gppi (sesskey, "CapsLockCyr", 0, &cfg->xlat_capslockcyr); diff --git a/terminal.c b/terminal.c index eaaa04dc..904f1b8c 100644 --- a/terminal.c +++ b/terminal.c @@ -2845,7 +2845,9 @@ static void term_out(Terminal *term) if (DIRECT_CHAR(c)) width = 1; if (!width) - width = wcwidth((wchar_t) c); + width = (term->cfg.cjk_ambig_wide ? + wcwidth_cjk((wchar_t) c) : + wcwidth((wchar_t) c)); if (term->wrapnext && term->wrap && width > 0) { cline->lattr |= LATTR_WRAPPED; diff --git a/testdata/utf8.txt b/testdata/utf8.txt index a8a87f9b..d7e1d773 100644 --- a/testdata/utf8.txt +++ b/testdata/utf8.txt @@ -19,3 +19,5 @@ Arabic and bidirectional text: عن جرير رضي الله عنه قال قال رسول الله صلى الله عليه وسلم: بني الاسلام على خمس شهادة ان لا اله الا الله واقام Mixed LTR and RTL text: جرير رضي back to LTR. + +East Asian Ambiguous characters: ¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾ diff --git a/wcwidth.c b/wcwidth.c index ed7529ba..403010b7 100644 --- a/wcwidth.c +++ b/wcwidth.c @@ -146,7 +146,6 @@ int wcswidth(const wchar_t *pwcs, size_t n) return width; } -#if 0 /* RDB: we don't need the cjk version */ /* * The following function is the same as wcwidth(), except that * spacing characters in the East Asian Ambiguous (A) category as @@ -155,7 +154,7 @@ int wcswidth(const wchar_t *pwcs, size_t n) * encodings who want to migrate to UCS. It is not otherwise * recommended for general use. */ -static int wcwidth_cjk(wchar_t ucs) +int wcwidth_cjk(wchar_t ucs) { /* sorted list of non-overlapping intervals of East Asian Ambiguous * characters */ @@ -233,4 +232,3 @@ int wcswidth_cjk(const wchar_t *pwcs, size_t n) return width; } -#endif diff --git a/windows/wincfg.c b/windows/wincfg.c index 1fb8e3e2..ea997c74 100644 --- a/windows/wincfg.c +++ b/windows/wincfg.c @@ -177,8 +177,7 @@ void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help, * the least we can do is ensure it never makes it to any other * platform (at least unless someone fixes it!). */ - s = ctrl_getset(b, "Window/Translation", "input", - "Enable character set translation on input data"); + s = ctrl_getset(b, "Window/Translation", "tweaks", NULL); ctrl_checkbox(s, "Caps Lock acts as Cyrillic switch", 's', HELPCTX(translation_cyrillic), dlg_stdcheckbox_handler, diff --git a/windows/winhelp.h b/windows/winhelp.h index 388538de..92ad7bef 100644 --- a/windows/winhelp.h +++ b/windows/winhelp.h @@ -112,6 +112,7 @@ #define WINHELP_CTX_colours_logpal "colours.logpal" #define WINHELP_CTX_colours_config "colours.config" #define WINHELP_CTX_translation_codepage "translation.codepage" +#define WINHELP_CTX_translation_cjk_ambig_wide "translation.cjkambigwide" #define WINHELP_CTX_translation_cyrillic "translation.cyrillic" #define WINHELP_CTX_translation_linedraw "translation.linedraw" #define WINHELP_CTX_ssh_tunnels_x11 "ssh.tunnels.x11"