Khonsu/Text.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 91.6% 11 / 12 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 94.4% 68 / 72 CC 10 SCAR 20.7
CC
10
Cov
97%
add
10.0
BEGIN
1.0
attributes
1.0
CRAP 7.9
↑ Summary Khonsu/Shape/Line.pm »
1 package Khonsu::Text;
2  
3 2 ▶use parent 'Khonsu::Ra';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 sub attributes {
6 7 ▶ 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 7 ▶ indent => {$a->RW, $a->NUM, default => sub { 0 }},
Subroutine __ANON__: called CC=1 SCAR=0.0
11 7 $a->FONT,
12 $a->POINTS
13 );
14 }
15  
16 sub add {
17 12 ▶ my ($self, $file, %attributes) = @_;
Subroutine add: called CC=10 SCAR=23.0
Pod undocumented
18  
19 12 ▶ my $font = $self->font->load($file, %{ delete $attributes{font} || {} });
Branch: 1 branch
BranchTrueFalseTotal
delete $attributes{"font"} or {} 4 8 12
20  
21 12 $self->set_attributes(%attributes);
22  
23 12 my $size = $self->font->size;
24
25 12 my $text = $file->page->current->text;
26
27 12 $text->font($font, $size);
28
29 12 $text->fillcolor($self->font->colour);
30  
31 12 my (%pos) = (
32 l => $self->font->line_height,
33 $self->get_points()
34 );
35  
36 12 my $ypos = $file->page->h - ($pos{y} + $pos{l});
37  
38 12 my $max_height = $ypos - $pos{h};
39  
40 12 my $xpos = $pos{x};
41  
42 12 my $indent = $self->indent;
43
44 12 my @paragraphs = split /\n/, $self->text;
45  
46 12 my $space = $text->advancewidth(" ");
47  
48 12 my @words = split / /, shift @paragraphs;
49  
50 12 ▶ if ($indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent) 1 11 12
51 1 unshift @words, map { " " } 1 .. $indent;
52 }
53
54 12 ▶ while ($ypos > $max_height && @words) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ypos > $max_height and @words) 137 12 149
Condition100%3/3
$ypos > $max_height and @words
!ll&&!rl&&r
111137
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
55 137 my $word = shift @words;
56 137 my ($width, @line) = ($text->advancewidth($word), ());
57 137 ▶ while ($width <= $pos{w} && $word) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width <= $pos{"w"} and $word) 2072 137 2209
Condition100%3/3
$width <= $pos{"w"} and $word
!ll&&!rl&&r
126112072
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
58 2072 $width += $space;
59 2072 push @line, $word;
60 2072 $word = shift @words;
61 2072 $width += $text->advancewidth($word);
62 }
63 137 ▶ unshift @words, $word if (scalar @words);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @words 126 11 137
64 137 $text->translate($xpos, $ypos);
65 137 $text->text(join(" ", @line));
66 137 $ypos -= $pos{l};
67 }
68  
69 12 ▶ if (!$self->overflow && scalar @words) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->overflow and scalar @words) 0 12 12
Condition100%2/2
not $self->overflow and scalar @words
!ll
111
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
70 0 die "Too many words to fit the max height: $pos{h} and width: $pos{w} overflow:" . join " ", @words;
71 }
72  
73 12 return $file;
74 }
75  
76 2 1;
↑ Summary Khonsu/Shape/Line.pm »