TableX/Cell.pm

filter: Statementstmt 94.8% 110 / 116 Branchbran 96.6% 29 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 16 / 18 Podpod 100% 5 / 5 totaltotal 94.6% 160 / 169 CC 19 SCAR 10.4
CC
19
Cov
95%
draw_content
5.0
draw_borders
5.0
_get_min_width
3.0
CRAP 2.8
« TableX.pm ↑ Summary TableX/Row.pm »
1 package PDF::TableX::Cell;
2  
3 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use MooseX::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use PDF::API2;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 with 'PDF::TableX::Drawable';
8 8 with 'PDF::TableX::Stylable';
9  
10 8 has width => (is => 'rw', isa => 'Num');
11 8 has min_width => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_min_width');
12 8 has reg_width => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_reg_width');
13 8 has height => (is => 'rw', isa => 'Num', lazy => 1, builder => '_get_height' );
14 99 ▶has content => (is => 'rw', isa => 'Str', default=> '', trigger => sub { $_[0]->{_overflow} = $_[0]->content; });
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 8 has _overflow => (is => 'ro', isa => 'Str', init_arg => undef, default => '');
17 8 has _pdf_api_content => (is => 'ro', isa => class_type('PDF::API2::Page'), lazy => 1, builder => '_get_content');
18 8 has _parent => (is => 'ro', isa => 'Object');
19 8 has _row_idx => (is => 'ro', isa => 'Int', default => 0);
20 8 has _col_idx => (is => 'ro', isa => 'Int', default => 0);
21  
22 643 ▶around 'content' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
23 643 my $orig = shift;
24 643 my $self = shift;
25 643 ▶ return $self->$orig() unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 544 99 643
26 99 $self->$orig(@_);
27 99 return $self;
28 8 };
29  
30 0 ▶sub _get_content { return PDF::API2->new()->page; }
Subroutine _get_content: not called CC=1 SCAR=6.9
31  
32 144 ▶sub _get_min_width {
Subroutine _get_min_width: called CC=3 SCAR=11.0
33 144 my ($self) = @_;
34 144 my $txt = PDF::API2->new()->page->text();
35 144 $txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size );
36 144 my $min_width = 0;
37 144 for (split(/\s/, $self->content)) {
38 2517 my $word_width = $txt->advancewidth($_);
39 2517 ▶ $min_width = ($word_width > $min_width) ? $word_width : $min_width;
Branch: 1 branch
BranchTrueFalseTotal
$word_width > $min_width ? : 184 2333 2517
40 }
41 144 return $min_width + $self->padding->[1] + $self->padding->[3];
42 }
43  
44 144 ▶sub _get_reg_width {
Subroutine _get_reg_width: called CC=3 SCAR=11.0
45 144 my ($self) = @_;
46 144 my $txt = PDF::API2->new()->page->text();
47 144 $txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size );
48 144 my $reg_width = 0;
49 144 for (split("\n", $self->content)) {
50 103 my $line_width = $txt->advancewidth($_);
51 103 ▶ $reg_width = ($line_width > $reg_width) ? $line_width : $reg_width;
Branch: 1 branch
BranchTrueFalseTotal
$line_width > $reg_width ? : 95 8 103
52 }
53 144 return $reg_width + $self->padding->[1] + $self->padding->[3];
54 }
55  
56 0 ▶sub _get_height {
Subroutine _get_height: not called CC=1 SCAR=6.9
57 0 my ($self) = @_;
58 0 my $height = $self->padding->[0] + $self->padding->[2];
59 0 $height += scalar(split("\n", $self->content)) * $self->font_size;
60 0 return $height;
61 }
62  
63 156 ▶sub draw_content {
Subroutine draw_content: called CC=5 SCAR=16.1
Pod documented
64 156 my ($self, $x, $y, $gfx, $txt) = @_;
65 156 $y -= $self->padding->[0] + $self->font_size;
66 156 ▶ $x += $self->padding->[3]
Branch: 2 branches
BranchTrueFalseTotal
$self->text_align eq 'right' ? : 48 108 156
$self->text_align eq 'center' ? : 39 117 156
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 my $width = 0;
71 156 $txt->save;
72 156 $txt->font( PDF::API2->new()->corefont( $self->font ), $self->font_size );
73 156 $txt->lead( $self->font_size );
74 156 $txt->fillcolor( $self->font_color );
75 156 $txt->translate($x, $y);
76 156 my $overflow = '';
77 156 for my $p ( split ( "\n", $self->{_overflow} ) ) {
78 115 ▶ if ($overflow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overflow) { } 0 115 115
79 0 $overflow .= "\n" . $p;
80 } else {
81 115 $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 $self->{_overflow} = $overflow;
85 156 $self->height( $y - [ $txt->textpos() ]->[1] + $self->padding->[0] + $self->padding->[2]);
86 156 $txt->restore;
87 156 return ($self->get_text_width, $self->height, length($overflow));
88 }
89  
90 152 ▶sub reset_content {
Subroutine reset_content: called CC=1 SCAR=0.0
Pod documented
91 152 my ($self) = @_;
92 152 $self->{_overflow} = $self->content;
93 152 return $self;
94 }
95  
96 358 ▶sub get_text_width {
Subroutine get_text_width: called CC=1 SCAR=0.0
Pod documented
97 358 my ($self) = @_;
98 358 return $self->width - $self->padding->[1] - $self->padding->[3];
99 }
100  
101 158 ▶sub draw_borders {
Subroutine draw_borders: called CC=5 SCAR=16.1
Pod documented
102 158 my ($self, $x, $y, $gfx, $txt) = @_;
103 158 ▶ if ($self->border_width->[0]) {$self->_draw_top_border($x, $y, $gfx)}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->border_width->[0]) 136 22 158
104 158 ▶ if ($self->border_width->[1]) {$self->_draw_right_border($x, $y, $gfx)}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->border_width->[1]) 136 22 158
105 158 ▶ if ($self->border_width->[2]) {$self->_draw_bottom_border($x, $y, $gfx)}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->border_width->[2]) 152 6 158
106 158 ▶ if ($self->border_width->[3]) {$self->_draw_left_border($x, $y, $gfx)}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->border_width->[3]) 152 6 158
107 }
108  
109 136 ▶sub _draw_top_border {
Subroutine _draw_top_border: called CC=2 SCAR=6.9
110 136 my ($self, $x, $y, $gfx) = @_;
111 136 ▶ $y = ($self->{_row_idx} == 0) ? $y-$self->border_width->[0]/2 : $y;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_row_idx'} == 0 ? : 19 117 136
112 136 $gfx->move($x, $y);
113 136 $gfx->linewidth($self->border_width->[0]);
114 136 $gfx->strokecolor($self->border_color->[0]);
115 136 $gfx->hline($x+$self->width);
116 136 $gfx->stroke();
117 }
118  
119 136 ▶sub _draw_right_border {
Subroutine _draw_right_border: called CC=2 SCAR=6.9
120 136 my ($self, $x, $y, $gfx) = @_;
121 136 ▶ $x = ($self->{_parent}->is_last_in_row($self->{_col_idx})) ? $x-$self->border_width->[1]/2 : $x;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_parent'}->is_last_in_row($self->{'_col_idx'}) ? : 21 115 136
122 136 $gfx->move($x+$self->width, $y);
123 136 $gfx->linewidth($self->border_width->[1]);
124 136 $gfx->strokecolor($self->border_color->[1]);
125 136 $gfx->vline($y-$self->height);
126 136 $gfx->stroke();
127 }
128  
129 152 ▶sub _draw_bottom_border {
Subroutine _draw_bottom_border: called CC=2 SCAR=6.9
130 152 my ($self, $x, $y, $gfx) = @_;
131 152 ▶ $y = ($self->{_parent}->is_last_in_col($self->{_row_idx})) ? $y+$self->border_width->[2]/2 : $y;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_parent'}->is_last_in_col($self->{'_row_idx'}) ? : 21 131 152
132 152 $gfx->move($x, $y-$self->height);
133 152 $gfx->linewidth($self->border_width->[2]);
134 152 $gfx->strokecolor($self->border_color->[2]);
135 152 $gfx->hline($x+$self->width);
136 152 $gfx->stroke();
137 }
138  
139 152 ▶sub _draw_left_border {
Subroutine _draw_left_border: called CC=2 SCAR=6.9
140 152 my ($self, $x, $y, $gfx) = @_;
141 152 ▶ $x = ($self->{_col_idx} == 0) ? $x+$self->border_width->[3]/2 : $x;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_col_idx'} == 0 ? : 37 115 152
142 152 $gfx->move($x, $y);
143 152 $gfx->linewidth($self->border_width->[3]);
144 152 $gfx->strokecolor($self->border_color->[3]);
145 152 $gfx->vline($y-$self->height);
146 152 $gfx->stroke();
147 }
148  
149 156 ▶sub draw_background {
Subroutine draw_background: called CC=2 SCAR=6.9
Pod documented
150 156 my ($self, $x, $y, $gfx, $txt) = @_;
151 156 ▶ if ( $self->background_color ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->background_color) 116 40 156
152 116 $gfx->linewidth(0);
153 116 $gfx->fillcolor($self->background_color);
154 116 $gfx->rect($x, $y-$self->height, $self->width, $self->height);
155 116 $gfx->fill();
156 }
157 }
158  
159 8 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
« TableX.pm ↑ Summary TableX/Row.pm »