for the char 0 to initialize a clean state, and then once with the string " "
(a space) so the routine knows how long a space is.
+In case no single character fits into the given width, the wordWidth function
+must return the width of exactly one character.
+
Wrapped lines get the isContinuation flag set and are continuationWidth less wide.
The sum of the return values of the processLine function will be returned.
}
out_inner:
spaceUsedForWord = wordWidth(passthroughCW, cursor, &wordLen, maxWidth - continuationWidth); // this may have reduced wordLen when it won't fit - but this is GOOD. TODO fix words that do fit in a non-continuation line
- if(wordLen < 1)
+ if(wordLen < 1) // cannot happen according to current spec of wordWidth
{
wordLen = 1;
spaceUsedForWord = maxWidth + 1; // too high, forces it in a line of itself
ti->colorindex = -1;
return ti->fontsize * ti->font->maxwidth;
}
- /*
if(maxWidth >= 0)
- return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize;
- else if(maxWidth == -1)
- return DrawQ_TextWidth_Font(w, *length, false, ti->font) * ti->fontsize;
- */
- if(maxWidth >= 0)
- return DrawQ_TextWidth_Font_UntilWidth_Size(w, ti->fontsize, ti->fontsize, length, false, ti->font, maxWidth);
+ return DrawQ_TextWidth_Font_UntilWidth_Size(w, ti->fontsize, ti->fontsize, length, false, ti->font, -maxWidth); // -maxWidth: we want at least one char
else if(maxWidth == -1)
return DrawQ_TextWidth_Font_Size(w, ti->fontsize, ti->fontsize, *length, false, ti->font);
else
}
}
+// NOTE: this function always draws exactly one character if maxwidth <= 0
float DrawQ_TextWidth_Font_UntilWidth_TrackColors_Size(const char *text, float w, float h, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
{
const char *text_start = text;
ft2_font_t *ft2 = fnt->ft2;
// float ftbase_x;
qboolean snap = true;
+ qboolean least_one = false;
if (!h) h = w;
if (!h) {
// maxwidth /= fnt->scale; // w and h are multiplied by it already
// ftbase_x = snap_to_pixel_x(0);
+
+ if(maxwidth <= 0)
+ {
+ least_one = true;
+ maxwidth = -maxwidth;
+ }
for (i = 0;((bytes_left = *maxlen - (text - text_start)) > 0) && *text;)
{
+ size_t i0 = i;
nextch = ch = u8_getnchar(text, &text, bytes_left);
i = text - text_start;
if (!ch)
x = snap_to_pixel_x(x, 0.4);
if (ch == ' ' && !fontmap)
{
+ if(!least_one || i0) // never skip the first character
if(x + fnt->width_of[(int) ' '] * w > maxwidth)
+ {
+ i = i0;
break; // oops, can't draw this
+ }
x += fnt->width_of[(int) ' '] * w;
continue;
}
if (fontmap)
map = ft2_oldstyle_map;
prevch = 0;
+ if(!least_one || i0) // never skip the first character
if(x + fnt->width_of[ch] * w > maxwidth)
+ {
+ i = i0;
break; // oops, can't draw this
+ }
x += fnt->width_of[ch] * w;
} else {
if (!map || map == ft2_oldstyle_map || map->start < ch || map->start + FONT_CHARS_PER_MAP >= ch)