| 1 | package PDF::Make::Builder::Page::Footer; | ||||||||||||||
| 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::Builder::Page::HeaderFooterContext; | ||||||||||||
|
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::Page::Footer', | |||||||||||||
| 9 | 'h:Num:default(30)', | ||||||||||||||
| 10 | 'padding:Num:default(20)', | ||||||||||||||
| 11 | 'show_page_num:Str', | ||||||||||||||
| 12 | 'page_num_text:Str:default(Page {num})', | ||||||||||||||
| 13 | 'cb:CodeRef', | ||||||||||||||
| 14 | ); | ||||||||||||||
| 15 | 53 | Object::Proto::import_accessors('PDF::Make::Builder::Page::Footer'); | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 14 | ▶ | sub render { | ||||||||||||
|
Subroutine
render: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||
| 19 | 14 | my ($self, $builder, $page, $page_num) = @_; | |||||||||||||
| 20 | 14 | my $canvas = $page->canvas; | |||||||||||||
| 21 | 14 | my $pw = $page->w; | |||||||||||||
| 22 | 14 | my $pad = padding $self; | |||||||||||||
| 23 | 14 | my $fh = $self->h; | |||||||||||||
| 24 | |||||||||||||||
| 25 | # Footer region: bottom of page | ||||||||||||||
| 26 | 14 | my $footer_y = $pad + $fh; | |||||||||||||
| 27 | |||||||||||||||
| 28 | # Custom callback | ||||||||||||||
| 29 | 14 | my $callback = cb $self; | |||||||||||||
| 30 | 14 | ▶ | if ($callback) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 9 | my $ctx = PDF::Make::Builder::Page::HeaderFooterContext->new( | |||||||||||||
| 32 | builder => $builder, | ||||||||||||||
| 33 | page => $page, | ||||||||||||||
| 34 | canvas => $canvas, | ||||||||||||||
| 35 | x0 => 0, | ||||||||||||||
| 36 | y0 => $pad, | ||||||||||||||
| 37 | w => $pw, | ||||||||||||||
| 38 | h => $fh, | ||||||||||||||
| 39 | padding => $pad, | ||||||||||||||
| 40 | num => $page_num, | ||||||||||||||
| 41 | role => 'footer', | ||||||||||||||
| 42 | ); | ||||||||||||||
| 43 | 9 | $callback->($self, $builder, | |||||||||||||
| 44 | ctx => $ctx, | ||||||||||||||
| 45 | canvas => $canvas, y => $footer_y, w => $pw, h => $fh, | ||||||||||||||
| 46 | page_num => $page_num); | ||||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | # Page number | ||||||||||||||
| 50 | 14 | my $show = show_page_num $self; | |||||||||||||
| 51 | 14 | ▶ | if ($show) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 5 | my $text = page_num_text $self; | |||||||||||||
| 53 | 5 | $text =~ s/\{num\}/$page_num/g; | |||||||||||||
| 54 | 5 | my $font = $builder->font; | |||||||||||||
| 55 | 5 | my $res = $font->ensure_loaded($page->xs_page, 'normal'); | |||||||||||||
| 56 | 5 | my $font_size = 8; | |||||||||||||
| 57 | 5 | my ($r, $g, $b) = $font->hex_to_rgb('#666'); | |||||||||||||
| 58 | 5 | ▶ | my $tw = $font->measure_text($text) * ($font_size / ($font->size || 9)); | ||||||||||||
|
Condition50%1/2
$font->size || 9
MC/DC0%0/1
$font->size || 9
$font->size
Truth table50%1/2
A
A= $font->size
| |||||||||||||||
| 59 | 5 | my $tx; | |||||||||||||
| 60 | 5 | ▶ | if ($show eq 'right') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 61 | 0 | $tx = $pw - $pad - $tw; | |||||||||||||
| 62 | } elsif ($show eq 'center') { | ||||||||||||||
| 63 | 5 | $tx = ($pw - $tw) / 2; | |||||||||||||
| 64 | } else { | ||||||||||||||
| 65 | 0 | $tx = $pad; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | 5 | my $tj = $font->show_op; | |||||||||||||
| 68 | 5 | $canvas->BT | |||||||||||||
| 69 | ->rg($r, $g, $b) | ||||||||||||||
| 70 | ->Tf($res, $font_size) | ||||||||||||||
| 71 | ->Tm(1, 0, 0, 1, $tx, $pad + 4) | ||||||||||||||
| 72 | ->$tj($font->encode($text)) | ||||||||||||||
| 73 | ->ET; | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 53 | 1; | |||||||||||||
| 78 | |||||||||||||||
| 79 | __END__ | ||||||||||||||