| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PDF::Boxer::Content::Grid; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$PDF::Boxer::Content::Grid::VERSION = '0.004'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
3
|
|
|
3
|
|
22
|
use Moose; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
30
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: a box of rows with column widths aligned |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
21882
|
use namespace::autoclean; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
35
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'PDF::Boxer::Content::Column'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'hborder' => ( isa => 'Int', is => 'rw', default => 0 ); |
|
13
|
|
|
|
|
|
|
has 'vborder' => ( isa => 'Int', is => 'rw', default => 0 ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
around 'render' => sub { |
|
16
|
|
|
|
|
|
|
my ($orig, $self) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $kids = $self->children; |
|
19
|
|
|
|
|
|
|
return unless @$kids; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $gfx = $self->boxer->doc->gfx; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ($self->hborder) { |
|
24
|
|
|
|
|
|
|
my @hlines; |
|
25
|
|
|
|
|
|
|
my $top_pos = $kids->[0]->padding_top; |
|
26
|
|
|
|
|
|
|
foreach my $kid (@$kids) { |
|
27
|
|
|
|
|
|
|
next if $top_pos == $kid->padding_top; |
|
28
|
|
|
|
|
|
|
$top_pos = $kid->padding_top; |
|
29
|
|
|
|
|
|
|
push @hlines, $top_pos; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if (@hlines) { |
|
33
|
|
|
|
|
|
|
$gfx->linewidth($self->hborder); |
|
34
|
|
|
|
|
|
|
for my $top (@hlines) { |
|
35
|
|
|
|
|
|
|
$gfx->move($self->content_left, $top); |
|
36
|
|
|
|
|
|
|
$gfx->line($self->content_right, $top); |
|
37
|
|
|
|
|
|
|
$gfx->stroke; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ($self->vborder) { |
|
43
|
|
|
|
|
|
|
my @vlines; |
|
44
|
|
|
|
|
|
|
my $grand_kids = $kids->[0]->children; |
|
45
|
|
|
|
|
|
|
if (@$grand_kids) { |
|
46
|
|
|
|
|
|
|
my $left_pos = $grand_kids->[0]->padding_left; |
|
47
|
|
|
|
|
|
|
foreach my $grand_kid (@$grand_kids) { |
|
48
|
|
|
|
|
|
|
next if $left_pos == $grand_kid->padding_left; |
|
49
|
|
|
|
|
|
|
$left_pos = $grand_kid->padding_left; |
|
50
|
|
|
|
|
|
|
push @vlines, $left_pos; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if (@vlines) { |
|
54
|
|
|
|
|
|
|
$gfx->linewidth($self->vborder); |
|
55
|
|
|
|
|
|
|
for my $left (@vlines) { |
|
56
|
|
|
|
|
|
|
$gfx->move($left, $self->content_top); |
|
57
|
|
|
|
|
|
|
$gfx->line($left, $self->content_bottom); |
|
58
|
|
|
|
|
|
|
$gfx->stroke; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->$orig(); |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub update_children{ |
|
69
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
70
|
0
|
0
|
|
|
|
|
$self->update_kids_size if $self->size_set; |
|
71
|
0
|
0
|
|
|
|
|
$self->update_kids_position if $self->position_set; |
|
72
|
0
|
|
|
|
|
|
$self->update_grand_kids; |
|
73
|
0
|
|
|
|
|
|
foreach my $kid (@{$self->children}){ |
|
|
0
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$kid->update; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
0
|
|
|
|
|
|
return 1; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub update_kids_position{ |
|
80
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
81
|
0
|
|
|
|
|
|
my $kids = $self->children; |
|
82
|
0
|
0
|
|
|
|
|
if (@$kids){ |
|
83
|
0
|
|
|
|
|
|
my $top = $self->content_top; |
|
84
|
0
|
|
|
|
|
|
my $left = $self->content_left; |
|
85
|
0
|
|
|
|
|
|
foreach my $kid (@$kids){ |
|
86
|
0
|
|
|
|
|
|
$kid->move($left, $top); |
|
87
|
0
|
|
|
|
|
|
$top -= $kid->margin_height; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
|
|
|
return 1; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub update_kids_size{ |
|
94
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my ($width, $height) = $self->get_default_size; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $kids = $self->children; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if (@$kids){ |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $space = $self->height - $height; |
|
103
|
0
|
|
|
|
|
|
my ($has_grow,$grow,$grow_all); |
|
104
|
0
|
|
|
|
|
|
my ($space_each); |
|
105
|
0
|
0
|
|
|
|
|
if ($space < $height/10){ |
|
106
|
0
|
|
|
|
|
|
foreach my $kid (@$kids){ |
|
107
|
0
|
0
|
|
|
|
|
$has_grow++ if $kid->grow; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
0
|
|
|
|
|
if (!$has_grow){ |
|
110
|
0
|
|
|
|
|
|
$grow_all = 1; |
|
111
|
0
|
|
|
|
|
|
$has_grow = @$kids; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
$space_each = int($space/$has_grow); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $kwidth = $self->content_width; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
foreach my $kid (@$kids){ |
|
119
|
0
|
|
|
|
|
|
my $kheight = $kid->margin_height; |
|
120
|
0
|
0
|
0
|
|
|
|
if ($grow_all || $kid->grow){ |
|
121
|
0
|
|
|
|
|
|
$kheight += $space_each; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
0
|
|
|
|
|
|
$kid->set_margin_size($kwidth, $kheight); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return 1; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub update_grand_kids{ |
|
132
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my ($width, $height) = $self->get_default_size; |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $kids = $self->children; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if (@$kids){ |
|
139
|
|
|
|
|
|
|
# calculate minumum widths of cells (kids) |
|
140
|
0
|
|
|
|
|
|
my @row_highs; |
|
141
|
0
|
|
|
|
|
|
foreach my $row (@$kids){ |
|
142
|
0
|
|
|
|
|
|
my @cells; |
|
143
|
0
|
|
|
|
|
|
foreach my $cell (@{$row->children}){ |
|
|
0
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
push(@cells, $cell->margin_width); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
0
|
|
|
|
|
|
my $idx = 0; |
|
147
|
0
|
|
|
|
|
|
foreach my $val (@cells){ |
|
148
|
0
|
0
|
0
|
|
|
|
$row_highs[$idx] = $val if $val > ($row_highs[$idx] || 0); |
|
149
|
0
|
|
|
|
|
|
$idx++; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
foreach (@$kids){ |
|
154
|
0
|
|
|
|
|
|
$_->set_kids_minimum_width({ min_widths => \@row_highs }); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return 1; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__END__ |
|
169
|
|
|
|
|
|
|
=pod |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 NAME |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
PDF::Boxer::Content::Grid - a box of rows with column widths aligned |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
version 0.004 |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Jason Galea <lecstor@cpan.org> |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Jason Galea. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
188
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
|