File Coverage

blib/lib/Khonsu/Form/Field.pm
Criterion Covered Total %
statement 32 32 100.0
branch 1 2 50.0
condition 2 5 40.0
subroutine 6 6 100.0
pod 0 3 0.0
total 41 48 85.4


line stmt bran cond sub pod time code
1             package Khonsu::Form::Field;
2              
3 5     5   1903 use parent 'Khonsu::Text';
  5         10  
  5         26  
4              
5 5     5   287 use PDF::API2::Basic::PDF::Utils;
  5         10  
  5         420  
6 5     5   32 use PDF::API2::Basic::PDF::Utils;
  5         30  
  5         2266  
7              
8             sub attributes {
9 12     12 0 26 my $a = shift;
10             return (
11 12         45 $a->SUPER::attributes(),
12             xo => { $a->RW, $a->OBJ },
13             annotate => { $a->RW, $a->OBJ },
14             name => { $a->RW, $a->STR },
15             );
16             }
17              
18             sub add {
19 7     7 0 28 my ($self, $file, %args) = @_;
20              
21 7         43 my %position = $self->get_points();
22              
23 7         41 my $field = $self->xo(
24             $file->pdf->xo_form()
25             );
26              
27 7         59 $self->SUPER::add($file, %args);
28              
29 7         40 my $annotate = $self->annotate(
30             $file->page->current->annotation
31             );
32 7         42 $field->{OpenAction} = PDFArray($self->annotate, PDFName('XYZ'), PDFNull, PDFNull, PDFNum(0));
33 7         413 $field->bbox(0, 0, 149.8, 14.4);
34 7         619 $annotate->{DR} = $self->font->load();
35 7   33     62 $annotate->{T} = PDFStr($self->name || $args{text});
36 7         134 $annotate->{Subtype} = PDFName('Widget');
37 7         118 $annotate->{P} = $file->page->current;
38 7   50     61 $args{position} ||= \@pps;
39 7 50       75 $self->configure($file, %args) if $self->can('configure');
40 7         66 $self->set_rect($file, %args);
41 7         594 $file->form->add_to_fields($file, $self->annotate);
42 7         40 return $file;
43             }
44              
45             sub set_rect {
46 3     3 0 15 my ($self, $file, %args) = @_;
47 3         14 my %position = $self->get_points();
48 3         22 $position{y} = $file->page->h - $position{y};
49             my @pos = (
50             $self->end_w + 2,
51             $position{y} + ($self->font->size*0.2),
52             $position{w},
53 3         23 $position{y} - ($self->font->size*1.4)
54             );
55 3         19 $self->annotate->rect(@pos);
56             }
57              
58             1;