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   36 use parent 'Khonsu::Text';
  5         56  
  5         28  
4              
5             sub attributes {
6 346     346 0 602 my $a = shift;
7             return (
8 346         981 $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 854 my ($self, $file, $outline, %attributes) = @_;
20 346         1141 $self->set_attributes(%attributes);
21 346         794 my %position = $self->get_points();
22 346         1450 $position{y} = $file->page->h - $position{y};
23 346         1883 $self->outline_position(\%position);
24             $outline = $outline->outline()->open()
25             ->title($self->text)
26 346         1270 ->dest($self->page->current, '-xyz' => [$position{x}, $position{y}, 0]);
27 346         42507 $self->outline($outline);
28 346         1006 return $file;
29             }
30              
31             sub render {
32 346     346 0 1908 my ($self, $file, %attributes) = @_;
33             $self->set_attributes(
34             pad => '.',
35             pad_end => $self->page->num + $attributes{page_offset},
36 346         1578 %attributes
37             );
38 346         1644 $self->SUPER::add($file, align => 'none');
39 346         1173 my %position = $self->get_points();
40 346         1546 my $outline_position = $self->outline_position;
41 346         1424 $attributes{y} = $position{y} + $self->font->size;
42 346         1599 $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         1510 )->link($self->page->current, '-xyz' => [$outline_position->{x}, $outline_position->{y}, 0]);
46 346         60998 my $y = $attributes{y};
47 346         693 my $num = $attributes{num};
48 346         520 for (@{$self->children}) {
  346         2168  
49 287         571 $y += $attributes{padding};
50 287 50       1236 if ($y > $file->page->h - ($file->page->footer ? $file->page->footer->h : 0)) {
    100          
51 3         29 $file->open_page($num->(1));
52 3 50       16 $y = $file->page->header ? $file->page->header->h : 0;
53             }
54 287         2612 $_->render($file, %attributes, y => $y);
55 287         1566 $y = $_->end_y;
56             }
57 346         1696 $self->end_y($y);
58             }
59              
60             1;