]>
Commit | Line | Data |
---|---|---|
86ec8038 AM |
1 | fix-utf8-status-padding-bug |
2 | ||
3 | Ensure that multibyte UTF8 characters are counted correctly when | |
4 | calculating and displaying the caption and hardstatus lines. | |
5 | ||
6 | Based on an earlier version by Kees Cook <address@hidden> | |
7 | ||
8 | Signed-off-by: Dustin Kirkland <address@hidden> | |
9 | ||
10 | === modified file 'src/display.c' | |
11 | Index: screen/display.c | |
12 | =================================================================== | |
13 | --- screen.orig/display.c 2012-03-20 22:15:02.000000000 +0100 | |
14 | +++ screen/display.c 2012-03-20 22:41:28.000000000 +0100 | |
15 | @@ -2155,7 +2155,7 @@ | |
16 | { | |
17 | int chars = strlen_onscreen((unsigned char *)(s + start), (unsigned char *)(s + max)); | |
18 | D_encoding = 0; | |
19 | - PutWinMsg(s, start, max); | |
20 | + PutWinMsg(s, start, max + ((max - start) - chars)); /* Multibyte count */ | |
21 | D_encoding = UTF8; | |
22 | D_x -= (max - chars); /* Yak! But this is necessary to count for | |
23 | the fact that not every byte represents a | |
24 | @@ -2249,11 +2249,15 @@ | |
25 | RefreshHStatus() | |
26 | { | |
27 | char *buf; | |
28 | - | |
29 | +#ifdef UTF8 | |
30 | + int extrabytes = strlen(hstatusstring) - strlen_onscreen(hstatusstring, NULL); | |
31 | +#else | |
32 | + int extrabytes = 0; | |
33 | +#endif | |
34 | evdeq(&D_hstatusev); | |
35 | if (D_status == STATUS_ON_HS) | |
36 | return; | |
37 | - buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP, &D_hstatusev, 0); | |
38 | + buf = MakeWinMsgEv(hstatusstring, D_fore, '%', (D_HS && D_has_hstatus == HSTATUS_HS && D_WS > 0) ? D_WS : D_width - !D_CLP + extrabytes, &D_hstatusev, 0); | |
39 | if (buf && *buf) | |
40 | { | |
41 | ShowHStatus(buf); | |
42 | @@ -2348,8 +2352,13 @@ | |
43 | { | |
44 | if (y == cv->c_ye + 1 && from >= cv->c_xs && from <= cv->c_xe) | |
45 | { | |
46 | +#ifdef UTF8 | |
47 | + int extrabytes = strlen(captionstring) - strlen_onscreen(captionstring, NULL); | |
48 | +#else | |
49 | + int extrabytes = 0; | |
50 | +#endif | |
51 | p = Layer2Window(cv->c_layer); | |
52 | - buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP), &cv->c_captev, 0); | |
53 | + buf = MakeWinMsgEv(captionstring, p, '%', cv->c_xe - cv->c_xs + (cv->c_xe + 1 < D_width || D_CLP) + extrabytes, &cv->c_captev, 0); | |
54 | if (cv->c_captev.timeout.tv_sec) | |
55 | evenq(&cv->c_captev); | |
56 | xx = to > cv->c_xe ? cv->c_xe : to; | |
57 | @@ -2358,7 +2367,7 @@ | |
58 | SetRendition(&mchar_so); | |
59 | if (l > xx - cv->c_xs + 1) | |
60 | l = xx - cv->c_xs + 1; | |
61 | - l = PrePutWinMsg(buf, from - cv->c_xs, l); | |
62 | + l = PrePutWinMsg(buf, from - cv->c_xs, l + extrabytes); | |
63 | from = cv->c_xs + l; | |
64 | for (; from <= xx; from++) | |
65 | PUTCHARLP(' '); |