File: Form.pm

package info (click to toggle)
libpdf-api2-perl 2.048-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,228 kB
  • sloc: perl: 42,239; makefile: 11
file content (92 lines) | stat: -rw-r--r-- 1,790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package PDF::API2::Resource::XObject::Form;

use base 'PDF::API2::Resource::XObject';

use strict;
use warnings;

our $VERSION = '2.048'; # VERSION

use PDF::API2::Basic::PDF::Utils;

=head1 NAME

PDF::API2::Resource::XObject::Form - Base class for external form objects

=head1 METHODS

=over

=item $form = PDF::API2::Resource::XObject::Form->new($pdf)

Creates a form resource.

=cut

sub new {
    my ($class, $pdf, $name) = @_;
    my $self = $class->SUPER::new($pdf, $name);

    $self->subtype('Form');
    $self->{'FormType'} = PDFNum(1);

    return $self;
}

=item ($llx, $lly, $urx, $ury) = $form->bbox($llx, $lly, $urx, $ury)

Get or set the coordinates of the form object's bounding box

=cut

sub bbox {
    my $self = shift();

    if (scalar @_) {
        $self->{'BBox'} = PDFArray(map { PDFNum($_) } @_);
    }

    return map { $_->val() } $self->{'BBox'}->elements();
}

=item $resource = $form->resource($type, $key)

=item $form->resource($type, $key, $object, $force)

Get or add a resource required by the form's contents, such as a Font, XObject, ColorSpace, etc.

By default, an existing C<$key> will not be overwritten.  Set C<$force> to override this behavior.

=cut

sub resource {
    my ($self, $type, $key, $object, $force) = @_;
    # we are a self-contained content stream.

    $self->{'Resources'} ||= PDFDict();

    my $dict = $self->{'Resources'};
    $dict->realise() if ref($dict) =~ /Objind$/;

    $dict->{$type} ||= PDFDict();
    $dict->{$type}->realise() if ref($dict->{$type}) =~ /Objind$/;

    unless (defined $object) {
        return $dict->{$type}->{$key} || undef;
    }

    if ($force) {
        $dict->{$type}->{$key} = $object;
    }
    else {
        $dict->{$type}->{$key} ||= $object;
    }

    return $dict;
}

=back

=cut

1;