various fonts we look for.
%work = %{$self->{_style}{text}};
}
$work{font}
- or return $self->_error("$name has no font parameter");
+ or return $self->_error("$name has no font parameter");
$work{font} = $self->_get_thing("$name.font")
- or return $self->_error("invalid font");
+ or return $self->_error("No $name.font defined, either set $name.font or font to a font");
UNIVERSAL::isa($work{font}, "Imager::Font")
or return $self->_error("$name.font is not a font");
if ($work{color} && !ref $work{color}) {
sub _text_bbox {
my ($self, $text, $name) = @_;
- my %text_info = $self->_text_style($name);
+ my %text_info = $self->_text_style($name)
+ or return;
- if (!defined $text_info{font}) {
- die "No font or invalid font specified, and we're trying to draw text.\n";
- }
my @bbox = $text_info{font}->bounding_box(%text_info, string=>$text,
canon=>1);
my @sizes;
my @offsets;
for my $label (@$labels) {
- my @text_box = $self->_text_bbox($label, 'legend');
+ my @text_box = $self->_text_bbox($label, 'legend')
+ or return;
push(@sizes, \@text_box);
my $entry_width = $patchsize + $gap + $text_box[2];
if ($pos == 0) {
my ($width, $height) = (0,0);
my @sizes;
for my $label (@$labels) {
- my @box = $self->_text_bbox($label, 'legend');
+ my @box = $self->_text_bbox($label, 'legend')
+ or return;
push(@sizes, \@box);
$width = $box[2] if $box[2] > $width;
if ($minrowsize > $box[3]) {
my ($self, $img, $chart_box) = @_;
my $title = $self->{_style}{title}{text};
- my @box = $self->_text_bbox($title, 'title');
+ my @box = $self->_text_bbox($title, 'title')
+ or return;
my $yoff = $box[1];
@box[0,1] = (0,0);
$self->_align_box(\@box, $chart_box, 'title');
- my %text_info = $self->_text_style('title');
+ my %text_info = $self->_text_style('title')
+ or return;
$img->string(%text_info, x=>$box[0], 'y'=>$box[3] + $yoff, text=>$title);
$self->_remove_box($chart_box, \@box);
1;
elsif ($style->{features}{labels}) {
$item->{label} = 1;
}
- $item->{lbox} = [ $self->_text_bbox($item->{text}, 'label') ];
+ my @lbox = $self->_text_bbox($item->{text}, 'label')
+ or return;
+ $item->{lbox} = \@lbox;
if ($item->{label}) {
unless ($self->_fit_text(0, 0, 'label', $item->{text}, $guessradius,
$item->{begin}, $item->{end})) {
$item->{callout} = 1 if $style->{features}{allcallouts};
if ($item->{callout}) {
$item->{label} = 0;
- $item->{cbox} = [ $self->_text_bbox($item->{text}, 'callout') ];
+ my @cbox = $self->_text_bbox($item->{text}, 'callout')
+ or return;
+ $item->{cbox} = \@cbox;
$item->{cangle} = ($item->{begin} + $item->{end}) / 2;
my $dist = cos($item->{cangle}) * ($guessradius+
$callout_outside);
my $callout_inside = $radius - $self->_get_number('callout.inside');
$callout_outside += $radius;
- my %callout_text = $self->_text_style('callout');
- my %label_text = $self->_text_style('label');
+ my %callout_text = $self->_text_style('callout')
+ or return;
+ my %label_text = $self->_text_style('label')
+ or return;
for my $label (@info) {
if ($label->{label}) {
my @loc = $self->_fit_text($cx, $cy, 'label', $label->{text}, $radius,
}
else {
$label->{callout} = 1;
- $label->{cbox} = [ $self->_text_bbox($label->{text}, 'callout') ];
+ my @cbox = $self->_text_bbox($label->{text}, 'callout')
+ or return;
+ $label->{cbox} = \@cbox;
$label->{cangle} = ($label->{begin} + $label->{end}) / 2;
}
}
my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
my @labels = qw(alpha beta gamma delta epsilon phi gi);
-plan tests => 16;
+plan tests => 26;
my $pie = Imager::Graph::Pie->new;
ok($pie, "creating pie chart object");
cmpimg($img, 'testimg/t10_noother.png', 500_000);
}
+{ # RT #535
+ # no font parameter would crash
+ my $im = $pie->draw
+ (
+ data => \@data,
+ title => 'test',
+ );
+ ok(!$im, "should fail to produce titled graph with no font");
+ like($pie->error, qr/title\.font/, "message should mention which font");
+
+ $im = $pie->draw
+ (
+ labels => \@labels,
+ data => \@data,
+ features => [ 'legend' ],
+ );
+ ok(!$im, "should fail to produce legended graph with no font");
+ like($pie->error, qr/legend\.font/, "message should mention which font");
+
+ $im = $pie->draw
+ (
+ data => \@data,
+ labels => \@labels,
+ features => [ 'legend' ],
+ legend => { orientation => "horizontal" },
+ );
+ ok(!$im, "should fail to produce horizontal legended graph with no font");
+ like($pie->error, qr/legend\.font/, "message should mention which font");
+
+ $im = $pie->draw
+ (
+ data => \@data,
+ labels => \@labels,
+ );
+ ok(!$im, "should fail to produce labelled graph with no font");
+ like($pie->error, qr/label\.font/, "message should mention which font");
+
+ SKIP:
+ {
+ $font
+ or skip("No font to setup the callout font", 2);
+ $im = $pie->draw
+ (
+ data => \@data,
+ labels => \@labels,
+ features => [ 'allcallouts' ],
+ label => { font => $font },
+ );
+ ok(!$im, "should fail to produce callout labelled graph with no font");
+ like($pie->error, qr/callout\.font/, "message should mention which font");
+ }
+}
+
sub cmpimg {
my ($img, $file, $limit) = @_;