File Coverage

blib/lib/PDF/API2/Resource/XObject/Form.pm
Criterion Covered Total %
statement 23 35 65.7
branch 2 10 20.0
condition 0 11 0.0
subroutine 6 7 85.7
pod 3 3 100.0
total 34 66 51.5


line stmt bran cond sub pod time code
1             package PDF::API2::Resource::XObject::Form;
2              
3 38     38   399 use base 'PDF::API2::Resource::XObject';
  38         93  
  38         17369  
4              
5 38     38   270 use strict;
  38         93  
  38         768  
6 38     38   207 use warnings;
  38         87  
  38         1537  
7              
8             our $VERSION = '2.043'; # VERSION
9              
10 38     38   219 use PDF::API2::Basic::PDF::Utils;
  38         90  
  38         16870  
11              
12             =head1 NAME
13              
14             PDF::API2::Resource::XObject::Form - Base class for external form objects
15              
16             =head1 METHODS
17              
18             =over
19              
20             =item $form = PDF::API2::Resource::XObject::Form->new($pdf)
21              
22             Creates a form resource.
23              
24             =cut
25              
26             sub new {
27 10     10 1 31 my ($class, $pdf, $name) = @_;
28 10         71 my $self = $class->SUPER::new($pdf, $name);
29              
30 10         67 $self->subtype('Form');
31 10         85 $self->{'FormType'} = PDFNum(1);
32              
33 10         28 return $self;
34             }
35              
36             =item ($llx, $lly, $urx, $ury) = $form->bbox($llx, $lly, $urx, $ury)
37              
38             Get or set the coordinates of the form object's bounding box
39              
40             =cut
41              
42             sub bbox {
43 11     11 1 32 my $self = shift();
44              
45 11 100       29 if (scalar @_) {
46 10         77 $self->{'BBox'} = PDFArray(map { PDFNum($_) } @_);
  40         86  
47             }
48              
49 11         114 return map { $_->val() } $self->{'BBox'}->elements();
  44         92  
50             }
51              
52             =item $resource = $form->resource($type, $key)
53              
54             =item $form->resource($type, $key, $object, $force)
55              
56             Get or add a resource required by the form's contents, such as a Font, XObject, ColorSpace, etc.
57              
58             By default, an existing C<$key> will not be overwritten. Set C<$force> to override this behavior.
59              
60             =cut
61              
62             sub resource {
63 0     0 1   my ($self, $type, $key, $object, $force) = @_;
64             # we are a self-contained content stream.
65              
66 0   0       $self->{'Resources'} ||= PDFDict();
67              
68 0           my $dict = $self->{'Resources'};
69 0 0         $dict->realise() if ref($dict) =~ /Objind$/;
70              
71 0   0       $dict->{$type} ||= PDFDict();
72 0 0         $dict->{$type}->realise() if ref($dict->{$type}) =~ /Objind$/;
73              
74 0 0         unless (defined $object) {
75 0   0       return $dict->{$type}->{$key} || undef;
76             }
77              
78 0 0         if ($force) {
79 0           $dict->{$type}->{$key} = $object;
80             }
81             else {
82 0   0       $dict->{$type}->{$key} ||= $object;
83             }
84              
85 0           return $dict;
86             }
87              
88             =back
89              
90             =cut
91              
92             1;