NAME
wordwrap – wrap text at word boundaries in a window |
SYNOPSIS
#include <u.h> #include <libc.h> #include <draw.h> #include wordwrap.h |
DESCRIPTION
The function wordwrap is like string(2), except it will wrap text
at word boundaries within the rectangle dst–>r. That is, it draws
in dst characters specified by the string s and font, with the
left of the first character positioned at p.x and the top of the
first line of text at 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 dst rectangle
in the given font starting at the current insertion point, leaving
margin around the perimiter, and if not updates the insertion
point to the leftmost edge (again, respecting margin) down one
line
(using the line height defined in 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.
Wordwrap returns the point it would continue layout at if the
input text were longer.
|
SOURCE
http://a.9srv.net/src/wordwrap.c, http://a.9srv.net/src/wordwrap.h |
BUGS
Since wordwrap uses 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 fixsep() in http://a.9srv.net/src/litclock.c
for an example of how to deal with this. This should probably
be integrated into wordwrap.
|