string WrapText(int wt_font, string wt_s, int wt_linelen)
Inserts the "|" character as line breaks. This is not speed optimised, but is fine for short blocks and once-only uses.
string WrapText(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 { int wt_i; string wt_tpara = ""; string wt_tline = ""; string wt_output = ""; int wt_breaks = TokenCount(wt_s, "|"); while (len(wt_s)) { wt_tpara = GetToken(wt_s, "|", 0); wt_s = right(wt_s, len(wt_s) - len(wt_tpara) - 1); if (TextWidth(wt_font, wt_tpara) < wt_linelen) { wt_output = wt_output + wt_tpara + "|"; } else { while (len(wt_tpara)) { wt_tline = wt_tline + GetToken(wt_tpara, " ", 0); wt_tpara = right(wt_tpara, len(wt_tpara) - len(GetToken(wt_tpara, " ", 0)) - 1); if (TextWidth(wt_font, wt_tline + GetToken(wt_tpara, " ", 0) + " ") > wt_linelen) { wt_output = wt_output + wt_tline + "|"; wt_tline = ""; } else wt_tline = wt_tline + " "; } if (len(wt_tline)) { wt_output = wt_output + left(wt_tline, len(wt_tline) - 1) + "|"; wt_tline = ""; } } } return wt_output + "|"; // Double "||" to terminate }
There are no talkbacks on this documentation page yet. Post the first?
Doc Nav |
Your docs |