| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | 1 | unshift @words, map { " " } 1 .. $indent; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 12 | ▶ | 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
| |||||||||||||||||||||||||||||
| 55 | 137 | my $word = shift @words; | |||||||||||||||||||||||||||
| 56 | 137 | my ($width, @line) = ($text->advancewidth($word), ()); | |||||||||||||||||||||||||||
| 57 | 137 | ▶ | 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||