I'm writing a CGI script that returns PNG graphs (using GD and GD::Graph)
based on database queries, and everything works great so far except for
this one annoying bug...

I have a subroutine which generates a text string on the GD canvas. You can
pass it an argument that sets the fontsize for the string to be printed.
This argument corresponds to key values in a hash which maps the argument
to a built-in GD font-name. 

The problem comes when I try to use the set_font() method, using values
returned from this hash. For some reason, I can't seem to use a variable as
the argument for this method, as it just prints the string using
gdSmallFont when I do it that way...yet when I "hardcode" the fontname into
the method, it works just as expected:

        $align->set_font(gdGiantFont);            # works
        $align->set_font($fontsizes{$fontsize});  # doesn't

The wierd thing is that the method SHOULD be getting the correct value,
because, as you can see in my code below, the print statements I inserted
(for debugging purpose) both return the proper, expected values!

This is on a Linux box running Perl 5.005_03 & GD::Text 0.80. What gives?
Any ideas?

Code sample follows....Thanks in advance!

----
GD_print_text('IMPROVEMENT PRIORITY FOR', 'left', 50, 20, 'giant');
GD_print_text('CLASSROOM SYSTEMS', 'left', 50, 38, 'giant');
GD_print_text('Hokulani Elementary', 'right', 650, 20, 'giant');
GD_print_text('School Year 2000-2001', 'right', 650, 38, 'giant');
GD_print_text('Results generated', 'center', 650, 70, 'small');
GD_print_text('Low', 'left', 167, 343);  # (note undef 5th arg)

sub GD_print_text {

        my $textstring = $_[0];
        my $alignment  = $_[1];
        my $x          = $_[2];
        my $y          = $_[3];
        
        # set fontsize to gdSmallFont as default if no arg is passed.
        my $fontsize   = !defined($_[4]) ? "small" : $_[4];

#print $fontsize;  # prints out expected value when uncommented!!!

        my %fontsizes = ( tiny       => 'gdTinyFont',
                          small      => 'gdSmallFont',
                          mediumbold => 'gdMediumBoldFont',
                          large      => 'gdLargeFont',
                          giant      => 'gdGiantFont' );


        my $align = GD::Text::Align->new($gd_image, 
                                         valign => 'top', 
                                         halign => 'left', 
                                         color  => $gd_black);
        $align->set_text($textstring);
        $align->set_halign($alignment);
        $align->set_valign('top'); 
         # $align->set_font(gdGiantFont);  # works when value is hardcoded...
        $align->set_font($fontsizes{$fontsize});  # but doesn't work when
it isnt.
        $align->draw($x,$y); 

#print $fontsizes{$fontsize}; # yet this prints out the correct & expected 
                                 # value when uncommented!!!
}
---------------


--
mel matsuoka                    Hawaiian Image Productions
Chief Executive Alphageek              (vox)1.808.531.5474
[EMAIL PROTECTED]                  (fax)1.808.526.4040

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to