Add an option to use wcwidth_cjk() instead of wcwidth(), as several people
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 22 Mar 2005 23:20:23 +0000 (23:20 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Tue, 22 Mar 2005 23:20:23 +0000 (23:20 +0000)
have asked for it.

git-svn-id: svn://svn.tartarus.org/sgt/putty@5542 cda61777-01e9-0310-a592-d414129be87e

config.c
doc/config.but
putty.h
settings.c
terminal.c
testdata/utf8.txt
wcwidth.c
windows/wincfg.c
windows/winhelp.h

index 5922e04..73ed703 100644 (file)
--- 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));
 
                  '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);
     str = dupprintf("Adjust how %s handles line drawing characters", appname);
     s = ctrl_getset(b, "Window/Translation", "linedraw", str);
     sfree(str);
index 0b50689..e01eb2a 100644 (file)
@@ -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.
 
 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}
 \S{config-cyr} \q{Caps Lock acts as Cyrillic switch}
 
 \cfg{winhelp-topic}{translation.cyrillic}
diff --git a/putty.h b/putty.h
index 430fd96..43a66e6 100644 (file)
--- a/putty.h
+++ b/putty.h
@@ -525,6 +525,7 @@ struct config_tag {
     /* translations */
     int vtmode;
     char line_codepage[128];
     /* translations */
     int vtmode;
     char line_codepage[128];
+    int cjk_ambig_wide;
     int utf8_override;
     int xlat_capslockcyr;
     /* X11 forwarding */
     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(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
 
 /*
  * Exports from mscrypto.c
index c480486..8b9caa0 100644 (file)
@@ -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_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);
     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));
      */
     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);
     gppi(sesskey, "UTF8Override", 1, &cfg->utf8_override);
     gpps(sesskey, "Printer", "", cfg->printer, sizeof(cfg->printer));
     gppi (sesskey, "CapsLockCyr", 0, &cfg->xlat_capslockcyr);
index eaaa04d..904f1b8 100644 (file)
@@ -2845,7 +2845,9 @@ static void term_out(Terminal *term)
                    if (DIRECT_CHAR(c))
                        width = 1;
                    if (!width)
                    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;
 
                    if (term->wrapnext && term->wrap && width > 0) {
                        cline->lattr |= LATTR_WRAPPED;
index a8a87f9..d7e1d77 100644 (file)
@@ -19,3 +19,5 @@ Arabic and bidirectional text:
                عن \e[44mجرير\e[m \e[41mرضي\e[m الله عنه قال قال رسول الله صلى الله عليه
           وسلم: بني الاسلام على خمس شهادة ان لا اله الا الله واقام              
 Mixed LTR and RTL text: \e[44mجرير\e[m \e[41mرضي\e[m back to LTR.
                عن \e[44mجرير\e[m \e[41mرضي\e[m الله عنه قال قال رسول الله صلى الله عليه
           وسلم: بني الاسلام على خمس شهادة ان لا اله الا الله واقام              
 Mixed LTR and RTL text: \e[44mجرير\e[m \e[41mرضي\e[m back to LTR.
+
+East Asian Ambiguous characters: ¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾¼½¾
index ed7529b..403010b 100644 (file)
--- a/wcwidth.c
+++ b/wcwidth.c
@@ -146,7 +146,6 @@ int wcswidth(const wchar_t *pwcs, size_t n)
   return width;
 }
 
   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
 /*
  * 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.
  */
  * 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 */
 {
   /* 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;
 }
 
   return width;
 }
-#endif
index 1fb8e3e..ea997c7 100644 (file)
@@ -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!).
      */
      * 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,
     ctrl_checkbox(s, "Caps Lock acts as Cyrillic switch", 's',
                  HELPCTX(translation_cyrillic),
                  dlg_stdcheckbox_handler,
index 388538d..92ad7be 100644 (file)
 #define WINHELP_CTX_colours_logpal "colours.logpal"
 #define WINHELP_CTX_colours_config "colours.config"
 #define WINHELP_CTX_translation_codepage "translation.codepage"
 #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"
 #define WINHELP_CTX_translation_cyrillic "translation.cyrillic"
 #define WINHELP_CTX_translation_linedraw "translation.linedraw"
 #define WINHELP_CTX_ssh_tunnels_x11 "ssh.tunnels.x11"