add: word1 = 0; while (1) { word2 = word1 + findNextWord(text+word1, beforecrlf-word1); if (word2 >= beforecrlf) break; w = WMWidthOfString(font, text, word2); if (w > width) break; word1 = word2; }  for (i=word1; i<word2; i++) { w = WMWidthOfString(font, text, i); if (w > width) { break; } }   if (!isspace(text[i]) && word1>0) { i = word1; } else if (isspace(text[i]) && i<beforecrlf) {  i++; }
context: fitText(char *text, WMFont *font, int width, int wrap){    int i, j;    int w;        if (text[0]==0)	return 0;        i = 0;    if (wrap) {	if (text[0]=='\n')	    return 0;		do {	    i++;	    w = WMWidthOfString(font, text, i);	} while (w < width && text[i]!='\n' && text[i]!=0);	if (text[i]=='\n')	    return i;		/* keep words complete */	if (!isspace(text[i])) {	    j = i;	    while (j>1 && !isspace(text[j]) && text[j]!=0)		j--;	    if (j>1)		i = j;	}    } else {	while (text[i]!='\n' && text[i]!=0)	    i++;    }    return i;}