/
Test.pm
92 lines (60 loc) · 1.73 KB
/
Test.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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.
The output is simple box for the whole string.
=head1 AUTHOR
Tony Cook <tonyc@cpan.org>
=cut