.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Imager::Font::Wrap 3pm" .TH Imager::Font::Wrap 3pm 2024-04-13 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME .Vb 1 \& Imager::Font::Wrap \- simple wrapped text output .Ve .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Imager::Font::Wrap; \& \& my $img = Imager\->new(xsize=>$xsize, ysize=>$ysize); \& \& my $font = Imager::Font\->new(file=>$fontfile); \& \& my $string = "..."; # text with or without newlines \& \& Imager::Font::Wrap\->wrap_text( image => $img, \& font => $font, \& string => $string, \& x => $left, \& y => $top, \& width => $width, \& .... ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This is a simple text wrapper with options to control the layout of text within the line. .PP You can control the position, width and height of the text with the \&\f(CW\*(C`image\*(C'\fR, \f(CW\*(C`x\*(C'\fR, \f(CW\*(C`y\*(C'\fR, \f(CW\*(C`width\*(C'\fR and \f(CW\*(C`height\*(C'\fR options. .PP You can simply calculate space usage by setting \f(CW\*(C`image\*(C'\fR to \f(CW\*(C`undef\*(C'\fR, or set \f(CW\*(C`savepos\*(C'\fR to see how much text can fit within the given \&\f(CW\*(C`height\*(C'\fR. .IP \fBwrap_text()\fR 4 .IX Item "wrap_text()" Draw word-wrapped text. .RS 4 .IP \(bu 4 \&\f(CW\*(C`x\*(C'\fR, \f(CW\*(C`y\*(C'\fR \- The top-left corner of the rectangle the text is formatted into. Defaults to (0, 0). .IP \(bu 4 \&\f(CW\*(C`width\*(C'\fR \- The width of the formatted text in pixels. Defaults to the horizontal gap between the top-left corner and the right edge of the image. If no image is supplied then this is required. .IP \(bu 4 \&\f(CW\*(C`height\*(C'\fR \- The maximum height of the formatted text in pixels. Not required. .IP \(bu 4 \&\f(CW\*(C`savepos\*(C'\fR \- The amount of text consumed (as a count of characters) will be stored into the scalar this refers to. .Sp .Vb 4 \& my $pagenum = 1; \& my $string = "..."; \& my $font = ...; \& my $savepos; \& \& while (length $string) { \& my $img = Imager\->new(xsize=>$xsize, ysize=>$ysize); \& Imager::Font::Wrap\->wrap_text(string=>$string, font=>$font, \& image=>$img, savepos => \e$savepos) \& or die $img\->errstr; \& $savepos > 0 \& or die "Could not fit any text on page\en"; \& $string = substr($string, $savepos); \& $img\->write(file=>"page$pagenum.ppm"); \& } .Ve .IP \(bu 4 \&\f(CW\*(C`image\*(C'\fR \- The image to render the text to. Can be supplied as \&\f(CW\*(C`undef\*(C'\fR or not provided to simply calculate the bounding box. .IP \(bu 4 \&\f(CW\*(C`font\*(C'\fR \- The font used to render the text. Required. .IP \(bu 4 \&\f(CW\*(C`size\*(C'\fR \- The size to render the font in. Defaults to the size stored in the font object. Required if it isn't stored in the font object. .IP \(bu 4 \&\f(CW\*(C`string\*(C'\fR \- The text to render. This can contain non-white-space, blanks (ASCII 0x20), and newlines. .Sp Newlines must match /(?:\ex0A\ex0D?|\ex0D\ex0A?)/. White-space other than blanks and newlines are completely ignored. .IP \(bu 4 \&\f(CW\*(C`justify\*(C'\fR .Sp The way text is formatted within each line. Possible values include: .RS 4 .IP \(bu 4 \&\f(CW\*(C`left\*(C'\fR \- left aligned against the left edge of the text box. .IP \(bu 4 \&\f(CW\*(C`right\*(C'\fR \- right aligned against the right edge of the text box. .IP \(bu 4 \&\f(CW\*(C`center\*(C'\fR \- centered horizontally in the text box. .IP \(bu 4 fill \- all but the final line of the paragraph has spaces expanded so that the line fills from the left to the right edge of the text box. .RE .RS 4 .RE .IP \(bu 4 \&\f(CW\*(C`linegap\*(C'\fR \- Gap between lines of text in pixels. This is in addition to the size from \f(CW\*(C`$font\->font_height\*(C'\fR. Can be positive or negative. Default 0. .RE .RS 4 .Sp Any other parameters are passed onto Imager::Font\->\fBdraw()\fR. .Sp Returns a list: .Sp .Vb 1 \& ($left, $top, $right, $bottom) .Ve .Sp which are the bounds of the space used to layout the text. .Sp If \f(CW\*(C`height\*(C'\fR is set then this is the space used within that height. .Sp You can use this to calculate the space required to format the text before doing it: .Sp .Vb 9 \& my ($left, $top, $right, $bottom) = \& Imager::Font::Wrap\->wrap_text(string => $string, \& font => $font, \& width => $xsize); \& my $img = Imager\->new(xsize=>$xsize, ysize=>$bottom); \& Imager::Font::Wrap\->wrap_text(string => $string, \& font => $font, \& width => $xsize, \& image => $image); .Ve .RE .SH BUGS .IX Header "BUGS" Imager::Font can handle UTF\-8 encoded text itself, but this module doesn't support that (and probably won't). This could probably be done with regex magic. .PP Currently ignores the \f(CW\*(C`sizew\*(C'\fR parameter, if you supply one it will be supplied to the \fBdraw()\fR function and the text will be too short or too long for the \f(CW\*(C`width\*(C'\fR. .PP Uses a simplistic text model, which is why there's no hyphenation, and no tabs. .SH AUTHOR .IX Header "AUTHOR" Tony Cook .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBImager\fR\|(3), \fBImager::Font\fR\|(3)