# $Id: Text.pm,v 1.37 2003/06/19 00:13:10 mgjv Exp $
package GD::Text;
($GD::Text::prog_version) = '$Revision: 1.37 $' =~ /\s([\d.]+)/;
$GD::Text::VERSION = '0.86';
=head1 NAME
GD::Text - Text utilities for use with GD
=head1 SYNOPSIS
use GD;
use GD::Text;
my $gd_text = GD::Text->new() or die GD::Text::error();
$gd_text->set_font('funny.ttf', 12) or die $gd_text->error;
$gd_text->set_font(gdTinyFont);
$gd_text->set_font(GD::Font::Tiny);
...
$gd_text->set_text($string);
my ($w, $h) = $gd_text->get('width', 'height');
if ($gd_text->is_ttf)
{
...
}
Or alternatively
my $gd_text = GD::Text->new(
text => 'Some text',
font => 'funny.ttf',
ptsize => 14,
);
=head1 DESCRIPTION
This module provides a font-independent way of dealing with text in
GD, for use with the GD::Text::* modules and GD::Graph.
=head1 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 could 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.
If you want to refer to builtin GD fonts by their short name
(C<gdTinyFont>, C<gdGiantFont>), you will need to C<use> the GD module
as well as one the GD::Text modules, because it is GD that exports
those names into your name space. If you don't like that, use the
longer alternatives (C<GD::Font->Giant>) instead.
=head1 METHODS
=cut
use strict;
use GD;
use Carp;
use Cwd;
use vars qw($FONT_PATH @FONT_PATH $OS);
BEGIN
{
$FONT_PATH = $ENV{FONT_PATH} ||
$ENV{TTF_FONT_PATH} ||
$ENV{TT_FONT_PATH} || '';
unless ($OS = $^O)
{
require Config;
$OS = $Config::Config{'os_name'};
}
}
my $ERROR;
=head2 GD::Text->new( attrib => value, ... )
Create a new object. See the C<set()> method for attributes.
=cut
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {
type => 'builtin',
font => gdSmallFont,
ptsize => 10,
};
bless $self => $class;
$self->set(@_) or return;
=1= |