lib/PDF/Boxer/Content/Text.pm

filter: Statementstmt 16.6% 14 / 84 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 22.2% 2 / 9 Podpod 20.0% 1 / 5 totaltotal 10.6% 17 / 160 CC 27 SCAR 35.9
CC
27
Cov
10%
__ANON__
72.0
__ANON__
42.0
split_line
42.0
CRAP 36.3
« lib/PDF/Boxer/Content/Image.pm ↑ Summary lib/PDF/Boxer/Content/Column.pm »
1 package PDF::Boxer::Content::Text;
2 {
3 3 $PDF::Boxer::Content::Text::VERSION = '0.004';
4 }
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: a box that displays text
7  
8 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'PDF::Boxer::Content::Box';
11 3 with 'PDF::Boxer::Role::Text';
12  
13 0 ▶sub get_default_size{
Subroutine get_default_size: not called CC=3 SCAR=24.8
Pod documented
14 0 my ($self) = @_;
15 0 my $space = $self->boxer->max_width;
16 0 my ($width, $height) = $self->find_smallest_block($space);
17 0 ▶ warn sprintf "Text %s default size: %s x %s\n", $self->name, $width, $height if $self->debug && $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug and $self->name 0 0 0
Condition0%0/3
$self->debug and $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->debug and $self->name
$self->debug $self->name
Truth table0%0/3
A and B
A= $self->debugB= $self->name
ABresult
0X0
100
111
18 0 return (int($width+1), int($height+1));
19 }
20  
21 0 ▶around 'update' => sub{
Subroutine __ANON__: not called CC=8 SCAR=42.8
22 0 my ($orig, $self) = @_;
23  
24 0 my ($width, $height) = $self->find_smallest_block($self->width);
25 0 ▶ warn sprintf "Text %s smallest_block %s x %s\n", ($self->name, $width, $height) if $self->debug && $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug and $self->name 0 0 0
Condition0%0/3
$self->debug and $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->debug and $self->name
$self->debug $self->name
Truth table0%0/3
A and B
A= $self->debugB= $self->name
ABresult
0X0
100
111
26 0 ▶ $self->set_height($height) if $self->height < $height;
Branch: 1 branch
BranchTrueFalseTotal
if $self->height < $height 0 0 0
27  
28 0 ▶ warn sprintf "Text %s child_adjusted_height? %s < %s\n", $self->name, $self->margin_bottom, $self->parent->content_bottom if $self->debug && $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug and $self->name 0 0 0
Condition0%0/3
$self->debug and $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->debug and $self->name
$self->debug $self->name
Truth table0%0/3
A and B
A= $self->debugB= $self->name
ABresult
0X0
100
111
29 0 ▶ if ($self->margin_bottom < $self->parent->content_bottom){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->margin_bottom < $self->parent->content_bottom) 0 0 0
30 0 ▶ warn "Text child_adjusted_height\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
31 0 $self->parent->child_adjusted_height($self);
32 }
33
34 3 };
35  
36 0 ▶around 'render' => sub{
Subroutine __ANON__: not called CC=6 SCAR=37.4
37 0 my ($orig, $self) = @_;
38  
39 0 my $text = $self->prepare_text;
40  
41 0 my $wrapped_lines = $self->wrapped_lines([@{$self->value}], $self->width);
42  
43 0 my $longest_line_length = $self->longest_line($wrapped_lines);
44  
45 0 my $font = $self->get_font;
46  
47 0 my $x = $self->content_left;
48 0 my $y = $self->baseline_top($font, $self->size);
49 0 my $align_method = 'text';
50  
51 0 ▶ foreach($self->align || ()){
Condition0%0/3
$self->align || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->align || ()
$self->align ()
Truth table0%0/3
A || B
A= $self->alignB= ()
ABresult
1X1
011
000
52 0 ▶ /^rig/ && do { $x = $self->content_right; $align_method = 'text_right' };
Branch: 1 branch
BranchTrueFalseTotal
/^rig/ and do { $x = $self->content_right; $align_method = "text_right" } 0 0 0
53 0 ▶ /^cen/ && do { $x += ($self->width/2); $align_method = 'text_center' };
Branch: 1 branch
BranchTrueFalseTotal
/^cen/ and do { $x += $self->width / 2; $align_method = "text_center" } 0 0 0
54 }
55  
56 0 $text->translate($x,$y);
57 0 foreach(@$wrapped_lines){
58 0 $text->$align_method( $_ );
59 0 $text->cr;
60 }
61  
62 0 $self->$orig();
63  
64 3 };
65  
66  
67  
68  
69 0 ▶sub find_smallest_block{
Subroutine find_smallest_block: not called CC=4 SCAR=30.0
Pod undocumented
70 0 my ($self, $space) = @_;
71 0 ▶ return if $space > 1000;
Branch: 1 branch
BranchTrueFalseTotal
if $space > 1000 0 0 0
72 0 my $wrapped_lines = $self->wrapped_lines([@{$self->value}], $space);
73 0 my $width = $self->longest_line($wrapped_lines);
74 0 my $height = $self->lead * scalar @$wrapped_lines;
75 0 ▶ warn sprintf "Text %s find_smallest_block: %s x %s\n", $self->name, $width, $height if $self->debug && $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug and $self->name 0 0 0
Condition0%0/3
$self->debug and $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->debug and $self->name
$self->debug $self->name
Truth table0%0/3
A and B
A= $self->debugB= $self->name
ABresult
0X0
100
111
76 0 return ($width, $height); # if 1 - $width/($height || 1) < .2;
77 }
78  
79 0 ▶sub longest_line{
Subroutine longest_line: not called CC=3 SCAR=24.8
Pod undocumented
80 0 my ($self, $lines) = @_;
81 0 my $text = $self->prepare_text;
82 0 my $longest_line_length = 0;
83 0 foreach my $line (@$lines){
84 0 my $len = $text->advancewidth($line);
85 0 ▶ $longest_line_length = $len if $len > $longest_line_length;
Branch: 1 branch
BranchTrueFalseTotal
if $len > $longest_line_length 0 0 0
86 }
87 0 return $longest_line_length;
88 }
89  
90 0 ▶sub wrapped_lines{
Subroutine wrapped_lines: not called CC=3 SCAR=24.8
Pod undocumented
91 0 my ($self, $lines, $space) = @_;
92 0 my @wrapped_lines;
93 0 my $text = $self->prepare_text;
94 0 foreach my $line (@$lines){
95 0 my $len = $text->advancewidth($line);
96 0 ▶ if ($len > $space){
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $space) { } 0 0 0
97 0 my $wrapped_lines = $self->split_line($line, $space);
98 0 push(@wrapped_lines, @$wrapped_lines);
99 } else {
100 0 push(@wrapped_lines, $line);
101 }
102 }
103 0 return (\@wrapped_lines);
104 }
105  
106 0 ▶sub split_line{
Subroutine split_line: not called CC=6 SCAR=37.4
Pod undocumented
107 0 my ($self, $line, $width) = @_;
108 0 ▶ my @words = ref $line ? @$line : split(/\s+/, $line);
Branch: 1 branch
BranchTrueFalseTotal
ref $line ? : 0 0 0
109 0 my @wrapped_lines;
110 0 my $text = $self->prepare_text;
111 0 ▶ while (@words){
Branch: 1 branch
BranchTrueFalseTotal
if (@words) 0 0 0
112 0 my $new_line = shift @words;
113 0 ▶ while (@words && $text->advancewidth($new_line.' '.$words[0]) < $width){
Branch: 1 branch
BranchTrueFalseTotal
if (@words and $text->advancewidth($new_line . ' ' . $words[0]) < $width) 0 0 0
Condition0%0/3
@words and $text->advancewidth($new_line . ' ' . $words[0]) < $width
!ll&&!rl&&r
000
MC/DC0%0/2
@words and $text->advancewidth($new_line . ' ' . $words[0]) < $width
@words $text->advancewidth($new_line . ' ' . $words[0]) < $width
Truth table0%0/3
A and B
A= @wordsB= $text->advancewidth($new_line . ' ' . $words[0]) < $width
ABresult
0X0
100
111
114 0 ▶ last unless @words;
Branch: 1 branch
BranchTrueFalseTotal
unless @words 0 0 0
115 0 $new_line .= ' ' . shift @words;
116 }
117 0 push(@wrapped_lines, $new_line);
118 }
119 0 return \@wrapped_lines;
120 }
121  
122  
123 3 __PACKAGE__->meta->make_immutable;
124  
125 3 1;
126  
127  
128 __END__
« lib/PDF/Boxer/Content/Image.pm ↑ Summary lib/PDF/Boxer/Content/Column.pm »