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
|
44
|
|
|
44
|
|
279
|
use strict; |
|
44
|
|
|
|
|
79
|
|
|
44
|
|
|
|
|
1253
|
|
19
|
44
|
|
|
44
|
|
200
|
use warnings; |
|
44
|
|
|
|
|
83
|
|
|
44
|
|
|
|
|
2063
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '3.024'; # VERSION |
22
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.024'; # manually update whenever code is changed |
23
|
|
|
|
|
|
|
|
24
|
44
|
|
|
44
|
|
16638
|
use PDF::Builder::Basic::PDF::Filter::ASCII85Decode; |
|
44
|
|
|
|
|
106
|
|
|
44
|
|
|
|
|
1215
|
|
25
|
44
|
|
|
44
|
|
16942
|
use PDF::Builder::Basic::PDF::Filter::ASCIIHexDecode; |
|
44
|
|
|
|
|
100
|
|
|
44
|
|
|
|
|
1296
|
|
26
|
44
|
|
|
44
|
|
17162
|
use PDF::Builder::Basic::PDF::Filter::FlateDecode; |
|
44
|
|
|
|
|
149
|
|
|
44
|
|
|
|
|
1881
|
|
27
|
44
|
|
|
44
|
|
22277
|
use PDF::Builder::Basic::PDF::Filter::LZWDecode; |
|
44
|
|
|
|
|
143
|
|
|
44
|
|
|
|
|
1766
|
|
28
|
44
|
|
|
44
|
|
20314
|
use PDF::Builder::Basic::PDF::Filter::RunLengthDecode; |
|
44
|
|
|
|
|
105
|
|
|
44
|
|
|
|
|
1585
|
|
29
|
|
|
|
|
|
|
# use PDF::Builder::Basic::PDF::Filter::CCITTFaxDecode; when TIFF changes in |
30
|
44
|
|
|
44
|
|
255
|
use Scalar::Util qw(blessed reftype); |
|
44
|
|
|
|
|
89
|
|
|
44
|
|
|
|
|
11005
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
PDF::Builder::Basic::PDF::Filter - Abstract superclass for PDF stream filters |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$f = PDF::Builder::Basic::PDF::Filter->new(); |
39
|
|
|
|
|
|
|
$str = $f->outfilt($str, 1); |
40
|
|
|
|
|
|
|
print OUTFILE $str; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
while (read(INFILE, $dat, 4096)) |
43
|
|
|
|
|
|
|
{ $store .= $f->infilt($dat, 0); } |
44
|
|
|
|
|
|
|
$store .= $f->infilt("", 1); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
A Filter object contains state information for the process of outputting |
49
|
|
|
|
|
|
|
and inputting data through the filter. The precise state information stored |
50
|
|
|
|
|
|
|
is up to the particular filter and may range from nothing to whole objects |
51
|
|
|
|
|
|
|
created and destroyed. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Each filter stores different state information for input and output and thus |
54
|
|
|
|
|
|
|
may handle one input filtering process and one output filtering process at |
55
|
|
|
|
|
|
|
the same time. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item PDF::Builder::Basic::PDF::Filter->new() |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a new filter object with empty state information ready for processing |
64
|
|
|
|
|
|
|
data both input and output. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item $dat = $f->infilt($str, $isend) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Filters from output to input the data. Notice that C<$isend == 0> implies that |
69
|
|
|
|
|
|
|
there is more data to come and so following it C<$f> may contain state |
70
|
|
|
|
|
|
|
information (usually due to the break-off point of C<$str> not being tidy). |
71
|
|
|
|
|
|
|
Subsequent calls will incorporate this stored state information. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
C<$isend == 1> implies that there is no more data to follow. The final state of |
74
|
|
|
|
|
|
|
C<$f> will be that the state information is empty. Error messages are most |
75
|
|
|
|
|
|
|
likely to occur here since if there is required state information to be stored |
76
|
|
|
|
|
|
|
following this data, then that would imply an error in the data. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item $str = $f->outfilt($dat, $isend) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Filter stored data ready for output. Parallels C. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub new { |
87
|
5
|
|
|
5
|
1
|
94
|
my $class = shift(); |
88
|
5
|
|
|
|
|
11
|
my $self = {}; |
89
|
|
|
|
|
|
|
|
90
|
5
|
|
|
|
|
10
|
bless $self, $class; |
91
|
|
|
|
|
|
|
|
92
|
5
|
|
|
|
|
15
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub release { |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
97
|
0
|
0
|
|
|
|
|
return $self unless ref($self); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# delete stuff that we know we can, here |
100
|
0
|
|
|
|
|
|
my @tofree = map { delete $self->{$_} } keys %$self; |
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
while (my $item = shift @tofree) { |
103
|
0
|
|
|
|
|
|
my $ref = ref($item); |
104
|
0
|
0
|
0
|
|
|
|
if (blessed($item) and $item->can('release')) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$item->release(); |
106
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
107
|
0
|
|
|
|
|
|
push @tofree, @$item ; |
108
|
|
|
|
|
|
|
} elsif (defined(reftype($ref)) and reftype($ref) eq 'HASH') { |
109
|
0
|
|
|
|
|
|
release($item); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# check that everything has gone |
114
|
0
|
|
|
|
|
|
foreach my $key (keys %$self) { |
115
|
|
|
|
|
|
|
# warn ref($self) . " still has '$key' key left after release.\n"; |
116
|
0
|
|
|
|
|
|
$self->{$key} = undef; |
117
|
0
|
|
|
|
|
|
delete $self->{$key}; |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |