.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(Image *dst, Point p, Image *src, Point sp, Font *font, char *s, int margin); .SH DESCRIPTION The function .I wordwrap is like .IR string (2), except it will wrap text at word boundaries within the rectangle .IR dst ->r. That is, it draws in .I dst characters specified by the string .I s and .IR font , with the left of the first character positioned at .I p.x and the top of the first line of text at .IR p.y . It 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 dst 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 ) down one line (using the line height defined in .IR font ) 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 an 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 getfields (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.