Khonsu/Text.pm

filter: Statementstmt 98.1% 53 / 54 Branchbran 88.4% 23 / 26 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 94.0% 94 / 100 CC 17 SCAR 26.4
CC
17
Cov
95%
add
17.0
BEGIN
1.0
attributes
1.0
CRAP 14.0
↑ Summary Khonsu/Page/Footer.pm »
1 package Khonsu::Text;
2  
3 3 ▶use parent 'Khonsu::Ra';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub attributes {
6 634 ▶ my $a = shift;
Subroutine attributes: called CC=1 SCAR=0.0
Pod undocumented
7 return (
8 text => {$a->RW, $a->STR},
9 overflow => {$a->RW, $a->BOOL},
10 634 ▶ indent => {$a->RW, $a->NUM, default => sub { 0 }},
Subroutine __ANON__: called CC=1 SCAR=0.0
11 pad => {$a->RW, $a->STR},
12 pad_end => {$a->RW, $a->STR},
13 634 ▶ align => {$a->RW, $a->STR, default => sub { 'left' }},
Subroutine __ANON__: called CC=1 SCAR=0.0
14 634 end_w => {$a->RW, $a->NUM},
15 $a->FONT,
16 $a->POINTS
17 );
18 }
19  
20 sub add {
21 1719 ▶ my ($self, $file, %attributes) = @_;
Subroutine add: called CC=17 SCAR=28.4
Pod undocumented
22  
23 1719 ▶ my $font = $self->font->load($file, %{ delete $attributes{font} || {} });
Branch: 1 branch
BranchTrueFalseTotal
delete $attributes{"font"} or {} 1101 618 1719
24
25 1719 $self->set_attributes(%attributes);
26  
27 1719 my $size = $self->font->size;
28
29 1719 my $text = $file->page->current->text;
30
31 1719 $text->font($font, $size);
32
33 1719 $text->fillcolor($self->font->colour);
34  
35 1719 my (%pos) = (
36 l => $self->font->line_height,
37 $self->get_points()
38 );
39  
40 1719 my $ypos = $file->page->h - ($pos{y} + $pos{l});
41  
42 1719 my $max_height = $ypos - $pos{h};
43  
44 1719 my $xpos = $pos{x};
45  
46 1719 my $indent = $self->indent;
47
48 1719 my @paragraphs = split /\n/, $self->text;
49
50 1719 my $space = $text->advancewidth(" ");
51  
52 1719 my @words = split / /, shift @paragraphs;
53  
54 1719 ▶ if ($indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent) 512 1207 1719
55 512 unshift @words, map { " " } 0 .. $indent;
56 }
57  
58 1719 ▶ while ($ypos > $max_height && @words) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ypos > $max_height and @words) 1969 1719 3688
Condition100%3/3
$ypos > $max_height and @words
!ll&&!rl&&r
52211971969
MC/DC100%2/2
$ypos > $max_height and @words
$ypos > $max_height @words
Truth table100%3/3
A and B
A= $ypos > $max_heightB= @words
ABresult
0X0
100
111
59 1969 my $word = shift @words;
60 1969 my ($width, @line) = ($text->advancewidth($word), ());
61 1969 ▶ while ($width <= $pos{w} && $word) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width <= $pos{"w"} and $word) 13306 1969 15275
Condition100%3/3
$width <= $pos{"w"} and $word
!ll&&!rl&&r
252171713306
MC/DC100%2/2
$width <= $pos{"w"} and $word
$width <= $pos{"w"} $word
Truth table100%3/3
A and B
A= $width <= $pos{"w"}B= $word
ABresult
0X0
100
111
62 13306 $width += $space;
63 13306 push @line, $word;
64 13306 $word = shift @words;
65 13306 $width += $text->advancewidth($word);
66 }
67 1969 $self->end_w($xpos + $width);
68 1969 ▶ if ($word) {
Branch: 2 branches
BranchTrueFalseTotal
if ($word) { } 252 1717 1969
elsif ($self->pad) { } 613 1104 1717
69 252 ▶ unshift @words, $word if (scalar @words);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @words 252 0 252
70 } elsif ($self->pad) {
71 613 my $pad_width = $text->advancewidth($self->pad);
72 613 ▶ my $pad_end_width = $self->pad_end ? $text->advancewidth($self->pad_end) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->pad_end ? : 612 1 613
73 613 my $left = int(($pos{w} - ($width + $pad_end_width)) / $pad_width);
74 613 ▶ push @line, $self->pad x $left if $left;
Branch: 1 branch
BranchTrueFalseTotal
if $left 613 0 613
75 613 ▶ push @line, $self->pad_end if $self->pad_end;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pad_end 612 1 613
76 613 $width = $pos{w};
77 }
78  
79 1969 my $align = $self->align;
80 1969 ▶ if ($align eq 'center') {
Branch: 2 branches
BranchTrueFalseTotal
if ($align eq 'center') { } 240 1729 1969
elsif ($align eq 'right') { } 120 1609 1729
81 240 $xpos = $xpos + ((($pos{w} - $width) / 2) - ($width / 2));
82 } elsif ($align eq 'right') {
83 120 $xpos = $xpos + ($pos{w} - $width);
84 }
85  
86 1969 $text->translate($xpos, $ypos);
87 1969 $text->text(join(" ", @line));
88 1969 $ypos -= $pos{l};
89 }
90  
91 1719 ▶ if (!$self->overflow && scalar @words) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->overflow and scalar @words) 0 1719 1719
Condition100%2/2
not $self->overflow and scalar @words
!ll
21717
MC/DC100%1/1
not $self->overflow and scalar @words
not $self->overflow
Truth table100%2/2
not(A)
A= not $self->overflow
Aresult
00
11
92 0 die "Too many words to fit the max height: $pos{h} and width: $pos{w} overflow:" . join " ", @words;
93 }
94  
95 1719 return $file;
96 }
97  
98 3 1;
↑ Summary Khonsu/Page/Footer.pm »