line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================= |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW: |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright Martin Hosken |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# No warranty or expression of effectiveness, least of all regarding |
8
|
|
|
|
|
|
|
# anyone's safety, is implied in this software or documentation. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# This specific module is licensed under the Perl Artistic License. |
11
|
|
|
|
|
|
|
# Effective 28 January 2021, the original author and copyright holder, |
12
|
|
|
|
|
|
|
# Martin Hosken, has given permission to use and redistribute this module |
13
|
|
|
|
|
|
|
# under the MIT license. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
#======================================================================= |
16
|
|
|
|
|
|
|
package PDF::Builder::Basic::PDF::Filter; |
17
|
|
|
|
|
|
|
|
18
|
40
|
|
|
40
|
|
346
|
use strict; |
|
40
|
|
|
|
|
85
|
|
|
40
|
|
|
|
|
1374
|
|
19
|
40
|
|
|
40
|
|
218
|
use warnings; |
|
40
|
|
|
|
|
77
|
|
|
40
|
|
|
|
|
2215
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
22
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.022'; # manually update whenever code is changed |
23
|
|
|
|
|
|
|
|
24
|
40
|
|
|
40
|
|
19007
|
use PDF::Builder::Basic::PDF::Filter::ASCII85Decode; |
|
40
|
|
|
|
|
113
|
|
|
40
|
|
|
|
|
1284
|
|
25
|
40
|
|
|
40
|
|
19348
|
use PDF::Builder::Basic::PDF::Filter::ASCIIHexDecode; |
|
40
|
|
|
|
|
108
|
|
|
40
|
|
|
|
|
1404
|
|
26
|
40
|
|
|
40
|
|
19580
|
use PDF::Builder::Basic::PDF::Filter::FlateDecode; |
|
40
|
|
|
|
|
167
|
|
|
40
|
|
|
|
|
2107
|
|
27
|
40
|
|
|
40
|
|
24535
|
use PDF::Builder::Basic::PDF::Filter::LZWDecode; |
|
40
|
|
|
|
|
153
|
|
|
40
|
|
|
|
|
1799
|
|
28
|
40
|
|
|
40
|
|
21381
|
use PDF::Builder::Basic::PDF::Filter::RunLengthDecode; |
|
40
|
|
|
|
|
110
|
|
|
40
|
|
|
|
|
1650
|
|
29
|
40
|
|
|
40
|
|
282
|
use Scalar::Util qw(blessed reftype); |
|
40
|
|
|
|
|
83
|
|
|
40
|
|
|
|
|
11764
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
PDF::Builder::Basic::PDF::Filter - Abstract superclass for PDF stream filters |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$f = PDF::Builder::Basic::PDF::Filter->new(); |
38
|
|
|
|
|
|
|
$str = $f->outfilt($str, 1); |
39
|
|
|
|
|
|
|
print OUTFILE $str; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
while (read(INFILE, $dat, 4096)) |
42
|
|
|
|
|
|
|
{ $store .= $f->infilt($dat, 0); } |
43
|
|
|
|
|
|
|
$store .= $f->infilt("", 1); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
A Filter object contains state information for the process of outputting |
48
|
|
|
|
|
|
|
and inputting data through the filter. The precise state information stored |
49
|
|
|
|
|
|
|
is up to the particular filter and may range from nothing to whole objects |
50
|
|
|
|
|
|
|
created and destroyed. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Each filter stores different state information for input and output and thus |
53
|
|
|
|
|
|
|
may handle one input filtering process and one output filtering process at |
54
|
|
|
|
|
|
|
the same time. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 PDF::Builder::Basic::PDF::Filter->new() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Creates a new filter object with empty state information ready for processing |
61
|
|
|
|
|
|
|
data both input and output. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 $dat = $f->infilt($str, $isend) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Filters from output to input the data. Notice that C<$isend == 0> implies that |
66
|
|
|
|
|
|
|
there is more data to come and so following it C<$f> may contain state |
67
|
|
|
|
|
|
|
information (usually due to the break-off point of C<$str> not being tidy). |
68
|
|
|
|
|
|
|
Subsequent calls will incorporate this stored state information. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
C<$isend == 1> implies that there is no more data to follow. The final state of |
71
|
|
|
|
|
|
|
C<$f> will be that the state information is empty. Error messages are most |
72
|
|
|
|
|
|
|
likely to occur here since if there is required state information to be stored |
73
|
|
|
|
|
|
|
following this data, then that would imply an error in the data. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 $str = $f->outfilt($dat, $isend) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Filter stored data ready for output. Parallels C. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub new { |
82
|
5
|
|
|
5
|
1
|
118
|
my $class = shift(); |
83
|
5
|
|
|
|
|
12
|
my $self = {}; |
84
|
|
|
|
|
|
|
|
85
|
5
|
|
|
|
|
14
|
bless $self, $class; |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
33
|
return $self; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub release { |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
92
|
0
|
0
|
|
|
|
|
return $self unless ref($self); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# delete stuff that we know we can, here |
95
|
0
|
|
|
|
|
|
my @tofree = map { delete $self->{$_} } keys %$self; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
while (my $item = shift @tofree) { |
98
|
0
|
|
|
|
|
|
my $ref = ref($item); |
99
|
0
|
0
|
0
|
|
|
|
if (blessed($item) and $item->can('release')) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$item->release(); |
101
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
102
|
0
|
|
|
|
|
|
push @tofree, @$item ; |
103
|
|
|
|
|
|
|
} elsif (defined(reftype($ref)) and reftype($ref) eq 'HASH') { |
104
|
0
|
|
|
|
|
|
release($item); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# check that everything has gone |
109
|
0
|
|
|
|
|
|
foreach my $key (keys %$self) { |
110
|
|
|
|
|
|
|
# warn ref($self) . " still has '$key' key left after release.\n"; |
111
|
0
|
|
|
|
|
|
$self->{$key} = undef; |
112
|
0
|
|
|
|
|
|
delete $self->{$key}; |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
return; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |