fixed string cutting 0e21ef5f
Anselm R.Garbe · 2006-08-14 08:52 1 file(s) · +10 −2
draw.c +10 −2
28 28
{
29 29
	int x, y, w, h;
30 30
	static char buf[256];
31 -
	unsigned int len;
31 +
	unsigned int len, olen;
32 32
	XGCValues gcv;
33 33
	XPoint points[5];
34 34
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
56 56
	if(!text)
57 57
		return;
58 58
59 -
	len = strlen(text);
59 +
	olen = len = strlen(text);
60 60
	if(len >= sizeof(buf))
61 61
		len = sizeof(buf) - 1;
62 62
	memcpy(buf, text, len);
69 69
	/* shorten text if necessary */
70 70
	while(len && (w = textnw(buf, len)) > dc.w - h)
71 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 81
	if(w > dc.w)
74 82
		return; /* too long */