| 1 | package PDF::Make::Builder::Image; | ||||||||||||||||||||||||||||
| 2 | 53 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 53 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 53 | ▶ | use Object::Proto; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 53 | ▶ | use PDF::Make::Image; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 53 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 53 | Object::Proto::define('PDF::Make::Builder::Image', | |||||||||||||||||||||||||||
| 9 | 'image:Str:required', | ||||||||||||||||||||||||||||
| 10 | 'mime:Str', | ||||||||||||||||||||||||||||
| 11 | 'align:Str', | ||||||||||||||||||||||||||||
| 12 | 'x:Num', 'y:Num', 'w:Num', 'h:Num', | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | 53 | Object::Proto::import_accessors('PDF::Make::Builder::Image'); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 10 | my ($self, $builder) = @_; | |||||||||||||||||||||||||||
| 19 | 10 | my $page = $builder->page; | |||||||||||||||||||||||||||
| 20 | 10 | my $canvas = $page->canvas; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Load the image | ||||||||||||||||||||||||||||
| 23 | 10 | my $img = PDF::Make::Image->from_file($self->image); | |||||||||||||||||||||||||||
| 24 | 10 | my $img_w = $img->width; | |||||||||||||||||||||||||||
| 25 | 10 | my $img_h = $img->height; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Write image XObject to document | ||||||||||||||||||||||||||||
| 28 | 10 | my $doc = $builder->doc; | |||||||||||||||||||||||||||
| 29 | 10 | my $obj_num = $img->write_to_doc($doc); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Generate unique resource name | ||||||||||||||||||||||||||||
| 32 | 10 | my $res_name = 'Im' . $obj_num; | |||||||||||||||||||||||||||
| 33 | 10 | $page->xs_page->add_image($res_name, $obj_num); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # Determine placement dimensions | ||||||||||||||||||||||||||||
| 36 | 10 | ▶ | my $draw_w = $self->w // $page->width; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->w // $page->width
MC/DC0%0/2
$self->w // $page->width
$self->w
$page->width
Truth table66%2/3
A // B
A= $self->wB= $page->width
| |||||||||||||||||||||||||||||
| 37 | 10 | my $draw_h = $self->h; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Maintain aspect ratio if only one dimension given | ||||||||||||||||||||||||||||
| 40 | 10 | ▶ | if (!defined $draw_h) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 6 | $draw_h = $draw_w * ($img_h / $img_w); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Position | ||||||||||||||||||||||||||||
| 45 | 10 | ▶ | my $draw_x = $self->x // $page->content_x; | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->x // $page->content_x
MC/DC0%0/2
$self->x // $page->content_x
$self->x
$page->content_x
Truth table66%2/3
A // B
A= $self->xB= $page->content_x
| |||||||||||||||||||||||||||||
| 46 | 10 | my $draw_y = $self->y; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | ▶ | if (!defined $draw_y) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 8 | $draw_y = $page->cursor_y - $draw_h; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Center alignment | ||||||||||||||||||||||||||||
| 53 | 10 | ▶ | if ($self->align && $self->align eq 'center') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->align and $self->align eq "center"
MC/DC100%2/2
$self->align and $self->align eq "center"
$self->align
$self->align eq "center"
Truth table100%3/3
A and B
A= $self->alignB= $self->align eq "center"
| |||||||||||||||||||||||||||||
| 54 | 2 | $draw_x = $page->content_x + ($page->width - $draw_w) / 2; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Draw | ||||||||||||||||||||||||||||
| 58 | 10 | $canvas->image($res_name, $draw_x, $draw_y, $draw_w, $draw_h); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Advance cursor | ||||||||||||||||||||||||||||
| 61 | 10 | $page->advance_y($draw_h + 5); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 10 | return $self; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 53 | 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||