Text::Wrap(3)
π NAME π
okay bestie, welcome to the Text::Wrap(3) manual page β itβs part of User Contributed Perl Documentation, manual name folded in like a lil name tag π. The module being described is GD::Text::Wrap, and its whole gig is wrap strings in boxes β¨.
πΈ SYNOPSIS πΈ
okay so hereβs the vibe in code, literally copy-paste energy:
use GD;
use GD::Text::Wrap;
my $gd = GD::Image->new(800,600);
# allocate colours, do other things.
my $text = <<EOSTR;
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore
magna aliquam erat volutpat.
EOSTR
my $wrapbox = GDTextWrap->new( $gd,
line_space => 4,
color => $black,
text => $text,
);
$wrapbox->set_font(gdMediumBoldFont);
$wrapbox->set_font('arial', 12);
$wrapbox->set(align => 'left', width => 120);
$wrapbox->draw(10,140);
$gd->rectangle($wrap_box->get_bounds(10,140), $color);
π¦ DESCRIPTION π¦
GD::Text::Wrap gives you an object that draws a formatted paragraph of text in a box on a GD::Image canvas π¨. It can use either a builtin GD font or a TrueType font. iconic.
π METHODS π
This class doesnβt inherit from GD::Text directly, bestie β it delegates most of its work to one (in fact, to a GD::Text::Align object) π«Ά. That means most of the GD::Text::Align methods are available for this class, specifically set_font and font_path. The other methods, plus the ones with a different interface, are described right here:
π§ GD::Text::Wrap->new( $gd_object, attribute => value, ... )
Create a new object. The first argument to new has to be a valid GD::Image object. The other arguments will be passed to the set() method for initialisation of the attributes. slay.
π $wrapbox->set( attribute => value, ... )
Set the value for an attribute. Valid attributes are:
widthβ the width of the box to draw the text in. If unspecified, it will default to the width of theGD::Imageobject. πline_spaceβ the number of pixels between lines. Defaults to2.para_space,paragraph_spaceβ the number of extra pixels between paragraphs, aboveline_space. Defaults to0.color,colourβ synonyms. The colour to use when drawing the font. Will be initialised to the last colour in the GD objectβs palette. π¨align,alignmentβ synonyms. One of'justified'(the default),'left','right'or'center'.textβ the text to draw. This is the only attribute that you absolutely have to set. π₯preserve_nlβ if set to a true value, newlines in the text will cause a line break. Note that lines will still be justified. If only one word appears on the line, it could get ugly. Defaults to0.
As with the methods, attributes unknown to this class get delegated to the GD::Text::Align class.
π $wrapbox->get( attribute );
Get the current value of an attribute. All attributes mentioned under the set() method can be retrieved.
π $wrapbox->get_bounds()
Returns the bounding box of the box that will be drawn with the current attribute settings as a list. The values returned are the coordinates of the upper left and lower right corner.
($left, $top, $right, $bottom) = $wrapbox->get_bounds();
Returns an empty list on error.
NOTE: The return list of this method may change in a future implementation that allows angled boxes. π
β $wrapbox->draw(x, y)
Draw the box, with (x,y) as the top right corner. Returns the same values as the getbounds() method.
NOTE: The return list of this method may change in a future implementation that allows angled boxes. π
π NOTES π
As with all Modules for Perl: please stick to using the interface. If you try to fiddle too much with knowledge of the internals of this module, you may get burned π₯. I may change them at any time.
You can only use TrueType fonts with version of GD > 1.20, and then only if compiled with support for this. If you attempt to do it anyway, you will get errors. no cap.
Even though this module lives in the GD::Text namespace, it is not a GD::Text. It does however delegate a lot of its functionality to a contained object that is one (GD::Text::Align). π«Ά
π BUGS π
None that I know of, but that doesnβt mean much. There may be some problems with exotic fonts, or locales and character encodings that I am not used to. bestie, exotic fonts are mysterious.
β¨ TODO β¨
- Angled boxes.
- At the moment, the only bit of the box that is allowed to be unspecified and in fact must be unspecified, is the bottom. If there is enough need for it, I might implement more flexibility, in that you need to only specify three of the four sides of the box, and the fourth will be calculated.
- Automatic resizing of a TrueType font to fit inside a box when four sides are specified, or maybe some other nifty things.
- More flexibility in the interface. Especially
drawneeds some thought. - More and better error handling.
- Warnings for lines that are too long and stick out of the box. Warning for emptyish lines?
π COPYRIGHT π
copyright 1999 Martien Verbruggen (mgjv@comdyn.com.au)
π SEE ALSO π
GDGD::TextGD::Text::Align
okay bye bestie π this page came from perl v5.42.0, dated 2018-03-13 β and yes, itβs the Text::Wrap(3) manual page. mwah π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-GDTextUtil 0.86-bp160.1.12 Β· Artistic-1.0 OR GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms