I try to first find one line max len,than back find '-' or ' '.
static int R_FontFindFit (const font_t *f, char *text, int maxlen, int maxWidth, int *widthp)
{
int bestbreak = 0;
int width;
int len;
*widthp = 0;
width = R_FontChunkLength(f, text, maxlen);
if (width<=maxWidth) {
*widthp = width;
return maxlen-1;
}
/* Break first word anywhere. */
for (len = max(6,maxlen*maxWidth/width)-5; len < maxlen; len++) {
if (UTF8_CONTINUATION_BYTE(text[len]))
continue;
width = R_FontChunkLength(f, text, len);
if (width > maxWidth)
break;
bestbreak = len;
*widthp = width;
}
/** @todo Smart breaking of Chinese text */
/* Fit whole words */ /* Fit hyphenated word parts */
/* last 1/6 Width to find break */
for (len = bestbreak; len > (bestbreak - bestbreak/6); len--) {
if (text[len] == ' ' || text[len] == '-') {
width = R_FontChunkLength(f, text, len);
bestbreak = len;
*widthp = width;
break;
}
}
return bestbreak;
}
in ufopedia this is ok,but in 3D Geoscape can't display basename or nation name .
[attachment deleted by admin]