TextWrapper

TextWrapper

Utility to wrap text across several lines, respecting Unicode grapheme clusters and, when possible, Unicode line break opportunities. Reference material:

  • Unicode Standard Annex #14: http://unicode.org/reports/tr14/
  • Unicode Standard Annex #39: http://unicode.org/reports/tr29/
  • "JavaScript has a Unicode problem" by Mathias Bynens: https://mathiasbynens.be/notes/javascript-unicode

Constructor

new TextWrapper(measurementProvider)

Construct a text wrapper which will measure text using the specified measurement provider.

Parameters:
Name Type Description
measurementProvider MeasurementProvider

a helper object to provide text measurement services.

Methods

wrapText(maxWidth, text) → {Array.<string>}

Wrap the provided text into lines restricted to a maximum width. See Unicode Standard Annex (UAX) #14.

Parameters:
Name Type Description
maxWidth number

the maximum allowed width of a line.

text string

the text to be wrapped. Will be split on whitespace.

Returns:

an array containing the wrapped lines of text.

Type
Array.<string>