| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 512 | unshift @words, map { " " } 0 .. $indent; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1719 | ▶ | while ($ypos > $max_height && @words) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ypos > $max_height and @words
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
| |||||||||||||||||||||||||||||
| 59 | 1969 | my $word = shift @words; | |||||||||||||||||||||||||||
| 60 | 1969 | my ($width, @line) = ($text->advancewidth($word), ()); | |||||||||||||||||||||||||||
| 61 | 1969 | ▶ | while ($width <= $pos{w} && $word) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$width <= $pos{"w"} and $word
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 69 | 252 | ▶ | unshift @words, $word if (scalar @words); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 75 | 613 | ▶ | push @line, $self->pad_end if $self->pad_end; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 613 | $width = $pos{w}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1969 | my $align = $self->align; | |||||||||||||||||||||||||||
| 80 | 1969 | ▶ | if ($align eq 'center') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition100%2/2
not $self->overflow and scalar @words
MC/DC100%1/1
not $self->overflow and scalar @words
not $self->overflow
Truth table100%2/2
not(A)
A= not $self->overflow
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||