create the test font driver, use it, and update the test comparison
authorTony Cook <tony@develop-help.com>
Mon, 17 Dec 2007 08:08:11 +0000 (08:08 +0000)
committerTony Cook <tony@develop-help.com>
Mon, 17 Dec 2007 08:08:11 +0000 (08:08 +0000)
images

t/lib/Imager/Font/Test.pm [new file with mode: 0644]
t/t10pie.t
testimg/t10_lin_fount.png
testimg/t10_mono.png
testimg/t10_pie1.png
testimg/t10_pie2.png
testimg/t10_rad_fount.png

diff --git a/t/lib/Imager/Font/Test.pm b/t/lib/Imager/Font/Test.pm
new file mode 100644 (file)
index 0000000..74de23d
--- /dev/null
@@ -0,0 +1,90 @@
+package Imager::Font::Test;
+use strict;
+
+use base 'Imager::Font';
+
+sub new {
+  my ($class, %opts) = @_;
+
+  bless \%opts, shift;
+}
+
+sub _draw {
+  my ($self, %input) = @_;
+
+  my $text = $input{string};
+
+  my $ppn = int($input{size} * 0.5 + 0.5);
+  my $desc = int($input{size} * 0.3 + 0.5);
+  my $asc = $input{size} - $desc;
+  my $width = $ppn * length $text;
+  my $x = $input{x};
+  my $y = $input{'y'};
+  $input{align} and $y -= $asc;
+
+  $input{image}->box(color => $input{color}, xmin => $x, ymin => $y,
+                    xmax => $x + $width-1, ymax => $y + $input{size} - 1);
+
+  return 1;
+}
+
+sub _bounding_box {
+  my ($self, %input) = @_;
+
+  my $text = $input{string};
+
+  my $ppn = int($input{size} * 0.5 + 0.5);
+  my $desc = int($input{size} * 0.3 + 0.5);
+  my $asc = $input{size} - $desc;
+
+  return ( 0, -$desc, $ppn * length $text, $asc, -$desc, $asc, $ppn * length $text, 0 );
+}
+
+sub has_chars {
+  my ($self, %input) = @_;
+
+  my $text = $input{string};
+  defined $text
+    or return Imager->_set_error("has_chars: No string parameter supplied");
+
+  return (1) x length $text;
+}
+
+sub face_name {
+  "test";
+}
+
+sub glyph_names {
+  my ($self, %input) = @_;
+
+  my $text = $input{string};
+  defined $text
+    or return Imager->_set_error("glyph_names: No string parameter supplied");
+
+  return (1) x length $text;
+}
+
+1;
+
+=head1 NAME'
+
+Imager::Font::Test - font driver producing consistent output for tests.
+
+=head1 SYNOPSIS
+
+  my $font = Imager::Font::Test->new;
+
+  # use $font where you use other fonts
+
+=head1 DESCRIPTION
+
+Imager::Font::Test is intended to produce consistent output without
+being subject to the inconsistent output produced by different
+versions of font libraries.
+
+=head1 AUTHOR
+
+Tony Cook <tony@imager.perl.org>
+
+=cut
+
index 61cf7f6f35168dab3e7ad3f620bb67809d83daf6..95204232a6d0925067c1650264d6ac9130d0a3a1 100644 (file)
@@ -1,6 +1,8 @@
 #!perl -w
 use strict;
 use Imager::Graph::Pie;
+use lib 't/lib';
+use Imager::Font::Test;
 use Test::More;
 
 -d 'testout' 
@@ -13,9 +15,10 @@ my $testnum = 1;
 
 use Imager qw(:handy);
 
-my $fontfile = 'ImUgly.ttf';
-my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
-  or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
+#my $fontfile = 'ImUgly.ttf';
+#my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
+#  or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
+my $font = Imager::Font::Test->new();
 
 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
 my @labels = qw(alpha beta gamma delta epsilon phi gi);
index 4b5985e2c7bda89cb8b7b0de7cb27957d94d34bc..06d82a76756577a8e5078f5c472b6c7b0e84094d 100644 (file)
Binary files a/testimg/t10_lin_fount.png and b/testimg/t10_lin_fount.png differ
index 52ed5a76ce54734012c6608a133d655b5824400e..dfa0ce62dd203d2c752a0aa025e0e79199c9360b 100644 (file)
Binary files a/testimg/t10_mono.png and b/testimg/t10_mono.png differ
index ca070ec235da06355a878bda6c81c3b5a68264f3..9675de4c49e7c27bf47e98c7120decc710bb32f6 100644 (file)
Binary files a/testimg/t10_pie1.png and b/testimg/t10_pie1.png differ
index 68b3b10cf885d70a11ce820af90e718f7d4f9cd0..59c45bf623122429d020fa0c11a2f7d57b5dd90b 100644 (file)
Binary files a/testimg/t10_pie2.png and b/testimg/t10_pie2.png differ
index 2309549a6274a9f0c27bdb160d6a888c9f4e45ef..8ac0d5b396a7344816885a02ee4a24d4eeb812f8 100644 (file)
Binary files a/testimg/t10_rad_fount.png and b/testimg/t10_rad_fount.png differ