line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Code in the PDF::API2::Basic::PDF namespace was originally copied from the |
2
|
|
|
|
|
|
|
# Text::PDF distribution. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright Martin Hosken |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Martin Hosken's code may be used under the terms of the MIT license. |
7
|
|
|
|
|
|
|
# Subsequent versions of the code have the same license as PDF::API2. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package PDF::API2::Basic::PDF::Filter; |
10
|
|
|
|
|
|
|
|
11
|
43
|
|
|
43
|
|
300
|
use strict; |
|
43
|
|
|
|
|
125
|
|
|
43
|
|
|
|
|
1275
|
|
12
|
43
|
|
|
43
|
|
224
|
use warnings; |
|
43
|
|
|
|
|
91
|
|
|
43
|
|
|
|
|
1814
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '2.044'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
43
|
|
|
43
|
|
18615
|
use PDF::API2::Basic::PDF::Filter::ASCII85Decode; |
|
43
|
|
|
|
|
120
|
|
|
43
|
|
|
|
|
1261
|
|
17
|
43
|
|
|
43
|
|
19066
|
use PDF::API2::Basic::PDF::Filter::ASCIIHexDecode; |
|
43
|
|
|
|
|
118
|
|
|
43
|
|
|
|
|
1383
|
|
18
|
43
|
|
|
43
|
|
19139
|
use PDF::API2::Basic::PDF::Filter::FlateDecode; |
|
43
|
|
|
|
|
196
|
|
|
43
|
|
|
|
|
2194
|
|
19
|
43
|
|
|
43
|
|
22562
|
use PDF::API2::Basic::PDF::Filter::LZWDecode; |
|
43
|
|
|
|
|
133
|
|
|
43
|
|
|
|
|
1626
|
|
20
|
43
|
|
|
43
|
|
18515
|
use PDF::API2::Basic::PDF::Filter::RunLengthDecode; |
|
43
|
|
|
|
|
139
|
|
|
43
|
|
|
|
|
1685
|
|
21
|
43
|
|
|
43
|
|
313
|
use Scalar::Util qw(blessed reftype); |
|
43
|
|
|
|
|
110
|
|
|
43
|
|
|
|
|
12567
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
PDF::API2::Basic::PDF::Filter - Abstract superclass for PDF stream filters |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$f = PDF::API2::Basic::PDF::Filter->new; |
30
|
|
|
|
|
|
|
$str = $f->outfilt($str, 1); |
31
|
|
|
|
|
|
|
print OUTFILE $str; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
while (read(INFILE, $dat, 4096)) |
34
|
|
|
|
|
|
|
{ $store .= $f->infilt($dat, 0); } |
35
|
|
|
|
|
|
|
$store .= $f->infilt("", 1); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
A Filter object contains state information for the process of outputting |
40
|
|
|
|
|
|
|
and inputting data through the filter. The precise state information stored |
41
|
|
|
|
|
|
|
is up to the particular filter and may range from nothing to whole objects |
42
|
|
|
|
|
|
|
created and destroyed. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Each filter stores different state information for input and output and thus |
45
|
|
|
|
|
|
|
may handle one input filtering process and one output filtering process at |
46
|
|
|
|
|
|
|
the same time. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 PDF::API2::Basic::PDF::Filter->new |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Creates a new filter object with empty state information ready for processing |
53
|
|
|
|
|
|
|
data both input and output. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 $dat = $f->infilt($str, $isend) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Filters from output to input the data. Notice that $isend == 0 implies that there |
58
|
|
|
|
|
|
|
is more data to come and so following it $f may contain state information |
59
|
|
|
|
|
|
|
(usually due to the break-off point of $str not being tidy). Subsequent calls |
60
|
|
|
|
|
|
|
will incorporate this stored state information. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$isend == 1 implies that there is no more data to follow. The |
63
|
|
|
|
|
|
|
final state of $f will be that the state information is empty. Error messages |
64
|
|
|
|
|
|
|
are most likely to occur here since if there is required state information to |
65
|
|
|
|
|
|
|
be stored following this data, then that would imply an error in the data. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 $str = $f->outfilt($dat, $isend) |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Filter stored data ready for output. Parallels C. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new { |
74
|
6
|
|
|
6
|
1
|
114
|
my $class = shift(); |
75
|
6
|
|
|
|
|
28
|
my $self = {}; |
76
|
|
|
|
|
|
|
|
77
|
6
|
|
|
|
|
17
|
bless $self, $class; |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
24
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub release { |
83
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
84
|
0
|
0
|
|
|
|
|
return $self unless ref($self); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# delete stuff that we know we can, here |
87
|
0
|
|
|
|
|
|
my @tofree = map { delete $self->{$_} } keys %$self; |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
while (my $item = shift @tofree) { |
90
|
0
|
|
|
|
|
|
my $ref = ref($item); |
91
|
0
|
0
|
0
|
|
|
|
if (blessed($item) and $item->can('release')) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$item->release(); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
95
|
0
|
|
|
|
|
|
push @tofree, @$item; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif (defined(reftype($ref)) and reftype($ref) eq 'HASH') { |
98
|
0
|
|
|
|
|
|
release($item); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# check that everything has gone |
103
|
0
|
|
|
|
|
|
foreach my $key (keys %$self) { |
104
|
|
|
|
|
|
|
# warn ref($self) . " still has '$key' key left after release.\n"; |
105
|
0
|
|
|
|
|
|
$self->{$key} = undef; |
106
|
0
|
|
|
|
|
|
delete $self->{$key}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |