Text Wrapper Module

From Spheriki

Jump to: navigation, search

The Text Wrapper Module by tunginobi is a custom script that provides character-wrapping and word-wrapping functions.

NOTE: The functionality in this module has mostly been replaced by the internal Sphere function Font.wordWrapString(), which breaks up a string into an word-wrapped array of lines.


Contents

Download and Usage

You can download a tech demo at the official project page. The core script is TextWrap.js. Copy it into the scripts folder of your project and place this on top of your main script:
RequireScript("TextWrap.js");


Variables and functions of TextWrap.js

  • WordWrapByFontWidth(textToWrap, font, pixelWidth)
    • splits the string 'textToWrap' into seperate lines. Each line will have a maximal width of 'pixelWidth' when drawn with 'font' (which must be a Sphere font object). Words are kept together.
    • returns an array of strings representing the lines.
  • WordWrapByStrLen(textToWrap, charsPerLine)
    • splits the string 'textToWrap' into seperate lines. Each line will have no more than 'charsPerLine' characters. Words are kept together.
    • returns an array of strings representing the lines.
  • CharWrapByFontWidth(textToWrap, font, pixelWidth)
    • same as WordWrapByFontWidth(), except that words aren't kept together.
  • CharWrapByStrLen(textToWrap, charsPerLine)
    • same as WordWrapByStrLen(), except that words aren't kept together.
  • ToLongString(linesArray)
    • converts a string array to a long string with line breaks ("\n").


Notes

  • To force a line break inside of a text to wrap, use the special character "\n".
  • "\t" will be interpreted as a tab.


Known bugs

  • WordWrapByFontWidth() and WordWrapByStrLen() don't handle forced linebreaks ("\n") correctly.


See also

Personal tools