.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Imager::Font::Wrap 3pm" .TH Imager::Font::Wrap 3pm "2011-06-06" "perl v5.14.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 "\fIwrap_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 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 (\s-1ASCII\s0 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\->\fIdraw()\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 \s-1UTF\-8\s0 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 \fIdraw()\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" \&\fIImager\fR\|(3), \fIImager::Font\fR\|(3)