.TH WORDWRAP 2 .SH NAME wordwrap \- wrap text at word boundaries in a window .SH SYNOPSIS .B #include .br .B #include .br .B #include .br .B #include "wordwrap.h" .PP .B Point wordwrap(char* m, Font *font, Point pi, int margin); .SH DESCRIPTION The function .I wordwrap takes the input text .I m and displays it in the font .I font within the Image .IR screen , which must already be defined as a global, as performed by .IR initdraw (2). .I Wordwrap will wrap the text at a word boundary, leaving .I margin pixels on the perimiter of the screen when performing the layout. .PP .I Wordwrap first makes its own copy of the input, then splits the that on newlines, then each line into words on spaces. It checks whether each word will fit within the .I screen rectangle in the given .I font starting at the current insertion point, leaving .I margin around the perimiter, and if not updates the insertion point to the leftmost edge (again, respecting .IR margin ) and then inserts the string. It re-inserts spaces between words (but see the note below), and will start each input line after the first at the leftmost margin. .I Wordwrap returns the point it would continue layout at if the input text were longer. .PP It is possible to mix fonts between calls to .I wordwrap to, for example, display a bold or italic string with a normal string, but care should be taken to match the font heights. There is no way for a call to .I wordwrap to know that n earlier call has used a taller font, so when it moves to the next line it will use the spacing of its current font. This can lead to unexpected overlap if mixing fonts of different heights. .SH SOURCE .BR http://a.9srv.net/src/wordwrap.c , .B http://a.9srv.net/src/wordwrap.h .SH BUGS Since .I wordwrap uses .IR getields (2) to split input lines on newline and words with lines on spaces, either of those characters on the beginning or end of the input are lost. See .I fixsep() in .I http://a.9srv.net/src/litclock.c for an example of how to deal with this. This should probably be integrated into wordwrap. .PP Like all the Plan 9 graphics utilities, .I wordwrap makes no attempt to deal with right-to-left layout.