| 1 |
package Imager::Font::Test; |
| 2 |
use 5.006; |
| 3 |
use strict; |
| 4 |
|
| 5 |
our $VERSION = "1.002"; |
| 6 |
|
| 7 |
use base 'Imager::Font'; |
| 8 |
|
| 9 |
sub new { |
| 10 |
my ($class, %opts) = @_; |
| 11 |
|
| 12 |
bless \%opts, shift; |
| 13 |
} |
| 14 |
|
| 15 |
sub _draw { |
| 16 |
my ($self, %input) = @_; |
| 17 |
|
| 18 |
my $text = $input{string}; |
| 19 |
|
| 20 |
my $ppn = int($input{size} * 0.5 + 0.5); |
| 21 |
my $desc = int($input{size} * 0.3 + 0.5); |
| 22 |
my $asc = $input{size} - $desc; |
| 23 |
my $width = $ppn * length $text; |
| 24 |
my $x = $input{x}; |
| 25 |
my $y = $input{'y'}; |
| 26 |
$input{align} and $y -= $asc; |
| 27 |
|
| 28 |
$input{image}->box(color => $input{color}, xmin => $x, ymin => $y, |
| 29 |
xmax => $x + $width-1, ymax => $y + $input{size} - 1); |
| 30 |
|
| 31 |
return 1; |
| 32 |
} |
| 33 |
|
| 34 |
sub _bounding_box { |
| 35 |
my ($self, %input) = @_; |
| 36 |
|
| 37 |
my $text = $input{string}; |
| 38 |
|
| 39 |
my $ppn = int($input{size} * 0.5 + 0.5); |
| 40 |
my $desc = int($input{size} * 0.3 + 0.5); |
| 41 |
my $asc = $input{size} - $desc; |
| 42 |
|
| 43 |
return ( 0, -$desc, $ppn * length $text, $asc, -$desc, $asc, $ppn * length $text, 0 ); |
| 44 |
} |
| 45 |
|
| 46 |
sub has_chars { |
| 47 |
my ($self, %input) = @_; |
| 48 |
|
| 49 |
my $text = $input{string}; |
| 50 |
defined $text |
| 51 |
or return Imager->_set_error("has_chars: No string parameter supplied"); |
| 52 |
|
| 53 |
return (1) x length $text; |
| 54 |
} |
| 55 |
|
| 56 |
sub face_name { |
| 57 |
"test"; |
| 58 |
} |
| 59 |
|
| 60 |
sub glyph_names { |
| 61 |
my ($self, %input) = @_; |
| 62 |
|
| 63 |
my $text = $input{string}; |
| 64 |
defined $text |
| 65 |
or return Imager->_set_error("glyph_names: No string parameter supplied"); |
| 66 |
|
| 67 |
return (1) x length $text; |
| 68 |
} |
| 69 |
|
| 70 |
1; |
| 71 |
|
| 72 |
=head1 NAME |
| 73 |
|
| 74 |
Imager::Font::Test - font driver producing consistent output for tests. |
| 75 |
|
| 76 |
=head1 SYNOPSIS |
| 77 |
|
| 78 |
my $font = Imager::Font::Test->new; |
| 79 |
|
| 80 |
# use $font where you use other fonts |
| 81 |
|
| 82 |
=head1 DESCRIPTION |
| 83 |
|
| 84 |
Imager::Font::Test is intended to produce consistent output without |
| 85 |
being subject to the inconsistent output produced by different |
| 86 |
versions of font libraries. |
| 87 |
|
| 88 |
The output is simple box for the whole string. |
| 89 |
|
| 90 |
=head1 AUTHOR |
| 91 |
|
| 92 |
Tony Cook <[email protected]> |
| 93 |
|
| 94 |
=cut |
| 95 |
|