]> git.imager.perl.org - imager-graph.git/commitdiff
define new style settings text.aa, lineaa and fill.aa each based on
authorTony Cook <tony@develop-help.com>
Tue, 14 Apr 2009 09:18:55 +0000 (09:18 +0000)
committerTony Cook <tony@develop-help.com>
Tue, 14 Apr 2009 09:18:55 +0000 (09:18 +0000)
the top level "aa" style.  Each text style depends on text.aa, each
line style depends on lineaa.

add _line_style() to populate a hash similar in concept to that used
by by _text_style(), so we can easily support pens and thick lines
from future Imager

Graph.pm
lib/Imager/Graph/Pie.pm
lib/Imager/Graph/Vertical.pm
testimg/t10_mono.png
testimg/t10_noother.png

index d8c43099dfbddd40d87e3d70a8ebe4767badf780..8c6b1ec688589f2a7bb59c0c4a8a667c2da1b593 100644 (file)
--- a/Graph.pm
+++ b/Graph.pm
@@ -1151,10 +1151,12 @@ my %style_defs =
   (
    back=> 'lookup(bg)',
    line=> 'lookup(fg)',
   (
    back=> 'lookup(bg)',
    line=> 'lookup(fg)',
+   aa => 1,
    text=>{
           color => 'lookup(fg)',
           font  => 'lookup(font)',
           size  => 14,
    text=>{
           color => 'lookup(fg)',
           font  => 'lookup(font)',
           size  => 14,
+         aa    => 'lookup(aa)',
          },
    title=>{ 
            color  => 'lookup(text.color)', 
          },
    title=>{ 
            color  => 'lookup(text.color)', 
@@ -1162,10 +1164,12 @@ my %style_defs =
            halign => 'center', 
            valign => 'top',
            size   => 'scale(text.size,2.0)',
            halign => 'center', 
            valign => 'top',
            size   => 'scale(text.size,2.0)',
+          aa     => 'lookup(text.aa)',
           },
    legend =>{
              color          => 'lookup(text.color)',
              font           => 'lookup(text.font)',
           },
    legend =>{
              color          => 'lookup(text.color)',
              font           => 'lookup(text.font)',
+            aa             => 'lookup(text.aa)',
              size           => 'lookup(text.size)',
              patchsize      => 'scale(legend.size,0.9)',
              patchgap       => 'scale(legend.patchsize,0.3)',
              size           => 'lookup(text.size)',
              patchsize      => 'scale(legend.size,0.9)',
              patchgap       => 'scale(legend.patchsize,0.3)',
@@ -1184,6 +1188,8 @@ my %style_defs =
                outside  => 'lookup(callout.size)',
                leadlen  => 'scale(0.8,callout.size)',
                gap      => 'scale(callout.size,0.3)',
                outside  => 'lookup(callout.size)',
                leadlen  => 'scale(0.8,callout.size)',
                gap      => 'scale(callout.size,0.3)',
+              aa       => 'lookup(text.aa)',
+              lineaa   => 'lookup(lineaa)',
               },
    label => {
              font          => 'lookup(text.font)',
               },
    label => {
              font          => 'lookup(text.font)',
@@ -1194,6 +1200,8 @@ my %style_defs =
              pad           => 'scale(label.size,0.2)',
              pcformat      => sub { sprintf "%s (%.0f%%)", $_[0], $_[1] },
              pconlyformat  => sub { sprintf "%.1f%%", $_[0] },
              pad           => 'scale(label.size,0.2)',
              pcformat      => sub { sprintf "%s (%.0f%%)", $_[0], $_[1] },
              pconlyformat  => sub { sprintf "%.1f%%", $_[0] },
+            aa            => 'lookup(text.aa)',
+            lineaa        => 'lookup(lineaa)',
              },
    dropshadow => {
                   fill    => { solid => Imager::Color->new(0, 0, 0, 96) },
              },
    dropshadow => {
                   fill    => { solid => Imager::Color->new(0, 0, 0, 96) },
@@ -1207,10 +1215,18 @@ my %style_defs =
                  },
    outline => {
                line =>'lookup(line)',
                  },
    outline => {
                line =>'lookup(line)',
+              lineaa => 'lookup(lineaa)',
               },
    size=>256,
    width=>'scale(1.5,size)',
    height=>'lookup(size)',
               },
    size=>256,
    width=>'scale(1.5,size)',
    height=>'lookup(size)',
+
+   # yes, the handling of fill and line AA is inconsistent, lack of
+   # forethought, unfortunately
+   fill => {
+           aa => 'lookup(aa)',
+          },
+   lineaa => 'lookup(aa)',
   );
 
 =item _error($message)
   );
 
 =item _error($message)
