diff options
author | Anselm R.Garbe <arg@10ksloc.org> | 2006-08-14 08:52:28 +0200 |
---|---|---|
committer | Anselm R.Garbe <arg@10ksloc.org> | 2006-08-14 08:52:28 +0200 |
commit | 0e21ef5f3701cafb9936b5fcbfc204bc477cb215 (patch) | |
tree | 95226dbdcbc24b6cecbc36e982eb2cc3223a1ac7 | |
parent | 2f3068fb77aed6c5128b7df1571bee1edaa35d92 (diff) |
fixed string cutting
-rw-r--r-- | draw.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -28,7 +28,7 @@ drawtext(const char *text, Bool invert, Bool border) | |||
28 | { | 28 | { |
29 | int x, y, w, h; | 29 | int x, y, w, h; |
30 | static char buf[256]; | 30 | static char buf[256]; |
31 | unsigned int len; | 31 | unsigned int len, olen; |
32 | XGCValues gcv; | 32 | XGCValues gcv; |
33 | XPoint points[5]; | 33 | XPoint points[5]; |
34 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 34 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
@@ -56,7 +56,7 @@ drawtext(const char *text, Bool invert, Bool border) | |||
56 | if(!text) | 56 | if(!text) |
57 | return; | 57 | return; |
58 | 58 | ||
59 | len = strlen(text); | 59 | olen = len = strlen(text); |
60 | if(len >= sizeof(buf)) | 60 | if(len >= sizeof(buf)) |
61 | len = sizeof(buf) - 1; | 61 | len = sizeof(buf) - 1; |
62 | memcpy(buf, text, len); | 62 | memcpy(buf, text, len); |
@@ -69,6 +69,14 @@ drawtext(const char *text, Bool invert, Bool border) | |||
69 | /* shorten text if necessary */ | 69 | /* shorten text if necessary */ |
70 | while(len && (w = textnw(buf, len)) > dc.w - h) | 70 | while(len && (w = textnw(buf, len)) > dc.w - h) |
71 | buf[--len] = 0; | 71 | buf[--len] = 0; |
72 | if(len < olen) { | ||
73 | if(len > 3) | ||
74 | memcpy(buf + len - 4, "...\0", 4); | ||
75 | else if(len > 2) | ||
76 | memcpy(buf + len - 3, "..\0", 3); | ||
77 | else if(len > 1) | ||
78 | memcpy(buf + len - 2, ".\0", 2); | ||
79 | } | ||
72 | 80 | ||
73 | if(w > dc.w) | 81 | if(w > dc.w) |
74 | return; /* too long */ | 82 | return; /* too long */ |