| 1 | package PDF::Boxer::Content::Image; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 3 | $PDF::Boxer::Content::Image::VERSION = '0.004'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | 3 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | # ABSTRACT: a box that displays an image | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | extends 'PDF::Boxer::Content::Box'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 3 | has 'src' => ( isa => 'Str', is => 'ro' ); | |||||||||||||||||||
| 13 | 3 | has 'scale' => ( isa => 'Num', is => 'ro' ); | |||||||||||||||||||
| 14 | 3 | has 'format' => ( isa => 'Str', is => 'ro', lazy_build => 1 ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | has 'image' => ( is => 'rw', lazy_build => 1 ); | |||||||||||||||||||
| 17 | 3 | has 'image_width' => ( isa => 'Int', is => 'rw', lazy_build => 1 ); | |||||||||||||||||||
| 18 | 3 | has 'image_height' => ( isa => 'Int', is => 'rw', lazy_build => 1 ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 3 | has 'align' => ( isa => 'Str', is => 'ro' ); | |||||||||||||||||||
| 21 | 3 | has 'valign' => ( isa => 'Str', is => 'ro' ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub _build_pressure_width{ 1 } | ||||||||||||||||||
|
Subroutine
_build_pressure_width: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 24 | 0 | ▶ | sub _build_pressure_height{ 0 } | ||||||||||||||||||
|
Subroutine
_build_pressure_height: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub _build_format{ | ||||||||||||||||||
|
Subroutine
_build_format: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 27 | 0 | my ($self) = @_; | |||||||||||||||||||
| 28 | 0 | ▶ | return unless $self->src; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | 0 | my ($ext) = $self->src =~ /\.([^\.]+)$/; | |||||||||||||||||||
| 30 | 0 | return $ext; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub _build_image{ | ||||||||||||||||||
|
Subroutine
_build_image: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 34 | 0 | my ($self) = @_; | |||||||||||||||||||
| 35 | 0 | ▶ | die $self->src.": $!" unless -f $self->src; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | my $pdf = $self->boxer->doc->pdf; | |||||||||||||||||||
| 37 | 0 | my $method = 'image_'.$self->format; | |||||||||||||||||||
| 38 | 0 | return $self->boxer->doc->pdf->$method($self->src); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub _build_image_width{ | ||||||||||||||||||
|
Subroutine
_build_image_width: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 42 | 0 | my ($self) = @_; | |||||||||||||||||||
| 43 | 0 | my $width = $self->image->width; | |||||||||||||||||||
| 44 | 0 | ▶ | if (my $sc = $self->scale){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | $width = $width * $sc / 100; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 0 | return $width; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | ▶ | sub _build_image_height{ | ||||||||||||||||||
|
Subroutine
_build_image_height: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 51 | 0 | my ($self) = @_; | |||||||||||||||||||
| 52 | 0 | my $height = $self->image->height; | |||||||||||||||||||
| 53 | 0 | ▶ | if (my $sc = $self->scale){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | $height = $height * $sc / 100; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 0 | return $height; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | sub get_default_size{ | ||||||||||||||||||
|
Subroutine
get_default_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 63 | 0 | my ($self) = @_; | |||||||||||||||||||
| 64 | 0 | return ($self->image_width, $self->image_height); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | around 'render' => sub{ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||
| 68 | 0 | my ($orig, $self) = @_; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | my $img = $self->image; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | my $gfx = $self->boxer->doc->gfx; | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | my $x = $self->content_left; | |||||||||||||||||||
| 75 | 0 | my $y = $self->content_top-$self->height; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | my @args = $self->scale ? ($self->scale/100) : ($self->image->width, $self->image->height); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | foreach($self->valign || ()){ | ||||||||||||||||||
|
Condition0%0/3
$self->valign || ()
MC/DC0%0/2
$self->valign || ()
$self->valign
()
Truth table0%0/3
A || B
A= $self->valignB= ()
| |||||||||||||||||||||
| 80 | 0 | ▶ | /^top/ && do { $y = $self->content_top - $self->image_height }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | ▶ | /^cen/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | my $bc = $self->content_top - ($self->content_height / 2); | |||||||||||||||||||
| 83 | 0 | my $ic = $self->image_height / 2; | |||||||||||||||||||
| 84 | 0 | $y = $bc - $ic; | |||||||||||||||||||
| 85 | }; | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | foreach($self->align || ()){ | ||||||||||||||||||
|
Condition0%0/3
$self->align || ()
MC/DC0%0/2
$self->align || ()
$self->align
()
Truth table0%0/3
A || B
A= $self->alignB= ()
| |||||||||||||||||||||
| 89 | 0 | ▶ | /^rig/ && do { $x = $self->content_right - $self->image_width }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | ▶ | /^cen/ && do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 0 | my $bc = $self->content_left + ($self->content_width / 2); | |||||||||||||||||||
| 92 | 0 | my $ic = $self->image_width / 2; | |||||||||||||||||||
| 93 | 0 | $x = $bc - $ic; | |||||||||||||||||||
| 94 | }; | ||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | $gfx->image($img, $x, $y, @args); | |||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | $self->$orig(); | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 3 | }; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 3 | 1; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||