string WrapTextX(int wt_font, string wt_s, int wt_linelen)
Inserts the "|" character as line breaks. This is speed optimised, but is still only recommended for short blocks (ie. not the entire works of Shakespeare passed in one argument) and once-only uses.
string WrapTextX(int wt_font, string wt_s, int wt_linelen)
// Pass: The font to use, the string to wrap, the length in pixels to fit into
// Return: The passed string with | characters inserted as breaks
// Assmes: The font is valid, and will overrun if a word is longer than linelen
// Note: Existing breaks will be respected, but adjacent | characters will be
// replaced with a single | so add a space for multiple line breaks
{
string wt_tpara = "";
int curpara = 0;
int nextpara, lenpara, curchr, nextchr, width;
int length = len(wt_s);
while (curpara < length)
{
nextpara = strstrp("|", wt_s, curpara + 1);
if (nextpara > curpara + 1)
{
lenpara = nextpara - curpara - 1;
wt_tpara = mid(wt_s, curpara + 1, lenpara);
if (TextWidth(wt_font, wt_tpara) > wt_linelen)
{
curchr = 0-1;
width = 0;
while (curchr < lenpara)
{
nextchr = strstrp(" ", wt_tpara, curchr + 1);
width += TextWidth(wt_font, mid(wt_tpara, curchr, nextchr - curchr));
if (width > wt_linelen)
{
wt_s = chrovr(curpara + curchr + 1, "\", wt_s);
width = TextWidth(wt_font, mid(wt_tpara, curchr + 1, nextchr - curchr - 1));
}
curchr = nextchr;
}
}
}
curpara = nextpara;
}
return wt_s;
}There are no talkbacks on this documentation page yet. Post the first?
Doc Nav |
![]() |
Your docs |
![]() |