If you okay with random hyphenation, then solution is trivial.
Just cutting a space on word-wrap boundary is easy.
wordwrap(line_length, input_string, output_string_list):
offset = backward_search_for_space( input_string + line_length )
if offset is zero ## a word taking more than a line !!
offset = forward_search(input_string )
append line_length[0:offset] to ouptput_string_list
if input_string is not null
wordwrap( line_length, input_string + offset, string_list)
If you want non-random hyphenation ( ie. un-known is allowed, byt unk-own is not ),
than you need to keep an hyphenated words list or set of rules, and modify above algorithm
if you want 'equally spaced', than after above algo, you need to take lines less than
line_length, and increases spaces in the middle of lines. Easy to do
If your font is variable width, you'll need to implement the algo in physical measurement units
rather than character count. It's also easy to do. A 'width' array is to be maintained, and line_length check is to be computed.