fixed string cutting in draw.c
4d67199a
1 file(s) · +10 −2
| 26 | 26 | { |
|
| 27 | 27 | int x, y, w, h; |
|
| 28 | 28 | static char buf[256]; |
|
| 29 | - | unsigned int len; |
|
| 29 | + | unsigned int len, olen; |
|
| 30 | 30 | XGCValues gcv; |
|
| 31 | 31 | XPoint points[5]; |
|
| 32 | 32 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
|
| 51 | 51 | return; |
|
| 52 | 52 | ||
| 53 | 53 | w = 0; |
|
| 54 | - | len = strlen(text); |
|
| 54 | + | olen = len = strlen(text); |
|
| 55 | 55 | if(len >= sizeof(buf)) |
|
| 56 | 56 | len = sizeof(buf) - 1; |
|
| 57 | 57 | memcpy(buf, text, len); |
|
| 64 | 64 | /* shorten text if necessary */ |
|
| 65 | 65 | while(len && (w = textnw(buf, len)) > dc.w - h) |
|
| 66 | 66 | buf[--len] = 0; |
|
| 67 | + | if(len < olen) { |
|
| 68 | + | if(len > 3) |
|
| 69 | + | memcpy(buf + len - 4, "...\0", 4); |
|
| 70 | + | else if(len > 2) |
|
| 71 | + | memcpy(buf + len - 3, "..\0", 3); |
|
| 72 | + | else if(len > 1) |
|
| 73 | + | memcpy(buf + len - 2, ".\0", 2); |
|
| 74 | + | } |
|
| 67 | 75 | ||
| 68 | 76 | if(w > dc.w) |
|
| 69 | 77 | return; /* too long */ |
|