| 1 | # $File: //member/autrijus/DBIx-ReportBuilder/lib/DBIx/ReportBuilder/Graph.pm $ $Author: autrijus $ | ||
| 2 | # $Revision: #5 $ $Change: 8390 $ $DateTime: 2003/10/12 16:53:29 $ | ||
| 3 | |||
| 4 | package DBIx::ReportBuilder::Graph; | ||
| 5 | |||
| 6 | =head1 SYNOPSIS | ||
| 7 | |||
| 8 | my $graph = DBIx::ReportBuilder::Graph->new( | ||
| 9 | shape => 'bars', | ||
| 10 | width => 100, | ||
| 11 | height => 100, | ||
| 12 | ); | ||
| 13 | open OUT, ">out.png" or die $!; | ||
| 14 | print OUT $graph->Plot([[ 'a' .. 'c' ], [ 1 .. 3 ]]); | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | |||
| 20 | sub new { | ||
| 21 | my ($class, %args) = @_; | ||
| 22 | my $pkg = __PACKAGE__ . '::'. ( $args{class} ||= 'GD' ); | ||
| 23 | my $file = $pkg; | ||
| 24 | $file =~ s{::}{/}g; | ||
| 25 | require "$file.pm"; | ||
| 26 | return $pkg->new(%args); | ||
| 27 | } | ||
| 28 | |||
| 29 | sub escape { | ||
| 30 | my $self = shift; | ||
| 31 | return $_[0] if $] < 5.007003 or !(defined($_[0]) and length($_[0])); | ||
| 32 | |||
| 33 | my $text = shift; | ||
| 34 | require Encode; | ||
| 35 | Encode::_utf8_on($text); | ||
| 36 | return Encode::encode(ascii => $text, Encode::FB_HTMLCREF()); | ||
| 37 | |||
| 38 | return $text; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub ttf_path { | ||
| 42 | return '/usr/local/share/fonts/TrueType' unless $^O eq 'MSWin32'; | ||
| 43 | return '/Progra~1/OurInternet/Common/fonts/truetype/arphic'; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub ttf_file { | ||
| 47 | my ($self, $font) = @_; | ||
| 48 | my $rv = $self->ttf_path . '/' . $font; | ||
| 49 | |||
| 50 | die "can't find $rv" unless -r $rv; | ||
| 51 | return $rv unless $^O eq 'MSWin32'; | ||
| 52 | |||
| 53 | $rv = Win32::GetFullPathName($rv); | ||
| 54 | $rv =~ s|\\|/|g; | ||
| 55 | $rv =~ s|^\w:||; | ||
| 56 | return $rv; | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; |