| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PDF::TableX::Cell; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1568
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use MooseX::Types; |
|
5
|
|
|
|
|
|
|
use PDF::API2; |
|
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
|
|
|
|
|
|
|
sub _get_content { return PDF::API2->new()->page; } |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _get_min_width { |
|
33
|
|
|
|
|
|
|
my ($self) = @_; |
|
34
|
|
|
|
|
|
|
my $txt = $self->_pdf_api_content->text(); |
|
35
|
|
|
|
|
|
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
|
36
|
|
|
|
|
|
|
my $min_width = 0; |
|
37
|
|
|
|
|
|
|
for (split(/\s/, $self->content)) { |
|
38
|
|
|
|
|
|
|
my $word_width = $txt->advancewidth($_); |
|
39
|
|
|
|
|
|
|
$min_width = ($word_width > $min_width) ? $word_width : $min_width; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
return $min_width + $self->padding->[1] + $self->padding->[3]; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _get_reg_width { |
|
45
|
|
|
|
|
|
|
my ($self) = @_; |
|
46
|
|
|
|
|
|
|
my $txt = $self->_pdf_api_content->text(); |
|
47
|
|
|
|
|
|
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
|
48
|
|
|
|
|
|
|
my $reg_width = 0; |
|
49
|
|
|
|
|
|
|
for (split("\n", $self->content)) { |
|
50
|
|
|
|
|
|
|
my $line_width = $txt->advancewidth($_); |
|
51
|
|
|
|
|
|
|
$reg_width = ($line_width > $reg_width) ? $line_width : $reg_width; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
return $reg_width + $self->padding->[1] + $self->padding->[3]; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _get_height { |
|
57
|
|
|
|
|
|
|
my ($self) = @_; |
|
58
|
|
|
|
|
|
|
my $height = $self->padding->[0] + $self->padding->[2]; |
|
59
|
|
|
|
|
|
|
$height += scalar(split("\n", $self->content)) * $self->font_size; |
|
60
|
|
|
|
|
|
|
return $height; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub draw_content { |
|
64
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx, $txt) = @_; |
|
65
|
|
|
|
|
|
|
$y -= $self->padding->[0] + $self->font_size; |
|
66
|
|
|
|
|
|
|
$x += $self->padding->[3] |
|
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
|
|
|
|
|
|
|
my $width = 0; |
|
71
|
|
|
|
|
|
|
$txt->save; |
|
72
|
|
|
|
|
|
|
$txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size ); |
|
73
|
|
|
|
|
|
|
$txt->lead( $self->font_size ); |
|
74
|
|
|
|
|
|
|
$txt->fillcolor( $self->font_color ); |
|
75
|
|
|
|
|
|
|
$txt->translate($x, $y); |
|
76
|
|
|
|
|
|
|
my $overflow = ''; |
|
77
|
|
|
|
|
|
|
for my $p ( split ( "\n", $self->{_overflow} ) ) { |
|
78
|
|
|
|
|
|
|
if ($overflow) { |
|
79
|
|
|
|
|
|
|
$overflow .= "\n" . $p; |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
$self->{_overflow} = $overflow; |
|
85
|
|
|
|
|
|
|
$self->height( $y - [ $txt->textpos() ]->[1] + $self->padding->[0] + $self->padding->[2]); |
|
86
|
|
|
|
|
|
|
$txt->restore; |
|
87
|
|
|
|
|
|
|
return ($self->get_text_width, $self->height, length($overflow)); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub reset_content { |
|
91
|
|
|
|
|
|
|
my ($self) = @_; |
|
92
|
|
|
|
|
|
|
$self->{_overflow} = $self->content; |
|
93
|
|
|
|
|
|
|
return $self; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_text_width { |
|
97
|
|
|
|
|
|
|
my ($self) = @_; |
|
98
|
|
|
|
|
|
|
return $self->width - $self->padding->[1] - $self->padding->[3]; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub draw_borders { |
|
102
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx, $txt) = @_; |
|
103
|
|
|
|
|
|
|
if ($self->border_width->[0]) {$self->_draw_top_border($x, $y, $gfx)} |
|
104
|
|
|
|
|
|
|
if ($self->border_width->[1]) {$self->_draw_right_border($x, $y, $gfx)} |
|
105
|
|
|
|
|
|
|
if ($self->border_width->[2]) {$self->_draw_bottom_border($x, $y, $gfx)} |
|
106
|
|
|
|
|
|
|
if ($self->border_width->[3]) {$self->_draw_left_border($x, $y, $gfx)} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _draw_top_border { |
|
110
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx) = @_; |
|
111
|
|
|
|
|
|
|
$y = ($self->{_row_idx} == 0) ? $y-$self->border_width->[0]/2 : $y; |
|
112
|
|
|
|
|
|
|
$gfx->move($x, $y); |
|
113
|
|
|
|
|
|
|
$gfx->linewidth($self->border_width->[0]); |
|
114
|
|
|
|
|
|
|
$gfx->strokecolor($self->border_color->[0]); |
|
115
|
|
|
|
|
|
|
$gfx->hline($x+$self->width); |
|
116
|
|
|
|
|
|
|
$gfx->stroke(); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _draw_right_border { |
|
120
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx) = @_; |
|
121
|
|
|
|
|
|
|
$x = ($self->{_parent}->is_last_in_row($self->{_col_idx})) ? $x-$self->border_width->[1]/2 : $x; |
|
122
|
|
|
|
|
|
|
$gfx->move($x+$self->width, $y); |
|
123
|
|
|
|
|
|
|
$gfx->linewidth($self->border_width->[1]); |
|
124
|
|
|
|
|
|
|
$gfx->strokecolor($self->border_color->[1]); |
|
125
|
|
|
|
|
|
|
$gfx->vline($y-$self->height); |
|
126
|
|
|
|
|
|
|
$gfx->stroke(); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _draw_bottom_border { |
|
130
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx) = @_; |
|
131
|
|
|
|
|
|
|
$y = ($self->{_parent}->is_last_in_col($self->{_row_idx})) ? $y+$self->border_width->[2]/2 : $y; |
|
132
|
|
|
|
|
|
|
$gfx->move($x, $y-$self->height); |
|
133
|
|
|
|
|
|
|
$gfx->linewidth($self->border_width->[2]); |
|
134
|
|
|
|
|
|
|
$gfx->strokecolor($self->border_color->[2]); |
|
135
|
|
|
|
|
|
|
$gfx->hline($x+$self->width); |
|
136
|
|
|
|
|
|
|
$gfx->stroke(); |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _draw_left_border { |
|
140
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx) = @_; |
|
141
|
|
|
|
|
|
|
$x = ($self->{_col_idx} == 0) ? $x+$self->border_width->[3]/2 : $x; |
|
142
|
|
|
|
|
|
|
$gfx->move($x, $y); |
|
143
|
|
|
|
|
|
|
$gfx->linewidth($self->border_width->[3]); |
|
144
|
|
|
|
|
|
|
$gfx->strokecolor($self->border_color->[3]); |
|
145
|
|
|
|
|
|
|
$gfx->vline($y-$self->height); |
|
146
|
|
|
|
|
|
|
$gfx->stroke(); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub draw_background { |
|
150
|
|
|
|
|
|
|
my ($self, $x, $y, $gfx, $txt) = @_; |
|
151
|
|
|
|
|
|
|
if ( $self->background_color ) { |
|
152
|
|
|
|
|
|
|
$gfx->linewidth(0); |
|
153
|
|
|
|
|
|
|
$gfx->fillcolor($self->background_color); |
|
154
|
|
|
|
|
|
|
$gfx->rect($x, $y-$self->height, $self->width, $self->height); |
|
155
|
|
|
|
|
|
|
$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 |