@@ -1306,6 +1322,7 @@ my %styles =
     pie =>{
            blur=>undef,
           },
     pie =>{
            blur=>undef,
           },
+    aa => 0,
    },
    fount_lin =>
    {
    },
    fount_lin =>
    {
@@ -1877,6 +1894,9 @@ and draw() methods intended for use in defining text styles.
 
 Returns an empty list on failure.
 
 
 Returns an empty list on failure.
 
+Returns the following attributes: font, color, size, aa, sizew
+(optionally)
+
 =cut
 
 sub _text_style {
 =cut
 
 sub _text_style {
@@ -1904,6 +1924,7 @@ sub _text_style {
   $work{size} = $self->_get_number("$name.size");
   $work{sizew} = $self->_get_number("$name.sizew")
     if $work{sizew};
   $work{size} = $self->_get_number("$name.size");
   $work{sizew} = $self->_get_number("$name.sizew")
     if $work{sizew};
+  $work{aa} = $self->_get_number("$name.aa");
 
   %work;
 }
 
   %work;
 }
@@ -1928,6 +1949,28 @@ sub _text_bbox {
   return @bbox[0..3];
 }
 
   return @bbox[0..3];
 }
 
+=item _line_style($name)
+
+Return parameters suitable for calls to Imager's line(), polyline(),
+and box() methods.
+
+For now this returns only color and aa parameters, but future releases
+of Imager may support extra parameters.
+
+=cut
+
+sub _line_style {
+  my ($self, $name) = @_;
+
+  my %line;
+  $line{color} = $self->_get_color("$name.line")
+    or return;
+  $line{aa} = $self->_get_number("$name.lineaa");
+  defined $line{aa} or $line{aa} = $self->_get_number("aa");
+
+  return %line;
+}
+
 sub _align_box {
   my ($self, $box, $chart_box, $name) = @_;
 
 sub _align_box {
   my ($self, $box, $chart_box, $name) = @_;
 
index 26caa768639d7a154b8b320304a5852cc6998c43..5a190d7fae0314ba793584659ad162f001642085 100644 (file)
@@ -373,30 +373,31 @@ sub draw {
   }
 
   my @fill_box = ( $cx-$radius, $cy-$radius, $cx+$radius, $cy+$radius );
   }
 
   my @fill_box = ( $cx-$radius, $cy-$radius, $cx+$radius, $cy+$radius );
+  my $fill_aa = $self->_get_number('fill.aa');
   for my $item (@info) {
     $item->{begin} < $item->{end}
       or next;
     my @fill = $self->_data_fill($item->{index}, \@fill_box)
       or return;
   for my $item (@info) {
     $item->{begin} < $item->{end}
       or next;
     my @fill = $self->_data_fill($item->{index}, \@fill_box)
       or return;
-    $img->arc(x=>$cx, 'y'=>$cy, r=>$radius, aa => 1,
+    $img->arc(x=>$cx, 'y'=>$cy, r=>$radius, aa => $fill_aa,
               d1=>180/PI * $item->{begin}, d2=>180/PI * $item->{end},
               @fill);
   }
   if ($style->{features}{outline}) {
               d1=>180/PI * $item->{begin}, d2=>180/PI * $item->{end},
               @fill);
   }
   if ($style->{features}{outline}) {
-    my $outcolor = $self->_get_color('outline.line');
+    my %outstyle = $self->_line_style('outline');
+    my $out_radius = 0.5 + $radius;
     for my $item (@info) {
     for my $item (@info) {
-      my $px = int($cx + $radius * cos($item->{begin}));
-      my $py = int($cy + $radius * sin($item->{begin}));
+      my $px = int($cx + $out_radius * cos($item->{begin}));
+      my $py = int($cy + $out_radius * sin($item->{begin}));
       $item->{begin} < $item->{end}
         or next;
       $item->{begin} < $item->{end}
         or next;
-      $img->line(x1=>$cx, y1=>$cy, x2=>$px, y2=>$py, color=>$outcolor);
+      $img->line(x1=>$cx, y1=>$cy, x2=>$px, y2=>$py, %outstyle);
       for (my $i = $item->{begin}; $i < $item->{end}; $i += PI/180) {
         my $stroke_end = $i + PI/180;
         $stroke_end = $item->{end} if $stroke_end > $item->{end};
       for (my $i = $item->{begin}; $i < $item->{end}; $i += PI/180) {
         my $stroke_end = $i + PI/180;
         $stroke_end = $item->{end} if $stroke_end > $item->{end};
-        my $nx = int($cx + $radius * cos($stroke_end));
-        my $ny = int($cy + $radius * sin($stroke_end));
-        $img->line(x1=>$px, y1=>$py, x2=>$nx, y2=>$ny, color=>$outcolor,
-                  antialias=>1);
+        my $nx = int($cx + $out_radius * cos($stroke_end));
+        my $ny = int($cy + $out_radius * sin($stroke_end));
+        $img->line(x1=>$px, y1=>$py, x2=>$nx, y2=>$ny, %outstyle);
         ($px, $py) = ($nx, $ny);
       }
     }
         ($px, $py) = ($nx, $ny);
       }
     }
@@ -406,6 +407,8 @@ sub draw {
   $callout_outside += $radius;
   my %callout_text;
   my %label_text;
   $callout_outside += $radius;
   my %callout_text;
   my %label_text;
+  my %callout_line;
+  my $leader_aa = $self->_get_number('callout.leadaa');
   for my $label (@info) {
     if ($label->{label} && !$label->{callout}) {
       # at this point we know we need the label font, to calculate
   for my $label (@info) {
     if ($label->{label} && !$label->{callout}) {
       # at this point we know we need the label font, to calculate
@@ -423,7 +426,7 @@ sub draw {
         #          color=>Imager::Color->new(0,0,0));
         $img->string(%label_text, x=>$tcx-$label->{lbox}[2]/2,
                      'y'=>$tcy+$label->{lbox}[3]/2+$label->{lbox}[1],
         #          color=>Imager::Color->new(0,0,0));
         $img->string(%label_text, x=>$tcx-$label->{lbox}[2]/2,
                      'y'=>$tcy+$label->{lbox}[3]/2+$label->{lbox}[1],
-                     text=>$label->{text}, aa => 1);
+                     text=>$label->{text});
       }
       else {
         $label->{callout} = 1;
       }
       else {
         $label->{callout} = 1;
@@ -437,25 +440,26 @@ sub draw {
       unless (%callout_text) {
         %callout_text = $self->_text_style('callout')
           or return;
       unless (%callout_text) {
         %callout_text = $self->_text_style('callout')
           or return;
+       %callout_line = $self->_line_style('callout');
       }
       my $ix = floor(0.5 + $cx + $callout_inside * cos($label->{cangle}));
       my $iy = floor(0.5 + $cy + $callout_inside * sin($label->{cangle}));
       my $ox = floor(0.5 + $cx + $callout_outside * cos($label->{cangle}));
       my $oy = floor(0.5 + $cy + $callout_outside * sin($label->{cangle}));
       my $lx = ($ox < $cx) ? $ox - $callout_leadlen : $ox + $callout_leadlen;
       }
       my $ix = floor(0.5 + $cx + $callout_inside * cos($label->{cangle}));
       my $iy = floor(0.5 + $cy + $callout_inside * sin($label->{cangle}));
       my $ox = floor(0.5 + $cx + $callout_outside * cos($label->{cangle}));
       my $oy = floor(0.5 + $cy + $callout_outside * sin($label->{cangle}));
       my $lx = ($ox < $cx) ? $ox - $callout_leadlen : $ox + $callout_leadlen;
-      $img->line(x1=>$ix, y1=>$iy, x2=>$ox, y2=>$oy, antialias=>1,
-                 color=>$self->_get_color('callout.color'));
-      $img->line(x1=>$ox, y1=>$oy, x2=>$lx, y2=>$oy, antialias=>1,
-                 color=>$self->_get_color('callout.color'));
+      $img->polyline(points => [ [ $ix, $iy ],
+                                [ $ox, $oy ],
+                                [ $lx, $oy ] ],
+                    %callout_line);
       #my $tx = $lx + $callout_gap;
       my $ty = $oy + $label->{cbox}[3]/2+$label->{cbox}[1];
       if ($lx < $cx) {
         $img->string(%callout_text, x=>$lx-$callout_gap-$label->{cbox}[2], 
       #my $tx = $lx + $callout_gap;
       my $ty = $oy + $label->{cbox}[3]/2+$label->{cbox}[1];
       if ($lx < $cx) {
         $img->string(%callout_text, x=>$lx-$callout_gap-$label->{cbox}[2], 
-                     'y'=>$ty, text=>$label->{text}, aa=>1);
+                     'y'=>$ty, text=>$label->{text});
       }
       else {
         $img->string(%callout_text, x=>$lx+$callout_gap, 'y'=>$ty, 
       }
       else {
         $img->string(%callout_text, x=>$lx+$callout_gap, 'y'=>$ty, 
-                     text=>$label->{text}, aa=>1);
+                     text=>$label->{text});
       }
     }
   }
       }
     }
   }
index 89b3da891c46636076f37f27b7064b2fc1c43a9f..1615fcf11fa5c82327384991d754d586ac3dceb7 100644 (file)
@@ -458,6 +458,7 @@ sub _draw_lines {
   my $col_width = int($size / $column_count) -1;
   my $graph_width = $col_width * $column_count + 1;
 
   my $col_width = int($size / $column_count) -1;
   my $graph_width = $col_width * $column_count + 1;
 
+  my $line_aa = $self->_get_number("lineaa");
   foreach my $series (@$line_series) {
     my @data = @{$series->{'data'}};
     my $data_size = scalar @data;
   foreach my $series (@$line_series) {
     my @data = @{$series->{'data'}};
     my $data_size = scalar @data;
@@ -484,7 +485,7 @@ sub _draw_lines {
       my $y2 = $bottom + ($value_range - $data[$i + 1] + $min_value)/$value_range * $size;
 
       push @marker_positions, [$x1, $y1];
       my $y2 = $bottom + ($value_range - $data[$i + 1] + $min_value)/$value_range * $size;
 
       push @marker_positions, [$x1, $y1];
-      $img->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2, aa => 1, color => $color) || die $img->errstr;
+      $img->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2, aa => $line_aa, color => $color) || die $img->errstr;
     }
 
     my $x2 = $left + ($data_size - 1) * $interval;
     }
 
     my $x2 = $left + ($data_size - 1) * $interval;
@@ -527,9 +528,11 @@ sub _draw_line_marker {
   my $type = $style->{'shape'};
   my $radius = $style->{'radius'};
 
   my $type = $style->{'shape'};
   my $radius = $style->{'radius'};
 
+  my $line_aa = $self->_get_number("lineaa");
+  my $fill_aa = $self->_get_number("fill.aa");
   if ($type eq 'circle') {
     my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
   if ($type eq 'circle') {
     my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
-    $img->circle(x => $x1, y => $y1, r => $radius, aa => 1, filled => 1, @fill);
+    $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
   }
   elsif ($type eq 'square') {
     my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
   }
   elsif ($type eq 'square') {
     my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
@@ -545,7 +548,7 @@ sub _draw_line_marker {
                     [$x1 + $radius, $y1],
                     [$x1, $y1 - $radius],
                   ],
                     [$x1 + $radius, $y1],
                     [$x1, $y1 - $radius],
                   ],
-        filled => 1, color => $color, aa => 1);
+        filled => 1, color => $color, aa => $fill_aa);
   }
   elsif ($type eq 'triangle') {
     # The gradient really doesn't work for triangle
   }
   elsif ($type eq 'triangle') {
     # The gradient really doesn't work for triangle
@@ -556,18 +559,18 @@ sub _draw_line_marker {
                     [$x1 + $radius, $y1 + $radius],
                     [$x1, $y1 - $radius],
                   ],
                     [$x1 + $radius, $y1 + $radius],
                     [$x1, $y1 - $radius],
                   ],
-        filled => 1, color => $color, aa => 1);
+        filled => 1, color => $color, aa => $fill_aa);
 
   }
   elsif ($type eq 'x') {
     my $color = $self->_data_color($series_counter);
 
   }
   elsif ($type eq 'x') {
     my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => 1, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => 1, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
   }
   elsif ($type eq 'plus') {
     my $color = $self->_data_color($series_counter);
   }
   elsif ($type eq 'plus') {
     my $color = $self->_data_color($series_counter);
-    $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => 1, color => $color) || die $img->errstr;
-    $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => 1, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
+    $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
   }
 }
 
   }
 }
 
index 31f40071900d2a61f6483675f09738fc76be03c2..d4474aef798c34e44d1fabc0f3d098f4c1e21d89 100644 (file)
Binary files a/testimg/t10_mono.png and b/testimg/t10_mono.png differ
index e468ecfd9aec835360aa5b5c88de26166e255602..53732f685ff1937ee02335f48e0a750166fe7000 100644 (file)
Binary files a/testimg/t10_noother.png and b/testimg/t10_noother.png differ