Skip to content

string split width break

Dustin edited this page Oct 7, 2015 · 2 revisions

string-split-width-break returns a modified version of string str which is wrapped to fit into a window of width w using the fontsize obtained from font fnt. Unlike string-split-width wrapping can occur between any two characters (words can be broken up), spaces and new lines in the text are not treated differently than other characters. This procedure is used by string-split-width when dealing with sections of text that are two long to fit on one line but do not contain any spaces (single words).

What is returned is a list, where each string in the list is one of the lines. This procedure assumes that at least one split is necessary, thus the list is at least length 2. Each string in the list is at least string-length 1.

Parameter Description
str The string to be split
w The maximal width before a split has to occur
fnt The font used to render the string

Example

Example 1: Wrap an 16pt string to fit onto a 100px wide window

> (string-split-width-break "abcdefghijklmnopqrstuvwxyz" 100 ascii_16.fnt)
("abcdefghijklm" "nopqrstuvwxy" "z")
Clone this wiki locally