line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::TableX::Cell; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
72
|
use Moose; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
43
|
|
4
|
7
|
|
|
7
|
|
45453
|
use MooseX::Types; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
43
|
|
5
|
7
|
|
|
7
|
|
29838
|
use PDF::API2; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
12773
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'PDF::TableX::Drawable'; |
8
|
|
|
|
|
|
|
with 'PDF::TableX::Stylable'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has width => (is => 'rw', isa => 'Num'); |
11
|
|
|
|
|
|
|
has min_width => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_min_width'); |
12
|
|
|
|
|
|
|
has reg_width => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_reg_width'); |
13
|
|
|
|
|
|
|
has height => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_height' ); |
14
|
|
|
|
|
|
|
has content => (is => 'rw', isa => 'Str', default=> '', trigger => sub { $_[0]->{_overflow} = $_[0]->content; }); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has _overflow => (is => 'ro', isa => 'Str', init_arg => undef, default => ''); |
17
|
|
|
|
|
|
|
has _pdf_api_content => (is => 'ro', isa => class_type('PDF::API2::Page'), lazy => 1, builder => '_get_content'); |
18
|
|
|
|
|
|
|
has _parent => (is => 'ro', isa => 'Object'); |
19
|
|
|
|
|
|
|
has _row_idx => (is => 'ro', isa => 'Int', default => 0); |
20
|
|
|
|
|
|
|
has _col_idx => (is => 'ro', isa => 'Int', default => 0); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
around 'content' => sub { |
23
|
|
|
|
|
|
|
my $orig = shift; |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
return $self->$orig() unless @_; |
26
|
|
|
|
|
|
|
$self->$orig(@_); |
27
|
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
|
0
|
sub _get_content { return PDF::API2->new()->page; } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _get_min_width { |
33
|
144
|
|
|
144
|
|
353
|
my ($self) = @_; |
34
|
144
|
|
|
|
|
751
|
my $txt = PDF::API2->new()->page->text(); |
35
|
144
|
|
|
|
|
266208
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
36
|
144
|
|
|
|
|
34520
|
my $min_width = 0; |
37
|
144
|
|
|
|
|
827
|
for (split(/\s/, $self->content)) { |
38
|
2517
|
|
|
|
|
5111
|
my $word_width = $txt->advancewidth($_); |
39
|
2517
|
100
|
|
|
|
349768
|
$min_width = ($word_width > $min_width) ? $word_width : $min_width; |
40
|
|
|
|
|
|
|
} |
41
|
144
|
|
|
|
|
1197
|
return $min_width + $self->padding->[1] + $self->padding->[3]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_reg_width { |
45
|
144
|
|
|
144
|
|
355
|
my ($self) = @_; |
46
|
144
|
|
|
|
|
810
|
my $txt = PDF::API2->new()->page->text(); |
47
|
144
|
|
|
|
|
273103
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
48
|
144
|
|
|
|
|
37118
|
my $reg_width = 0; |
49
|
144
|
|
|
|
|
917
|
for (split("\n", $self->content)) { |
50
|
103
|
|
|
|
|
431
|
my $line_width = $txt->advancewidth($_); |
51
|
103
|
100
|
|
|
|
87770
|
$reg_width = ($line_width > $reg_width) ? $line_width : $reg_width; |
52
|
|
|
|
|
|
|
} |
53
|
144
|
|
|
|
|
870
|
return $reg_width + $self->padding->[1] + $self->padding->[3]; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _get_height { |
57
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
58
|
0
|
|
|
|
|
0
|
my $height = $self->padding->[0] + $self->padding->[2]; |
59
|
0
|
|
|
|
|
0
|
$height += scalar(split("\n", $self->content)) * $self->font_size; |
60
|
0
|
|
|
|
|
0
|
return $height; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub draw_content { |
64
|
156
|
|
|
156
|
1
|
538
|
my ($self, $x, $y, $gfx, $txt) = @_; |
65
|
156
|
|
|
|
|
531
|
$y -= $self->padding->[0] + $self->font_size; |
66
|
156
|
100
|
|
|
|
535
|
$x += $self->padding->[3] |
|
|
100
|
|
|
|
|
|
67
|
|
|
|
|
|
|
+ ($self->text_align eq 'right' ? $self->get_text_width : 0) |
68
|
|
|
|
|
|
|
+ ($self->text_align eq 'center' ? $self->get_text_width/2 : 0) |
69
|
|
|
|
|
|
|
; |
70
|
156
|
|
|
|
|
359
|
my $width = 0; |
71
|
156
|
|
|
|
|
796
|
$txt->save; |
72
|
156
|
|
|
|
|
2017
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
73
|
156
|
|
|
|
|
46012
|
$txt->lead( $self->font_size ); |
74
|
156
|
|
|
|
|
14695
|
$txt->fillcolor( $self->font_color ); |
75
|
156
|
|
|
|
|
28463
|
$txt->translate($x, $y); |
76
|
156
|
|
|
|
|
80652
|
my $overflow = ''; |
77
|
156
|
|
|
|
|
975
|
for my $p ( split ( "\n", $self->{_overflow} ) ) { |
78
|
115
|
50
|
|
|
|
14453
|
if ($overflow) { |
79
|
0
|
|
|
|
|
0
|
$overflow .= "\n" . $p; |
80
|
|
|
|
|
|
|
} else { |
81
|
115
|
|
|
|
|
526
|
$overflow = $txt->paragraph($p, $self->get_text_width, ($y-$self->margin->[2]-$self->padding->[2]+$self->font_size), -spillover => 0, -align => $self->text_align); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
156
|
|
|
|
|
1599546
|
$self->{_overflow} = $overflow; |
85
|
156
|
|
|
|
|
779
|
$self->height( $y - [ $txt->textpos() ]->[1] + $self->padding->[0] + $self->padding->[2]); |
86
|
156
|
|
|
|
|
901
|
$txt->restore; |
87
|
156
|
|
|
|
|
1747
|
return ($self->get_text_width, $self->height, length($overflow)); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub reset_content { |
91
|
152
|
|
|
152
|
1
|
285
|
my ($self) = @_; |
92
|
152
|
|
|
|
|
411
|
$self->{_overflow} = $self->content; |
93
|
152
|
|
|
|
|
406
|
return $self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_text_width { |
97
|
358
|
|
|
358
|
1
|
858
|
my ($self) = @_; |
98
|
358
|
|
|
|
|
10603
|
return $self->width - $self->padding->[1] - $self->padding->[3]; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub draw_borders { |
102
|
158
|
|
|
158
|
1
|
383
|
my ($self, $x, $y, $gfx, $txt) = @_; |
103
|
158
|
100
|
|
|
|
568
|
if ($self->border_width->[0]) {$self->_draw_top_border($x, $y, $gfx)} |
|
136
|
|
|
|
|
414
|
|
104
|
158
|
100
|
|
|
|
6067
|
if ($self->border_width->[1]) {$self->_draw_right_border($x, $y, $gfx)} |
|
136
|
|
|
|
|
459
|
|
105
|
158
|
100
|
|
|
|
5975
|
if ($self->border_width->[2]) {$self->_draw_bottom_border($x, $y, $gfx)} |
|
152
|
|
|
|
|
461
|
|
106
|
158
|
100
|
|
|
|
6480
|
if ($self->border_width->[3]) {$self->_draw_left_border($x, $y, $gfx)} |
|
152
|
|
|
|
|
475
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _draw_top_border { |
110
|
136
|
|
|
136
|
|
317
|
my ($self, $x, $y, $gfx) = @_; |
111
|
136
|
100
|
|
|
|
435
|
$y = ($self->{_row_idx} == 0) ? $y-$self->border_width->[0]/2 : $y; |
112
|
136
|
|
|
|
|
557
|
$gfx->move($x, $y); |
113
|
136
|
|
|
|
|
15687
|
$gfx->linewidth($self->border_width->[0]); |
114
|
136
|
|
|
|
|
6718
|
$gfx->strokecolor($self->border_color->[0]); |
115
|
136
|
|
|
|
|
24239
|
$gfx->hline($x+$self->width); |
116
|
136
|
|
|
|
|
14151
|
$gfx->stroke(); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _draw_right_border { |
120
|
136
|
|
|
136
|
|
328
|
my ($self, $x, $y, $gfx) = @_; |
121
|
136
|
100
|
|
|
|
572
|
$x = ($self->{_parent}->is_last_in_row($self->{_col_idx})) ? $x-$self->border_width->[1]/2 : $x; |
122
|
136
|
|
|
|
|
3595
|
$gfx->move($x+$self->width, $y); |
123
|
136
|
|
|
|
|
15645
|
$gfx->linewidth($self->border_width->[1]); |
124
|
136
|
|
|
|
|
6683
|
$gfx->strokecolor($self->border_color->[1]); |
125
|
136
|
|
|
|
|
23925
|
$gfx->vline($y-$self->height); |
126
|
136
|
|
|
|
|
14054
|
$gfx->stroke(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _draw_bottom_border { |
130
|
152
|
|
|
152
|
|
330
|
my ($self, $x, $y, $gfx) = @_; |
131
|
152
|
100
|
|
|
|
591
|
$y = ($self->{_parent}->is_last_in_col($self->{_row_idx})) ? $y+$self->border_width->[2]/2 : $y; |
132
|
152
|
|
|
|
|
3802
|
$gfx->move($x, $y-$self->height); |
133
|
152
|
|
|
|
|
17425
|
$gfx->linewidth($self->border_width->[2]); |
134
|
152
|
|
|
|
|
7252
|
$gfx->strokecolor($self->border_color->[2]); |
135
|
152
|
|
|
|
|
26771
|
$gfx->hline($x+$self->width); |
136
|
152
|
|
|
|
|
15752
|
$gfx->stroke(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _draw_left_border { |
140
|
152
|
|
|
152
|
|
322
|
my ($self, $x, $y, $gfx) = @_; |
141
|
152
|
100
|
|
|
|
475
|
$x = ($self->{_col_idx} == 0) ? $x+$self->border_width->[3]/2 : $x; |
142
|
152
|
|
|
|
|
519
|
$gfx->move($x, $y); |
143
|
152
|
|
|
|
|
16855
|
$gfx->linewidth($self->border_width->[3]); |
144
|
152
|
|
|
|
|
7246
|
$gfx->strokecolor($self->border_color->[3]); |
145
|
152
|
|
|
|
|
26415
|
$gfx->vline($y-$self->height); |
146
|
152
|
|
|
|
|
15379
|
$gfx->stroke(); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub draw_background { |
150
|
156
|
|
|
156
|
1
|
380
|
my ($self, $x, $y, $gfx, $txt) = @_; |
151
|
156
|
100
|
|
|
|
531
|
if ( $self->background_color ) { |
152
|
116
|
|
|
|
|
513
|
$gfx->linewidth(0); |
153
|
116
|
|
|
|
|
6211
|
$gfx->fillcolor($self->background_color); |
154
|
116
|
|
|
|
|
22079
|
$gfx->rect($x, $y-$self->height, $self->width, $self->height); |
155
|
116
|
|
|
|
|
17187
|
$gfx->fill(); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 NAME |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
PDF::TableX::Cell |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 VERSION |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Version 0.01 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 SYNOPSIS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 METHODS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 background_color |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
TODO |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 border_color |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
TODO |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 border_style |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
TODO |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 border_width |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
TODO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 content |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
TODO |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 draw_background |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
TODO |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 draw_borders |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
TODO |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 draw_content |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
TODO |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 font |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
TODO |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 font_color |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
TODO |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 font_size |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
TODO |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 get_text_width |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
TODO |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 height |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
TODO |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 margin |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
TODO |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 meta |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
TODO |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 min_width |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
TODO |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 padding |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
TODO |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 reg_width |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
TODO |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 reset_content |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
TODO |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head2 text_align |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
TODO |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 width |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
TODO |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 AUTHOR |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Grzegorz Papkala, C<< <grzegorzpapkala at gmail.com> >> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 BUGS |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Please report any bugs or feature requests at: L<https://github.com/grzegorzpapkala/PDF-TableX/issues> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 SUPPORT |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
PDF::TableX is hosted on GitHub L<https://github.com/grzegorzpapkala/PDF-TableX> |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Copyright 2013 Grzegorz Papkala, all rights reserved. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
278
|
|
|
|
|
|
|
under the same terms as Perl itself. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=cut |