lib/CAM/PDFTaxforms.pm

filter: Statementstmt 76.5% 209 / 273 Branchbran 51.6% 93 / 180 Conditioncond 35.2% 18 / 51 MC/DCmcdc 10.0% 3 / 30 Subroutinesub 90.0% 9 / 10 Podpod 100% 5 / 5 totaltotal 61.3% 337 / 549 CC 115 SCAR 51.1
CC
115
Cov
63%
fillFormFields
275.7
getFormField
143.2
writeAny
17.1
CRAP 165.6
↑ Summary script/listpdffields2.pl »
1 package CAM::PDFTaxforms;
2  
3 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use parent 'CAM::PDF';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '1.20';
9  
10 =head1 NAME
11  
12 CAM::PDFTaxforms - CAM::PDF wrapper to also allow editing of checkboxes (ie. for IRS Tax forms).
13  
14 =head1 AUTHOR
15  
16 Jim Turner C<< <https://metacpan.org/author/TURNERJW> >>.
17  
18 This module is a wrapper around and a drop-in replacement for
19 L<CAM::PDF>, by Chris Dolan.
20  
21 =head1 ACKNOWLEDGMENTS
22  
23 Thanks to Chris Dolan and everyone involved in developing and
24 supporting CAM::PDF, on which this module is based and relies on.
25  
26 =head1 LICENSE AND COPYRIGHT
27  
28 Copyright (c) 2010-2019 Jim Turner C<< <mailto:turnerjw784@yahoo.com> >>
29  
30 This library is free software; you can redistribute it and/or modify it
31 under the same terms as CAM::PDF and Perl itself.
32  
33 L<CAM::PDF>:
34  
35 Copyright (c) 2002-2006 Clotho Advanced Media, Inc., L<http://www.clotho.com/>
36  
37 Copyright (c) 2007-2008 Chris Dolan
38  
39 This library is free software; you can redistribute it and/or modify it
40 under the same terms as Perl itself.
41  
42 =head1 SYNOPSIS
43  
44 #!/usr/bin/perl -w
45  
46 use strict;
47 use CAM::PDFTaxforms;
48 my $pdf = CAM::PDFTaxforms->new('f1040.pdf') or die "Could not open PDF ($!)!";
49 my $page1 = $pdf->getPageContent(1);
50  
51 #DISPLAY THE LIST NAMES OF EDITABLE FIELDS:
52 my @fieldnames = $pdf->getFormFieldList();
53 print "--fields=".join('|',@fieldnames)."=\n";
54  
55 #UPDATE THE VALUES OF ONE OF THE FIELDS AND A COUPLE OF THE CHECKBOXES:
56 $pdf->fillFormFields('fieldname1' => 'value1', 'fieldname2' => 'value2');
57  
58 #WRITE THE UPDATED PDF FORM TO A NEW FILE NAME:
59 $pdf->cleanoutput('f1040_completed.pdf');
60  
61 Many example programs are included in this distribution to do useful
62 tasks. See the C<bin> subdirectory.
63  
64 =head1 DESCRIPTION
65  
66 This package is a wrapper for and creates a L<CAM::PDF> object. The
67 difference is that some method functions are overridden to fix some
68 issues and add some new features, namely to better handle IRS tax
69 forms, many of which have checkboxes, in addition to numeric and text
70 fields. Several other patches have also been applied, particularly
71 those provided by CAM::PDF bugs #58144, #122890 and #125299.
72 Otherwise, it should work well as a full drop-in replacement for
73 CAM::PDF in the API.
74  
75 CAM::PDF description:
76  
77 This package reads and writes any document that conforms to the PDF
78 specification generously provided by Adobe at
79 L<http://partners.adobe.com/public/developer/pdf/index_reference.html>
80 (link last checked Oct 2005).
81  
82 The file format through PDF 1.5 is well-supported, with the exception
83 of the "linearized" or "optimized" output format, which this module
84 can read but not write. Many specific aspects of the document model
85 are not manipulable with this package (like fonts), but if the input
86 document is correctly written, then this module will preserve the
87 model integrity.
88  
89 The PDF writing feature saves as PDF 1.4-compatible. That means that
90 we cannot write compressed object streams. The consequence is that
91 reading and then writing a PDF 1.5+ document may enlarge the resulting
92 file by a fair margin.
93  
94 This library grants you some power over the PDF security model. Note
95 that applications editing PDF documents via this library MUST respect
96 the security preferences of the document. Any violation of this
97 respect is contrary to Adobe's intellectual property position, as
98 stated in the reference manual at the above URL.
99  
100 Technical detail regarding corrupt PDFs: This library adheres strictly
101 to the PDF specification. Adobe's Acrobat Reader is more lenient,
102 allowing some corrupted PDFs to be viewable. Therefore, it is
103 possible that some PDFs may be readable by Acrobat that are illegible
104 to this library. In particular, files which have had line endings
105 converted to or from DOS/Windows style (i.e. CR-NL) may be rendered
106 unusable even though Acrobat does not complain. Future library
107 versions may relax the parser, but not yet.
108  
109 This version is HACKED by Jim Turner 09/2010 to enable the fillFormFields()
110 function to also modify checkboxes (primarily on IRS Tax forms).
111  
112 =head1 EXAMPLES
113  
114 See the I<example/> subdirectory in the source tree. There is a sample
115 blank 2018 official IRS Schedule B tax form and two programs:
116 I<dof1040sb.pl>, which fills in the form using the sample input data
117 text file I<f1040sb_inputs.txt>, and creates a filled in version of the
118 form called I<f1040sb_out.pdf>. The other program (I<test1040sb.pl>)
119 can read the data filled in the filled in form created by the other
120 program and displays it as output.
121  
122 To run the programs, switch to the I<example/> subdirectory in the source
123 tree and run them without arguments (ie. B<./dof1040sb.pl>).
124  
125 To see the names of the fields and their current values in a PDF form,
126 such as the aforementioned tax form, run the included program, ie:
127 I<listpdffields2.pl -d f1040sb_out.pdf>.
128  
129 =head1 API
130  
131 =head2 Functions intended to be used externally
132  
133 $self = CAM::PDFTaxforms->new(content | filename | '-')
134 $self->toPDF()
135 $self->needsSave()
136 $self->save()
137 $self->cleansave()
138 $self->output(filename | '-')
139 $self->cleanoutput(filename | '-')
140 $self->previousRevision()
141 $self->allRevisions()
142 $self->preserveOrder()
143 $self->appendObject(olddoc, oldnum, [follow=(1|0)])
144 $self->replaceObject(newnum, olddoc, oldnum, [follow=(1|0)])
145 (olddoc can be undef in the above for adding new objects)
146 $self->numPages()
147 $self->getPageText(pagenum)
148 $self->getPageDimensions(pagenum)
149 $self->getPageContent(pagenum)
150 $self->setPageContent(pagenum, content)
151 $self->appendPageContent(pagenum, content)
152 $self->deletePage(pagenum)
153 $self->deletePages(pagenum, pagenum, ...)
154 $self->extractPages(pagenum, pagenum, ...)
155 $self->appendPDF(CAM::PDF object)
156 $self->prependPDF(CAM::PDF object)
157 $self->wrapString(string, width, fontsize, page, fontlabel)
158 $self->getFontNames(pagenum)
159 $self->addFont(page, fontname, fontlabel, [fontmetrics])
160 $self->deEmbedFont(page, fontname, [newfontname])
161 $self->deEmbedFontByBaseName(page, basename, [newfont])
162 $self->getPrefs()
163 $self->setPrefs()
164 $self->canPrint()
165 $self->canModify()
166 $self->canCopy()
167 $self->canAdd()
168 $self->getFormFieldList()
169 $self->fillFormFields(fieldname, value, [fieldname, value, ...])
170 or $self->fillFormFields(%values)
171 $self->clearFormFieldTriggers(fieldname, fieldname, ...)
172  
173 Note: 'clean' as in cleansave() and cleanobject() means write a fresh
174 PDF document. The alternative (e.g. save()) reuses the existing doc
175 and just appends to it. Also note that 'clean' functions sort the
176 objects numerically. If you prefer that the new PDF docs more closely
177 resemble the old ones, call preserveOrder() before cleansave() or
178 cleanobject().
179  
180 =head2 For additional methods and functions, see the L<CAM::PDF> documentation.
181  
182 =head1 METHODS
183  
184 =over
185  
186 =item $doc = CAM::PDFTaxforms->new($content)
187  
188 =item $doc = CAM::PDFTaxforms->new($ownerpass, $userpass)
189  
190 =item $doc = CAM::PDFTaxforms->new($content, $ownerpass, $userpass, $prompt)
191  
192 =item $doc = CAM::PDFTaxforms->new($content, $ownerpass, $userpass, $options)
193  
194 Instantiate a new CAM::PDFTaxforms object. C<$content> can be a document
195 in a string, a filename, or '-'. The latter indicates that the document
196 should be read from standard input. If the document is password
197 protected, the passwords should be passed as additional arguments. If
198 they are not known, a boolean C<$prompt> argument allows the programmer to
199 suggest that the constructor prompt the user for a password. This is
200 rudimentary prompting: passwords are in the clear on the console.
201  
202 This constructor takes an optional final argument which is a hash
203 reference. This hash can contain any of the following optional
204 parameters:
205  
206 =over
207  
208 =item prompt_for_password => $boolean
209  
210 This is the same as the C<$prompt> argument described above.
211  
212 =item fault_tolerant => $boolean
213  
214 This flag causes the instance to be more lenient when reading the
215 input PDF. Currently, this only affects PDFs which cannot be
216 successfully decrypted.
217  
218 =back
219  
220 =item $hashref = $doc->getFieldValue('fieldname1' [, fieldname2, ... fieldnameN ])
221  
222 (CAM::PDFTaxforms only, not available in CAM::PDF)
223  
224 Fetches the corresponding current values for each field name in the
225 argument list. Returns a reference to a hash containing the field
226 names as keys and the corresponding values. If a field does not
227 exist or does not contain a value, an empty string is returned in
228 the hash as it's value. If called in array / hash context, then
229 a list of field names and values in the order (fieldname1, value1,
230 fieldname2, value2, ... fieldnameN valueN) is returned.
231  
232 =cut
233  
234 sub getFieldValue #JWT:NEW FUNCTION ADDED 20100921 TO RETURN CORRECT VALUES
235 #FOR EACH FIELD WHETHER IT'S A TEXT FIELD OR A CHECKBOX:
236 1 ▶{
Subroutine getFieldValue: called CC=8 SCAR=21.0
Pod documented
237 1 my $self = shift;
238 1 my @fieldNames = @_;
239  
240 1 my ($objnode, $propdict, $dict, $fieldType, $fieldHashRef);
241 1 LOOP1: foreach my $fieldName (@fieldNames)
242 {
243 3 $objnode = $self->getFormField($fieldName);
244 3 $fieldHashRef->{$fieldName} = undef;
245 3 ▶ next LOOP1 unless ($objnode);
Branch: 1 branch
BranchTrueFalseTotal
unless $objnode 0 3 3
246  
247 # This read-only dict includes inherited properties
248 3 my $propdict = $self->getFormFieldDict($objnode);
249  
250 # This read-write dict does not include inherited properties
251 3 my $dict = $self->getValue($objnode);
252  
253 3 ▶ if ($propdict->{FT} && $self->getValue($propdict->{FT}) =~ /^Btn$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{'FT'} and $self->getValue($propdict->{'FT'}) =~ /^Btn$/o) { } 1 2 3
Condition66%2/3
$propdict->{"FT"} and $self->getValue($propdict->{"FT"}) =~ /^Btn$/o
!ll&&!rl&&r
021
MC/DC50%1/2
$propdict->{"FT"} and $self->getValue($propdict->{"FT"}) =~ /^Btn$/o
$propdict->{"FT"} $self->getValue($propdict->{"FT"}) =~ /^Btn$/o
Truth table66%2/3
A and B
A= $propdict->{"FT"}B= $self->getValue($propdict->{"FT"}) =~ /^Btn$/o
ABresult
0X0
100
111
254 $fieldHashRef->{$fieldName} = (defined $dict->{AS}->{value})
255 1 ▶ ? $dict->{AS}->{value} : $dict->{V}->{value};
Branch: 1 branch
BranchTrueFalseTotal
defined $dict->{'AS'}{'value'} ? : 1 0 1
256 } else {
257 2 $fieldHashRef->{$fieldName} = $dict->{V}->{value};
258 }
259 }
260 1 ▶ return $fieldHashRef unless (wantarray); #RETURN HASHREF IN SCALAR CONTEXT.
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 1 1
261 1 my @fieldValues;
262 1 foreach my $fieldName (@fieldNames) #BUILD ARRAY FROM HASH TO RETURN IN ARRAY CONTEXT:
263 {
264 3 push (@fieldValues, $fieldName, $fieldHashRef->{$fieldName});
265 }
266 1 return @fieldValues;
267 }
268  
269 =item $doc->fillFormFields($name => $value, ...)
270  
271 =item $doc->fillFormFields($opts_hash, $name => $value, ...)
272  
273 Set the default values of PDF form fields. The name should be the
274 full hierarchical name of the field as output by the
275 getFormFieldList() function. The argument list can be a hash if you
276 like. A simple way to use this function is something like this:
277  
278 my %fields = (fname => 'John', lname => 'Smith', state => 'WI');
279 $field{zip} = 53703;
280 $self->fillFormFields(%fields);
281  
282 NOTE: For checkbox fields specify any value that is I<false> in Perl
283 (ie. 0, '', or I<undef>), or any of the strings: 'Off', 'No', or
284 'Unchecked' (case insensitive) to un-check a checkbox, or any other
285 value that is I<true> in Perl to check it. Checkbox fields are only
286 supported by CAM::PDFTaxforms and was the original reason for
287 creating it.
288  
289 If the first argument is a hash reference, it is interpreted as
290 options for how to render the filled data:
291  
292 =over
293  
294 =item background_color =E<lt> 'none' | $gray | [$r, $g, $b]
295  
296 Specify the background color for the text field.
297  
298 =back
299  
300 =cut
301  
302 sub fillFormFields ## no critic(Subroutines::ProhibitExcessComplexity, Unpack)
303 12 ▶{
Subroutine fillFormFields: called CC=65 SCAR=56.2
Pod documented
304 12 my $self = shift;
305 12 ▶ my $opts = ref $_[0] ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 12 12
306 12 my @list = (@_);
307  
308 my %opts = (
309 background_color => 1,
310 12 %{$opts},
311 );
312  
313 12 my $filled = 0;
314 12 ▶LOOP1: while (@list > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@list > 0) 25 12 37
315 {
316 25 my $key = shift @list;
317 25 my $value = shift @list;
318  
319 25 ▶ $value = q{} unless (defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 25 25
320 25 ▶ next if (!$key || ref($key));
Branch: 1 branch
BranchTrueFalseTotal
if not $key or ref $key 0 25 25
Condition33%1/3
not $key or ref $key
l!l&&r!l&&!r
0025
MC/DC0%0/2
not $key or ref $key
not $key ref $key
Truth table33%1/3
not(A) or B
A= not $keyB= ref $key
ABresult
1X1
011
000
321  
322 25 my $objnode = $self->getFormField($key);
323 25 ▶ next unless ($objnode);
Branch: 1 branch
BranchTrueFalseTotal
unless $objnode 0 25 25
324  
325 25 my $objnum = $objnode->{objnum};
326 25 my $gennum = $objnode->{gennum};
327  
328 # This read-only dict includes inherited properties
329 25 my $propdict = $self->getFormFieldDict($objnode);
330  
331 # This read-write dict does not include inherited properties
332 25 my $dict = $self->getValue($objnode);
333 25 $dict->{V} = CAM::PDF::Node->new('string', $value, $objnum, $gennum);
334  
335 25 ▶ if ($propdict->{FT} && $self->getValue($propdict->{FT}) =~ /^(Tx|Btn)$/o) # Is it a text field?
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{"FT"} and $self->getValue($propdict->{"FT"}) =~ /^(Tx|Btn)$/o) 25 0 25
Condition33%1/3
$propdict->{"FT"} and $self->getValue($propdict->{"FT"}) =~ /^(Tx|Btn)$/o
!ll&&!rl&&r
0025
MC/DC0%0/2
$propdict->{"FT"} and $self->getValue($propdict->{"FT"}) =~ /^(Tx|Btn)$/o
$propdict->{"FT"} $self->getValue($propdict->{"FT"}) =~ /^(Tx|Btn)$/o
Truth table33%1/3
A and B
A= $propdict->{"FT"}B= $self->getValue($propdict->{"FT"}) =~ /^(Tx|Btn)$/o
ABresult
0X0
100
111
336 {
337 25 my $fieldType = $1; #JWT:ADDED NEXT 6 TO ALLOW SETTING OF CHECKBOX BUTTONS (VALUE MUST BE EITHER "Yes" or "Off"!:
338 25 ▶ if ($fieldType eq 'Btn') #WE'RE A BUTTON (CHECKBOX OR RADIO)
Branch: 1 branch
BranchTrueFalseTotal
if ($fieldType eq 'Btn') { } 2 23 25
339 {
340 2 my @kidnames = $self->getFormFieldList($key);
341 2 ▶ if (@kidnames > 0) { #WE HAVE KIDS, SO WE'RE A RADIO-BUTTON:
Branch: 1 branch
BranchTrueFalseTotal
if (@kidnames > 0) { } 0 2 2
342 0 ▶ local * setRadioButtonKids = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
343 0 my ($indx, $vindx) = @_;
344 0 my $objnode = $self->getFormField($kidnames[$indx]);
345 0 ▶ return unless ($objnode);
Branch: 1 branch
BranchTrueFalseTotal
unless $objnode 0 0 0
346 0 my $dict = $self->getValue($objnode);
347 0 ▶ if ($indx == $vindx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indx == $vindx) { } 0 0 0
348 0 $dict->{AS}->{value} = $value;
349 } else {
350 0 $dict->{AS}->{value} = 'Off';
351 }
352 0 return;
353 0 };
354  
355 0 ▶ $dict->{V}->{value} = ($value > 0) ? $value : 'Off';
Branch: 1 branch
BranchTrueFalseTotal
$value > 0 ? : 0 0 0
356 0 my $vindx = $value - 1;
357 0 ▶ for (my $i=0;$i<=$#kidnames;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#kidnames) 0 0 0
358 0 &setRadioButtonKids($i, $vindx);
359 }
360 } else { #WE'RE A SINGLE CHECKBOX:
361 2 ▶ if (!$value || $value =~ /^(?:Off|No|Unchecked)$/io) { #USER WANTS IT UNCHECKED:
Branch: 1 branch
BranchTrueFalseTotal
if (not $value or $value =~ /^(?:Off|No|Unchecked)$/io) { } 0 2 2
Condition33%1/3
not $value or $value =~ /^(?:Off|No|Unchecked)$/io
l!l&&r!l&&!r
002
MC/DC0%0/2
not $value or $value =~ /^(?:Off|No|Unchecked)$/io
not $value $value =~ /^(?:Off|No|Unchecked)$/io
Truth table33%1/3
not(A) or B
A= not $valueB= $value =~ /^(?:Off|No|Unchecked)$/io
ABresult
1X1
011
000
362 0 $dict->{AS}->{value} = 'Off';
363 0 $dict->{V}->{value} = 'Off';
364 } else { #USER WANTS IT CHECKED:
365 my ($onValue) = defined($dict->{AP}->{value}->{N}->{value}
366 && ref($dict->{AP}->{value}->{N}->{value}) =~ /^HASH/)
367 2 ▶ ? keys(%{$dict->{AP}->{value}->{N}->{value}}) : ('Yes');
Branch: 1 branch
BranchTrueFalseTotal
defined($dict->{'AP'}{'value'}{'N'}{'value'} && ref($dict->{'AP'}{'value'}{'N'}{'value'}) =~ /^HASH/) ? : 2 0 2
Condition33%1/3
$dict->{'AP'}{'value'}{'N'}{'value'} && ref($dict->{'AP'}{'value'}{'N'}{'value'}) =~ /^HASH/
!ll&&!rl&&r
002
MC/DC0%0/2
$dict->{'AP'}{'value'}{'N'}{'value'} && ref($dict->{'AP'}{'value'}{'N'}{'value'}) =~ /^HASH/
$dict->{'AP'}{'value'}{'N'}{'value'} ref($dict->{'AP'}{'value'}{'N'}{'value'}) =~ /^HASH/
Truth table33%1/3
A && B
A= $dict->{'AP'}{'value'}{'N'}{'value'}B= ref($dict->{'AP'}{'value'}{'N'}{'value'}) =~ /^HASH/
ABresult
0X0
100
111
368 2 $dict->{AS}->{value} = $onValue;
369 2 $dict->{V}->{value} = $onValue;
370 }
371 }
372 2 $filled++;
373 2 next LOOP1;
374 }
375 else #WE'RE A TEXT FIELD:
376 {
377 23 $dict->{V}->{value} = $value;
378 }
379  
380 # Set up display of form value
381 23 ▶ $dict->{AP} = CAM::PDF::Node->new('dictionary', {}, $objnum, $gennum) unless ($dict->{AP});
Branch: 1 branch
BranchTrueFalseTotal
unless $dict->{"AP"} 23 0 23
382 23 ▶ unless ($dict->{AP}->{value}->{N})
Branch: 1 branch
BranchTrueFalseTotal
unless ($dict->{"AP"}{"value"}{"N"}) 23 0 23
383 {
384 23 my $newobj = CAM::PDF::Node->new('object',
385 CAM::PDF::Node->new('dictionary',{}),
386 );
387 23 my $num = $self->appendObject(undef, $newobj, 0);
388 23 $dict->{AP}->{value}->{N} = CAM::PDF::Node->new('reference', $num, $objnum, $gennum);
389 }
390 my $formobj = ($self->dereference($fieldType eq 'Btn' && defined($dict->{AS}->{value})
391 && $dict->{AS}->{value}
392 && defined($dict->{AP}->{value}->{N}->{value}->{$dict->{AS}->{value}}->{value})
393 ? $dict->{AP}->{value}->{N}->{value}->{$dict->{AS}->{value}}->{value}
394 23 ▶ : $dict->{AP}->{value}->{N}->{value}));
Branch: 1 branch
BranchTrueFalseTotal
$fieldType eq 'Btn' && defined $dict->{'AS'}{'value'} && $dict->{'AS'}{'value'} && defined $dict->{'AP'}{'value'}{'N'}{'value'}{$dict->{'AS'}{'value'}}{'value'} ? : 0 23 23
Condition33%3/9
$fieldType eq "Btn" and defined $dict->{"AS"}{"value"} and $dict->{"AS"}{"value"} and defined $dict->{"AP"}{"value"}{"N"}{"value"}{$dict->{"AS"}{"value"}}{"value"}
!ll&&!rl&&r
2300
$fieldType eq "Btn" and defined $dict->{"AS"}{"value"} and $dict->{"AS"}{"value"}
!ll&&!rl&&r
2300
$fieldType eq "Btn" and defined $dict->{"AS"}{"value"}
!ll&&!rl&&r
2300
MC/DC0%0/4
$fieldType eq "Btn" and defined $dict->{"AS"}{"value"} and $dict->{"AS"}{"value"} and defined $dict->{"AP"}{"value"}{"N"}{"value"}{$dict->{"AS"}{"value"}}{"value"}
$fieldType eq "Btn" defined $dict->{"AS"}{"value"} $dict->{"AS"}{"value"} defined $dict->{"AP"}{"value"}{"N"}{"value"}{$dict->{"AS"}{"value"}}{"value"}
Truth table20%1/5
A and B and C and D
A= $fieldType eq "Btn"B= defined $dict->{"AS"}{"value"}C= $dict->{"AS"}{"value"}D= defined $dict->{"AP"}{"value"}{"N"}{"value"}{$dict->{"AS"}{"value"}}{"value"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
395 23 my $formonum = $formobj->{objnum};
396 23 my $formgnum = $formobj->{gennum};
397 23 my $formdict = $self->getValue($formobj);
398  
399 $formdict->{Subtype} = CAM::PDF::Node->new('label', 'Form', $formonum, $formgnum)
400 23 ▶ unless ($formdict->{Subtype});
Branch: 1 branch
BranchTrueFalseTotal
unless $formdict->{"Subtype"} 23 0 23
401  
402 23 my @rect = (0,0,0,0);
403 23 ▶ if ($dict->{Rect})
Branch: 1 branch
BranchTrueFalseTotal
if ($dict->{"Rect"}) 23 0 23
404 {
405 ## no critic(Bangs::ProhibitNumberedNames)
406 23 my $r = $self->getValue($dict->{Rect});
407 23 my ($x1, $y1, $x2, $y2) = @{$r};
408 23 @rect = (
409 $self->getValue($x1),
410 $self->getValue($y1),
411 $self->getValue($x2),
412 $self->getValue($y2),
413 );
414 }
415 23 my $dx = $rect[2]-$rect[0];
416 23 my $dy = $rect[3]-$rect[1];
417 23 ▶ unless ($formdict->{BBox})
Branch: 1 branch
BranchTrueFalseTotal
unless ($formdict->{"BBox"}) 23 0 23
418 {
419 23 $formdict->{BBox} = CAM::PDF::Node->new('array',
420 [
421 CAM::PDF::Node->new('number', 0, $formonum, $formgnum),
422 CAM::PDF::Node->new('number', 0, $formonum, $formgnum),
423 CAM::PDF::Node->new('number', $dx, $formonum, $formgnum),
424 CAM::PDF::Node->new('number', $dy, $formonum, $formgnum),
425 ],
426 $formonum, $formgnum);
427 }
428 23 my $text = $value;
429 23 $text =~ s/ \r\n? /\n/gxmso;
430 23 $text =~ s/ \n+\z //xmso;
431  
432 23 my @rsrcs;
433 23 my $fontmetrics = 0;
434 23 my $fontname = q{};
435 23 my $fontsize = 0;
436 23 my $da = q{};
437 23 my $tl = q{};
438 #JWT:CHGD TO NEXT PER BUG#122890: my $border = 2;
439 23 my $border = 1;
440 23 my $tx = $border;
441 #JWT:CHGD TO NEXT PER BUG#122890: my $ty = $border + 2;
442 23 my $ty = $border + 1;
443 23 my $stringwidth;
444 23 ▶ if ($propdict->{DA}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{"DA"}) 23 0 23
445 23 $da = $self->getValue($propdict->{DA});
446  
447 # Try to pull out all of the resources used in the text object
448 23 @rsrcs = ($da =~ m{ /([^\s<>/\[\]()]+) }gxmso);
449  
450 # Try to pull out the font size, if any. If more than
451 # one, pick the last one. Font commands look like:
452 # "/<fontname> <size> Tf"
453 #JWT: CHGD. TO NEXT (BUG#58144 PATCH): if ($da =~ m{ \s*/(\w+)\s+(\d+)\s+Tf.*? \z }xms)
454 23 ▶ if ($da =~ m{ \s*/([\w-]+)\s+([.\d]+)\s+Tf.*? \z }xmso)
Branch: 1 branch
BranchTrueFalseTotal
if ($da =~ m[ \s*/([\w-]+)\s+([.\d]+)\s+Tf.*? \z ]mosx) 23 0 23
455 {
456 23 $fontname = $1;
457 23 $fontsize = $2;
458 23 ▶ if ($fontname)
Branch: 1 branch
BranchTrueFalseTotal
if ($fontname) 23 0 23
459 {
460 23 ▶ if ($propdict->{DR})
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{"DR"}) 0 23 23
461 {
462 0 my $dr = $self->getValue($propdict->{DR});
463 0 $fontmetrics = $self->getFontMetrics($dr, $fontname);
464 }
465 #print STDERR "Didn't get font\n" if (!$fontmetrics);
466 }
467 }
468 }
469  
470 23 my %flags = (
471 Justify => 'left',
472 );
473 23 ▶ if ($propdict->{Ff})
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{"Ff"}) 22 1 23
474 {
475 # Just decode the ones we actually care about
476 # PDF ref, 3rd ed pp 532,543
477 22 my $ff = $self->getValue($propdict->{Ff});
478 22 my @flags = split m//xms, unpack 'b*', pack 'V', $ff;
479 22 $flags{ReadOnly} = $flags[0];
480 22 $flags{Required} = $flags[1];
481 22 $flags{NoExport} = $flags[2];
482 22 $flags{Multiline} = $flags[12];
483 22 $flags{Password} = $flags[13];
484 22 $flags{FileSelect} = $flags[20];
485 22 $flags{DoNotSpellCheck} = $flags[22];
486 22 $flags{DoNotScroll} = $flags[23];
487 }
488 23 ▶ if ($propdict->{Q})
Branch: 1 branch
BranchTrueFalseTotal
if ($propdict->{"Q"}) 23 0 23
489 {
490 23 ▶ my $q = $self->getValue($propdict->{Q}) || 0;
Condition100%2/2
$self->getValue($propdict->{'Q'}) || 0
l!l
1310
MC/DC100%1/1
$self->getValue($propdict->{'Q'}) || 0
$self->getValue($propdict->{'Q'})
Truth table100%2/2
A
A= $self->getValue($propdict->{'Q'})
Aresult
11
00
491 23 ▶ $flags{Justify} = $q==2 ? 'right' : ($q==1 ? 'center' : 'left');
Branch: 2 branches
BranchTrueFalseTotal
$q == 2 ? : 12 11 23
$q == 1 ? : 1 10 11
492 }
493  
494 # The order of the following sections is important!
495 23 ▶ $text =~ s/ [^\n] /*/gxms if ($flags{Password}); # Asterisks for password characters
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"Password"} 0 23 23
496  
497 23 ▶ if ($fontmetrics && ! $fontsize)
Branch: 1 branch
BranchTrueFalseTotal
if ($fontmetrics and not $fontsize) 0 23 23
Condition33%1/3
$fontmetrics and not $fontsize
!ll&&!rl&&r
2300
MC/DC0%0/2
$fontmetrics and not $fontsize
$fontmetrics not $fontsize
Truth table33%1/3
A and not(B)
A= $fontmetricsB= not $fontsize
ABresult
0X0
100
111
498 {
499 # Fix autoscale fonts
500 0 $stringwidth = 0;
501 0 my $lines = 0;
502 0 for my $line (split /\n/xmso, $text) # trailing null strings omitted
503 {
504 0 $lines++;
505 0 my $w = $self->getStringWidth($fontmetrics, $line);
506 0 ▶ $stringwidth = $w if ($w && $w > $stringwidth);
Branch: 1 branch
BranchTrueFalseTotal
if $w and $w > $stringwidth 0 0 0
Condition0%0/3
$w and $w > $stringwidth
!ll&&!rl&&r
000
MC/DC0%0/2
$w and $w > $stringwidth
$w $w > $stringwidth
Truth table0%0/3
A and B
A= $wB= $w > $stringwidth
ABresult
0X0
100
111
507 }
508 0 ▶ $lines ||= 1;
Condition0%0/2
$lines ||= 1
l!l
00
MC/DC0%0/1
$lines ||= 1
$lines
Truth table0%0/2
A
A= $lines
Aresult
11
00
509 # Initial guess
510 0 $fontsize = ($dy - 2 * $border) / ($lines * 1.5);
511 0 my $fontwidth = $fontsize * $stringwidth;
512 0 my $maxwidth = $dx - 2 * $border;
513 0 ▶ $fontsize *= $maxwidth / $fontwidth if ($fontwidth > $maxwidth);
Branch: 1 branch
BranchTrueFalseTotal
if $fontwidth > $maxwidth 0 0 0
514 0 $da =~ s/ \/$fontname\s+0\s+Tf\b /\/$fontname $fontsize Tf/gxms;
515 }
516 23 ▶ if ($fontsize)
Branch: 1 branch
BranchTrueFalseTotal
if ($fontsize) 23 0 23
517 {
518 # This formula is TOTALLY empirical. It's probably wrong.
519 # #JWT:CHGD. TO NEXT: $ty = $border + 2 + (9 - $fontsize) * 0.4;
520 23 $ty = $border + 2 + (5 - $fontsize) * 0.4;
521 }
522  
523  
524 # escape characters
525 23 $text = $self->writeString($text);
526  
527 23 ▶ if ($flags{Multiline})
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{'Multiline'}) { } 0 23 23
528 {
529 # TODO: wrap the field with wrapString()??
530 # Shawn Dawson of Silent Solutions pointed out that this does not auto-wrap the input text
531  
532 0 my $linebreaks = $text =~ s/ \\n /\) Tj T* \(/gxms;
533  
534 # Total guess work:
535 # line height is either 150% of fontsize or thrice
536 # the corner offset
537 0 ▶ $tl = $fontsize ? $fontsize * 1.5 : $ty * 3;
Branch: 1 branch
BranchTrueFalseTotal
$fontsize ? : 0 0 0
538  
539 # Bottom aligned
540 #$ty += $linebreaks * $tl;
541 # Top aligned
542 0 $ty = $dy - $border - $tl;
543 0 ▶ warn 'Justified text not supported for multiline fields' if ($flags{Justify} ne 'left');
Branch: 1 branch
BranchTrueFalseTotal
if $flags{"Justify"} ne "left" 0 0 0
544 0 $tl .= ' TL';
545 }
546 else
547 {
548 #JWT: CHGD. TO NEXT (BUG#58144 PATCH): if ($flags{Justify} ne 'left' && $fontmetrics)
549 23 ▶ if ($flags{Justify} ne 'left')
Branch: 1 branch
BranchTrueFalseTotal
if ($flags{"Justify"} ne "left") 13 10 23
550 {
551 #JWT: CHGD. TO NEXT 8: my $width = $stringwidth || $self->getStringWidth($fontmetrics, $text);
552 13 my $width;
553 13 ▶ if ($stringwidth || $fontmetrics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stringwidth or $fontmetrics) { } 0 13 13
Condition33%1/3
$stringwidth or $fontmetrics
l!l&&r!l&&!r
0013
MC/DC0%0/2
$stringwidth or $fontmetrics
$stringwidth $fontmetrics
Truth table33%1/3
A or B
A= $stringwidthB= $fontmetrics
ABresult
1X1
011
000
554 #JWT:CHGD TO NEXT PER BUG#122890: $width = $self->getStringWidth($fontmetrics, $text);
555 0 $width = $self->getStringWidth($fontmetrics, (substr $text, 1, (length $text)-2));
556 } else { #JWT: NO FONT METRICS, SO HAVE TO GUESS WIDTH:
557 13 $width = (length($text)-1) * 0.57; #JWT:FIXME (HACK) FOR RIGHT-JUSTIFYING STANDARD SIZE 8 NUMERIC FONT.
558 13 my $commas = $text;
559 13 ▶ $width -= 0.29 while ($commas =~ s/\,//o); #JWT:FIXME (HACK) FUDGE FOR WIDTH OF COMMAS (SMALLER THAN DIGITS)
Branch: 1 branch
BranchTrueFalseTotal
$commas =~ s/\,//o and do { $width -= "0.29" } 4 13 17
560 }
561 13 my $diff = $dx - $width * $fontsize;
562 13 ▶ $diff = 0 if ($diff < 0); #JWT:ADDED.
Branch: 1 branch
BranchTrueFalseTotal
if $diff < 0 0 13 13
563  
564 13 ▶ if ($flags{Justify} eq 'center')
Branch: 2 branches
BranchTrueFalseTotal
if ($flags{'Justify'} eq 'center') { } 1 12 13
elsif ($flags{'Justify'} eq 'right') { } 12 0 12
565 {
566 1 $text = ($diff/2)." 0 Td $text";
567 }
568 elsif ($flags{Justify} eq 'right')
569 {
570 12 $text = "$diff 0 Td $text";
571 }
572 }
573 }
574  
575 # Move text from lower left corner of form field
576 23 my $tm = "1 0 0 1 $tx $ty Tm ";
577  
578 # if not 'none', draw a background as a filled rectangle of solid color
579 my $background_color
580 = $opts{background_color} eq 'none' ? q{}
581 0 ▶ : ref $opts{background_color} ? "@{$opts{background_color}} rgb"
Branch: 2 branches
BranchTrueFalseTotal
$opts{'background_color'} eq 'none' ? : 0 23 23
ref $opts{'background_color'} ? : 0 23 23
582 : "$opts{background_color} g";
583 23 ▶ my $background = $background_color ? "$background_color 0 0 $dx $dy re f" : q{};
Branch: 1 branch
BranchTrueFalseTotal
$background_color ? : 23 0 23
584  
585 23 $text = "$tl $da $tm $text Tj";
586 23 $text = "$background /Tx BMC q 1 1 ".($dx-$border).q{ }.($dy-$border)." re W n BT $text ET Q EMC";
587 23 ▶ unless ($fieldType eq 'Btn') #JWT:ADDED CONDITION:
Branch: 1 branch
BranchTrueFalseTotal
unless ($fieldType eq "Btn") 23 0 23
588 {
589 23 $formdict->{Length} = CAM::PDF::Node->new('number', length($text), $formonum, $formgnum);
590 # JWT:NEXT 3 ADDED PER BUG#125299 PATCH:
591 23 $formdict->{StreamData} = CAM::PDF::Node->new('stream', $text, $formonum, $formgnum);
592 23 delete $formdict->{ Filter };
593 23 $self-> encodeObject( $formonum, 'FlateDecode' );
594 }
595  
596 23 ▶ if (@rsrcs > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rsrcs > 0) 23 0 23
597 $formdict->{Resources} = CAM::PDF::Node->new('dictionary', {}, $formonum, $formgnum)
598 23 ▶ unless ($formdict->{Resources});
Branch: 1 branch
BranchTrueFalseTotal
unless $formdict->{"Resources"} 23 0 23
599  
600 23 my $rdict = $self->getValue($formdict->{Resources});
601 23 ▶ unless ($rdict->{ProcSet})
Branch: 1 branch
BranchTrueFalseTotal
unless ($rdict->{"ProcSet"}) 23 0 23
602 {
603 23 $rdict->{ProcSet} = CAM::PDF::Node->new('array',
604 [
605 CAM::PDF::Node->new('label', 'PDF', $formonum, $formgnum),
606 CAM::PDF::Node->new('label', 'Text', $formonum, $formgnum),
607 ],
608 $formonum, $formgnum);
609 }
610 $rdict->{Font} = CAM::PDF::Node->new('dictionary', {}, $formonum, $formgnum)
611 23 ▶ unless ($rdict->{Font});
Branch: 1 branch
BranchTrueFalseTotal
unless $rdict->{"Font"} 23 0 23
612  
613 23 my $fdict = $self->getValue($rdict->{Font});
614  
615 # Search out font resources. This is a total kluge.
616 # TODO: the right way to do this is to look for the DR
617 # attribute in the form element or it's ancestors.
618 23 for my $font (@rsrcs)
619 {
620 #JWT: CHGD. TO NEXT 11 (BUG#58144 PATCH): my $fobj = $self->dereference("/$font", 'All');
621 #JWT: CHGD. TO NEXT 11 (BUG#58144 PATCH): if (!$fobj)
622 23 my $root = $self->getRootDict()->{AcroForm};
623 23 my $ifdict = $self->getValue($root);
624 23 ▶ unless (exists $ifdict->{DR})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ifdict->{"DR"}) 0 23 23
625 {
626 #JWT:die "Could not find resource /$font while preparing form field $key\n";
627 0 warn "Could not find resource1 /$font while preparing form field $key\n";
628 }
629 23 my $dr = $self->getValue($ifdict->{DR});
630 23 my $fobjnum = $dr->{Font}->{value}->{$font}->{value};
631  
632 23 ▶ unless ($fobjnum)
Branch: 1 branch
BranchTrueFalseTotal
unless ($fobjnum) 0 23 23
633 {
634 #JWT:die "Could not find resource /$font while preparing form field $key\n";
635 0 warn "Could not find resource2 /$font while preparing form field $key\n";
636 }
637 #JWT: CHGD. TO NEXT (BUG#58144 PATCH): $fdict->{$font} = CAM::PDF::Node->new('reference', $fobj->{objnum}, $formonum, $formgnum);
638 23 $fdict->{$font} = CAM::PDF::Node->new('reference', $fobjnum, $formonum, $formgnum);
639 }
640 }
641 }
642 23 $filled++;
643 }
644  
645 12 return $filled;
646 }
647  
648 =item $doc->getFormFieldList()
649  
650 Return an array of the names of all of the PDF form fields. The names
651 are the full hierarchical names constructed as explained in the PDF
652 reference manual. These names are useful for the fillFormFields()
653 function.
654  
655 =cut
656  
657 sub getFormFieldList
658 222 ▶{
Subroutine getFormFieldList: called CC=15 SCAR=28.0
Pod documented
659 222 my $self = shift;
660 222 my $parentname = shift; # very optional
661  
662 222 ▶ my $prefix = (defined $parentname ? $parentname . q{.} : q{});
Branch: 1 branch
BranchTrueFalseTotal
defined $parentname ? : 220 2 222
663  
664 222 my $kidlist;
665 222 ▶ if (defined $parentname && $parentname ne q{})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parentname and $parentname ne '') { } 220 2 222
Condition66%2/3
defined $parentname and $parentname ne ""
!ll&&!rl&&r
20220
MC/DC50%1/2
defined $parentname and $parentname ne ""
defined $parentname $parentname ne ""
Truth table66%2/3
A and B
A= defined $parentnameB= $parentname ne ""
ABresult
0X0
100
111
666 {
667 220 my $parent = $self->getFormField($parentname);
668 220 ▶ return unless ($parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 220 220
669 220 my $dict = $self->getValue($parent);
670 220 ▶ return unless (exists $dict->{Kids});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $dict->{"Kids"} 216 4 220
671 4 $kidlist = $self->getValue($dict->{Kids});
672 }
673 else
674 {
675 2 my $root = $self->getRootDict()->{AcroForm};
676 2 ▶ return unless ($root);
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 2 2
677 2 my $parent = $self->getValue($root);
678 2 ▶ return unless (exists $parent->{Fields});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $parent->{"Fields"} 0 2 2
679 2 $kidlist = $self->getValue($parent->{Fields});
680 }
681  
682 6 my @list;
683 6 my $nonamecnt = '0';
684 6 for my $kid (@{$kidlist})
685 {
686 218 ▶ if ((! ref $kid) || (ref $kid) ne 'CAM::PDF::Node' || $kid->{type} ne 'reference')
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $kid or ref $kid ne "CAM::PDF::Node" or $kid->{"type"} ne "reference") 0 218 218
Condition33%2/6
not ref $kid or ref $kid ne "CAM::PDF::Node" or $kid->{"type"} ne "reference"
l!l&&r!l&&!r
00218
not ref $kid or ref $kid ne "CAM::PDF::Node"
l!l&&r!l&&!r
00218
MC/DC0%0/3
not ref $kid or ref $kid ne "CAM::PDF::Node" or $kid->{"type"} ne "reference"
not ref $kid ref $kid ne "CAM::PDF::Node" $kid->{"type"} ne "reference"
Truth table25%1/4
not(A) or B or C
A= not ref $kidB= ref $kid ne "CAM::PDF::Node"C= $kid->{"type"} ne "reference"
ABCresult
1XX1
01X1
0011
0000
687 {
688 0 die "Expected a reference as the form child of '$parentname'\n";
689 }
690 218 my $objnode = $self->dereference($kid->{value});
691 218 my $dict = $self->getValue($objnode);
692 218 my $name = "(no name$nonamecnt)"; # assume the worst
693 218 ++$nonamecnt;
694 218 ▶ $name = $self->getValue($dict->{T}) if (exists $dict->{T});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dict->{"T"} 218 0 218
695 218 $name = $prefix . $name;
696 218 $name =~ s/\x00//gso; #JWT:HANDLE IRS'S FSCKED-UP HIGH-ASCII FIELD NAMES!
697 218 push @list, $name;
698 218 ▶ push @list, $prefix . $self->getValue($dict->{TU}) . ' (alternate name)' if (exists $dict->{TU});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dict->{"TU"} 0 218 218
699 218 $self->{formcache}->{$name} = $objnode;
700 218 my @kidnames = $self->getFormFieldList($name);
701 218 ▶ if (@kidnames > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@kidnames > 0) 4 214 218
702 {
703 #push @list, 'descend...';
704 4 push @list, @kidnames;
705 #push @list, 'ascend...';
706 }
707 }
708 6 return @list;
709 }
710  
711 =item $doc->getFormField($name)
712  
713 I<For INTERNAL use>
714  
715 Return the object containing the form field definition for the
716 specified field name. C<$name> can be either the full name or the
717 "short/alternate" name.
718  
719 =cut
720  
721 sub getFormField
722 248 ▶{
Subroutine getFormField: called CC=14 SCAR=49.6
Pod documented
723 248 my $self = shift;
724 248 my $fieldname = shift;
725  
726 248 ▶ return unless (defined $fieldname);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fieldname 0 248 248
727  
728 248 ▶ unless (exists $self->{formcache}->{$fieldname})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"formcache"}{$fieldname}) 0 248 248
729 {
730 0 my $kidlist;
731 my $parent;
732 0 ▶ if ($fieldname =~ m/ [.] /xms)
Branch: 1 branch
BranchTrueFalseTotal
if ($fieldname =~ / [.] /msx) { } 0 0 0
733 {
734 0 my $parentname;
735 #JWT: CHGD. TO NEXT (BUG#58144 PATCH): if ($fieldname =~ s/ \A(.*)[.]([.]+)\z /$2/xms)
736 0 ▶ $parentname = $1 if ($fieldname =~ s/ \A(.*)[.]([^.]+)\z /$2/xms);
Branch: 1 branch
BranchTrueFalseTotal
if $fieldname =~ s/ \A(.*)[.]([^.]+)\z /$2/msx 0 0 0
737 0 ▶ return unless ($parentname);
Branch: 1 branch
BranchTrueFalseTotal
unless $parentname 0 0 0
738 0 $parent = $self->getFormField($parentname);
739 0 ▶ return unless ($parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
740 0 my $dict = $self->getValue($parent);
741 0 ▶ return unless (exists $dict->{Kids});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $dict->{"Kids"} 0 0 0
742 0 $kidlist = $self->getValue($dict->{Kids});
743 }
744 else
745 {
746 0 my $root = $self->getRootDict()->{AcroForm};
747 0 ▶ return unless ($root);
Branch: 1 branch
BranchTrueFalseTotal
unless $root 0 0 0
748 0 $parent = $self->dereference($root->{value});
749 0 ▶ return unless ($parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
750 0 my $dict = $self->getValue($parent);
751 0 ▶ return unless (exists $dict->{Fields});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $dict->{"Fields"} 0 0 0
752 0 $kidlist = $self->getValue($dict->{Fields});
753 }
754  
755 0 $self->{formcache}->{$fieldname} = undef; # assume the worst...
756 0 for my $kid (@{$kidlist})
757 {
758 0 my $objnode = $self->dereference($kid->{value});
759 0 $objnode->{formparent} = $parent;
760 0 my $dict = $self->getValue($objnode);
761 0 ▶ $self->{formcache}->{$self->getValue($dict->{T})} = $objnode if (exists $dict->{T});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dict->{"T"} 0 0 0
762 0 ▶ $self->{formcache}->{$self->getValue($dict->{TU})} = $objnode if (exists $dict->{TU});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dict->{"TU"} 0 0 0
763 }
764 }
765  
766 248 return $self->{formcache}->{$fieldname};
767 }
768  
769 =item $doc->writeAny($node)
770  
771 Returns the serialization of the specified node. This handles all
772 Node types, including object Nodes.
773  
774 =cut
775  
776 sub writeAny
777 22413 ▶{
Subroutine writeAny: called CC=15 SCAR=28.4
Pod documented
778 22413 my $self = shift;
779 22413 my $objnode = shift;
780  
781 22413 ▶ die 'Not a ref' unless (ref $objnode);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $objnode 0 22413 22413
782  
783 22413 my $key = $objnode->{type};
784  
785 22413 ▶ return 1 unless (defined($key) && $key); #JWT:ADDED!
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and $key 0 22413 22413
Condition33%1/3
defined $key and $key
!ll&&!rl&&r
0022413
MC/DC0%0/2
defined $key and $key
defined $key $key
Truth table33%1/3
A and B
A= defined $keyB= $key
ABresult
0X0
100
111
786  
787 22413 my $val = $objnode->{value};
788 22413 my $objnum = $objnode->{objnum};
789 22413 my $gennum = $objnode->{gennum};
790  
791 return $key eq 'string' ? $self->writeString($self->{crypt}->encrypt($self, $val, $objnum, $gennum))
792 22413 ▶ : $key eq 'hexstring' ? '<' . (unpack 'H*', $self->{crypt}->encrypt($self, $val, $objnum, $gennum)) . '>'
Branch: 10 branches
BranchTrueFalseTotal
$key eq 'string' ? : 504 21909 22413
$key eq 'hexstring' ? : 161 21748 21909
$key eq 'number' ? : 11463 10285 21748
$key eq 'reference' ? : 2600 7685 10285
$key eq 'boolean' ? : 14 7671 7685
$key eq 'null' ? : 0 7671 7671
$key eq 'label' ? : 4167 3504 7671
$key eq 'array' ? : 625 2879 3504
$key eq 'dictionary' ? : 1607 1272 2879
$key eq 'object' ? : 1272 0 1272
Condition0%0/2
$objnum || '<none>'
l!l
00
MC/DC0%0/1
$objnum || '<none>'
$objnum
Truth table0%0/2
A
A= $objnum
Aresult
11
00
793 : $key eq 'number' ? "$val"
794 : $key eq 'reference' ? "$val 0 R" # TODO: lookup the gennum and use it instead of 0 (?)
795 : $key eq 'boolean' ? $val
796 : $key eq 'null' ? 'null'
797 : $key eq 'label' ? "/$val"
798 : $key eq 'array' ? $self->_writeArray($objnode)
799 : $key eq 'dictionary' ? $self->_writeDictionary($objnode)
800 : $key eq 'object' ? $self->_writeObject($objnode)
801 #JWT:CHGD. TO NEXT (TO PREVENT DEATH!): : die "Unknown key '$key' in writeAny (objnum ".($objnum||'<none>').")\n";
802 : warn "Unknown key '$key' (value=$val= objnum=$objnum gen=$gennum) in writeAny (objnum ".($objnum||'<none>').")\n";
803 }
804  
805 4 1;
806  
807 __END__
↑ Summary script/listpdffields2.pl »