| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6a28b58 commit ec8bfa3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,15 @@ | |||
| 1 | + 2010-05-20 Ethan A Merritt <merritt@u.washington.edu> | ||
| 2 | + | ||
| 3 | + * term/estimate.trm (ENHest_writec strlen_utf8) | ||
| 4 | + src/term.c (estimate_strlen): | ||
| 5 | + | ||
| 6 | + Teach estimate_strlen() to handle UTF-8 encoded strings. The estimate | ||
| 7 | + is imperfect, but then again the estimate is already imperfect for any | ||
| 8 | + proportional font. To truly do this more accurately would require | ||
| 9 | + customized implementations for each terminal type. Any unicode code | ||
| 10 | + point below 0x3000 is treated as requiring one character width; code | ||
| 11 | + points above 0x3000 are treated as requiring two character widths. | ||
| 12 | + | ||
| 1 | 13 | 2010-05-16 Ethan A Merritt <merritt@u.washington.edu> | |
| 2 | 14 | ||
| 3 | 15 | * src/hidden3d.c (draw_edge): Add support for coloring lines in | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | #ifndef lint | |
| 2 | - static char *RCSid() { return RCSid("$Id: term.c,v 1.202 2010/03/14 22:44:38 sfeam Exp $"); } | ||
| 2 | + static char *RCSid() { return RCSid("$Id: term.c,v 1.203 2010/05/05 18:03:50 sfeam Exp $"); } | ||
| 3 | 3 | #endif | |
| 4 | 4 | ||
| 5 | 5 | /* GNUPLOT - term.c */ | |
@@ -2789,7 +2789,9 @@ int len; | |||
| 2789 | 2789 | FPRINTF((stderr,"Estimating length %d height %g for enhanced text string \"%s\"\n", | |
| 2790 | 2790 | len, (double)(term->ymax)/10., text)); | |
| 2791 | 2791 | term = tsave; | |
| 2792 | - } else | ||
| 2792 | + } else if (encoding == S_ENC_UTF8) | ||
| 2793 | + len = strlen_utf8(text); | ||
| 2794 | + else | ||
| 2793 | 2795 | #endif | |
| 2794 | 2796 | len = strlen(text); | |
| 2795 | 2797 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | /* Hello, Emacs, this is -*-C-*- | |
| 2 | - * $Id: estimate.trm,v 1.7 2008/06/02 19:49:50 sfeam Exp $ | ||
| 2 | + * $Id: estimate.trm,v 1.8 2009/03/26 00:49:20 sfeam Exp $ | ||
| 3 | 3 | * | |
| 4 | 4 | */ | |
| 5 | 5 | ||
@@ -44,6 +44,9 @@ static TBOOLEAN ENHest_widthflag = TRUE; | |||
| 44 | 44 | #define ENHest_font "" | |
| 45 | 45 | static double ENHest_base; | |
| 46 | 46 | ||
| 47 | + /* Internal routines for UTF-8 support */ | ||
| 48 | + static size_t strlen_utf8 __PROTO((const char *s)); | ||
| 49 | + | ||
| 47 | 50 | TERM_PUBLIC void | |
| 48 | 51 | ENHest_OPEN( | |
| 49 | 52 | char *fontname, | |
@@ -123,7 +126,10 @@ ENHest_put_text(unsigned int x, unsigned int y, const char *str) | |||
| 123 | 126 | ||
| 124 | 127 | /* If no enhanced text processing is needed, strlen() is sufficient */ | |
| 125 | 128 | if (ignore_enhanced_text || !strpbrk(str, "{}^_@&~\n")) { | |
| 126 | - term->xmax = strlen(str); | ||
| 129 | + if (encoding == S_ENC_UTF8) | ||
| 130 | + term->xmax = strlen_utf8(str); | ||
| 131 | + else | ||
| 132 | + term->xmax = strlen(str); | ||
| 127 | 133 | term->ymax = 10; | |
| 128 | 134 | return; | |
| 129 | 135 | } | |
@@ -158,7 +164,37 @@ ENHest_writec(int c) | |||
| 158 | 164 | ENHest_x = 0; | |
| 159 | 165 | } | |
| 160 | 166 | ||
| 161 | - ENHest_fragment_width += ENHest_fontsize; | ||
| 167 | + if (encoding == S_ENC_UTF8) { | ||
| 168 | + /* Skip all but the first byte of UTF-8 multi-byte characters. */ | ||
| 169 | + if ((c & 0xc0) != 0x80) { | ||
| 170 | + ENHest_fragment_width += ENHest_fontsize; | ||
| 171 | + /* [most] characters above 0x3000 are square CJK glyphs, */ | ||
| 172 | + /* which are wider than western characters. */ | ||
| 173 | + if ((unsigned int)c >= 0xec) | ||
| 174 | + ENHest_fragment_width += ENHest_fontsize; | ||
| 175 | + } | ||
| 176 | + } else | ||
| 177 | + ENHest_fragment_width += ENHest_fontsize; | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + /* | ||
| 181 | + * This routine accounts for multi-byte characters in UTF-8. | ||
| 182 | + * NB: It does not return the _number_ of characters in the string, but | ||
| 183 | + * rather their approximate _width_ in units of typical character width. | ||
| 184 | + * As with the ENHest_writec() routine, it approximates the width of characters | ||
| 185 | + * above unicode 0x3000 as being twice that of western alphabetic characters. | ||
| 186 | + */ | ||
| 187 | + size_t strlen_utf8(const char *s) { | ||
| 188 | + int i = 0, j = 0; | ||
| 189 | + while (s[i]) { | ||
| 190 | + if ((s[i] & 0xc0) != 0x80) { | ||
| 191 | + j++; | ||
| 192 | + if ((unsigned char)(s[i]) >= 0xe3) | ||
| 193 | + j++; | ||
| 194 | + } | ||
| 195 | + i++; | ||
| 196 | + } | ||
| 197 | + return j; | ||
| 162 | 198 | } | |
| 163 | 199 | ||
| 164 | 200 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments