File Coverage

blib/lib/Khonsu/TOC/Outline.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 6 66.6
condition n/a
subroutine 4 4 100.0
pod 0 3 0.0
total 40 45 88.8


line stmt bran cond sub pod time code
1             package Khonsu::TOC::Outline;
2              
3 5     5   44 use parent 'Khonsu::Text';
  5         57  
  5         29  
4              
5             sub attributes {
6 346     346 0 593 my $a = shift;
7             return (
8 346         999 $a->SUPER::attributes(),
9             page => {$a->RW, $a->OBJ},
10             outline => {$a->RW, $a->OBJ},
11             outline_position => {$a->RW, $a->DHR},
12             end_y => {$a->RW, $a->NUM},
13             level => {$a->RW, $a->NUM},
14             children => {$a->RW, $a->DAR},
15             );
16             }
17              
18             sub add {
19 346     346 0 779 my ($self, $file, $outline, %attributes) = @_;
20 346         1219 $self->set_attributes(%attributes);
21 346         790 my %position = $self->get_points();
22 346         1576 $position{y} = $file->page->h - $position{y};
23 346         1887 $self->outline_position(\%position);
24             $outline = $outline->outline()->open()
25             ->title($self->text)
26 346         1161 ->dest($self->page->current, '-xyz' => [$position{x}, $position{y}, 0]);
27 346         42573 $self->outline($outline);
28 346         1019 return $file;
29             }
30              
31             sub render {
32 346     346 0 1942 my ($self, $file, %attributes) = @_;
33             $self->set_attributes(
34             pad => '.',
35             pad_end => $self->page->num + $attributes{page_offset},
36 346         1767 %attributes
37             );
38 346         1804 $self->SUPER::add($file, align => 'none');
39 346         1294 my %position = $self->get_points();
40 346         1659 my $outline_position = $self->outline_position;
41 346         1618 $attributes{y} = $position{y} + $self->font->size;
42 346         1927 $position{y} = $file->page->h - $position{y};
43             my $annotation = $file->page->current->annotation()->rect(
44             $position{x}, $position{y}, $position{w}, $position{y} - $self->font->size
45 346         1683 )->link($self->page->current, '-xyz' => [$outline_position->{x}, $outline_position->{y}, 0]);
46 346         62719 my $y = $attributes{y};
47 346         709 my $num = $attributes{num};
48 346         585 for (@{$self->children}) {
  346         2013  
49 287         677 $y += $attributes{padding};
50 287 50       1406 if ($y > $file->page->h - ($file->page->footer ? $file->page->footer->h : 0)) {
    100          
51 3         19 $file->open_page($num->(1));
52 3 50       20 $y = $file->page->header ? $file->page->header->h : 0;
53             }
54 287         2450 $_->render($file, %attributes, y => $y);
55 287         1591 $y = $_->end_y;
56             }
57 346         1580 $self->end_y($y);
58             }
59              
60             1;