File Coverage

blib/lib/Khonsu/Form/Field/Checkbox.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Khonsu::Form::Field::Checkbox;
2              
3 5     5   35 use parent 'Khonsu::Form::Field';
  5         11  
  5         28  
4              
5 5     5   297 use PDF::API2::Resource::XObject::Form;
  5         12  
  5         108  
6 5     5   22 use PDF::API2::Basic::PDF::Literal;
  5         11  
  5         104  
7 5     5   25 use PDF::API2::Basic::PDF::Utils;
  5         10  
  5         2114  
8              
9             sub attributes {
10 4     4 0 10 my $a = shift;
11             return (
12             $a->SUPER::attributes(),
13 4     4   9 width => {$a->RW, $a->NUM, default => sub { 50 }}
14 4         22 );
15             }
16              
17             sub configure {
18 1     1 0 6 my ($self, $file, %args) = @_;
19 1         5 $self->annotate->{Type} = PDFName( 'Annot' );
20 1         5 $self->annotate->{Subtype} = PDFName( 'Widget' );
21 1         5 $self->annotate->{FT} = PDFName( 'Btn' );
22 1         6 $self->annotate->{T} = PDFStr( 'checkbox1' );
23 1         5 $self->annotate->{V} = PDFName( 'Off' );
24 1         16 $self->annotate->{Rect} = PDF::API2::Basic::PDF::Literal->new( "[100 300 200 400]" );
25 1         5 $self->annotate->{H} = PDFName( 'N' );
26 1         4 $self->annotate->{AS} = PDFName('Off');
27 1         5 $self->annotate->{AP} = PDFDict();
28 1         6 $self->annotate->{AP}->realise();
29 1         8 $self->annotate->{AP}->{N} = PDFDict();
30 1         7 $self->annotate->{AP}->{N}->realise();
31             }
32              
33             sub set_rect {
34 1     1 0 5 my ($self, $file, %args) = @_;
35 1         5 my %position = $self->get_points();
36 1         8 $position{y} = $file->page->h - $position{y};
37             my @pos = (
38             $self->end_w,
39             $position{y} + ($self->font->size*0.4),
40             $self->end_w + $self->width,
41 1         6 $position{y} - ($self->font->size*1.2)
42             );
43 1         7 $self->annotate->rect(@pos);
44             }
45              
46             1;