NAME
GD::Text::Wrap - Wrap strings in boxes
SYNOPSIS
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('cetus.ttf', 12);
$wrapbox->set(align => 'left', width => 120);
$wrapbox->draw(10,140);
$gd->rectangle($wrap_box->get_bounds(10,140), $color);
DESCRIPTION
GD::Text::Wrap provides an object that draws a formatted paragraph of text in a box on a GD::Image canvas, using either a builtin GD font or a TrueType font.
METHODS
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.
$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, they will default to the width of the GD::Image object.
- line_space
-
The number of pixels between lines. Defaults to 2.
- 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.
$wrapbox->get( attribute );
Get the current value of an attribute. All attributes mentioned under the set()
method can be retrieved
$wrapbox->set_font( font attributes );
Set the font to use for this string. The arguments are either a GD builtin font (like gdSmallFont or GD::Font->Small) or the name of a TrueType font file and the size of the font to use. See also the set_font()
method in GD::Text.
Returns true on success, and undef on an error. if an error is returned, $@ will contain an error message.
$wrap_box->can_do_ttf()
Return true if this object can handle TTF fonts. See also the can_do_ttf()
method in GD::Text.
$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.
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.
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 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 draw needs some thought.
More and better error handling.
Better handling of GD version before and after 1.20. This may be by delegation to GD::Text.
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
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 153:
You forgot a '=back' before '=head2'