| 1 | package PDF::Make::Builder::Page; | ||||||||||||||||||||
| 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 | |||||||||||||||||||||
| 6 | 53 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 53 | Object::Proto::define('PDF::Make::Builder::Page', | |||||||||||||||||||
| 8 | 'page_size:Str:default(A4)', | ||||||||||||||||||||
| 9 | 'background:Str:default(#fff)', | ||||||||||||||||||||
| 10 | 'columns:Int:default(1)', | ||||||||||||||||||||
| 11 | 'column:Int:default(1)', | ||||||||||||||||||||
| 12 | 'column_y:Num:default(0)', | ||||||||||||||||||||
| 13 | 'is_rotated:Bool:default(0)', | ||||||||||||||||||||
| 14 | 'header:Any', | ||||||||||||||||||||
| 15 | 'footer:Any', | ||||||||||||||||||||
| 16 | 'padding:Num:default(20)', | ||||||||||||||||||||
| 17 | 'num:Int:required', | ||||||||||||||||||||
| 18 | 'x:Num:default(0)', | ||||||||||||||||||||
| 19 | 'y:Num:default(0)', | ||||||||||||||||||||
| 20 | 'w:Num:required', | ||||||||||||||||||||
| 21 | 'h:Num:required', | ||||||||||||||||||||
| 22 | 'canvas:Any:required', | ||||||||||||||||||||
| 23 | 'xs_page:Any:required', | ||||||||||||||||||||
| 24 | 'imported:Bool:default(0)', | ||||||||||||||||||||
| 25 | 'redactions:ArrayRef:default([])', | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | 53 | Object::Proto::import_accessors('PDF::Make::Builder::Page', 'page_'); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 53 | my %PAGE_SIZES = ( | |||||||||||||||||||
| 31 | A4 => [595, 842], | ||||||||||||||||||||
| 32 | Letter => [612, 792], | ||||||||||||||||||||
| 33 | Legal => [612, 1008], | ||||||||||||||||||||
| 34 | A3 => [842, 1191], | ||||||||||||||||||||
| 35 | A5 => [420, 595], | ||||||||||||||||||||
| 36 | B5 => [499, 709], | ||||||||||||||||||||
| 37 | Tabloid => [792, 1224], | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 579 | ▶ | sub page_dimensions { | ||||||||||||||||||
|
Subroutine
page_dimensions: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||
| 41 | 579 | my ($class_or_size) = @_; | |||||||||||||||||||
| 42 | 579 | ▶ | my $size = ref $class_or_size ? $class_or_size->page_size : $class_or_size; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 579 | ▶ | return @{$PAGE_SIZES{$size} // $PAGE_SIZES{A4}}; | ||||||||||||||||||
|
Condition66%2/3
$PAGE_SIZES{$size} // $PAGE_SIZES{"A4"}
MC/DC0%0/2
$PAGE_SIZES{$size} // $PAGE_SIZES{"A4"}
$PAGE_SIZES{$size}
$PAGE_SIZES{"A4"}
Truth table66%2/3
A // B
A= $PAGE_SIZES{$size}B= $PAGE_SIZES{"A4"}
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 909 | ▶ | sub top_y { | ||||||||||||||||||
|
Subroutine
top_y: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 47 | 909 | my ($self) = @_; | |||||||||||||||||||
| 48 | 909 | my $ph = page_h $self; | |||||||||||||||||||
| 49 | 909 | my $pad = page_padding $self; | |||||||||||||||||||
| 50 | 909 | my $hdr = page_header $self; | |||||||||||||||||||
| 51 | 909 | my $top = $ph - $pad; | |||||||||||||||||||
| 52 | 909 | ▶ | if ($hdr) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | # A header is anchored to its own padding, not to the page margin: it | ||||||||||||||||||||
| 54 | # occupies [ph - hdr_pad - hdr_h, ph - hdr_pad], which for the default | ||||||||||||||||||||
| 55 | # padding of 20 is the strip from 20 to 50 points down the page. | ||||||||||||||||||||
| 56 | # Subtracting its height from an already-margined top stacked the two | ||||||||||||||||||||
| 57 | # instead of overlapping them, so every point by which the margin | ||||||||||||||||||||
| 58 | # exceeded the header's padding became dead space between the header | ||||||||||||||||||||
| 59 | # and the first line of content - 20pt on a 40pt margin, 30pt on 50. | ||||||||||||||||||||
| 60 | # Content starts below the header, or below the margin, whichever is | ||||||||||||||||||||
| 61 | # lower down the page. | ||||||||||||||||||||
| 62 | 9 | my $below_header = $ph - $hdr->padding - $hdr->h; | |||||||||||||||||||
| 63 | 9 | ▶ | $top = $below_header if $below_header < $top; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 909 | return $top; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 1113 | ▶ | sub bottom_y { | ||||||||||||||||||
|
Subroutine
bottom_y: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | 1113 | my ($self) = @_; | |||||||||||||||||||
| 70 | 1113 | my $pad = page_padding $self; | |||||||||||||||||||
| 71 | 1113 | my $ftr = page_footer $self; | |||||||||||||||||||
| 72 | 1113 | my $bot = $pad; | |||||||||||||||||||
| 73 | 1113 | ▶ | $bot += $ftr->h if $ftr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 1113 | return $bot; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | ▶ | sub remaining_height { | ||||||||||||||||||
|
Subroutine
remaining_height: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 78 | 1 | my ($self) = @_; | |||||||||||||||||||
| 79 | 1 | return $self->cursor_y - $self->bottom_y; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 4532 | ▶ | sub width { | ||||||||||||||||||
|
Subroutine
width: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 83 | 4532 | my ($self) = @_; | |||||||||||||||||||
| 84 | 4532 | my $pw = page_w $self; | |||||||||||||||||||
| 85 | 4532 | my $pad = page_padding $self; | |||||||||||||||||||
| 86 | 4532 | my $cols = page_columns $self; | |||||||||||||||||||
| 87 | 4532 | my $usable = $pw - 2 * $pad; | |||||||||||||||||||
| 88 | 4532 | ▶ | if ($cols > 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 137 | my $col_gap = 20; | |||||||||||||||||||
| 90 | 137 | return ($usable - ($cols - 1) * $col_gap) / $cols; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | 4395 | return $usable; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 4499 | ▶ | sub content_x { | ||||||||||||||||||
|
Subroutine
content_x: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 96 | 4499 | my ($self) = @_; | |||||||||||||||||||
| 97 | 4499 | my $pad = page_padding $self; | |||||||||||||||||||
| 98 | 4499 | my $col = page_column $self; | |||||||||||||||||||
| 99 | 4499 | ▶ | if ((page_columns $self) > 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 69 | my $col_gap = 20; | |||||||||||||||||||
| 101 | 69 | my $col_w = $self->width; | |||||||||||||||||||
| 102 | 69 | return $pad + ($col - 1) * ($col_w + $col_gap); | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | 4430 | return $pad; | |||||||||||||||||||
| 105 | } | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 8658 | ▶ | sub cursor_y { | ||||||||||||||||||
|
Subroutine
cursor_y: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 108 | 8658 | my ($self) = @_; | |||||||||||||||||||
| 109 | 8658 | my $cy = page_y $self; | |||||||||||||||||||
| 110 | 8658 | ▶ | return $cy > 0 ? $cy : $self->top_y; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 4089 | ▶ | sub advance_y { | ||||||||||||||||||
|
Subroutine
advance_y: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 114 | 4089 | my ($self, $amount) = @_; | |||||||||||||||||||
| 115 | 4089 | my $current = $self->cursor_y; | |||||||||||||||||||
| 116 | 4089 | page_y $self, $current - $amount; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 21 | ▶ | sub has_next_column { | ||||||||||||||||||
|
Subroutine
has_next_column: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 120 | 21 | my ($self) = @_; | |||||||||||||||||||
| 121 | 21 | return (page_column $self) < (page_columns $self); | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 6 | ▶ | sub next_column { | ||||||||||||||||||
|
Subroutine
next_column: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 125 | 6 | my ($self) = @_; | |||||||||||||||||||
| 126 | 6 | my $col = page_column $self; | |||||||||||||||||||
| 127 | 6 | my $cols = page_columns $self; | |||||||||||||||||||
| 128 | 6 | ▶ | return 0 if $col >= $cols; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | # Save cursor for the column we're leaving (for balanced columns) | ||||||||||||||||||||
| 131 | 6 | ▶ | if ($col == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 5 | page_column_y $self, $self->cursor_y; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 6 | page_column $self, $col + 1; | |||||||||||||||||||
| 136 | # Reset cursor to top of content area for the new column | ||||||||||||||||||||
| 137 | 6 | page_y $self, $self->top_y; | |||||||||||||||||||
| 138 | 6 | return 1; | |||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 1 | ▶ | sub reset_columns { | ||||||||||||||||||
|
Subroutine
reset_columns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 142 | 1 | my ($self) = @_; | |||||||||||||||||||
| 143 | 1 | page_column $self, 1; | |||||||||||||||||||
| 144 | 1 | page_column_y $self, 0; | |||||||||||||||||||
| 145 | 1 | page_y $self, $self->top_y; | |||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 53 | 1; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||