WrapText

WrapText
string WrapText(int wt_font, string wt_s, int wt_linelen)

Documentation

Inserts the "|" character as line breaks. This is not speed optimised, but is fine for short blocks and once-only uses.

Example Usage

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
}
Talkback

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.