blib/lib/PDF/Make/Builder/Page/Header.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 88.3% 53 / 60 CC 6 SCAR 13.4
CC
6
Cov
88%
render
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« blib/lib/PDF/Make/Builder/Font.pm ↑ Summary blib/lib/PDF/Make/Builder/Page/Footer.pm »
1 package PDF::Make::Builder::Page::Header;
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::Header',
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::Header');
16 }
17  
18 20 ▶sub render {
Subroutine render: called CC=6 SCAR=18.2
Pod documented
19 20 my ($self, $builder, $page, $page_num) = @_;
20 20 my $canvas = $page->canvas;
21 20 my $pw = $page->w;
22 20 my $ph = $page->h;
23 20 my $pad = padding $self;
24 20 my $hh = $self->h;
25  
26 # Header region: top of page
27 20 my $header_y = $ph - $pad;
28  
29 # Custom callback
30 20 my $callback = cb $self;
31 20 ▶ if ($callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) 14 6 20
32 14 my $ctx = PDF::Make::Builder::Page::HeaderFooterContext->new(
33 builder => $builder,
34 page => $page,
35 canvas => $canvas,
36 x0 => 0,
37 y0 => $header_y - $hh,
38 w => $pw,
39 h => $hh,
40 padding => $pad,
41 num => $page_num,
42 role => 'header',
43 );
44 14 $callback->($self, $builder,
45 ctx => $ctx,
46 canvas => $canvas, y => $header_y, w => $pw, h => $hh);
47 }
48  
49 # Page number
50 20 my $show = show_page_num $self;
51 20 ▶ if ($show) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show) 5 15 20
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
l!l
50
MC/DC0%0/1
$font->size || 9
$font->size
Truth table50%1/2
A
A= $font->size
Aresult
11
00
59 5 my $tx;
60 5 ▶ if ($show eq 'right') {
Branch: 2 branches
BranchTrueFalseTotal
if ($show eq 'right') { } 5 0 5
elsif ($show eq 'center') { } 0 0 0
61 5 $tx = $pw - $pad - $tw;
62 } elsif ($show eq 'center') {
63 0 $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, $header_y - $font_size)
72 ->$tj($font->encode($text))
73 ->ET;
74 }
75 }
76  
77 53 1;
78  
79 __END__
« blib/lib/PDF/Make/Builder/Font.pm ↑ Summary blib/lib/PDF/Make/Builder/Page/Footer.pm »