Reuse.pm

filter: Statementstmt 31.5% 1090 / 3454 Branchbran 21.3% 342 / 1606 Conditioncond 20.0% 111 / 553 MC/DCmcdc 4.0% 12 / 296 Subroutinesub 49.3% 78 / 158 Podpod 43.3% 36 / 83 totaltotal 27.1% 1669 / 6150 CC 1086 SCAR 62.5
CC
1086
Cov
27%
behandlaNames
2070.0
getPage
1377.4
prImage
1332.0
CRAP 517.6
↑ Summary Reuse/Util.pm »
1 package PDF::Reuse;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 require Exporter;
8 3 require Digest::MD5;
9 3 ▶use autouse 'Carp' => qw(carp
Subroutine BEGIN: called CC=1 SCAR=0.0
10 cluck
11 3 croak);
12  
13 3 ▶use Compress::Zlib qw(compress inflateInit);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use autouse 'Data::Dumper' => qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 #use AutoLoader qw(AUTOLOAD);
17  
18 3 our $VERSION = '0.44';
19 3 our @ISA = qw(Exporter);
20 3 our @EXPORT = qw(prFile
21 prPage
22 prId
23 prIdType
24 prInitVars
25 prEnd
26 prExtract
27 prForm
28 prImage
29 prAltJpeg
30 prJpeg
31 prDoc
32 prDocForm
33 prFont
34 prFontSize
35 prGraphState
36 prGetLogBuffer
37 prAdd
38 prBar
39 prText
40 prDocDir
41 prLogDir
42 prLog
43 prVers
44 prCid
45 prJs
46 prInit
47 prField
48 prTouchUp
49 prCompress
50 prMbox
51 prBookmark
52 prStrWidth
53 prLink
54 prTTFont
55 prSinglePage);
56  
57 3 our ($utfil, $slutNod, $formCont, $imSeq, $duplicateInits, $page, $sidObjNr, $sida,
58 $interActive, $NamesSaved, $AARootSaved, $AAPageSaved, $root,
59 $AcroFormSaved, $id, $ldir, $checkId, $formNr, $imageNr,
60 $filnamn, $interAktivSida, $taInterAkt, $type, $runfil, $checkCs,
61 $confuseObj, $compress, $pos, $fontNr, $objNr, $docProxy,
62 $defGState, $gSNr, $pattern, $shading, $colorSpace, $totalCount);
63  
64 3 our (@kids, @counts, @formBox, @objekt, @parents, @aktuellFont, @skapa,
65 @jsfiler, @inits, @bookmarks, @annots);
66  
67 3 our ( %old, %oldObject, %resurser, %form, %image, %objRef, %nyaFunk, %fontSource,
68 %sidFont, %sidXObject, %sidExtGState, %font, %intAct, %fields, %script,
69 %initScript, %sidPattern, %sidShading, %sidColorSpace, %knownToFile,
70 %processed, %embedded, %dummy, %behandlad, %unZipped, %links, %prefs);
71  
72 3 our $stream = '';
73 3 our $idTyp = '';
74 3 our $ddir = '';
75 3 our $log = '';
76  
77 #########################
78 # Konstanter för objekt
79 #########################
80  
81 3 ▶use constant oNR => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 3 ▶use constant oPOS => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 3 ▶use constant oSTREAMP => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 3 ▶use constant oKIDS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 3 ▶use constant oFORM => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 3 ▶use constant oIMAGENR => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 3 ▶use constant oWIDTH => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 3 ▶use constant oHEIGHT => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 3 ▶use constant oTYPE => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 3 ▶use constant oNAME => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 ###################################
93 # Konstanter för formulär
94 ###################################
95  
96 3 ▶use constant fOBJ => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 3 ▶use constant fRESOURCE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 3 ▶use constant fBBOX => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 3 ▶use constant fIMAGES => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 3 ▶use constant fMAIN => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 3 ▶use constant fKIDS => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 3 ▶use constant fNOKIDS => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 3 ▶use constant fID => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 3 ▶use constant fVALID => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
105  
106 ####################################
107 # Konstanter för images
108 ####################################
109  
110 3 ▶use constant imWIDTH => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 3 ▶use constant imHEIGHT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 3 ▶use constant imXPOS => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 3 ▶use constant imYPOS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 3 ▶use constant imXSCALE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 3 ▶use constant imYSCALE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 3 ▶use constant imIMAGENO => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 #####################################
119 # Konstanter för interaktiva objekt
120 #####################################
121  
122 3 ▶use constant iNAMES => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 3 ▶use constant iACROFORM => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 3 ▶use constant iAAROOT => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 3 ▶use constant iANNOTS => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
126 3 ▶use constant iSTARTSIDA => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 3 ▶use constant iAAPAGE => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 #####################################
130 # Konstanter för fonter
131 #####################################
132  
133 3 ▶use constant foREFOBJ => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 3 ▶use constant foINTNAMN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 3 ▶use constant foEXTNAMN => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 3 ▶use constant foORIGINALNR => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 3 ▶use constant foSOURCE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
138 3 ▶use constant foTYP => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 3 ▶use constant foFONTOBJ => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
140  
141 ##########
142 # Övrigt
143 ##########
144  
145 3 ▶use constant IS_MODPERL => $ENV{MOD_PERL}; # For mod_perl 1.
Subroutine BEGIN: called CC=1 SCAR=0.0
146 # For mod_perl 2 pass $r to prFile()
147 3 our $touchUp = 1;
148  
149 3 our %stdFont =
150 ('Times-Roman' => 'Times-Roman',
151 'Times-Bold' => 'Times-Bold',
152 'Times-Italic' => 'Times-Italic',
153 'Times-BoldItalic' => 'Times-BoldItalic',
154 'Courier' => 'Courier',
155 'Courier-Bold' => 'Courier-Bold',
156 'Courier-Oblique' => 'Courier-Oblique',
157 'Courier-BoldOblique' => 'Courier-BoldOblique',
158 'Helvetica' => 'Helvetica',
159 'Helvetica-Bold' => 'Helvetica-Bold',
160 'Helvetica-Oblique' => 'Helvetica-Oblique',
161 'Helvetica-BoldOblique' => 'Helvetica-BoldOblique',
162 'Symbol' => 'Symbol',
163 'ZapfDingbats' => 'ZapfDingbats',
164 'TR' => 'Times-Roman',
165 'TB' => 'Times-Bold',
166 'TI' => 'Times-Italic',
167 'TBI' => 'Times-BoldItalic',
168 'C' => 'Courier',
169 'CB' => 'Courier-Bold',
170 'CO' => 'Courier-Oblique',
171 'CBO' => 'Courier-BoldOblique',
172 'H' => 'Helvetica',
173 'HB' => 'Helvetica-Bold',
174 'HO' => 'Helvetica-Oblique',
175 'HBO' => 'Helvetica-BoldOblique',
176 'S' => 'Symbol',
177 'Z' => 'ZapfDingbats');
178  
179 3 our $ws = '\s';#'(?:[ \0\n\r\t\f]|%[^\r\n]*[\r\n])';
180  
181 3 our $genLowerX = 0;
182 3 our $genLowerY = 0;
183 3 our $genUpperX = 595,
184 our $genUpperY = 842;
185 3 our $genFont = 'Helvetica';
186 3 our $fontSize = 12;
187  
188 3 keys(%resurser) = 10;
189  
190 sub prFont
191 1 ▶{ my $nyFont = shift;
Subroutine prFont: called CC=5 SCAR=18.7
Pod documented
192 1 my ($intnamn, $extnamn, $objektnr, $oldIntNamn, $oldExtNamn);
193  
194 1 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 1 1
195 0 { errLog("No output file, you have to call prFile first");
196 }
197 1 $oldIntNamn = $aktuellFont[foINTNAMN];
198 1 $oldExtNamn = $aktuellFont[foEXTNAMN];
199 1 ▶ if ($nyFont)
Branch: 1 branch
BranchTrueFalseTotal
if ($nyFont) { } 1 0 1
200 1 { ($intnamn, $extnamn, $objektnr) = findFont($nyFont);
201 }
202 else
203 0 { $intnamn = $aktuellFont[foINTNAMN];
204 0 $extnamn = $aktuellFont[foEXTNAMN];
205 }
206 1 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 1 1
207 0 { $log .= "Font~$nyFont\n";
208 }
209 1 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
210 0 { return ($intnamn, $extnamn, $oldIntNamn, $oldExtNamn, \%font);
211 }
212 else
213 1 { return $intnamn;
214 }
215 }
216  
217 sub prFontSize
218 18 ▶{ my $fSize = shift || 12;
Subroutine prFontSize: called CC=5 SCAR=18.1
Pod documented
Condition50%1/2
shift() || 12
l!l
180
MC/DC0%0/1
shift() || 12
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
219 18 my $oldFontSize = $fontSize;
220 18 ▶ if ($fSize =~ m'\d+\.?\d*'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($fSize =~ /\d+\.?\d*/o) 18 0 18
221 18 { $fontSize = $fSize;
222 18 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 18 18
223 0 { $log .= "FontSize~$fontSize\n";
224 }
225 }
226 18 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 18 18
227 0 { errLog("No output file, you have to call prFile first");
228 }
229  
230 18 return ($fontSize, $oldFontSize);
231 }
232  
233 sub prFile
234 18 ▶{ if ($pos)
Subroutine prFile: called CC=43 SCAR=53.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::pos) 0 18 18
235 0 { prEnd();
236 0 close UTFIL;
237 }
238 18 %prefs = ();
239 18 my $param = shift;
240 18 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 18 18
241 0 { $filnamn = '-';
242 0 for (keys %{$param})
243 0 { my $key = lc($_);
244 0 ▶ if ($key eq 'name')
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'name') { } 0 0 0
elsif ($key eq 'hidetoolbar' or $key eq 'hidemenubar' or $key eq 'hidewindowui' or $key eq 'fitwindow' or $key eq 'centerwindow') { } 0 0 0
245 0 { $filnamn = $param->{$_}; }
246 ▶ elsif (($key eq 'hidetoolbar')
Condition0%0/12
$key eq "hidetoolbar" or $key eq "hidemenubar" or $key eq "hidewindowui" or $key eq "fitwindow" or $key eq "centerwindow"
l!l&&r!l&&!r
000
$key eq "hidetoolbar" or $key eq "hidemenubar" or $key eq "hidewindowui" or $key eq "fitwindow"
l!l&&r!l&&!r
000
$key eq "hidetoolbar" or $key eq "hidemenubar" or $key eq "hidewindowui"
l!l&&r!l&&!r
000
$key eq "hidetoolbar" or $key eq "hidemenubar"
l!l&&r!l&&!r
000
MC/DC0%0/5
$key eq "hidetoolbar" or $key eq "hidemenubar" or $key eq "hidewindowui" or $key eq "fitwindow" or $key eq "centerwindow"
$key eq "hidetoolbar" $key eq "hidemenubar" $key eq "hidewindowui" $key eq "fitwindow" $key eq "centerwindow"
Truth table0%0/6
A or B or C or D or E
A= $key eq "hidetoolbar"B= $key eq "hidemenubar"C= $key eq "hidewindowui"D= $key eq "fitwindow"E= $key eq "centerwindow"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
247 || ($key eq 'hidemenubar')
248 || ($key eq 'hidewindowui')
249 || ($key eq 'fitwindow')
250 || ($key eq 'centerwindow'))
251 0 { $prefs{$key} = $param->{$_};
252 }
253 }
254 }
255 else
256 18 ▶ { $filnamn = $param || '-';
Condition50%1/2
$param || '-'
l!l
180
MC/DC0%0/1
$param || '-'
$param
Truth table50%1/2
A
A= $param
Aresult
11
00
257 18 ▶ $prefs{hidetoolbar} = $_[1] if defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 0 18 18
258 18 ▶ $prefs{hidemenubar} = $_[2] if defined $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] 0 18 18
259 18 ▶ $prefs{hidewindowui} = $_[3] if defined $_[3];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[3] 0 18 18
260 18 ▶ $prefs{fitwindow} = $_[4] if defined $_[4];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[4] 0 18 18
261 18 ▶ $prefs{centerwindow} = $_[5] if defined $_[5];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[5] 0 18 18
262 }
263 18 my $kortNamn;
264 18 ▶ if ($filnamn ne '-')
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::filnamn ne '-') { } 18 0 18
265 18 { my $ri = rindex($filnamn,'/');
266 18 ▶ if ($ri > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($ri > 0) { } 17 1 18
267 17 { $kortNamn = substr($filnamn, ($ri + 1));
268 17 ▶ $utfil = $ddir ? $ddir . $kortNamn : $filnamn;
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::ddir ? : 0 17 17
269 }
270 else
271 1 ▶ { $utfil = $ddir ? $ddir . $filnamn : $filnamn;
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::ddir ? : 0 1 1
272 }
273 18 $ri = rindex($utfil,'/');
274 18 ▶ if ($ri > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($ri > 0) { } 17 1 18
275 17 { my $dirdel = substr($utfil,0,$ri);
276 17 ▶ if (! -e $dirdel)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dirdel) 0 17 17
277 0 ▶ { mkdir $dirdel || errLog("Couldn't create dir $dirdel, $!");
Condition0%0/3
$dirdel || errLog("Couldn't create dir $dirdel, $!")
l!l&&r!l&&!r
000
MC/DC0%0/2
$dirdel || errLog("Couldn't create dir $dirdel, $!")
$dirdel errLog("Couldn't create dir $dirdel, $!")
Truth table0%0/3
A || B
A= $dirdelB= errLog("Couldn't create dir $dirdel, $!")
ABresult
1X1
011
000
278 }
279 }
280 else
281 1 { $ri = rindex($utfil,'\\');
282 1 ▶ if ($ri > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($ri > 0) 0 1 1
283 0 { my $dirdel = substr($utfil,0,$ri);
284 0 ▶ if (! -e $dirdel)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dirdel) 0 0 0
285 0 ▶ { mkdir $dirdel || errLog("Couldn't create dir $dirdel, $!");
Condition0%0/3
$dirdel || errLog("Couldn't create dir $dirdel, $!")
l!l&&r!l&&!r
000
MC/DC0%0/2
$dirdel || errLog("Couldn't create dir $dirdel, $!")
$dirdel errLog("Couldn't create dir $dirdel, $!")
Truth table0%0/3
A || B
A= $dirdelB= errLog("Couldn't create dir $dirdel, $!")
ABresult
1X1
011
000
286 }
287 }
288 }
289 }
290 else
291 0 { $utfil = $filnamn;
292 }
293  
294 18 my $utfil_ref = ref $utfil;
295 3 ▶ { no warnings; untie *UTFIL; } # Clear any previous tie (e.g., from IO::String)
Subroutine BEGIN: called CC=1 SCAR=0.0
296 18 ▶ if ($utfil_ref and ($utfil_ref eq 'Apache2::RequestRec') or
Branch: 2 branches
BranchTrueFalseTotal
if ($utfil_ref and $utfil_ref eq 'Apache2::RequestRec' or $utfil_ref eq 'Apache::RequestRec') { } 0 18 18
elsif ($utfil_ref and $utfil_ref eq 'IO::String') { } 1 17 18
Condition50%3/6
$utfil_ref and $utfil_ref eq "Apache2::RequestRec" or $utfil_ref eq "Apache::RequestRec"
l!l&&r!l&&!r
0018
$utfil_ref and $utfil_ref eq "Apache2::RequestRec"
!ll&&!rl&&r
1710
MC/DC0%0/3
$utfil_ref and $utfil_ref eq "Apache2::RequestRec" or $utfil_ref eq "Apache::RequestRec"
$utfil_ref $utfil_ref eq "Apache2::RequestRec" $utfil_ref eq "Apache::RequestRec"
Truth table40%2/5
A and B or C
A= $utfil_refB= $utfil_ref eq "Apache2::RequestRec"C= $utfil_ref eq "Apache::RequestRec"
ABCresult
11X1
0X11
1011
0X00
1000
297 ($utfil_ref eq 'Apache::RequestRec') ) # mod_perl 2
298 0 { tie *UTFIL, $utfil;
299 }
300 elsif (IS_MODPERL && $utfil eq '-') # mod_perl 1
301 { tie *UTFIL, 'Apache';
302 }
303 ▶ elsif ($utfil_ref and $utfil_ref eq 'IO::String')
Condition66%2/3
$utfil_ref and $utfil_ref eq "IO::String"
!ll&&!rl&&r
1701
MC/DC50%1/2
$utfil_ref and $utfil_ref eq "IO::String"
$utfil_ref $utfil_ref eq "IO::String"
Truth table66%2/3
A and B
A= $utfil_refB= $utfil_ref eq "IO::String"
ABresult
0X0
100
111
304 1 { tie *UTFIL, $utfil;
305 }
306 else
307 17 ▶ { open (UTFIL, ">$utfil") || errLog("Couldn't open file $utfil, $!");
Branch: 1 branch
BranchTrueFalseTotal
open UTFIL, ">$PDF::Reuse::utfil" or errLog("Couldn't open file $PDF::Reuse::utfil, $!") 17 0 17
308 }
309  
310 # Opening for write just discarded whatever this name held, so any cached
311 # parse of it now describes bytes that no longer exist. Drop it here, at
312 # the moment of truncation, rather than at prEnd() -- otherwise the stale
313 # entry stays live for the whole time the file is being rewritten.
314 18 ▶ if (!ref $utfil)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $PDF::Reuse::utfil) 17 1 18
315 17 { delete $processed{$utfil};
316 17 delete $behandlad{$utfil};
317 }
318 18 binmode UTFIL;
319 18 my $utrad = "\%PDF-1.4\n\%\â\ã\Ï\Ó\n";
320  
321 18 $pos = syswrite UTFIL, $utrad;
322  
323 18 ▶ if (defined $ldir)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::ldir) 0 18 18
324 0 ▶ { if ($utfil eq '-')
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::utfil eq "-") 0 0 0
325 0 { $kortNamn = 'stdout';
326 }
327 0 ▶ if ($kortNamn)
Branch: 1 branch
BranchTrueFalseTotal
if ($kortNamn) { } 0 0 0
328 0 { $runfil = $ldir . $kortNamn . '.dat';
329 }
330 else
331 0 { $runfil = $ldir . $filnamn . '.dat';
332 }
333 0 ▶ open (RUNFIL, ">>$runfil") || errLog("Couldn't open logfile $runfil, $!");
Branch: 1 branch
BranchTrueFalseTotal
open RUNFIL, ">>$PDF::Reuse::runfil" or errLog("Couldn't open logfile $PDF::Reuse::runfil, $!") 0 0 0
334 0 $log .= "Vers~$VERSION\n";
335 }
336  
337  
338 18 @parents = ();
339 18 @kids = ();
340 18 @counts = ();
341 18 @objekt = ();
342 18 $objNr = 2; # Reserverat objekt 1 för root och 2 för initial sidnod
343 18 $parents[0] = 2;
344 18 $page = 0;
345 18 $formNr = 0;
346 18 $imageNr = 0;
347 18 $fontNr = 0;
348 18 $gSNr = 0;
349 18 $pattern = 0;
350 18 $shading = 0;
351 18 $colorSpace = 0;
352 18 $sida = 0;
353 18 %font = ();
354 18 %resurser = ();
355 18 %fields = ();
356 18 @jsfiler = ();
357 18 @inits = ();
358 18 %nyaFunk = ();
359 18 %objRef = ();
360 18 %knownToFile = ();
361 18 @aktuellFont = ();
362 18 %old = ();
363 18 %behandlad = ();
364 18 @bookmarks = ();
365 18 %links = ();
366 18 undef $defGState;
367 18 undef $interActive;
368 18 undef $NamesSaved;
369 18 undef $AARootSaved;
370 18 undef $AcroFormSaved;
371 18 $checkId = '';
372 18 undef $duplicateInits;
373 18 undef $confuseObj;
374 18 $fontSize = 12;
375 18 $genLowerX = 0;
376 18 $genLowerY = 0;
377 18 $genUpperX = 595,
378 $genUpperY = 842;
379  
380 18 prPage(1);
381 18 $stream = ' ';
382 18 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 18 18
383 0 { $filnamn = prep($filnamn);
384 0 $log .= "File~$filnamn";
385 0 ▶ $log .= (exists $prefs{hidetoolbar}) ? "~$prefs{hidetoolbar}" : '~';
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::prefs{'hidetoolbar'} ? : 0 0 0
386 0 ▶ $log .= (exists $prefs{hidemenubar}) ? "~$prefs{hidemenubar}" : '~';
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::prefs{'hidemenubar'} ? : 0 0 0
387 0 ▶ $log .= (exists $prefs{hidewindowui}) ? "~$prefs{hidewindowui}" : '~';
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::prefs{'hidewindowui'} ? : 0 0 0
388 0 ▶ $log .= (exists $prefs{fitwindow}) ? "~$prefs{fitwindow}" : '~';
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::prefs{'fitwindow'} ? : 0 0 0
389 0 ▶ $log .= (exists $prefs{centerwindow}) ? "~$prefs{centerwindow}" : "~\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::prefs{'centerwindow'} ? : 0 0 0
390 }
391 18 1;
392 }
393  
394  
395 sub prPage
396 34 ▶{ my $noLogg = shift;
Subroutine prPage: called CC=6 SCAR=19.0
Pod documented
397 34 ▶ if ((defined $stream) && (length($stream) > 0))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0) 16 18 34
Condition66%2/3
defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0
!ll&&!rl&&r
01816
MC/DC50%1/2
defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0
defined $PDF::Reuse::stream length $PDF::Reuse::stream > 0
Truth table66%2/3
A and B
A= defined $PDF::Reuse::streamB= length $PDF::Reuse::stream > 0
ABresult
0X0
100
111
398 16 { skrivSida();
399 }
400  
401 34 $page++;
402 34 $objNr++;
403 34 $sidObjNr = $objNr;
404  
405 #
406 # Resurserna nollställs
407 #
408  
409 34 %sidXObject = ();
410 34 %sidExtGState = ();
411 34 %sidFont = ();
412 34 %sidPattern = ();
413 34 %sidShading = ();
414 34 %sidColorSpace = ();
415 34 @annots = ();
416  
417 34 undef $interAktivSida;
418 34 undef $checkCs;
419 34 ▶ if (($runfil) && (! $noLogg))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil and not $noLogg) 0 34 34
Condition33%1/3
$PDF::Reuse::runfil and not $noLogg
!ll&&!rl&&r
3400
MC/DC0%0/2
$PDF::Reuse::runfil and not $noLogg
$PDF::Reuse::runfil not $noLogg
Truth table33%1/3
A and not(B)
A= $PDF::Reuse::runfilB= not $noLogg
ABresult
0X0
100
111
420 0 { $log .= "Page~\n";
421 0 print RUNFIL $log;
422 0 $log = '';
423 }
424 34 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 34 34
425 0 { errLog("No output file, you have to call prFile first");
426 }
427 34 1;
428  
429 }
430  
431 sub prText
432 26 ▶{ my $xPos = shift;
Subroutine prText: called CC=30 SCAR=54.6
Pod documented
433 26 my $yPos = shift;
434 26 my $TxT = shift;
435 26 ▶ my $align = shift || 'left';
Condition50%1/2
shift() || 'left'
l!l
026
MC/DC0%0/1
shift() || 'left'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
436 26 ▶ my $rot = shift || '0';
Condition50%1/2
shift() || '0'
l!l
026
MC/DC0%0/1
shift() || '0'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
437  
438 26 my $width = 0;
439 26 my $x_align_offset = 0;
440  
441 26 ▶ if (! defined $TxT)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $TxT) 0 26 26
442 0 { $TxT = '';
443 }
444  
445 26 ▶ if (($xPos !~ m'\-?[\d\.]+'o) || (! defined $xPos))
Branch: 1 branch
BranchTrueFalseTotal
unless ($xPos =~ /\-?[\d\.]+/o and defined $xPos) 0 26 26
Condition33%1/3
$xPos =~ /\-?[\d\.]+/o and defined $xPos
!ll&&!rl&&r
0026
MC/DC0%0/2
$xPos =~ /\-?[\d\.]+/o and defined $xPos
$xPos =~ /\-?[\d\.]+/o defined $xPos
Truth table33%1/3
A and B
A= $xPos =~ /\-?[\d\.]+/oB= defined $xPos
ABresult
0X0
100
111
446 0 { errLog("Illegal x-position for text: $xPos");
447 }
448 26 ▶ if (($yPos !~ m'\-?[\d\.]+'o) || (! defined $yPos))
Branch: 1 branch
BranchTrueFalseTotal
unless ($yPos =~ /\-?[\d\.]+/o and defined $yPos) 0 26 26
Condition33%1/3
$yPos =~ /\-?[\d\.]+/o and defined $yPos
!ll&&!rl&&r
0026
MC/DC0%0/2
$yPos =~ /\-?[\d\.]+/o and defined $yPos
$yPos =~ /\-?[\d\.]+/o defined $yPos
Truth table33%1/3
A and B
A= $yPos =~ /\-?[\d\.]+/oB= defined $yPos
ABresult
0X0
100
111
449 0 { errLog("Illegal y-position for text: $yPos");
450 }
451  
452 26 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 26 26
453 0 { my $Texten = prep($TxT);
454 0 $log .= "Text~$xPos~$yPos~$Texten~$align~$rot\n";
455 }
456  
457 26 ▶ if (length($stream) < 3)
Branch: 1 branch
BranchTrueFalseTotal
if (length $PDF::Reuse::stream < 3) 26 0 26
458 26 { $stream = "0 0 0 rg\n 0 g\nf\n";
459 }
460  
461  
462 26 ▶ if (! $aktuellFont[foINTNAMN])
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::aktuellFont[1]) 10 16 26
463 10 { findFont();
464 }
465 26 my $Font = $aktuellFont[foINTNAMN]; # Namn i strömmen
466 26 $sidFont{$Font} = $aktuellFont[foREFOBJ];
467 26 my $fontname = $aktuellFont[foEXTNAMN];
468 26 ▶ my $ttfont = $font{$fontname} ? $font{$fontname}[foFONTOBJ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::font{$fontname} ? : 26 0 26
469  
470  
471 # define what the offset for alignment is
472  
473 26 ▶ if ((wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray or $align ne "left") 0 26 26
Condition33%1/3
wantarray or $align ne "left"
l!l&&r!l&&!r
0026
MC/DC0%0/2
wantarray or $align ne "left"
wantarray $align ne "left"
Truth table33%1/3
A or B
A= wantarrayB= $align ne "left"
ABresult
1X1
011
000
474 || ($align ne 'left'))
475 0 { $width = prStrWidth($TxT, $aktuellFont[foEXTNAMN], $fontSize);
476 0 ▶ if($align eq 'right')
Branch: 2 branches
BranchTrueFalseTotal
if ($align eq 'right') { } 0 0 0
elsif ($align eq 'center') { } 0 0 0
477 0 { $x_align_offset = - $width;
478 }
479 elsif ($align eq 'center')
480 0 { $x_align_offset = -$width / 2;
481 }
482 }
483  
484 26 $TxT =~ s|\(|\\(|gos;
485 26 $TxT =~ s|\)|\\)|gos;
486  
487  
488 26 ▶ unless($rot)
Branch: 1 branch
BranchTrueFalseTotal
if ($rot) { } 0 26 26
489 26 { $stream .= "\nBT /$Font $fontSize Tf ";
490 26 ▶ if($ttfont)
Branch: 2 branches
BranchTrueFalseTotal
if ($ttfont) { } 0 26 26
elsif (not $PDF::Reuse::aktuellFont[5]) { } 26 0 26
491 0 { $TxT = $ttfont->encode_text($TxT);
492 0 $stream .= $xPos+$x_align_offset . " $yPos Td $TxT Tj ET\n";
493 }
494 elsif (!$aktuellFont[foTYP])
495 26 { $stream .= $xPos+$x_align_offset . " $yPos Td \($TxT\) Tj ET\n";
496 }
497 else
498 0 { my $text;
499 0 $TxT =~ s/\\(\d\d\d)/chr(oct($1))/eg;
500 0 for (unpack ('C*', $TxT))
501 0 { $text .= sprintf("%04x", ($_ - 29));
502 }
503 0 $stream .= $xPos+$x_align_offset . " $yPos Td \<$text\> Tj ET\n";
504 }
505 }
506 else
507 0 ▶ { if ($rot =~ m'q(\d)'oi)
Branch: 1 branch
BranchTrueFalseTotal
if ($rot =~ /q(\d)/io) 0 0 0
508 0 ▶ { if ($1 eq '1')
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq '1') { } 0 0 0
elsif ($1 eq '2') { } 0 0 0
509 0 { $rot = 270;
510 }
511 elsif ($1 eq '2')
512 0 { $rot = 180;
513 }
514 else
515 0 { $rot = 90;
516 }
517 }
518  
519 0 my $radian = sprintf("%.6f", $rot / 57.2957795); # approx.
520 0 my $Cos = sprintf("%.6f", cos($radian));
521 0 my $Sin = sprintf("%.6f", sin($radian));
522 0 my $negSin = $Sin * -1;
523  
524 0 ▶ my $encText = $ttfont ? $ttfont->encode_text($TxT) : "\($TxT\)";
Branch: 1 branch
BranchTrueFalseTotal
$ttfont ? : 0 0 0
525 0 $stream .= "\nq\n" # enter a new stack frame
526 # . "/Gs0 gs\n" # reset graphic mode
527 . "$Cos $Sin $negSin $Cos $xPos $yPos cm\n" # rotation/translation in the CM
528 . "\nBT /$Font $fontSize Tf "
529 . "$x_align_offset 0 Td $encText Tj ET\n" # text @ 0,0
530 . "Q\n"; # close the stack frame
531 }
532 26 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 26 26
533 0 { errLog("No output file, you have to call prFile first");
534 }
535  
536  
537 26 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 26 26
538 { # return a new "cursor" position...
539  
540 0 ▶ if($rot==0)
Branch: 1 branch
BranchTrueFalseTotal
if ($rot == 0) { } 0 0 0
541 0 ▶ { if($align eq 'left')
Branch: 3 branches
BranchTrueFalseTotal
if ($align eq 'left') { } 0 0 0
elsif ($align eq 'center') { } 0 0 0
elsif ($align eq 'right') { } 0 0 0
542 0 { return ($xPos, $xPos + $width);
543 }
544 elsif($align eq 'center')
545 0 { return ($xPos - $x_align_offset, $xPos + $x_align_offset);
546 }
547 elsif($align eq 'right')
548 0 { return ($xPos - $width, $xPos);
549 }
550  
551 }
552 else
553 { # todo
554 # we could some trigonometry to return an x/y point
555 0 return 1;
556 }
557 }
558 else
559 26 { return 1;
560 }
561  
562 }
563  
564  
565 sub prAdd
566 0 ▶{ my $contents = shift;
Subroutine prAdd: not called CC=3 SCAR=24.8
Pod documented
567 0 $stream .= "\n$contents\n";
568 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
569 0 { $contents = prep($contents);
570 0 $log .= "Add~$contents\n";
571 }
572 0 $checkCs = 1;
573 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
574 0 { errLog("No output file, you have to call prFile first");
575 }
576 0 1;
577 }
578  
579 ##########################
580 # Ett grafiskt "formulär"
581 ##########################
582  
583 sub prForm
584 1 ▶{ my ($sidnr, $adjust, $effect, $tolerant, $infil, $x, $y, $size, $xsize,
Subroutine prForm: called CC=55 SCAR=66.1
Pod documented
585 $ysize, $rotate);
586 1 my $param = shift;
587 1 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 1 0 1
588 1 { $infil = $param->{'file'};
589 1 ▶ $sidnr = $param->{'page'} || 1;
Condition50%1/2
$param->{'page'} || 1
l!l
01
MC/DC0%0/1
$param->{'page'} || 1
$param->{'page'}
Truth table50%1/2
A
A= $param->{'page'}
Aresult
11
00
590 1 ▶ $adjust = $param->{'adjust'} || '';
Condition50%1/2
$param->{'adjust'} || ''
l!l
01
MC/DC0%0/1
$param->{'adjust'} || ''
$param->{'adjust'}
Truth table50%1/2
A
A= $param->{'adjust'}
Aresult
11
00
591 1 ▶ $effect = $param->{'effect'} || 'print';
Condition50%1/2
$param->{'effect'} || 'print'
l!l
01
MC/DC0%0/1
$param->{'effect'} || 'print'
$param->{'effect'}
Truth table50%1/2
A
A= $param->{'effect'}
Aresult
11
00
592 1 ▶ $tolerant = $param->{'tolerant'} || '';
Condition50%1/2
$param->{'tolerant'} || ''
l!l
01
MC/DC0%0/1
$param->{'tolerant'} || ''
$param->{'tolerant'}
Truth table50%1/2
A
A= $param->{'tolerant'}
Aresult
11
00
593 1 ▶ $x = $param->{'x'} || 0;
Condition50%1/2
$param->{'x'} || 0
l!l
01
MC/DC0%0/1
$param->{'x'} || 0
$param->{'x'}
Truth table50%1/2
A
A= $param->{'x'}
Aresult
11
00
594 1 ▶ $y = $param->{'y'} || 0;
Condition50%1/2
$param->{'y'} || 0
l!l
01
MC/DC0%0/1
$param->{'y'} || 0
$param->{'y'}
Truth table50%1/2
A
A= $param->{'y'}
Aresult
11
00
595 1 ▶ $rotate = $param->{'rotate'} || 0;
Condition50%1/2
$param->{'rotate'} || 0
l!l
01
MC/DC0%0/1
$param->{'rotate'} || 0
$param->{'rotate'}
Truth table50%1/2
A
A= $param->{'rotate'}
Aresult
11
00
596 1 ▶ $size = $param->{'size'} || 1;
Condition50%1/2
$param->{'size'} || 1
l!l
01
MC/DC0%0/1
$param->{'size'} || 1
$param->{'size'}
Truth table50%1/2
A
A= $param->{'size'}
Aresult
11
00
597 1 ▶ $xsize = $param->{'xsize'} || 1;
Condition50%1/2
$param->{'xsize'} || 1
l!l
01
MC/DC0%0/1
$param->{'xsize'} || 1
$param->{'xsize'}
Truth table50%1/2
A
A= $param->{'xsize'}
Aresult
11
00
598 1 ▶ $ysize = $param->{'ysize'} || 1;
Condition50%1/2
$param->{'ysize'} || 1
l!l
01
MC/DC0%0/1
$param->{'ysize'} || 1
$param->{'ysize'}
Truth table50%1/2
A
A= $param->{'ysize'}
Aresult
11
00
599 }
600 else
601 0 { $infil = $param;
602 0 ▶ $sidnr = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
603 0 ▶ $adjust = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
604 0 ▶ $effect = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
605 0 ▶ $tolerant = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
606 0 ▶ $x = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
607 0 ▶ $y = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
608 0 ▶ $rotate = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
609 0 ▶ $size = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
610 0 ▶ $xsize = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
611 0 ▶ $ysize = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
612 }
613  
614 # Support IO::String and other IO handles as input (RT #168975)
615 1 ▶ if (ref($infil)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $infil) 1 0 1
616 1 require File::Temp;
617 1 my $data;
618 1 ▶ if (ref($infil) eq "SCALAR") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $infil eq 'SCALAR') { } 0 1 1
619 0 $data = $$infil;
620 } else {
621 1 local $/;
622 1 $data = <$infil>;
623 1 ▶ seek($infil, 0, 0) if $infil->can("seek");
Branch: 1 branch
BranchTrueFalseTotal
if $infil->can("seek") 1 0 1
624 }
625 1 my ($tmpfh, $tmpfile) = File::Temp::tempfile(SUFFIX => ".pdf", UNLINK => 1);
626 1 binmode $tmpfh;
627 1 print $tmpfh $data;
628 1 close $tmpfh;
629 1 $infil = $tmpfile;
630 }
631  
632 1 my $refNr;
633 my $namn;
634 1 $type = 'form';
635 1 my $fSource = $infil . '_' . $sidnr;
636 1 ▶ if (! exists $form{$fSource})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::form{$fSource}) { } 1 0 1
637 1 { $formNr++;
638 1 $namn = 'Fm' . $formNr;
639 1 $knownToFile{$fSource} = $namn;
640 1 my $action;
641 1 ▶ if ($effect eq 'load')
Branch: 1 branch
BranchTrueFalseTotal
if ($effect eq 'load') { } 0 1 1
642 0 { $action = 'load'
643 }
644 else
645 1 { $action = 'print'
646 }
647 1 $refNr = getPage($infil, $sidnr, $action);
648 1 ▶ if ($refNr)
Branch: 1 branch
BranchTrueFalseTotal
if ($refNr) { } 1 0 1
649 1 { $objRef{$namn} = $refNr;
650 }
651 else
652 0 ▶ { if ($tolerant)
Branch: 2 branches
BranchTrueFalseTotal
if ($tolerant) { } 0 0 0
elsif (not defined $refNr) { } 0 0 0
653 0 ▶ { if ((defined $refNr) && ($refNr eq '0')) # Sidnumret existerar inte, men ok
Branch: 1 branch
BranchTrueFalseTotal
if (defined $refNr and $refNr eq '0') { } 0 0 0
Condition0%0/3
defined $refNr and $refNr eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $refNr and $refNr eq 0
defined $refNr $refNr eq 0
Truth table0%0/3
A and B
A= defined $refNrB= $refNr eq 0
ABresult
0X0
100
111
654 0 { $namn = '0';
655 }
656 else
657 0 { undef $namn; # Sidan kan inte användas som form
658 }
659 }
660 elsif (! defined $refNr)
661 0 { my $mess = "$fSource can't be used as a form. See the documentation\n"
662 . "under prForm how to concatenate streams\n";
663 0 errLog($mess);
664 }
665 else
666 0 { errLog("File : $infil Page: $sidnr doesn't exist");
667 }
668 }
669 }
670 else
671 0 ▶ { if (exists $knownToFile{$fSource})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::knownToFile{$fSource}) { } 0 0 0
672 0 { $namn = $knownToFile{$fSource};
673 }
674 else
675 0 { $formNr++;
676 0 $namn = 'Fm' . $formNr;
677 0 $knownToFile{$fSource} = $namn;
678 }
679 0 ▶ if (exists $objRef{$namn})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::objRef{$namn}) { } 0 0 0
680 0 { $refNr = $objRef{$namn};
681 }
682 else
683 0 ▶ { if (! $form{$fSource}[fVALID])
Branch: 2 branches
BranchTrueFalseTotal
if (not $PDF::Reuse::form{$fSource}[8]) { } 0 0 0
elsif ($effect ne 'load') { } 0 0 0
684 0 { my $mess = "$fSource can't be used as a form. See the documentation\n"
685 . "under prForm how to concatenate streams\n";
686 0 ▶ if ($tolerant)
Branch: 1 branch
BranchTrueFalseTotal
if ($tolerant) { } 0 0 0
687 0 { cluck $mess;
688 0 undef $namn;
689 }
690 else
691 0 { errLog($mess);
692 }
693 }
694 elsif ($effect ne 'load')
695 0 { $refNr = byggForm($infil, $sidnr);
696 0 $objRef{$namn} = $refNr;
697 }
698 }
699 }
700 1 ▶ my @BBox = @{$form{$fSource}[fBBOX]} if ($refNr);
Branch: 1 branch
BranchTrueFalseTotal
if $refNr 1 0 1
701 1 ▶ if (($effect eq 'print') && ($form{$fSource}[fVALID]) && ($refNr))
Branch: 1 branch
BranchTrueFalseTotal
if ($effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr) 1 0 1
Condition33%2/6
$effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr
!ll&&!rl&&r
001
$effect eq "print" and $PDF::Reuse::form{$fSource}[8]
!ll&&!rl&&r
001
MC/DC0%0/3
$effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr
$effect eq "print" $PDF::Reuse::form{$fSource}[8] $refNr
Truth table25%1/4
A and B and C
A= $effect eq "print"B= $PDF::Reuse::form{$fSource}[8]C= $refNr
ABCresult
0XX0
10X0
1100
1111
702 1 ▶ { if (! defined $defGState)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::defGState) 1 0 1
703 1 { prDefaultGrState();
704 }
705  
706 1 ▶ if ($adjust)
Branch: 2 branches
BranchTrueFalseTotal
if ($adjust) { } 0 1 1
elsif ($x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1) { } 0 1 1
707 0 { $stream .= "q\n";
708 0 $stream .= fillTheForm(@BBox, $adjust);
709 0 $stream .= "\n/Gs0 gs\n";
710 0 $stream .= "/$namn Do\n";
711 0 $stream .= "Q\n";
712 }
713 ▶ elsif (($x) || ($y) || ($rotate) || ($size != 1)
Condition33%5/15
$x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1
l!l&&r!l&&!r
001
$x or $y or $rotate or $size != 1 or $xsize != 1
l!l&&r!l&&!r
001
$x or $y or $rotate or $size != 1
l!l&&r!l&&!r
001
$x or $y or $rotate
l!l&&r!l&&!r
001
$x or $y
l!l&&r!l&&!r
001
MC/DC0%0/6
$x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1
$x $y $rotate $size != 1 $xsize != 1 $ysize != 1
Truth table14%1/7
A or B or C or D or E or F
A= $xB= $yC= $rotateD= $size != 1E= $xsize != 1F= $ysize != 1
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
714 || ($xsize != 1) || ($ysize != 1))
715 0 { $stream .= "q\n";
716 0 $stream .= calcMatrix($x, $y, $rotate, $size,
717 $xsize, $ysize, $BBox[2], $BBox[3]);
718 0 $stream .= "\n/Gs0 gs\n";
719 0 $stream .= "/$namn Do\n";
720 0 $stream .= "Q\n";
721 }
722 else
723 1 { $stream .= "\n/Gs0 gs\n";
724 1 $stream .= "/$namn Do\n";
725  
726 }
727 1 $sidXObject{$namn} = $refNr;
728 1 $sidExtGState{'Gs0'} = $defGState;
729 }
730 1 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 1 1
731 0 { $infil = prep($infil);
732 0 $log .= "Form~$infil~$sidnr~$adjust~$effect~$tolerant";
733 0 $log .= "~$x~$y~$rotate~$size~$xsize~$ysize\n";
734 }
735 1 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 1 1
736 0 { errLog("No output file, you have to call prFile first");
737 }
738 1 ▶ if (($effect ne 'print') && ($effect ne 'add'))
Branch: 1 branch
BranchTrueFalseTotal
if ($effect ne "print" and $effect ne "add") 0 1 1
Condition33%1/3
$effect ne "print" and $effect ne "add"
!ll&&!rl&&r
100
MC/DC0%0/2
$effect ne "print" and $effect ne "add"
$effect ne "print" $effect ne "add"
Truth table33%1/3
A and B
A= $effect ne "print"B= $effect ne "add"
ABresult
0X0
100
111
739 0 { undef $namn;
740 }
741 1 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
742 0 { my $images = 0;
743 0 ▶ if (exists $form{$fSource}[fIMAGES])
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::form{$fSource}[3]) 0 0 0
744 0 { $images = scalar(@{$form{$fSource}[fIMAGES]});
745 }
746 0 return ($namn, $BBox[0], $BBox[1], $BBox[2],
747 $BBox[3], $images);
748 }
749 else
750 1 { return $namn;
751 }
752 }
753  
754  
755  
756 ##########################################################
757 sub prDefaultGrState
758 ##########################################################
759 2 ▶{ $objNr++;
Subroutine prDefaultGrState: called CC=2 SCAR=7.1
Pod undocumented
760 2 $defGState = $objNr;
761 2 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 2 2
762 0 { errLog("No output file, you have to call prFile first");
763 }
764  
765 2 $objekt[$objNr] = $pos;
766 2 my $utrad = "$objNr 0 obj" . '<</Type/ExtGState/SA false/SM 0.02/TR2 /Default'
767 . ">>endobj\n";
768 2 $pos += syswrite UTFIL, $utrad;
769 2 $objRef{'Gs0'} = $objNr;
770 2 return ('Gs0', $defGState);
771 }
772  
773 ######################################################
774 # En font lokaliseras och fontobjektet skrivs ev. ut
775 ######################################################
776  
777 sub findFont
778 3 ▶{ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine findFont: called CC=9 SCAR=28.2
Pod undocumented
779 12 ▶ my $Font = shift || '';
Condition100%2/2
shift() || ''
l!l
111
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
780  
781 12 ▶ if (! (exists $fontSource{$Font})) # Fonten måste skapas
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::fontSource{$Font}) { } 12 0 12
782 12 ▶ { if (exists $stdFont{$Font})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::stdFont{$Font}) { } 1 11 12
783 1 { $Font = $stdFont{$Font};}
784 else
785 11 { $Font = $genFont; } # Helvetica sätts om inget annat finns
786 12 ▶ if (! (exists $font{$Font}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::font{$Font}) 12 0 12
787 12 { $objNr++;
788 12 $fontNr++;
789 12 my $fontAbbr = 'Ft' . $fontNr;
790 12 my $fontObjekt = "$objNr 0 obj<</Type/Font/Subtype/Type1" .
791 "/BaseFont/$Font/Encoding/WinAnsiEncoding>>endobj\n";
792 12 $font{$Font}[foINTNAMN] = $fontAbbr;
793 12 $font{$Font}[foREFOBJ] = $objNr;
794 12 $objRef{$fontAbbr} = $objNr;
795 12 $fontSource{$Font}[foSOURCE] = 'Standard';
796 12 $objekt[$objNr] = $pos;
797 12 $pos += syswrite UTFIL, $fontObjekt;
798 }
799 }
800 else
801 0 ▶ { if (defined $font{$Font}[foREFOBJ]) # Finns redan i filen
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::font{$Font}[0]) { } 0 0 0
802 { ; }
803 else
804 0 ▶ { if ($fontSource{$Font}[foSOURCE] eq 'Standard')
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::fontSource{$Font}[4] eq 'Standard') { } 0 0 0
805 0 { $objNr++;
806 0 $fontNr++;
807 0 my $fontAbbr = 'Ft' . $fontNr;
808 0 my $fontObjekt = "$objNr 0 obj<</Type/Font/Subtype/Type1" .
809 "/BaseFont/$Font/Encoding/WinAnsiEncoding>>endobj\n";
810 0 $font{$Font}[foINTNAMN] = $fontAbbr;
811 0 $font{$Font}[foREFOBJ] = $objNr;
812 0 $objRef{$fontAbbr} = $objNr;
813 0 $objekt[$objNr] = $pos;
814 0 $pos += syswrite UTFIL, $fontObjekt;
815 }
816 else
817 0 { my $fSource = $fontSource{$Font}[foSOURCE];
818 0 my $ri = rindex($fSource, '_');
819 0 my $Source = substr($fSource, 0, $ri);
820 0 my $Page = substr($fSource, ($ri + 1));
821  
822 0 ▶ if (! $fontSource{$Font}[foORIGINALNR])
Branch: 1 branch
BranchTrueFalseTotal
if (not $PDF::Reuse::fontSource{$Font}[3]) { } 0 0 0
823 0 { errLog("Couldn't find $Font, aborts");
824 }
825 else
826 { my $namn = extractObject($Source, $Page,
827 0 $fontSource{$Font}[foORIGINALNR], 'Font');
828 }
829 }
830 }
831 }
832  
833 12 $aktuellFont[foEXTNAMN] = $Font;
834 12 $aktuellFont[foREFOBJ] = $font{$Font}[foREFOBJ];
835 12 $aktuellFont[foINTNAMN] = $font{$Font}[foINTNAMN];
836 12 $aktuellFont[foTYP] = $font{$Font}[foTYP];
837  
838 12 $sidFont{$aktuellFont[foINTNAMN]} = $aktuellFont[foREFOBJ];
839 12 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 12 12
840 0 { errLog("No output file, you have to call prFile first");
841 }
842  
843 12 return ($aktuellFont[foINTNAMN], $aktuellFont[foEXTNAMN], $aktuellFont[foREFOBJ]);
844 }
845  
846 sub skrivSida
847 29 ▶{ my ($compressFlag, $streamObjekt, @extObj);
Subroutine skrivSida: called CC=36 SCAR=54.3
Pod undocumented
848 29 ▶ if ($checkCs)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkCs) 0 29 29
849 0 { @extObj = ($stream =~ m'/(\S+)\s*'gso);
850 0 checkContentStream(@extObj);
851 }
852 29 ▶ if (( $compress ) && ( length($stream) > 99 ))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::compress and length $PDF::Reuse::stream > 99) 0 29 29
Condition33%1/3
$PDF::Reuse::compress and length $PDF::Reuse::stream > 99
!ll&&!rl&&r
2900
MC/DC0%0/2
$PDF::Reuse::compress and length $PDF::Reuse::stream > 99
$PDF::Reuse::compress length $PDF::Reuse::stream > 99
Truth table33%1/3
A and B
A= $PDF::Reuse::compressB= length $PDF::Reuse::stream > 99
ABresult
0X0
100
111
853 0 { my $output = compress($stream);
854 0 ▶ if ((length($output) > 25) && (length($output) < (length($stream))))
Branch: 1 branch
BranchTrueFalseTotal
if (length $output > 25 and length $output < length $PDF::Reuse::stream) 0 0 0
Condition0%0/3
length $output > 25 and length $output < length $PDF::Reuse::stream
!ll&&!rl&&r
000
MC/DC0%0/2
length $output > 25 and length $output < length $PDF::Reuse::stream
length $output > 25 length $output < length $PDF::Reuse::stream
Truth table0%0/3
A and B
A= length $output > 25B= length $output < length $PDF::Reuse::stream
ABresult
0X0
100
111
855 0 { $stream = $output;
856 0 $compressFlag = 1;
857 }
858 }
859  
860 29 ▶ if (! $parents[0])
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::parents[0]) 0 29 29
861 0 { $objNr++;
862 0 $parents[0] = $objNr;
863 }
864 29 my $parent = $parents[0];
865  
866 ##########################################
867 # Interaktiva funktioner läggs ev. till
868 ##########################################
869  
870 29 ▶ if ($interAktivSida)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::interAktivSida) 0 29 29
871 0 { my ($infil, $sidnr) = split(/\s+/, $interActive);
872 0 ($NamesSaved, $AARootSaved, $AAPageSaved, $AcroFormSaved)
873 = AcroFormsEtc($infil, $sidnr);
874 }
875  
876 ##########################
877 # Skapa resursdictionary
878 ##########################
879 29 my $resursDict = "/ProcSet[/PDF/Text]";
880 29 ▶ if (scalar %sidFont)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidFont) 26 3 29
881 26 { $resursDict .= '/Font << ';
882 26 my $i = 0;
883 26 for (sort keys %sidFont)
884 27 { $resursDict .= "/$_ $sidFont{$_} 0 R";
885 }
886  
887 26 $resursDict .= " >>";
888 }
889 29 ▶ if (scalar %sidXObject)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidXObject) 2 27 29
890 2 { $resursDict .= '/XObject<<';
891 2 for (sort keys %sidXObject)
892 2 { $resursDict .= "/$_ $sidXObject{$_} 0 R";
893 }
894 2 $resursDict .= ">>";
895 }
896 29 ▶ if (scalar %sidExtGState)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidExtGState) 2 27 29
897 2 { $resursDict .= '/ExtGState<<';
898 2 for (sort keys %sidExtGState)
899 2 { $resursDict .= "\/$_ $sidExtGState{$_} 0 R";
900 }
901 2 $resursDict .= ">>";
902 }
903 29 ▶ if (scalar %sidPattern)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidPattern) 0 29 29
904 0 { $resursDict .= '/Pattern<<';
905 0 for (sort keys %sidPattern)
906 0 { $resursDict .= "/$_ $sidPattern{$_} 0 R";
907 }
908 0 $resursDict .= ">>";
909 }
910 29 ▶ if (scalar %sidShading)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidShading) 0 29 29
911 0 { $resursDict .= '/Shading<<';
912 0 for (sort keys %sidShading)
913 0 { $resursDict .= "/$_ $sidShading{$_} 0 R";
914 }
915 0 $resursDict .= ">>";
916 }
917 29 ▶ if (scalar %sidColorSpace)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidColorSpace) 0 29 29
918 0 { $resursDict .= '/ColorSpace<<';
919 0 for (sort keys %sidColorSpace)
920 0 { $resursDict .= "/$_ $sidColorSpace{$_} 0 R";
921 }
922 0 $resursDict .= ">>";
923 }
924  
925  
926 29 my $resursObjekt;
927  
928 29 ▶ if (exists $resurser{$resursDict})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::resurser{$resursDict}) { } 15 14 29
929 15 { $resursObjekt = $resurser{$resursDict}; # Fanns ett identiskt,
930 } # använd det
931 else
932 14 { $objNr++;
933 14 ▶ if ( keys(%resurser) < 10)
Branch: 1 branch
BranchTrueFalseTotal
if (keys %PDF::Reuse::resurser < 10) 14 0 14
934 14 { $resurser{$resursDict} = $objNr; # Spara 10 första resursobjekten
935 }
936 14 $resursObjekt = $objNr;
937 14 $objekt[$objNr] = $pos;
938 14 $resursDict = "$objNr 0 obj<<$resursDict>>endobj\n";
939 14 $pos += syswrite UTFIL, $resursDict ;
940 }
941 29 my $sidObjekt;
942  
943 29 ▶ if (! $touchUp)
Branch: 1 branch
BranchTrueFalseTotal
if (not $PDF::Reuse::touchUp) { } 0 29 29
944 { #
945 # Contents objektet skapas
946 #
947  
948 0 my $devX = "900";
949 0 my $devY = "900";
950  
951 0 my $mellanObjekt = '<</Type/XObject/Subtype/Form/FormType 1';
952 0 ▶ if (defined $resursObjekt)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resursObjekt) 0 0 0
953 0 { $mellanObjekt .= "/Resources $resursObjekt 0 R";
954 }
955 0 $mellanObjekt .= "/BBox \[$genLowerX $genLowerY $genUpperX $genUpperY\]" .
956 "/Matrix \[ 1 0 0 1 -$devX -$devY \]";
957  
958 0 my $langd = length($stream);
959  
960 0 $objNr++;
961 0 $objekt[$objNr] = $pos;
962 0 ▶ if (! $compressFlag)
Branch: 1 branch
BranchTrueFalseTotal
if (not $compressFlag) { } 0 0 0
963 0 { $mellanObjekt = "$objNr 0 obj\n$mellanObjekt/Length $langd>>stream\n"
964 . $stream;
965 0 $mellanObjekt .= "endstream\nendobj\n";
966 }
967 else
968 0 { $stream = "\n" . $stream . "\n";
969 0 $langd++;
970 0 $mellanObjekt = "$objNr 0 obj\n$mellanObjekt/Filter/FlateDecode"
971 . "/Length $langd>>stream" . $stream;
972 0 $mellanObjekt .= "endstream\nendobj\n";
973 }
974  
975 0 $pos += syswrite UTFIL, $mellanObjekt;
976 0 $mellanObjekt = $objNr;
977  
978 0 ▶ if (! defined $confuseObj)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::confuseObj) 0 0 0
979 0 { $objNr++;
980 0 $objekt[$objNr] = $pos;
981  
982 0 $stream = "\nq\n1 0 0 1 $devX $devY cm\n/Xwq Do\nQ\n";
983 0 $langd = length($stream);
984 0 $confuseObj = $objNr;
985 0 $stream = "$objNr 0 obj<</Length $langd>>stream\n" . "$stream";
986 0 $stream .= "\nendstream\nendobj\n";
987 0 $pos += syswrite UTFIL, $stream;
988 }
989 0 $sidObjekt = "$sidObjNr 0 obj\n<</Type/Page/Parent $parent 0 R/Contents $confuseObj 0 R"
990 . "/MediaBox \[$genLowerX $genLowerY $genUpperX $genUpperY\]"
991 . "/Resources <</ProcSet[/PDF/Text]/XObject<</Xwq $mellanObjekt 0 R>>>>";
992 }
993 else
994 29 { my $langd = length($stream);
995  
996 29 $objNr++;
997 29 $objekt[$objNr] = $pos;
998 29 ▶ if (! $compressFlag)
Branch: 1 branch
BranchTrueFalseTotal
if (not $compressFlag) { } 29 0 29
999 29 { $streamObjekt = "$objNr 0 obj<</Length $langd>>stream\n" . $stream;
1000 29 $streamObjekt .= "\nendstream\nendobj\n";
1001 }
1002 else
1003 0 { $stream = "\n" . $stream . "\n";
1004 0 $langd++;
1005  
1006 0 $streamObjekt = "$objNr 0 obj<</Filter/FlateDecode"
1007 . "/Length $langd>>stream" . $stream;
1008 0 $streamObjekt .= "endstream\nendobj\n";
1009 }
1010  
1011 29 $pos += syswrite UTFIL, $streamObjekt;
1012 29 $streamObjekt = $objNr;
1013 ##################################
1014 # Så skapas och skrivs sidobjektet
1015 ##################################
1016  
1017 29 $sidObjekt = "$sidObjNr 0 obj<</Type/Page/Parent $parent 0 R/Contents $streamObjekt 0 R"
1018 . "/MediaBox \[$genLowerX $genLowerY $genUpperX $genUpperY\]"
1019 . "/Resources $resursObjekt 0 R";
1020 }
1021  
1022 29 $stream = '';
1023  
1024 29 my $tSida = $sida + 1;
1025 29 ▶ if ((@annots)
Branch: 1 branch
BranchTrueFalseTotal
if (@PDF::Reuse::annots or %PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}) 0 29 29
Condition33%4/12
@PDF::Reuse::annots or %PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
l!l&&r!l&&!r
0029
@PDF::Reuse::annots or %PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};}
l!l&&r!l&&!r
0029
%PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};}
!ll&&!rl&&r
2900
%PDF::Reuse::links and $PDF::Reuse::links{-1}
!ll&&!rl&&r
2900
MC/DC0%0/5
@PDF::Reuse::annots or %PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
@PDF::Reuse::annots %PDF::Reuse::links $PDF::Reuse::links{-1} @{$PDF::Reuse::links{-1};} %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
Truth table12%1/8
A or B and C and D or E
A= @PDF::Reuse::annotsB= %PDF::Reuse::linksC= $PDF::Reuse::links{-1}D= @{$PDF::Reuse::links{-1};}E= %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
ABCDEresult
1XXXX1
0111X1
00XX11
010X11
011011
00XX00
010X00
011000
1026 0 ▶ || (%links && $links{'-1'} && @{$links{'-1'}})
Condition33%2/6
%PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
!ll&&!rl&&r
2900
%PDF::Reuse::links and $PDF::Reuse::links{$tSida}
!ll&&!rl&&r
2900
MC/DC0%0/3
%PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
%PDF::Reuse::links $PDF::Reuse::links{$tSida} @{$PDF::Reuse::links{$tSida};}
Truth table0%0/4
A and B and C
A= %PDF::Reuse::linksB= $PDF::Reuse::links{$tSida}C= @{$PDF::Reuse::links{$tSida};}
ABCresult
0XX0
10X0
1100
1111
1027 0 || (%links && $links{$tSida} && @{$links{$tSida}}))
1028 0 { $sidObjekt .= '/Annots ' . mergeLinks() . ' 0 R';
1029 }
1030 29 ▶ if (defined $AAPageSaved)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::AAPageSaved) 0 29 29
1031 0 { $sidObjekt .= "/AA $AAPageSaved";
1032 0 undef $AAPageSaved;
1033 }
1034 29 $sidObjekt .= ">>endobj\n";
1035 29 $objekt[$sidObjNr] = $pos;
1036 29 $pos += syswrite UTFIL, $sidObjekt;
1037 29 push @{$kids[0]}, $sidObjNr;
1038 29 $sida++;
1039 29 $counts[0]++;
1040 29 ▶ if ($counts[0] > 9)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::counts[0] > 9) 0 29 29
1041 0 { ordnaNoder(8); }
1042 }
1043  
1044  
1045 sub prEnd
1046 18 ▶{ if (! $pos)
Subroutine prEnd: called CC=32 SCAR=52.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 18 18
1047 0 { return;
1048 }
1049 18 ▶ if ($stream)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::stream) 13 5 18
1050 13 { skrivSida(); }
1051 18 skrivUtNoder();
1052  
1053 18 ▶ if($docProxy)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::docProxy) 0 18 18
1054 0 { PDF::Reuse::TTFont::attach_tounicode($docProxy);
1055 0 $docProxy->write_objects;
1056 # Release Font::TTF data and TTFont0 objects now that they are written
1057 0 for my $obj (values %{ $docProxy->{' objcache'} })
1058 0 ▶ { if ($obj->isa('Text::PDF::TTFont0'))
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Text::PDF::TTFont0")) 0 0 0
1059 0 ▶ { if (my $font = delete $obj->{' font'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $font = delete $obj->{" font"}) 0 0 0
1060 0 { $font->release();
1061 }
1062 0 $obj->release();
1063 }
1064 }
1065 0 undef $docProxy; # Break circular refs
1066 }
1067  
1068 ###################
1069 # Skriv root
1070 ###################
1071  
1072 18 ▶ if (! defined $objekt[$objNr])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::objekt[$PDF::Reuse::objNr]) 0 18 18
1073 0 { $objNr--; # reserverat sidobjektnr utnyttjades aldrig
1074 }
1075  
1076 18 my $utrad = "1 0 obj<</Type/Catalog/Pages $slutNod 0 R";
1077 18 ▶ if (defined $NamesSaved)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $PDF::Reuse::NamesSaved) { } 0 18 18
elsif (scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler) { } 0 18 18
1078 0 { $utrad .= "\/Names $NamesSaved 0 R\n";
1079 }
1080 ▶ elsif ((scalar %fields) || (scalar @jsfiler))
Condition50%1/2
scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler
l!l
018
MC/DC0%0/1
scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler
scalar %PDF::Reuse::fields
Truth table50%1/2
A
A= scalar %PDF::Reuse::fields
Aresult
11
00
1081 0 { $utrad .= "\/Names " . behandlaNames() . " 0 R\n";
1082 }
1083 18 ▶ if (defined $AARootSaved)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::AARootSaved) 0 18 18
1084 0 { $utrad .= "/AA $AARootSaved\n";
1085 }
1086 18 ▶ if ((scalar @inits) || (scalar %fields))
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields) 0 18 18
Condition50%1/2
scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields
l!l
018
MC/DC0%0/1
scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields
scalar @PDF::Reuse::inits
Truth table50%1/2
A
A= scalar @PDF::Reuse::inits
Aresult
11
00
1087 0 { my $nyttANr = skrivKedja();
1088 0 $utrad .= "/OpenAction $nyttANr 0 R";
1089 }
1090  
1091 18 ▶ if (defined $AcroFormSaved)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::AcroFormSaved) 0 18 18
1092 0 { $utrad .= "/AcroForm $AcroFormSaved\n";
1093 }
1094  
1095 18 ▶ if (scalar @bookmarks)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::bookmarks) 0 18 18
1096 0 { my $outLine = ordnaBookmarks();
1097 0 $utrad .= "/Outlines $outLine 0 R/PageMode /UseOutlines\n";
1098 }
1099 18 ▶ if (scalar %prefs)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::prefs) 0 18 18
1100 0 { $utrad .= '/ViewerPreferences << ';
1101 0 ▶ if (exists $prefs{hidetoolbar})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::prefs{"hidetoolbar"}) 0 0 0
1102 0 ▶ { $utrad .= ($prefs{hidetoolbar}) ? '/HideToolbar true'
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::prefs{'hidetoolbar'} ? : 0 0 0
1103 : '/HideToolbar false';
1104 }
1105 0 ▶ if (exists $prefs{hidemenubar})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::prefs{"hidemenubar"}) 0 0 0
1106 0 ▶ { $utrad .= ($prefs{hidemenubar}) ? '/HideMenubar true'
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::prefs{'hidemenubar'} ? : 0 0 0
1107 : '/HideMenubar false';
1108 }
1109 0 ▶ if (exists $prefs{hidewindowui})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::prefs{"hidewindowui"}) 0 0 0
1110 0 ▶ { $utrad .= ($prefs{hidewindowui}) ? '/HideWindowUI true'
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::prefs{'hidewindowui'} ? : 0 0 0
1111 : '/HideWindowUI false';
1112 }
1113 0 ▶ if (exists $prefs{fitwindow})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::prefs{"fitwindow"}) 0 0 0
1114 0 ▶ { $utrad .= ($prefs{fitwindow}) ? '/FitWindow true'
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::prefs{'fitwindow'} ? : 0 0 0
1115 : '/FitWindow false';
1116 }
1117 0 ▶ if (exists $prefs{centerwindow})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::prefs{"centerwindow"}) 0 0 0
1118 0 ▶ { $utrad .= ($prefs{centerwindow}) ? '/CenterWindow true'
Branch: 1 branch
BranchTrueFalseTotal
$PDF::Reuse::prefs{'centerwindow'} ? : 0 0 0
1119 : '/CenterWindow false';
1120 }
1121 0 $utrad .= '>> ';
1122 }
1123  
1124 18 $utrad .= ">>endobj\n";
1125  
1126 18 $objekt[1] = $pos;
1127 18 $pos += syswrite UTFIL, $utrad;
1128 18 my $antal = $#objekt;
1129 18 my $startxref = $pos;
1130 18 my $xrefAntal = $antal + 1;
1131 18 $pos += syswrite UTFIL, "xref\n";
1132 18 $pos += syswrite UTFIL, "0 $xrefAntal\n";
1133 18 $pos += syswrite UTFIL, "0000000000 65535 f \n";
1134  
1135 18 ▶ for (my $i = 1; $i <= $antal; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $antal) 192 18 210
1136 192 ▶ { $utrad = sprintf "%.10d 00000 n \n", $objekt[$i] // 0;
Condition50%1/2
$PDF::Reuse::objekt[$i] // 0
l!l
1920
MC/DC0%0/1
$PDF::Reuse::objekt[$i] // 0
$PDF::Reuse::objekt[$i]
Truth table50%1/2
A
A= $PDF::Reuse::objekt[$i]
Aresult
11
00
1137 192 $pos += syswrite UTFIL, $utrad;
1138 }
1139  
1140 18 $utrad = "trailer\n<<\n/Size $xrefAntal\n/Root 1 0 R\n";
1141 18 ▶ if ($idTyp ne 'None')
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::idTyp ne "None") 18 0 18
1142 18 { my ($id1, $id2) = definieraId();
1143 18 $utrad .= "/ID [<$id1><$id2>]\n";
1144 18 $log .= "IdType~rep\n";
1145 18 $log .= "Id~$id1\n";
1146 }
1147 18 $utrad .= ">>\nstartxref\n$startxref\n";
1148 18 $pos += syswrite UTFIL, $utrad;
1149 18 $pos += syswrite UTFIL, "%%EOF\n";
1150 18 close UTFIL;
1151 3 ▶ { no warnings; untie *UTFIL; }
Subroutine BEGIN: called CC=1 SCAR=0.0
1152  
1153 18 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 18 18
1154 0 ▶ { if ($log)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::log) 0 0 0
1155 0 { print RUNFIL $log;
1156 }
1157 0 close RUNFIL;
1158 }
1159 18 $log = '';
1160 18 $runfil = '';
1161 18 $pos = 0;
1162 18 1;
1163 }
1164  
1165 sub ordnaNoder
1166 0 ▶{ my $antBarn = shift;
Subroutine ordnaNoder: not called CC=4 SCAR=30.0
Pod undocumented
1167 0 my $i = 0;
1168 0 my $j = 1;
1169 0 my $vektor;
1170  
1171 0 ▶ while ($antBarn < $#{$kids[$i]})
Branch: 1 branch
BranchTrueFalseTotal
if ($antBarn < $#{$PDF::Reuse::kids[$i];}) 0 0 0
1172 { #
1173 # Skriv ut aktuell förälder
1174 # flytta till nästa nivå
1175 #
1176 0 $vektor = '[';
1177  
1178 0 for (@{$kids[$i]})
1179 0 { $vektor .= "$_ 0 R "; }
1180 0 $vektor .= ']';
1181  
1182 0 ▶ if (! $parents[$j])
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::parents[$j]) 0 0 0
1183 0 { $objNr++;
1184 0 $parents[$j] = $objNr;
1185 }
1186  
1187 0 my $nodObjekt;
1188 0 $nodObjekt = "$parents[$i] 0 obj<</Type/Pages/Parent $parents[$j] 0 R\n/Kids $vektor\n/Count $counts[$i]>>endobj\n";
1189  
1190 0 $objekt[$parents[$i]] = $pos;
1191 0 $pos += syswrite UTFIL, $nodObjekt;
1192 0 $counts[$j] += $counts[$i];
1193 0 $counts[$i] = 0;
1194 0 $kids[$i] = [];
1195 0 push @{$kids[$j]}, $parents[$i];
1196 0 undef $parents[$i];
1197 0 $i++;
1198 0 $j++;
1199 }
1200 }
1201  
1202 sub skrivUtNoder
1203 3 ▶{ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine skrivUtNoder: called CC=8 SCAR=29.2
Pod undocumented
1204 18 my ($i, $j, $vektor, $nodObjekt);
1205 18 my $si = -1;
1206 #
1207 # Hitta slutnoden
1208 #
1209 18 for (@parents)
1210 18 { $slutNod = $_;
1211 18 $si++;
1212 }
1213  
1214 18 ▶ for ($i = 0; $parents[$i] ne $slutNod; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::parents[$i] ne $PDF::Reuse::slutNod) 0 18 18
1215 0 ▶ { if (defined $parents[$i]) # Bara definierat om det finns kids
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::parents[$i]) 0 0 0
1216 0 { $vektor = '[';
1217 0 for (@{$kids[$i]})
1218 0 { $vektor .= "$_ 0 R "; }
1219 0 $vektor .= ']';
1220 ########################################
1221 # Hitta förälder till aktuell förälder
1222 ########################################
1223 0 my $nod;
1224 0 ▶ for ($j = $i + 1; (! $nod); $j++)
Branch: 1 branch
BranchTrueFalseTotal
unless ($nod) 0 0 0
1225 0 ▶ { if ($parents[$j])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::parents[$j]) 0 0 0
1226 0 { $nod = $parents[$j];
1227 0 $counts[$j] += $counts[$i];
1228 0 push @{$kids[$j]}, $parents[$i];
1229 }
1230 }
1231  
1232 0 $nodObjekt = "$parents[$i] 0 obj<</Type/Pages/Parent $nod 0 R\n/Kids $vektor/Count $counts[$i]>>endobj\n";
1233  
1234 0 $objekt[$parents[$i]] = $pos;
1235 0 $pos += syswrite UTFIL, $nodObjekt;
1236 }
1237 }
1238 #####################################
1239 # Så ordnas och skrivs slutnoden ut
1240 #####################################
1241 18 $vektor = '[';
1242 18 for (@{$kids[$si]})
1243 51 { $vektor .= "$_ 0 R "; }
1244 18 $vektor .= ']';
1245 18 $nodObjekt = "$slutNod 0 obj<</Type/Pages/Kids $vektor/Count $counts[$si]";
1246 # $nodObjekt .= "/MediaBox \[$genLowerX $genLowerY $genUpperX $genUpperY\]";
1247 18 $nodObjekt .= " >>endobj\n";
1248 18 $objekt[$slutNod] = $pos;
1249 18 $pos += syswrite UTFIL, $nodObjekt;
1250  
1251 }
1252  
1253 sub findGet
1254 7 ▶{ my ($fil, $cid) = @_;
Subroutine findGet: called CC=6 SCAR=26.9
Pod undocumented
1255 7 $fil =~ s|\s+$||o;
1256 7 my ($req, $extFil, $tempFil, $fil2, $tStamp, $res);
1257  
1258 7 ▶ if (-e $fil)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $fil) 7 0 7
1259 7 { $tStamp = (stat($fil))[9];
1260 7 ▶ if ($cid)
Branch: 1 branch
BranchTrueFalseTotal
if ($cid) { } 0 7 7
1261 {
1262 0 ▶ if ($cid eq $tStamp)
Branch: 1 branch
BranchTrueFalseTotal
if ($cid eq $tStamp) 0 0 0
1263 0 { return ($fil, $cid);
1264 }
1265 }
1266 else
1267 7 { return ($fil, $tStamp);
1268 }
1269 }
1270 0 ▶ if ($cid)
Branch: 1 branch
BranchTrueFalseTotal
if ($cid) 0 0 0
1271 0 { $fil2 = $fil . $cid;
1272 0 ▶ if (-e $fil2)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $fil2) 0 0 0
1273 0 { return ($fil2, $cid);
1274 }
1275 }
1276 0 errLog("The file $fil can't be found, aborts");
1277 }
1278  
1279 sub definieraId
1280 18 ▶{ if ($idTyp eq 'rep')
Subroutine definieraId: called CC=4 SCAR=20.3
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if ($PDF::Reuse::idTyp eq 'rep') { } 0 18 18
elsif ($PDF::Reuse::idTyp eq 'add') { } 0 18 18
1281 0 ▶ { if (! defined $id)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::id) 0 0 0
1282 0 { errLog("Can't replicate the id if is missing, aborting");
1283 }
1284 0 my $tempId = $id;
1285 0 undef $id;
1286 0 return ($tempId, $tempId);
1287 }
1288 elsif ($idTyp eq 'add')
1289 0 { $id++;
1290 0 return ($id, $id);
1291 }
1292 else
1293 18 { my $str = time();
1294 18 $str .= $filnamn . $pos;
1295 18 $str = Digest::MD5::md5_hex($str);
1296 18 return ($str, $str);
1297 }
1298 }
1299  
1300 sub prStrWidth
1301 0 ▶{ require PDF::Reuse::Util;
Subroutine prStrWidth: not called CC=12 SCAR=50.5
Pod documented
1302 0 my $string = shift;
1303 0 my $Font = shift;
1304 0 ▶ my $FontSize = shift || $fontSize;
Condition0%0/3
shift() || $PDF::Reuse::fontSize
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $PDF::Reuse::fontSize
shift() $PDF::Reuse::fontSize
Truth table0%0/3
A || B
A= shift()B= $PDF::Reuse::fontSize
ABresult
1X1
011
000
1305 0 my $w = 0;
1306  
1307 # there's no use continuing if no string is passed in
1308 0 ▶ if (! defined($string))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $string) 0 0 0
1309 0 { errLog("undefined value passed to prStrWidth");
1310 }
1311  
1312 0 ▶ if (length($string) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == 0) 0 0 0
1313 0 { return 0;
1314 }
1315  
1316 0 ▶ if(my($width) = ttfStrWidth($string, $Font, $FontSize))
Branch: 1 branch
BranchTrueFalseTotal
if (my($width) = ttfStrWidth($string, $Font, $FontSize)) 0 0 0
1317 0 { return $width;
1318 }
1319  
1320 0 ▶ if (! $Font)
Branch: 1 branch
BranchTrueFalseTotal
unless ($Font) 0 0 0
1321 0 ▶ { if (! $aktuellFont[foEXTNAMN])
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::aktuellFont[2]) 0 0 0
1322 0 { findFont();
1323 }
1324 0 $Font = $aktuellFont[foEXTNAMN];
1325 }
1326  
1327 0 ▶ if (! exists $PDF::Reuse::Util::font_widths{$Font})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::Util::font_widths{$Font}) 0 0 0
1328 0 ▶ { if (exists $stdFont{$Font})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::stdFont{$Font}) 0 0 0
1329 0 { $Font = $stdFont{$Font};
1330 }
1331 0 ▶ if (! exists $PDF::Reuse::Util::font_widths{$Font})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::Util::font_widths{$Font}) 0 0 0
1332 0 { $Font = 'Helvetica';
1333 }
1334 }
1335  
1336 0 ▶ if (ref($PDF::Reuse::Util::font_widths{$Font}) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $PDF::Reuse::Util::font_widths{$Font} eq 'ARRAY') { } 0 0 0
1337 0 { my @font_table = @{ $PDF::Reuse::Util::font_widths{$Font} };
1338 0 for (unpack ("C*", $string))
1339 0 { $w += $font_table[$_];
1340 }
1341 }
1342 else
1343 0 { $w = length($string) * $PDF::Reuse::Util::font_widths{$Font};
1344 }
1345 0 $w = $w / 1000 * $FontSize;
1346  
1347 0 return $w;
1348 }
1349  
1350 sub prTTFont
1351 0 ▶{ return prFont() if ! @_;
Subroutine prTTFont: not called CC=8 SCAR=42.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1352 0 my($selector, $fontname) = @_;
1353  
1354 # Have we loaded this font already?
1355 0 my $ttfont = findTTFont($selector);
1356 0 ▶ if (! $ttfont and $font{$selector} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $ttfont and $PDF::Reuse::font{$selector}) 0 0 0
Condition0%0/3
not $ttfont and $PDF::Reuse::font{$selector}
!ll&&!rl&&r
000
MC/DC0%0/2
not $ttfont and $PDF::Reuse::font{$selector}
not $ttfont $PDF::Reuse::font{$selector}
Truth table0%0/3
not(A) and B
A= not $ttfontB= $PDF::Reuse::font{$selector}
ABresult
0X0
100
111
1357 0 { return prFont($selector);
1358 }
1359 0 ▶ $fontname = $ttfont->fontname if $ttfont;
Branch: 1 branch
BranchTrueFalseTotal
if $ttfont 0 0 0
1360  
1361 # Create a new TTFont object if we haven't loaded this one before
1362 0 ▶ if (! $ttfont)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ttfont) 0 0 0
1363 { $docProxy ||= PDF::Reuse::DocProxy->new(
1364 0 ▶ next_obj => sub { ++$objNr },
Subroutine __ANON__: not called CC=1 SCAR=6.9
1365 0 ▶ prObj => \&prObj,
Condition0%0/3
$PDF::Reuse::docProxy ||= "PDF::Reuse::DocProxy"->new("next_obj", sub { ++$objNr; } , "prObj", \&PDF::Reuse::prObj)
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDF::Reuse::docProxy ||= "PDF::Reuse::DocProxy"->new("next_obj", sub { ++$objNr; } , "prObj", \&PDF::Reuse::prObj)
$PDF::Reuse::docProxy "PDF::Reuse::DocProxy"->new("next_obj", sub { ++$objNr; } , "prObj", \&PDF::Reuse::prObj)
Truth table0%0/3
A ||= B
A= $PDF::Reuse::docProxyB= "PDF::Reuse::DocProxy"->new("next_obj", sub { ++$objNr; } , "prObj", \&PDF::Reuse::prObj)
ABresult
1X1
011
000
1366 );
1367  
1368 0 my $ttfont = PDF::Reuse::TTFont->new(
1369 filename => $selector,
1370 fontname => $fontname,
1371 fontAbbr => 'Ft' . ++$fontNr,
1372 docProxy => $docProxy,
1373 );
1374 0 $fontname = $ttfont->fontname;
1375  
1376 0 $font{$fontname}[foINTNAMN] = $ttfont->fontAbbr;
1377 0 $font{$fontname}[foREFOBJ] = $ttfont->obj_num;
1378 0 $font{$fontname}[foFONTOBJ] = $ttfont;
1379 0 $objRef{$ttfont->fontAbbr} = $ttfont->obj_num;
1380 0 $fontSource{$fontname}[foSOURCE] = 'Standard';
1381 }
1382  
1383 0 my $oldIntNamn = $aktuellFont[foINTNAMN];
1384 0 my $oldExtNamn = $aktuellFont[foEXTNAMN];
1385  
1386 0 $aktuellFont[foEXTNAMN] = $fontname;
1387 0 $aktuellFont[foREFOBJ] = $font{$fontname}[foREFOBJ];
1388 0 $aktuellFont[foINTNAMN] = $font{$fontname}[foINTNAMN];
1389 0 $aktuellFont[foTYP] = $font{$fontname}[foTYP];
1390  
1391 0 $sidFont{$aktuellFont[foINTNAMN]} = $aktuellFont[foREFOBJ];
1392  
1393 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
1394 0 { return ($aktuellFont[foINTNAMN], $aktuellFont[foEXTNAMN], $oldIntNamn, $oldExtNamn, \%font);
1395 }
1396 else
1397 0 { return $aktuellFont[foINTNAMN];
1398 }
1399 }
1400  
1401  
1402 sub prObj
1403 0 ▶{ my($objNr, $data) = @_;
Subroutine prObj: not called CC=1 SCAR=6.9
Pod undocumented
1404  
1405 0 $objekt[$objNr] = $pos;
1406 0 $pos += syswrite UTFIL, $data;
1407 }
1408  
1409  
1410 sub findTTFont
1411 0 ▶{ my $selector = shift || $aktuellFont[foEXTNAMN];
Subroutine findTTFont: not called CC=7 SCAR=40.3
Pod undocumented
Condition0%0/3
shift() || $PDF::Reuse::aktuellFont[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $PDF::Reuse::aktuellFont[2]
shift() $PDF::Reuse::aktuellFont[2]
Truth table0%0/3
A || B
A= shift()B= $PDF::Reuse::aktuellFont[2]
ABresult
1X1
011
000
1412  
1413 0 ▶ return $font{$selector}[foFONTOBJ] if $font{$selector};
Branch: 1 branch
BranchTrueFalseTotal
if $PDF::Reuse::font{$selector} 0 0 0
1414 0 foreach my $name (keys %font)
1415 0 ▶ { if ( $font{$name}[foINTNAMN] eq $selector
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::font{$name}[1] eq $selector or $PDF::Reuse::font{$name}[6] and $PDF::Reuse::font{$name}[6]->filename eq $selector) 0 0 0
Condition0%0/6
$PDF::Reuse::font{$name}[1] eq $selector or $PDF::Reuse::font{$name}[6] and $PDF::Reuse::font{$name}[6]->filename eq $selector
l!l&&r!l&&!r
000
$PDF::Reuse::font{$name}[6] and $PDF::Reuse::font{$name}[6]->filename eq $selector
!ll&&!rl&&r
000
MC/DC0%0/3
$PDF::Reuse::font{$name}[1] eq $selector or $PDF::Reuse::font{$name}[6] and $PDF::Reuse::font{$name}[6]->filename eq $selector
$PDF::Reuse::font{$name}[1] eq $selector $PDF::Reuse::font{$name}[6] $PDF::Reuse::font{$name}[6]->filename eq $selector
Truth table0%0/4
A or B and C
A= $PDF::Reuse::font{$name}[1] eq $selectorB= $PDF::Reuse::font{$name}[6]C= $PDF::Reuse::font{$name}[6]->filename eq $selector
ABCresult
1XX1
0111
00X0
0100
1416 or $font{$name}[foFONTOBJ] && $font{$name}[foFONTOBJ]->filename eq $selector
1417 )
1418 0 { return $font{$name}[foFONTOBJ];
1419 }
1420 }
1421 0 return;
1422 }
1423  
1424  
1425 sub ttfStrWidth
1426 0 ▶{ my($string, $selector, $fontsize) = @_;
Subroutine ttfStrWidth: not called CC=2 SCAR=17.9
Pod undocumented
1427  
1428 0 ▶ my $ttfont = findTTFont($selector) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ttfont = findTTFont($selector) or return 0 0 0
1429 0 return $ttfont->text_width($string, $fontsize);
1430 }
1431  
1432  
1433 # This 'glue' package emulates the bits of the Text::PDF::File API that are
1434 # needed by Text::PDF::TTFont0 (below) and ties them in to the PDF::Reuse API.
1435  
1436 package PDF::Reuse::DocProxy;
1437  
1438 sub new
1439 0 ▶{ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
1440  
1441 0 my $self = bless { ' version' => 3, @_, '>buffer' => '', }, $class;
1442 }
1443  
1444  
1445 sub new_obj
1446 0 ▶{ my $self = shift;
Subroutine new_obj: not called CC=2 SCAR=17.9
1447 0 ▶ my $obj = shift or die 'No base for new_obj';
Branch: 1 branch
BranchTrueFalseTotal
my $obj = shift() or die "No base for new_obj" 0 0 0
1448  
1449 0 my $num = $self->{next_obj}->();
1450 0 my $gen = 0;
1451  
1452 0 $self->{' objcache'}{$num, $gen} = $obj;
1453 0 $self->{' objects'}{$obj->uid} = [ $num, $gen ];
1454 0 return $obj;
1455 }
1456  
1457  
1458 sub object_number
1459 0 ▶{ my($self, $obj) = @_;
Subroutine object_number: not called CC=2 SCAR=17.9
1460 0 ▶ my $num = $self->{' objects'}{$obj->uid} || return;
Condition0%0/2
$self->{' objects'}{$obj->uid} || (return)
l!l
00
MC/DC0%0/1
$self->{' objects'}{$obj->uid} || (return)
$self->{' objects'}{$obj->uid}
Truth table0%0/2
A
A= $self->{' objects'}{$obj->uid}
Aresult
11
00
1461 0 return $num->[0];
1462 }
1463  
1464  
1465 sub print
1466 0 ▶{ my($self, $data) = @_;
Subroutine print: not called CC=2 SCAR=17.9
1467  
1468 0 ▶ if(my($tail, $rest) = $data =~ m{\A(.*?\nendobj\n)(.*)\z}s)
Branch: 1 branch
BranchTrueFalseTotal
if (() = $data =~ /\A(.*?\nendobj\n)(.*)\z/s) { } 0 0 0
1469 0 { my($obj_num) = $self->{'>buffer'} =~ /(\d+)/;
1470 # Pass serialised object back to PDF::Reuse
1471 0 $self->{prObj}->($obj_num, $self->{'>buffer'} . $tail);
1472 0 $self->{'>buffer'} = $rest;
1473 }
1474 else
1475 0 { $self->{'>buffer'} .= $data;
1476 }
1477 }
1478  
1479  
1480 sub printf
1481 0 ▶{ my($self, $format, @args) = @_;;
Subroutine printf: not called CC=1 SCAR=6.9
1482 0 $self->print(sprintf($format, @args));
1483 }
1484  
1485  
1486 sub out_obj
1487 0 ▶{ my($self, $obj) = @_;
Subroutine out_obj: not called CC=2 SCAR=17.9
1488 0 ▶ return $self->new_obj($obj) unless defined $self->{' objects'}{$obj->uid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{" objects"}{$obj->uid} 0 0 0
1489 0 push @{ $self->{'>todo'} }, $obj->uid;
1490 }
1491  
1492  
1493 sub tell
1494 0 ▶{ return length shift->{'>buffer'};
Subroutine tell: not called CC=1 SCAR=6.9
1495 }
1496  
1497  
1498 sub write_objects
1499 0 ▶{ my($self) = @_;
Subroutine write_objects: not called CC=3 SCAR=24.8
1500  
1501 0 $self->{'>done'} = {};
1502 0 $self->{'>todo'} = [ sort map { $_->uid } values %{ $self->{' objcache'} } ];
1503 0 ▶ while(my $id = shift @{ $self->{'>todo'} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = shift @{$$self{">todo"};}) 0 0 0
1504 0 ▶ next if $self->{'>done'}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{">done"}{$id} 0 0 0
1505 0 my($num, $gen) = @{ $self->{' objects'}{$id} };
1506 0 $self->printf("%d %d obj\n", $num, $gen);
1507 0 $self->{' objcache'}{$num, $gen}->outobjdeep($self, $self);
1508 0 $self->print("\nendobj\n");
1509 0 $self->{'>done'}{$id}++;
1510 }
1511 }
1512  
1513  
1514 # This is a wrapper around Text::PDF::TTFont0, which provides support for
1515 # embedding TrueType fonts
1516  
1517 package PDF::Reuse::TTFont;
1518  
1519 sub new
1520 0 ▶{ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
1521  
1522 0 require Text::PDF::TTFont0;
1523 0 require Text::PDF::Utils;
1524  
1525 0 my $self = bless { 'subset' => 1, @_, }, $class;
1526  
1527 $self->{ttfont} = Text::PDF::TTFont0->new(
1528 $self->{docProxy},
1529 $self->{filename},
1530 $self->{fontAbbr},
1531 -subset => $self->{subset},
1532 0 );
1533 0 $self->{ttfont}->{' subvec'} = '';
1534  
1535 0 $self->{obj_num} = $self->{docProxy}->object_number($self->{ttfont});
1536  
1537 0 ▶ $self->{fontname} ||= $self->find_name();
Condition0%0/3
$self->{"fontname"} ||= $self->find_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"fontname"} ||= $self->find_name
$self->{"fontname"} $self->find_name
Truth table0%0/3
A ||= B
A= $self->{"fontname"}B= $self->find_name
ABresult
1X1
011
000
1538  
1539 0 return $self;
1540 }
1541  
1542 # Build a /ToUnicode CMap for every embedded TrueType font and attach it to
1543 # the font dictionary, so text in the output is searchable and copyable.
1544 # RT #123564 / GitHub #15.
1545 #
1546 # Text::PDF::TTFont0 has its own ToUnicode option, but its CMap generation is
1547 # broken (RT #123562, unfixed upstream since 2017) and would emit malformed
1548 # data. The mapping is built here instead: Text::PDF::Dict::outobjdeep
1549 # serialises dictionary keys generically, and DocProxy owns object
1550 # registration, so nothing in Text::PDF needs to change.
1551 #
1552 # Called from prEnd() before write_objects, which is the first moment the
1553 # subset vector is complete -- so only glyphs actually used are mapped.
1554 sub attach_tounicode
1555 0 ▶{ my $proxy = shift;
Subroutine attach_tounicode: not called CC=12 SCAR=50.5
1556  
1557 0 for my $ttfont (values %{ $proxy->{' objcache'} })
1558 0 ▶ { next unless eval { $ttfont->isa('Text::PDF::TTFont0') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $ttfont->isa("Text::PDF::TTFont0") } } 0 0 0
1559 0 ▶ next if $ttfont->{'ToUnicode'};
Branch: 1 branch
BranchTrueFalseTotal
if $ttfont->{"ToUnicode"} 0 0 0
1560 0 ▶ my $font = $ttfont->{' font'} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $font = $ttfont->{" font"} or next 0 0 0
1561 0 ▶ my $cmap = $font->{'cmap'} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $cmap = $font->{"cmap"} or next 0 0 0
1562 0 ▶ my @rev = eval { $cmap->read->reverse } or next;
Branch: 1 branch
BranchTrueFalseTotal
my(@rev) = eval { do { $cmap->read->reverse } } or next 0 0 0
1563  
1564 0 my @pairs;
1565 0 for my $gid (0 .. $#rev)
1566 0 { my $uni = $rev[$gid];
1567 0 ▶ next unless defined $uni;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uni 0 0 0
1568 0 ▶ next if $ttfont->{' subset'} && ! vec($ttfont->{' subvec'}, $gid, 1);
Branch: 1 branch
BranchTrueFalseTotal
if $ttfont->{" subset"} and not vec($ttfont->{" subvec"}, $gid, 1) 0 0 0
Condition0%0/3
$ttfont->{" subset"} and not vec($ttfont->{" subvec"}, $gid, 1)
!ll&&!rl&&r
000
MC/DC0%0/2
$ttfont->{" subset"} and not vec($ttfont->{" subvec"}, $gid, 1)
$ttfont->{" subset"} not vec($ttfont->{" subvec"}, $gid, 1)
Truth table0%0/3
A and not(B)
A= $ttfont->{" subset"}B= not vec($ttfont->{" subvec"}, $gid, 1)
ABresult
0X0
100
111
1569 0 push @pairs, [ $gid, $uni ];
1570 }
1571 0 ▶ next unless @pairs;
Branch: 1 branch
BranchTrueFalseTotal
unless @pairs 0 0 0
1572  
1573 0 my $stream = tounicode_cmap(\@pairs);
1574 0 my $dict = Text::PDF::Utils::PDFDict();
1575 0 $proxy->new_obj($dict);
1576 0 $dict->{' stream'} = $stream;
1577 0 $ttfont->{'ToUnicode'} = $dict;
1578 }
1579 0 return;
1580 }
1581  
1582 sub tounicode_cmap
1583 0 ▶{ my $pairs = shift;
Subroutine tounicode_cmap: not called CC=4 SCAR=30.0
1584  
1585 0 my $str = "/CIDInit /ProcSet findresource begin 12 dict begin begincmap\n"
1586 . "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n"
1587 . "/CMapName /Adobe-Identity-UCS def\n"
1588 . "/CMapType 2 def\n"
1589 . "1 begincodespacerange <0000> <FFFF> endcodespacerange\n";
1590  
1591 # Adobe caps a bfchar section at 100 entries.
1592 0 my $total = scalar @$pairs;
1593 0 ▶ for (my $i = 0; $i < $total; $i += 100)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $total) 0 0 0
1594 0 ▶ { my $end = $i + 100 > $total ? $total : $i + 100;
Branch: 1 branch
BranchTrueFalseTotal
$i + 100 > $total ? : 0 0 0
1595 0 $str .= ($end - $i) . " beginbfchar\n";
1596 0 for my $p (@{$pairs}[$i .. $end - 1])
1597 0 { $str .= sprintf("<%04X> <%s>\n", $p->[0], utf16be_hex($p->[1]));
1598 }
1599 0 $str .= "endbfchar\n";
1600 }
1601  
1602 0 $str .= "endcmap CMapName currentdict /CMap defineresource pop end end\n";
1603 0 return $str;
1604 }
1605  
1606 # ToUnicode destinations are UTF-16BE, so anything outside the BMP needs a
1607 # surrogate pair rather than a bare value.
1608 sub utf16be_hex
1609 0 ▶{ my $uni = shift;
Subroutine utf16be_hex: not called CC=2 SCAR=17.9
1610 0 ▶ return sprintf("%04X", $uni) if $uni <= 0xFFFF;
Branch: 1 branch
BranchTrueFalseTotal
if $uni <= 65535 0 0 0
1611 0 my $v = $uni - 0x10000;
1612 0 return sprintf("%04X%04X", 0xD800 + ($v >> 10), 0xDC00 + ($v & 0x3FF));
1613 }
1614  
1615 0 ▶sub filename { return $_[0]->{filename}; }
Subroutine filename: not called CC=1 SCAR=6.9
1616 0 ▶sub fontname { return $_[0]->{fontname}; }
Subroutine fontname: not called CC=1 SCAR=6.9
1617 0 ▶sub obj_num { return $_[0]->{obj_num}; }
Subroutine obj_num: not called CC=1 SCAR=6.9
1618 0 ▶sub fontAbbr { return $_[0]->{fontAbbr}; }
Subroutine fontAbbr: not called CC=1 SCAR=6.9
1619 0 ▶sub docProxy { return $_[0]->{docProxy}; }
Subroutine docProxy: not called CC=1 SCAR=6.9
1620  
1621 sub find_name
1622 0 ▶{ my $self = shift;
Subroutine find_name: not called CC=4 SCAR=30.0
1623 0 my($filebase) = $self->filename =~ m{.*[\\/](.*)\.};
1624 0 ▶ my $font = $self->{ttfont}->{' font'} or return $filebase;
Branch: 1 branch
BranchTrueFalseTotal
my $font = $self->{"ttfont"}{" font"} or return $filebase 0 0 0
1625 0 ▶ my $obj = $font->{'name'} or return $filebase;
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $font->{"name"} or return $filebase 0 0 0
1626 0 ▶ my $name = $obj->read->find_name(4) or return $filebase;
Branch: 1 branch
BranchTrueFalseTotal
my $name = $obj->read->find_name(4) or return $filebase 0 0 0
1627 0 $name =~ s{\W}{}g;
1628 0 return $name;
1629 }
1630  
1631 sub encode_text
1632 0 ▶{ my($self, $text) = @_;
Subroutine encode_text: not called CC=1 SCAR=6.9
1633 0 $text =~ s|\\\(|(|gos;
1634 0 $text =~ s|\\\)|)|gos;
1635 0 return $self->{ttfont}->out_text($text);
1636 }
1637  
1638 sub text_width
1639 0 ▶{ my($self, $text, $size) = @_;
Subroutine text_width: not called CC=1 SCAR=6.9
1640 0 return $self->{ttfont}->width($text) * $size;
1641 }
1642  
1643 sub DESTROY
1644 0 ▶{ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
1645 # Do NOT release the ttfont (TTFont0) object here -- it is still
1646 # owned by the DocProxy's objcache and will be cleaned up in prEnd().
1647 # Releasing it here would wipe its ' uid' field causing write_objects
1648 # to crash (GitHub issue #24).
1649 0 %$self = ();
1650 }
1651  
1652  
1653 package PDF::Reuse; # Applies to the autoloaded methods below (?)
1654  
1655 3 1;
1656  
1657 ##__END__
1658  
1659 =head1 NAME
1660  
1661 PDF::Reuse - Reuse and mass produce PDF documents
1662  
1663 =head1 SYNOPSIS
1664  
1665 =for SYNOPSIS.pl begin
1666  
1667 use PDF::Reuse;
1668 prFile('myFile.pdf');
1669 prText(100, 500, 'Hello World !');
1670 prEnd();
1671  
1672 =for end
1673  
1674 =head1 DESCRIPTION
1675  
1676 This module could be used when you want to mass produce similar (but not identical)
1677 PDF documents and reuse templates, JavaScripts and some other components. It is
1678 functional to be fast, and to give your programs capacity to produce many pages
1679 per second and very big PDF documents if necessary.
1680  
1681 The module produces PDF-1.4 files. Some features of PDF-1.5, like "object streams"
1682 and "cross reference streams", are supported, but only at an experimental level. More
1683 testing is needed. (If you get problems with a new document from Acrobat 6 or higher, try to
1684 save it or recreate it as a PDF-1.4 document first, before using it together with
1685 this module.)
1686  
1687 =over 2
1688  
1689 =item Templates
1690  
1691 Use your favorite program, probably a commercial visual tool, to produce single
1692 PDF-files to be used as templates, and then use this module to B<mass produce> files
1693 from them.
1694  
1695 (If you want small PDF-files or want special graphics, you can use this module also,
1696 but visual tools are often most practical.)
1697  
1698 =item Lists
1699  
1700 The module uses "XObjects" extensively. This is a format that makes it possible
1701 create big lists, which are compact at the same time.
1702  
1703  
1704 =item PDF-operators
1705  
1706 The module gives you a good possibility to program at a "low level" with the basic
1707 graphic operators of PDF, if that is what you want to do. You can build your
1708 own libraries of low level routines, with PDF-directives "controlled" by Perl.
1709  
1710 =item Archive-format
1711  
1712 If you want, you get your new documents logged in a format suitable for archiving
1713 or transfer.
1714  
1715  
1716 PDF::Reuse::Tutorial might show you best what you can do with this module.
1717  
1718 =item JavaScript
1719  
1720 You can attach JavaScripts to your PDF-files.
1721  
1722 You can have libraries of JavaScripts. No cutting or pasting, and those who include
1723 the scripts in documents only need to know how to initiate them. (Of course those
1724 who write the scripts have to know Acrobat JavaScript well.)
1725  
1726 =back
1727  
1728 =head2 Remarks about JavaScript
1729  
1730 Some of the functions handling JavaScript have to be rewritten for Acrobat 7.
1731  
1732 There are many limitations with Acrobat JavaScript, and the rules often change.
1733 So what works for one version of Acrobat/Reader, might not work for another.
1734 Another complication is this:
1735 When documents are downloaded via the net by Acrobat, they are most often
1736 converted (!) and necessary JavaScripts are lost.
1737  
1738  
1739 =head1 FUNCTIONS
1740  
1741 All functions which are successful return specified values or 1.
1742  
1743 The module doesn't make any attempt to import anything from encrypted files.
1744  
1745 =head1 Overview
1746  
1747 To write a program with PDF::Reuse, you need these components:
1748  
1749 =begin html
1750  
1751 <style>
1752 pre span.comment {
1753 color:AA0000 ;
1754 font-style: italic;
1755 }
1756 </style>
1757  
1758  
1759 <TABLE border=1 cellpadding="7">
1760 <THEAD bgcolor="lightblue">
1761 <TH title="Mandatory">First</TH>
1762 <TH title="Slightly deprecated functions for your output">Perhaps*</TH>
1763 <TH title="Mandatory">Always</TH>
1764 <TH title="If you want to add someting">Any or None</TH>
1765 <TH title="Often you need to indicate that you need a new page and possibly from where">Probably**</TH>
1766 <TH title="Mandatory">Finally</TH>
1767 </THEAD>
1768 <TR valign="top" bgcolor="lightgreen">
1769 <TD title="To include the module"><B>use PDF::Reuse</B></TD>
1770 <TD></TD>
1771 <TD title="Finish an old document and direct output for a new document"><B>prFile</B></TD>
1772 <TD title="To add new contents, JavaScript, links and so on..">prInitVars<BR>
1773 prExtract<BR>
1774 prForm<BR>
1775 prInit<BR>
1776 prField<BR>
1777 prImage<BR>
1778 prAltJpeg<BR>
1779 prJpeg<BR>
1780 prFont<BR>
1781 prFontSize<BR>
1782 prTTFont<BR>
1783 prGraphState<BR>
1784 prAdd<BR>
1785 prText<BR>
1786 prJs<BR>
1787 prCompress<BR>
1788 prMbox<BR>
1789 prBookmark<BR>
1790 prStrWidth<BR>
1791 prLink</TD>
1792 <TD title="These functions collect available contents and create the pages">prDoc<BR>
1793 prPage<BR>
1794 prSinglePage</TD>
1795 <TD title="To finish last document and clean up"><B>prEnd</B></TD>
1796 <TR valign="top" bgcolor="lightyellow">
1797 <TD></TD>
1798 <TD>prDocDir*<BR>
1799 prLogDir*</TD>
1800 <TD></TD>
1801 <TD>prDocForm*<BR>
1802 prGetLogBuffer*<BR>
1803 prBar*<BR>
1804 prLog*<BR>
1805 prTouchUp*<BR>
1806 prVers*<BR>
1807 prCid*<BR>
1808 prId*<BR>
1809 prIdType*<BR></TD>
1810 <TD></TD>
1811 <TD></TD>
1812 </TR>
1813 <TR bgcolor="lightgrey">
1814 <TD colspan=6> * = internal/ deprecated function</TD>
1815 </TR>
1816 <TR bgcolor="lightgrey">
1817 <TD colspan=6> ** = not needed before prEnd or a new prFile<BR>
1818 In those cases prPage is automatically inserted </TD>
1819 </TR>
1820 </TABLE>
1821  
1822  
1823  
1824 =end html
1825  
1826 =head1 Mandatory Functions
1827  
1828 =head2 prFile - define output
1829  
1830 Alternative 1:
1831  
1832 prFile ( $fileName );
1833  
1834 Alternative 2 with parameters in an anonymous hash:
1835  
1836 prFile ( { Name => $fileName,
1837 HideToolbar => 1, # 1 or 0
1838 HideMenubar => 1, # 1 or 0
1839 HideWindowUI => 1, # 1 or 0
1840 FitWindow => 1, # 1 or 0
1841 CenterWindow => 1 } ); # 1 or 0
1842  
1843 Alternative 3:
1844  
1845 prFile ( $r ); # For mod_perl 2 pass the request object
1846  
1847 $fileName is optional, just like the rest of the parameters.
1848 File to create. If another file is current when this function is called, the first
1849 one is written and closed. Only one file is processed at a single moment. If
1850 $fileName is undefined, output is written to STDOUT.
1851  
1852 HideToolbar, HideMenubar, HideWindowUI, FitWindow and CenterWindow control the
1853 way the document is initially displayed.
1854  
1855 Look at any program in this documentation for examples. prInitVars() shows how
1856 this function could be used together with a web server.
1857  
1858 =head2 prEnd - end/flush buffers
1859  
1860 prEnd ()
1861  
1862 When the processing is going to end, the buffers of the B<last> file has to be written to the disc.
1863 If this function is not called, the page structure, xref part and so on will be
1864 lost.
1865  
1866 Look at any program in this documentation for an example.
1867  
1868 =head1 Optional Functions
1869  
1870 =head2 prAdd - add "low level" instructions
1871  
1872 prAdd ( $string )
1873  
1874 With this command you can add whatever you want to the current content stream.
1875 No syntactical checks are made, but if you use an internal name, the module tries
1876 to add the resource of the "name object" to the "Resources" of current page.
1877 "Name objects" always begin with a '/'.
1878  
1879 (In this documentation I often use talk about an "internal name". It denotes a
1880 "name object". When PDF::Reuse creates these objects, it assigns Ft1, Ft2, Ft3 ...
1881 for fonts, Ig1, Ig2, Ig3 for images, Fo1 .. for forms, Cs1 .. for Color spaces,
1882 Pt1 .. for patterns, Sh1 .. for shading directories, Gs0 .. for graphic state
1883 parameter dictionaries. These names are kept until the program finishes,
1884 and my ambition is also to keep the resources available in internal tables.)
1885  
1886 This is a simple and very powerful function. You should study the examples and
1887 the "PDF-reference manual", if you want to use it.(When this text is written,
1888 a possible link to download it is:
1889 http://partners.adobe.com/asn/developer/acrosdk/docs.html)
1890  
1891 This function is intended to give you detail control at a low level.
1892  
1893 use PDF::Reuse;
1894 use strict;
1895  
1896 prFile('myFile.pdf');
1897 my $string = "150 600 100 50 re\n"; # a rectangle
1898 $string .= "0 0 1 rg\n"; # blue (to fill)
1899 $string .= "b\n"; # fill and stroke
1900 prAdd($string);
1901 prEnd();
1902  
1903  
1904 =head2 prBookmark - define bookmarks
1905  
1906 prBookmark($reference)
1907  
1908 Defines a "bookmark". $reference refers to a hash or array of hashes which looks
1909 something like this:
1910  
1911 { text => 'Document',
1912 act => 'this.pageNum = 0; this.scroll(40, 500);',
1913 kids => [ { text => 'Chapter 1',
1914 act => '1, 40, 600'
1915 },
1916 { text => 'Chapter 2',
1917 act => '10, 40, 600'
1918 }
1919 ]
1920 }
1921  
1922 Each hash can have these components:
1923  
1924 text the text shown beside the bookmark
1925 act the action to be triggered. Has to be a JavaScript action.
1926 (Three simple numbers are translated to page, x and y in the
1927 sentences: this.pageNum = page; this.scroll(x, y); )
1928 kids will have a reference to another hash or array of hashes
1929 close if this component is present, the bookmark will be closed
1930 when the document is opened
1931 color 3 numbers, RGB-colors e.g. '0.5 0.5 1' for light blue
1932 style 0, 1, 2, or 3. 0 = Normal, 1 = Italic, 2 = Bold, 3 = Bold Italic
1933  
1934 Creating bookmarks for a document:
1935  
1936 use PDF::Reuse;
1937 use strict;
1938  
1939 my @pageMarks;
1940  
1941 prFile('myDoc.pdf');
1942  
1943 for (my $i = 0; $i < 100; $i++)
1944 { prText(40, 600, 'Something is written');
1945 # ...
1946 my $page = $i + 1;
1947 my $bookMark = { text => "Page $page",
1948 act => "$i, 40, 700" };
1949 push @pageMarks, $bookMark;
1950 prPage();
1951 }
1952 prBookmark( { text => 'Document',
1953 close => 1,
1954 kids => \@pageMarks } );
1955 prEnd();
1956  
1957  
1958 Traditionally bookmarks have mainly been used for navigation within a document,
1959 but they can be used for many more things. You can e.g. use them to navigate within
1960 your data. You can let your users go to external links also, so they can "drill down"
1961 to other documents.
1962  
1963 B<See "Remarks about JavaScript">
1964  
1965 =head2 prCompress - compress/zip added streams
1966  
1967 prCompress (1)
1968  
1969 '1' here is a directive to compress all B<new> streams of the current file. Streams
1970 which are included with prForm, prDocForm, prDoc or prSinglePage are not changed. New
1971 JavaScripts are also created as streams and compressed, if they are at least 100
1972 bytes long. The streams are compressed in memory, so probably there is a limit of
1973 how big they can be.
1974  
1975 prCompress(); is a directive not to compress. This is default.
1976  
1977 See e.g. "Starting to reuse" in the tutorial for an example.
1978  
1979 =head2 prDoc - include pages from a document
1980  
1981 prDoc ( $documentName, $firstPage, $lastPage )
1982  
1983 or with the parameters in an anonymous hash:
1984  
1985 prDoc ( { file => $documentName,
1986 first => $firstPage,
1987 last => $lastPage } );
1988  
1989 Returns number of extracted pages.
1990  
1991 If "first" is not given, 1 is assumed. If "last" is not given, you don't have any upper
1992 limit. N.B. The numbering of the pages differs from Acrobat JavaScript. In JavaScript
1993 the first page has index 0.
1994  
1995 Adds pages from a document to the one you are creating.
1996 N.B. From version 0.32 of this module:
1997 If there are contents created with with prText, prImage,prAdd, prForm and so on,
1998 prDoc tries to put the contents on the first extracted page
1999 from the old document.
2000  
2001  
2002 If it is the first interactive
2003 component ( prDoc() or prDocForm() ) the interactive functions are kept and also merged
2004 with JavaScripts you have added, if any. But, if you specify a first page different than 1
2005 or a last page, no JavaScript are extracted from the document, because then there is a
2006 risk that an included JavaScript function might refer to something not included.
2007  
2008 use PDF::Reuse;
2009 use strict;
2010  
2011 prFile('myFile.pdf'); # file to make
2012 prJs('customerResponse.js'); # include a JavaScript file
2013 prInit('nameAddress(12, 150, 600);'); # init a JavaScript function
2014 prForm('best.pdf'); # page 1 from best.pdf
2015 prPage();
2016 prDoc('long.pdf'); # a document with 11 pages
2017 prForm('best.pdf'); # page 1 from best.pdf
2018 prText(150, 700, 'Customer Data'); # a line of text
2019 prEnd();
2020  
2021 To extract pages 2-3 and 5-7 from a document and create a new document:
2022  
2023 use PDF::Reuse;
2024 use strict;
2025  
2026 prFile('new.pdf');
2027 prDoc( { file => 'old.pdf',
2028 first => 2,
2029 last => 3 });
2030 prDoc( { file => 'old.pdf',
2031 first => 5,
2032 last => 7 });
2033 prEnd();
2034  
2035  
2036 To add a form, image and page number to each page of an 16 pages long document
2037 (The document Battery.pdf is cropped so each page is fairly small) You could also have
2038 used prSinglePage, look at a very similar example under that function.
2039  
2040 use PDF::Reuse;
2041 use PDF::Reuse::Util;
2042 use strict;
2043  
2044 prFile('test.pdf');
2045  
2046 my $pageNumber = 0;
2047  
2048 for (my $page = 1; $page < 17; $page++)
2049 { $pageNumber++;
2050 prForm( { file =>'Words.pdf',
2051 page => 5,
2052 x => 150,
2053 y => 150} );
2054  
2055 prImage( { file =>'Media.pdf',
2056 page => 6,
2057 imageNo => 1,
2058 x => 450,
2059 y => 450 } );
2060 blackText();
2061 prText( 360, 250, $pageNumber);
2062 prDoc('Battery.pdf', $pageNumber, $pageNumber);
2063 }
2064 prEnd;
2065  
2066  
2067 =head2 prDocDir - set directory for produced documents
2068  
2069 prDocDir ( $directoryName )
2070  
2071 Sets directory for produced documents
2072  
2073 use PDF::Reuse;
2074 use strict;
2075  
2076 prDocDir('C:/temp/doc');
2077 prFile('myFile.pdf'); # writes to C:\temp\doc\myFile.pdf
2078 prForm('myFile.pdf'); # page 1 from ..\myFile.pdf
2079 prText(200, 600, 'New text');
2080 prEnd();
2081  
2082 =head2 prDocForm - use an interactive page as a form
2083  
2084 Alternative 1) You put your parameters in an anonymous hash (only B<file> is really
2085 necessary, the others get default values if not given).
2086  
2087 prDocForm ( { file => $pdfFile, # template file
2088 page => $page, # page number (of imported template)
2089 adjust => $adjust, # try to fill the media box
2090 effect => $effect, # action to be taken
2091 tolerant => $tolerant, # continue even with an invalid form
2092 x => $x, # $x points from the left
2093 y => $y, # $y points from the bottom
2094 rotate => $degree, # rotate
2095 size => $size, # multiply everything by $size
2096 xsize => $xsize, # multiply horizontally by $xsize
2097 ysize => $ysize } ) # multiply vertically by $ysize
2098 Ex.:
2099 my $internalName = prDocForm ( {file => 'myFile.pdf',
2100 page => 2 } );
2101  
2102 Alternative 2) You put your parameters in this order
2103  
2104 prDocForm ( $pdfFile, [$page, $adjust, $effect, $tolerant, $x, $y, $degree,
2105 $size, $xsize, $ysize] )
2106  
2107  
2108 Anyway the function returns in list context: B<$intName, @BoundingBox,
2109 $numberOfImages>, in scalar context: B<$internalName> of the form.
2110  
2111 Look at prForm() for an explanation of the parameters.
2112  
2113 N.B. Usually you shouldn't adjust or change size and proportions of an interactive
2114 page. The graphic and interactive components are independent of each other and there
2115 is a great risk that any coordination is lost.
2116  
2117 This function redefines a page to an "XObject" (the graphic parts), then the
2118 page can be reused in a much better way. Unfortunately there is an important
2119 limitation here. "XObjects" can only have single streams. If the page consists
2120 of many streams, you should concatenate them first. Adobe Acrobat can do that.
2121 (If it is an important file, take a copy of it first. Sometimes the procedure fails.)
2122 Open the document with Acrobat. Then choose the the "TouchUp Text" tool (icon or
2123 from the tools menu). Select a line of text somewhere on the page. Right-click the
2124 mouse. Choose "Attributes".Change font size or anything else, and then you change
2125 it back to the old value. Save the document.
2126 If there was no text on the page, use some other "Touch Up" tool.
2127 Alternatively, use GhostScript to convert multi-stream PDFs (see prForm documentation
2128 for the command).
2129  
2130  
2131 use PDF::Reuse;
2132 use strict;
2133  
2134 prDocDir('C:/temp/doc');
2135 prFile('newForm.pdf');
2136 prField('Mr/Ms', 'Mr');
2137 prField('First_Name', 'Lars');
2138 prDocForm('myFile.pdf');
2139 prFontSize(24);
2140 prText(75, 790, 'This text is added');
2141 prEnd();
2142  
2143 (You can use the output from the example in prJs() as input to this example.
2144 Remember to save that file before closing it.)
2145  
2146 B<See Remarks about JavaScript>
2147  
2148 =head2 prExtract - extract an object group
2149  
2150 prExtract ( $pdfFile, $pageNo, $oldInternalName )
2151  
2152 B<oldInternalName>, a "name"-object. This is the internal name you find in the original file.
2153 Returns a B<$newInternalName> which can be used for "low level" programming. You
2154 have better look at graphObj_pl and modules it has generated for the tutorial,
2155 e.g. thermometer.pm, to see how this function can be used.
2156  
2157 When you call this function, the necessary objects will be copied to your new
2158 PDF-file, and you can refer to them with the new name you receive.
2159  
2160  
2161 =head2 prField - assign a value to an interactive field
2162  
2163 prField ( $fieldName, $value )
2164  
2165 B<$fieldName> is an interactive field in the document you are creating.
2166 It has to be spelled exactly the same way here as it spelled in the document.
2167 B<$value> is what you want to assigned to the field.
2168 Put all your sentences with prField early in your script. After prFile and B<before>
2169 prDoc or prDocForm and of course before prEnd. Each sentence with prField is
2170 translated to JavaScript and merged with old JavaScript
2171  
2172 See prDocForm() for an example
2173  
2174 If you are going to assign a value to a field consisting of several lines, you
2175 can write like this:
2176  
2177 my $string = "This is the first line \r second line \n 3:rd line";
2178 prField('fieldName', $string);
2179  
2180 You can also let '$value' be a snippet of JavaScript-code that assigns something
2181 to the field. Then you have to put 'js:' first in "$value" like this:
2182  
2183 my $sentence = encrypt('This will be decrypted by "unPack"(JavaScript) ');
2184 prField('Interest_9', "js: unPack('$sentence')");
2185  
2186 If you refer to a JavaScript function, it has to be included with prJs first. (The
2187 JavaScript interpreter will simply not be aware of old functions in the PDF-document,
2188 when the initiation is done.)
2189  
2190  
2191 =head2 prFont - set current font
2192  
2193 prFont ( $fontName )
2194  
2195 $fontName is an "external" font name. The parameter is optional.
2196 In list context returns B<$internalName, $externalName, $oldInternalName,
2197 $oldExternalname> The first two variables refer to the current font, the two later
2198 to the font before the change. In scalar context returns b<$internalName>
2199  
2200 If a font wasn't found, Helvetica will be set.
2201 These names are always recognized:
2202 B<Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold,
2203 Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique,
2204 Helvetica-BoldOblique> or abbreviated
2205 B<TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO>.
2206 (B<Symbol and ZapfDingbats> or abbreviated B<S, Z>, also belong to the predefined
2207 fonts, but there is something with them that I really don't understand. You should
2208 print them first on a page, and then use other fonts, otherwise they are not displayed.)
2209  
2210 You can also use a font name from an included page. It has to be spelled exactly as
2211 it is done there. Look in the file and search for "/BaseFont" and the font
2212 name. But take care, e.g. the PDFMaker which converts to PDF from different
2213 Microsoft programs, only defines exactly those letters you can see on the page. You
2214 can use the font, but perhaps some of your letters were not defined.
2215  
2216 In the distribution there is an utility program, 'reuseComponent_pl', which displays
2217 included fonts in a PDF-file and prints some letters. Run it to see the name of the
2218 font and if it is worth extracting.
2219  
2220 use PDF::Reuse;
2221 use strict;
2222 prFile('myFile.pdf');
2223  
2224 ####### One possibility #########
2225  
2226 prFont('Times-Roman'); # Just setting a font
2227 prFontSize(20);
2228 prText(180, 790, "This is a heading");
2229  
2230 ####### Another possibility #######
2231  
2232 my $font = prFont('C'); # Setting a font, getting an
2233 # internal name
2234 prAdd("BT /$font 12 Tf 25 760 Td (This is some other text)Tj ET");
2235 prEnd();
2236  
2237 The example above shows you two ways of setting and using a font. One simple, and
2238 one complicated with a possibility to detail control.
2239  
2240  
2241 =head2 prFontSize - set current font size
2242  
2243 prFontSize ( $size )
2244  
2245 Returns B<$actualSize, $fontSizeBeforetheChange>. Without parameters
2246 prFontSize() sets the size to 12 points, which is default.
2247  
2248 =head2 prForm - use a page from an old document as a form/background
2249  
2250 Alternative 1) You put your parameters in an anonymous hash (only B<file> is really
2251 necessary, the others get default values if not given).
2252  
2253 prForm ( { file => $pdfFile, # template file
2254 page => $page, # page number (of imported template)
2255 adjust => $adjust, # try to fill the media box
2256 effect => $effect, # action to be taken
2257 tolerant => $tolerant, # continue even with an invalid form
2258 x => $x, # $x points from the left
2259 y => $y, # $y points from the bottom
2260 rotate => $degree, # rotate
2261 size => $size, # multiply everything by $size
2262 xsize => $xsize, # multiply horizontally by $xsize
2263 ysize => $ysize } ) # multiply vertically by $ysize
2264 Ex.:
2265 my $internalName = prForm ( {file => 'myFile.pdf',
2266 page => 2 } );
2267  
2268 Alternative 2) You put your parameters in this order
2269  
2270 prForm ( $pdfFile, $page, $adjust, $effect, $tolerant, $x, $y, $degree,
2271 $size, $xsize, $ysize )
2272  
2273  
2274 Anyway the function returns in list context: B<$intName, @BoundingBox,
2275 $numberOfImages>, in scalar context: B<$internalName> of the form.
2276  
2277 B<file> can be a filename, an IO::String object, a filehandle, or a scalar
2278 reference to PDF data in memory.
2279  
2280 if B<page> is excluded 1 is assumed.
2281  
2282 B<adjust>, could be 1, 2 or 0/nothing. If it is 1, the program tries to adjust the
2283 form to the current media box (paper size) and keeps the proportions unchanged.
2284 If it is 2, the program tries to fill as much of the media box as possible, without
2285 regards to the original proportions.
2286 If this parameter is given, "x", "y", "rotate", "size", "xsize" and "ysize"
2287 will be ignored.
2288  
2289 B<effect> can have 3 values: B<'print'>, which is default, loads the page in an internal
2290 table, adds it to the document and prints it to the current page. B<'add'>, loads the
2291 page and adds it to the document. (Now you can "manually" manage the way you want to
2292 print it to different pages within the document.) B<'load'> just loads the page in an
2293 internal table. (You can now take I<parts> of a page like fonts and objects and manage
2294 them, without adding all the page to the document.)You don't get any defined
2295 internal name of the form, if you let this parameter be 'load'.
2296  
2297 B<tolerant> can be nothing or something. If it is undefined, you will get an error if your program tries to load
2298 a page which the system cannot really handle, if it e.g. consists of many streams.
2299 If it is set to something, you have to test the first return value $internalName to
2300 know if the function was successful. Look at the program 'reuseComponent_pl' for an
2301 example of usage.
2302  
2303 B<x> where to start along the x-axis (cannot be combined with "adjust")
2304  
2305 B<y> where to start along the y-axis (cannot be combined with "adjust")
2306  
2307 B<rotate> A degree 0-360 to rotate the form counter-clockwise. (cannot be combined
2308 with "adjust") Often the form disappears out of the media box if degree >= 90.
2309 Then you can move it back with the x and y-parameters. If degree == 90, you can
2310 add the width of the form to x, If degree == 180 add both width and height to x
2311 and y, and if degree == 270 you can add the height to y.
2312  
2313 B<rotate> can also by one of 'q1', 'q2' or 'q3'. Then the system rotates the form
2314 clockwise 90, 180 or 270 degrees and tries to keep the form within the media box.
2315  
2316 The rotation takes place after the form has been resized or moved.
2317  
2318 Ex. To rotate from portrait (595 x 842 pt) to landscape (842 x 595 pt)
2319  
2320 use PDF::Reuse;
2321 use strict;
2322  
2323 prFile('New_Report.pdf');
2324 prMbox(0, 0, 842, 595);
2325  
2326 prForm({file => 'cert1.pdf',
2327 rotate => 'q1' } );
2328 prEnd();
2329  
2330 The same rotation can be achieved like this:
2331  
2332 use PDF::Reuse;
2333 use strict;
2334  
2335 prFile('New_Report.pdf');
2336 prMbox(0, 0, 842, 595);
2337  
2338 prForm({file => 'cert1.pdf',
2339 rotate => 270,
2340 y => 595 } );
2341 prEnd();
2342  
2343 B<size> multiply every measure by this value (cannot be combined with "adjust")
2344  
2345 B<xsize> multiply horizontally by this value (cannot be combined with "adjust")
2346  
2347 B<ysize> multiply vertically by $ysize (cannot be combined with "adjust")
2348  
2349 This function redefines a page to an "XObject" (the graphic parts), then the
2350 page can be reused and referred to as a unit. Unfortunately there is an important
2351 limitation here. "XObjects" can only have single streams. If the page consists
2352 of many streams, you should concatenate them first. Adobe Acrobat can do that.
2353 (If it is an important file, take a copy of it first. Sometimes the procedure fails.)
2354 Open the document with Acrobat. Then choose the "TouchUp Text" tool.
2355 Select a line of text somewhere. Right-click the mouse. Choose "Attributes".
2356 Change font size or anything else, and then you change it back to the old value.
2357 Save the document. You could alternatively save the file as Postscript and redistill
2358 it with the distiller or with Ghost script, but this is a little more risky. You
2359 might loose fonts or something else. Another alternative could be to use prSinglePage().
2360  
2361 Alternatively, GhostScript can be used to convert multi-stream PDFs into
2362 single-stream format compatible with prForm:
2363  
2364 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default \
2365 -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \
2366 -dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
2367  
2368  
2369 use PDF::Reuse;
2370 use strict;
2371  
2372 prFile('myFile.pdf');
2373 prForm('best.pdf'); # Takes page No 1
2374 prText(75, 790, 'Dear Mr Gates');
2375 # ...
2376 prPage();
2377 prMbox(0, 0, 900, 960);
2378 my @vec = prForm( { file => 'EUSA.pdf',
2379 adjust => 1 } );
2380 prPage();
2381 prMbox();
2382 prText(35, 760, 'This is the final page');
2383  
2384 # More text ..
2385  
2386 #################################################################
2387 # We want to put a miniature of EUSA.pdf, 35 points from the left
2388 # 85 points up, and in the format 250 X 200 points
2389 #################################################################
2390  
2391 my $xScale = 250 / ($vec[3] - $vec[1]);
2392 my $yScale = 200 / ($vec[4] - $vec[2]);
2393  
2394 prForm ({ file => 'EUSA.pdf',
2395 xsize => $xScale,
2396 ysize => $yScale,
2397 x => 35,
2398 y => 85 });
2399  
2400 prEnd();
2401  
2402 The first prForm(), in the code, is a simple and "normal" way of using the
2403 the function. The second time it is used, the size of the imported page is
2404 changed. It is adjusted to the media box which is current at that moment.
2405 Also data about the form is taken, so you can control more in detail how it
2406 will be displayed.
2407  
2408 =head2 prGetLogBuffer - get the log buffer.
2409  
2410 prGetLogBuffer ()
2411  
2412 returns a B<$buffer> of the log of the current page. (It could be used
2413 e.g. to calculate a MD5-digest of what has been registered that far, instead of
2414 accumulating the single values) A log has to be active, see prLogDir() below
2415  
2416 Look at "Using the template" and "Restoring a document from the log" in the
2417 tutorial for examples of usage.
2418  
2419 =head2 prGraphState - define a graphic state parameter dictionary
2420  
2421 prGraphState ( $string )
2422  
2423 This is a "low level" function. Returns B<$internalName>. The B<$string> has to
2424 be a complete dictionary with initial "<<" and terminating ">>". No syntactical
2425 checks are made. Perhaps you will never have to use this function.
2426  
2427 use PDF::Reuse;
2428 use strict;
2429  
2430 prFile('myFile.pdf');
2431  
2432 ###################################################
2433 # Draw a triangle with Gs0 (automatically defined)
2434 ###################################################
2435  
2436 my $str = "q\n";
2437 $str .= "/Gs0 gs\n";
2438 $str .= "150 700 m\n";
2439 $str .= "225 800 l\n";
2440 $str .= "300 700 l\n";
2441 $str .= "150 700 l\n";
2442 $str .= "S\n";
2443 $str .= "Q\n";
2444 prAdd($str);
2445  
2446 ########################################################
2447 # Define a new graph. state param. dic. and draw a new
2448 # triangle further down
2449 ########################################################
2450  
2451 $str = '<</Type/ExtGState/SA false/SM 0.02/TR2 /Default'
2452 . '/LW 15/LJ 1/ML 1>>';
2453 my $gState = prGraphState($str);
2454 $str = "q\n";
2455 $str .= "/$gState gs\n";
2456 $str .= "150 500 m\n";
2457 $str .= "225 600 l\n";
2458 $str .= "300 500 l\n";
2459 $str .= "150 500 l\n";
2460 $str .= "S\n";
2461 $str .= "Q\n";
2462 prAdd($str);
2463  
2464 prEnd();
2465  
2466  
2467 =head2 prImage - reuse an image from an old PDF document
2468  
2469 Alternative 1) You put your parameters in an anonymous hash (only B<file> is really
2470 necessary, the others get default values if not given).
2471  
2472 prImage( { file => $pdfFile, # template file
2473 page => $page, # page number
2474 imageNo => $imageNo # image number
2475 adjust => $adjust, # try to fill the media box
2476 effect => $effect, # action to be taken
2477 x => $x, # $x points from the left
2478 y => $y, # $y points from the bottom
2479 rotate => $degree, # rotate
2480 size => $size, # multiply everything by $size
2481 xsize => $xsize, # multiply horizontally by $xsize
2482 ysize => $ysize } ) # multiply vertically by $ysize
2483 Ex.:
2484 prImage( { file => 'myFile.pdf',
2485 page => 10,
2486 imageNo => 2 } );
2487  
2488 Alternative 2) You put your parameters in this order
2489  
2490 prImage ( $pdfFile, [$page, $imageNo, $effect, $adjust, $x, $y, $degree,
2491 $size, $xsize, $ysize] )
2492  
2493 Returns in scalar context B<$internalName> As a list B<$internalName, $width,
2494 $height>
2495  
2496 Assumes that $pageNo and $imageNo are 1, if not specified. If $effect is given and
2497 anything else then 'print', the image will be defined in the document,
2498 but not shown at this moment.
2499  
2500 For all other parameters, look at prForm().
2501  
2502 use PDF::Reuse;
2503 use strict;
2504  
2505 prFile('myFile.pdf');
2506 my @vec = prImage({ file => 'best.pdf',
2507 x => 10,
2508 y => 400,
2509 xsize => 0.9,
2510 ysize => 0.8 } );
2511 prText(35, 760, 'This is some text');
2512 # ...
2513 prPage();
2514 my @vec2 = prImage( { file => 'destiny.pdf',
2515 page => 1,
2516 imageNo => 1,
2517 effect => 'add' } );
2518 prText(25, 760, "There shouldn't be any image on this page");
2519 prPage();
2520 ########################################################
2521 # Now we make both images so that they could fit into
2522 # a box 300 X 300 points, and they are displayed
2523 ########################################################
2524  
2525 prText(25, 800, 'This is the first image :');
2526  
2527 my $xScale = 300 / $vec[1];
2528 my $yScale = 300 / $vec[2];
2529 if ($xScale < $yScale)
2530 { $yScale = $xScale;
2531 }
2532 else
2533 { $xScale = $yScale;
2534 }
2535 prImage({ file => 'best.pdf',
2536 x => 25,
2537 y => 450,
2538 xsize => $xScale,
2539 ysize => $yScale} );
2540  
2541 prText(25, 400, 'This is the second image :');
2542  
2543 $xScale = 300 / $vec2[1];
2544 $yScale = 300 / $vec2[2];
2545 if ($xScale < $yScale)
2546 { $yScale = $xScale;
2547 }
2548 else
2549 { $xScale = $yScale;
2550 }
2551 prImage({ file => 'destiny.pdf',
2552 x => 25,
2553 y => 25,
2554 xsize => $xScale,
2555 ysize => $yScale} );
2556  
2557 prEnd();
2558  
2559 On the first page an image is displayed in a simple way. While the second page
2560 is processed, prImage(), loads an image, but it is not shown here. On the 3:rd
2561 page, the two images are scaled and shown.
2562  
2563 In the distribution there is an utility program, 'reuseComponent_pl', which displays
2564 included images in a PDF-file and their "names".
2565  
2566 =head2 prInit - add JavaScript to be executed at initiation
2567  
2568 prInit ( $string, $duplicateCode )
2569  
2570 B<$string> can be any JavaScript code, but you can only refer to functions included
2571 with prJs. The JavaScript interpreter will not know other functions in the document.
2572 Often you can add new things, but you can't remove or change interactive fields,
2573 because the interpreter hasn't come that far, when initiation is done.
2574  
2575 B<$duplicateCode> is undefined or anything. It duplicates the JavaScript code
2576 which has been used at initiation, so you can look at it from within Acrobat and
2577 debug it. It makes the document bigger. This parameter is B<deprecated>.
2578  
2579 use PDF::Reuse;
2580 use strict;
2581  
2582 prFile('myFile.pdf');
2583 prInit('app.alert("This is displayed when opening the document");');
2584  
2585 prEnd();
2586  
2587  
2588 Remark: Avoid to use "return" in the code you use at initiation. If your user has
2589 downloaded a page with Web Capture, and after that opens a PDF-document where a
2590 JavaScript is run at initiation and that JavaScript contains a return-statement,
2591 a bug occurs. The JavaScript interpreter "exits" instead of returning, the execution
2592 of the JavaScript might finish to early. This is a bug in Acrobat/Reader 5.
2593  
2594  
2595 =head2 prInitVars - initiate global variables and internal tables
2596  
2597 prInitVars(1)
2598  
2599 If you run programs with PDF::Reuse as persistent procedures, you probably need to
2600 initiate global variables. If you have '1' or anything as parameter, internal tables for forms, images, fonts
2601 and interactive functions are B<not> initiated. The module "learns" offset and sizes of
2602 used objects, and can process them faster, but at the same time the size of the
2603 program grows.
2604  
2605 use PDF::Reuse;
2606 use strict;
2607 prInitVars(); # To initiate ALL global variables and tables
2608 # prInitVars(1); # To make it faster, but more memory consuming
2609  
2610 $| = 1;
2611 print STDOUT "Content-Type: application/pdf \n\n";
2612  
2613 prFile(); # To send the document uncatalogued to STDOUT
2614  
2615 prForm('best.pdf');
2616 prText(25, 790, 'Dear Mr. Anders Persson');
2617 # ...
2618 prEnd();
2619  
2620 If you call this function without parameters all global variables, including the
2621 internal tables, are initiated.
2622  
2623  
2624 =head2 prAltJpeg - import a low-res jpeg-image for display and a high-res jpeg-image for printing
2625  
2626 prAltJpeg ( $imageData, $width, $height, $format, $altImageData, $altWidth, $altHeight, $altFormat )
2627  
2628 B<$imageData> contains 1 single jpeg-image. B<$width> and B<$height>
2629 also have to be specified. B<$format> indicates the format the image
2630 data takes: 0 for file, 1 for binary string. B<$altImageData> etc.
2631 follows the same foramt. Returns the B<$internalName>
2632  
2633 use PDF::Reuse;
2634 use Image::Info qw(image_info dim);
2635 use strict;
2636  
2637 my $file = 'myImage.jpg';
2638 my $info = image_info($file);
2639 my ($width, $height) = dim($info); # Get the dimensions
2640 my $colortype = $info->{color_type}; # get color space
2641  
2642 my $alt_file = 'myImage.jpg';
2643 my $alt_info = image_info($alt_file);
2644 my ($alt_width, $alt_height) = dim($alt_info);
2645  
2646 prFile('myFile.pdf');
2647 my $intName = prAltJpeg("$file", # Define the image
2648 $width, # in the document
2649 $height,
2650 0,
2651 "$alt_file",
2652 $alt_width,
2653 $alt_height,
2654 0);
2655  
2656 my $str = "q\n";
2657 $str .= "$width 0 0 $height 10 10 cm\n";
2658 $str .= "/$intName Do\n";
2659 $str .= "Q\n";
2660 prAdd($str);
2661 prEnd();
2662  
2663  
2664 =head2 prJpeg - import a jpeg-image
2665  
2666 prJpeg ( $imageData, $width, $height, $format )
2667  
2668 B<$imageData> contains 1 single jpeg-image. B<$width> and B<$height>
2669 also have to be specified. B<$format> indicates the format the image
2670 data takes: 0 for file, 1 for binary string. Returns the B<$internalName>
2671  
2672 use PDF::Reuse;
2673 use Image::Info qw(image_info dim);
2674 use strict;
2675  
2676 my $file = 'myImage.jpg';
2677 my $info = image_info($file);
2678 my ($width, $height) = dim($info); # Get the dimensions
2679  
2680 prFile('myFile.pdf');
2681 my $intName = prJpeg("$file", # Define the image
2682 $width, # in the document
2683 $height,
2684 0);
2685  
2686 my $str = "q\n";
2687 $str .= "$width 0 0 $height 10 10 cm\n";
2688 $str .= "/$intName Do\n";
2689 $str .= "Q\n";
2690 prAdd($str);
2691 prEnd();
2692  
2693 This is a little like an extra or reserve routine to add images to the document.
2694 The most simple way is to use prImage()
2695  
2696 =head2 prJs - add JavaScript
2697  
2698 prJs ( $string|$fileName )
2699  
2700 To add JavaScript to your new document. B<$string> has to consist only of
2701 JavaScript functions: function a (..){ ... } function b (..) { ...} and so on
2702 If B<$string> doesn't contain '{', B<$string> is interpreted as a filename.
2703 In that case the file has to consist only of JavaScript functions.
2704  
2705 B<See "Remarks about JavaScript">
2706  
2707 =head2 prLink - add a hyper link
2708  
2709 prLink( { page => $pageNo, # Starting with 1 !
2710 x => $x,
2711 y => $y,
2712 width => $width,
2713 height => $height,
2714 URI => $URI } );
2715  
2716 You can also call prLink like this:
2717  
2718 prLink($page, $x, $y, $width, $height, $URI);
2719  
2720 You have to put prLink B<after prFile and before the sentences where its' page
2721 is created>. The links are created at the page-breaks. If the page is already
2722 created, no new link will be inserted.
2723  
2724 Here is an example where the links of a 4 page document are preserved, and a link is
2725 added at the end of the document. We assume that there is some suitable text at that
2726 place (x = 400, y = 350):
2727  
2728 use strict;
2729 use PDF::Reuse;
2730  
2731 prFile('test.pdf');
2732  
2733 prLink( {page => 4,
2734 x => 400,
2735 y => 350,
2736 width => 105,
2737 height => 15,
2738 URI => 'http://www.purelyInvented.com/info.html' } );
2739  
2740 prDoc('fourPages.pdf');
2741  
2742 prEnd();
2743  
2744 ( If you are creating each page of a document separately, you can also use 'hyperLink'
2745 from PDF::Reuse::Util. Then you get an external text in Helvetica-Oblique, underlined
2746 and in blue.
2747  
2748 use strict;
2749 use PDF::Reuse;
2750 use PDF::Reuse::Util;
2751  
2752 prFile('test.pdf');
2753 prForm('template.pdf', 5);
2754 my ($from, $pos) = prText(25, 700, 'To get more information ');
2755  
2756 $pos = hyperLink( $pos, 700, 'Press this link',
2757 'http://www.purelyInvented.com/info.html' );
2758 ($from, $pos) = prText( $pos, 700, ' And get connected');
2759 prEnd();
2760  
2761 'hyperLink' has a few parameters: $x, $y, $textToBeShown, $hyperLink and
2762 $fontSize (not shown in the example). It returns current x-position. )
2763  
2764 =head2 prLog - add a string to the log
2765  
2766 prLog ( $string )
2767  
2768 Adds whatever you want to the current log (a reference No, a commentary, a tag ?)
2769 A log has to be active see prLogDir()
2770  
2771 Look at "Using the template" and "Restoring the document from the log" in
2772 the tutorial for an example.
2773  
2774 =head2 prLogDir - set directory for the log
2775  
2776 prLogDir ( $directory )
2777  
2778 Sets a directory for the logs and activates the logging.
2779 A little log file is created for each PDF-file. Normally it should be much, much
2780 more compact then the PDF-file, and it should be possible to restore or verify
2781 a document with the help of it. (Of course you could compress or store the logs in a
2782 database to save even more space.)
2783  
2784 use PDF::Reuse;
2785 use strict;
2786  
2787 prDocDir('C:/temp/doc');
2788 prLogDir('C:/run');
2789  
2790 prFile('myFile.pdf');
2791 prForm('best.pdf');
2792 prText(25, 790, 'Dear Mr. Anders Persson');
2793 # ...
2794 prEnd();
2795  
2796 In this example a log file with the name 'myFile.pdf.dat' is created in the
2797 directory 'C:\run'. If that directory doesn't exist, the system tries to create it.
2798 (But, just as mkdir does, it only creates the last level in a directory tree.)
2799  
2800 =head2 prMbox - define the format (MediaBox) for a new page.
2801  
2802 prMbox ( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY )
2803  
2804 If the function or the parameters are missing, they are set to 0, 0, 595, 842 points respectively.
2805 Only for new pages. Pages created with prDoc and prSinglePage keep their media boxes unchanged.
2806  
2807 See prForm() for an example.
2808  
2809  
2810 =head2 prPage - create/insert a page
2811  
2812 prPage ($noLog)
2813  
2814 Don't use the optional parameter, it is only used internally, not to clutter the log,
2815 when automatic page breaks are made.
2816  
2817  
2818 See prForm() for an example.
2819  
2820 =head2 prSinglePage - take single pages, one by one, from an old document
2821  
2822 prSinglePage($file, $pageNumber)
2823  
2824 $pageNumber is optional. If not given, next page is assumed
2825 Returns number of remaining pages.
2826 This function is a variant of prDoc for single pages, with the addition that it
2827 has a counter of last page read, and total number of pages of the old document,
2828 so it can be used to loop through a document.
2829  
2830  
2831 To add a form, image and page number to each page of a document
2832 (The document Battery.pdf is cropped so each page is fairly small) You could also have
2833 used prDoc, but only if you knew in advance the number of pages of the old document
2834  
2835 use PDF::Reuse;
2836 use PDF::Reuse::Util;
2837 use strict;
2838  
2839 prFile('test.pdf');
2840  
2841 my $pageNumber = 0;
2842 my $left = 1; # Every valid PDF-document has at least 1 page,
2843 # so that can be assumed
2844  
2845 while ($left)
2846 { $pageNumber++;
2847 prForm( { file =>'Words.pdf',
2848 page => 5,
2849 x => 150,
2850 y => 150} );
2851  
2852 prImage( { file =>'Media.pdf',
2853 page => 6,
2854 imageNo => 1,
2855 x => 450,
2856 y => 450 } );
2857 blackText();
2858 prText( 360, 250, $pageNumber);
2859 $left = prSinglePage('Battery.pdf');
2860 }
2861  
2862 prEnd;
2863  
2864 prSinglePage creates a new page from an old document and adds new content (to the array of
2865 streams of that page). Most often you can add new contents to the page like the example above,
2866 and it works fine, but sometimes you get surprises. There can e.g. be instructions in the earlier
2867 contents to make filling color white, and then you will probably not see added new text. That
2868 is why PDF::Reuse::Util::blackText() is used in the example. There can be other instructions
2869 like moving or rotating the user space. Also new contents can end up outside the crop-box.
2870 Of course all new programs should be tested. If prSinglePage can't be used, try to use prForm
2871 followed by prPage instead.
2872  
2873  
2874 =head2 prStrWidth - calculate the string width
2875  
2876 prStrWidth($string, $font, $fontSize)
2877  
2878 Returns string width in points.
2879 Should be used in conjunction with one of these predefined fonts of Acrobat/Reader:
2880 Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold, Courier-Oblique,
2881 Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique,
2882 Helvetica-BoldOblique or with a TrueType font embedded with prTTFont. If some other font is
2883 given, Helvetica is used, and the returned value will at the best be approximate.
2884  
2885 =head2 prText - add a text-string
2886  
2887 prText ( $x, $y, $string, $align, $rotation )
2888  
2889 Puts B<$string> at position B<$x, $y>
2890 Returns 1 in scalar context. Returns ($xFrom, $xTo) in list context. $xTo will not
2891 be defined together with a rotation. prStrWidth() is used to calculate the length of the
2892 strings, so only the predefined fonts together with Acrobat/Reader, or embedded TrueType
2893 fonts will give reliable values for $xTo.
2894  
2895 $align can be 'left' (= default), 'center' or 'right'. The parameter is optional.
2896  
2897 $rotation can be a degree 0 - 360, 'q1', 'q2' or 'q3'. Also optional.
2898  
2899 Current font and font size are used. (If you use prAdd() before this function,
2900 many other things could also influence the text.)
2901  
2902 use strict;
2903 use PDF::Reuse;
2904  
2905 prFile('test.pdf');
2906  
2907 #####################################
2908 # Use a "curser" ($pos) along a line
2909 #####################################
2910  
2911 my ($from, $pos) = prText(25, 800, 'First write this. ');
2912 ($from, $pos) = prText($pos, 800, 'Then write this. ');
2913 prText($pos, 800, 'Finally write this.');
2914  
2915 #####################################
2916 # Right adjust and center sentences
2917 #####################################
2918  
2919 prText( 200, 750, 'A short sentence', 'right');
2920 prText( 200, 735, 'This is a longer sentence', 'right');
2921 prText( 200, 720, 'A word', 'right');
2922  
2923 prText( 200, 705, 'Centered around a point 200 points from the left', 'center');
2924 prText( 200, 690, 'The same center', 'center');
2925 prText( 200, 675, '->.<-', 'center');
2926  
2927 ############
2928 # Rotation
2929 ############
2930  
2931 prText( 200, 550, ' Rotate 0 degrees','', 0);
2932 prText( 200, 550, ' Rotate 60 degrees','', 60);
2933 prText( 200, 550, ' Rotate 120 degrees','', 120);
2934 prText( 200, 550, ' Rotate 180 degrees','', 180);
2935 prText( 200, 550, ' Rotate 240 degrees','', 240);
2936 prText( 200, 550, ' Rotate 300 degrees','', 300);
2937  
2938 prText( 400, 430, 'Rotate 90 degrees clock-wise','','q1');
2939 prText( 400, 430, 'Rotate 180 degrees clock-wise','', 'q2');
2940 prText( 400, 430, 'Rotate 270 degrees clock-wise','', 'q3');
2941  
2942 ##########################
2943 # Rotate and right adjust
2944 ##########################
2945  
2946 prText( 200, 230, 'Rotate 90 degrees clock-wise ra->','right','q1');
2947 prText( 200, 230, 'Rotate 180 degrees clock-wise ra->','right', 'q2');
2948 prText( 200, 230, 'Rotate 270 degrees clock-wise ra->','right', 'q3');
2949  
2950 prEnd();
2951  
2952 =head2 prTTFont - select and embed a TrueType font
2953  
2954 prTTFont ( "/path/to/font/file.ttf" )
2955  
2956 This function is equivalent to C<prFont> except that rather than restricting
2957 you to the list of core built-in fonts, it allows you to select an external
2958 TrueType font file and have it embedded in your PDF document. Using TrueType
2959 fonts also enables the C<prText> function to accept UTF-8 strings, which allows
2960 you to use characters outside the Mac-Roman/Win-ANSI character sets used by the
2961 built-in fonts.
2962  
2963 You can specify the same font path multiple times in one document and only one
2964 copy will be embedded. Alternatively, C<prTTFont> returns an identifier which
2965 can be used to select the same font again:
2966  
2967 my $arial = prTTFont('/path/to/Arial.ttf');
2968 prFontSize(20);
2969 prText(20, 700, 'Some text in Arial');
2970 #
2971 # ... later ...
2972 #
2973 prPage();
2974 prTTFont($arial);
2975 prFontSize(12);
2976 prText(20, 700, 'Some more text in Arial');
2977 #
2978 # to pass a UTF8 string to prText
2979 #
2980 prText(20, 675, "T\x{113}n\x{101} koutou"); # T?n? Koutou
2981  
2982 In list context this function returns C<$internalName>, C<$externalName>,
2983 C<$oldInternalName>, C<$oldExternalname>. The first two variables refer to the
2984 current font, the last two refer to the font before the change. In scalar
2985 context only C<$internalName> is returned.
2986  
2987 Note: To use this function, you must have the L<Font::TTF> and L<Text::PDF>
2988 modules installed.
2989  
2990 Text set in an embedded TrueType font is searchable and copyable: a
2991 /ToUnicode CMap mapping the embedded glyphs back to Unicode is generated
2992 automatically and written with the font. Only the glyphs actually used are
2993 mapped, so the mapping costs nothing for characters the document does not
2994 contain. Code points outside the Basic Multilingual Plane are encoded as
2995 UTF-16BE surrogate pairs, as the PDF specification requires.
2996  
2997 No option is provided to suppress the CMap. It is small, it is what makes
2998 the text usable, and a PDF whose text cannot be extracted is rarely what
2999 anyone wants.
3000  
3001  
3002 =head1 INTERNAL OR DEPRECATED FUNCTIONS
3003  
3004 =over 2
3005  
3006 =item prBar - define and paint bars for bar fonts
3007  
3008 prBar ($x, $y, $string)
3009  
3010 Prints a bar font pattern at the current page.
3011 Returns $internalName for the font.
3012 $x and $y are coordinates in points and $string should consist of the characters
3013 '0', '1' and '2' (or 'G'). '0' is a white bar, '1' is a dark bar. '2' and 'G' are
3014 dark, slightly longer bars, guard bars.
3015 You can use e.g. GD::Barcode or one module in that group to calculate the bar code
3016 pattern. prBar "translates" the pattern to white and black bars.
3017  
3018 use PDF::Reuse;
3019 use GD::Barcode::Code39;
3020 use strict;
3021  
3022 prFile('myFile.pdf');
3023 my $oGdB = GD::Barcode::Code39->new('JOHN DOE');
3024 my $sPtn = $oGdB->barcode();
3025 prBar(100, 600, $sPtn);
3026 prEnd();
3027  
3028 Internally the module uses a font for the bars, so you might want to change the font size before calling
3029 this function. In that case, use prFontSize() .
3030 If you call this function without arguments it defines the bar font but does
3031 not write anything to the current page.
3032  
3033 B<An easier and often better way to produce bar codes is to use PDF::Reuse::Barcode.>
3034 Look at that module!
3035  
3036 =item prCid - define time stamp/check id
3037  
3038 prCid ( $timeStamp )
3039  
3040 An internal function. Don't bother about it. It is used in automatic
3041 routines when you want to restore a document. It gives modification time of
3042 the next PDF-file or JavaScript.
3043 See "Restoring a document from the log" in the tutorial for more about the
3044 time stamp
3045  
3046  
3047  
3048 =item prId - define id-string of a PDF document
3049  
3050 prId ( $string )
3051  
3052 An internal function. Don't bother about it. It is used e.g. when a document is
3053 restored and an id has to be set, not calculated.
3054  
3055 =item prIdType - define id-type
3056  
3057 prIdType ( $string )
3058  
3059 An internal function. Avoid using it. B<$string> could be "Rep" for replace or
3060 "None" to avoid calculating an id.
3061  
3062 Normally you don't use this function. Then an id is calculated with the help of
3063 Digest::MD5::md5_hex and some data from the run.
3064  
3065  
3066 =item prTouchUp - make changes and reuse more difficult
3067  
3068 prTouchUp (1);
3069  
3070 By default and after you have issued prTouchUp(1), you can change the document
3071 with the TouchUp tool from within Acrobat.
3072 If you want to switch off this possibility, you use prTouchUp() without any
3073 parameter. Then the user shouldn't be able to change anything graphic by mistake.
3074 He has to do something premeditated and perhaps with a little effort.
3075 He could still save it as Postscript and redistill, or he could remove or add single pages.
3076 (Here is a strong reason why the log files, and perhaps also check sums, are needed.
3077 It would be very difficult to forge a document unless the forger also has access to your
3078 computer and knows how the check sums are calculated.)
3079  
3080 B<Avoid to switch off the TouchUp tool for your templates.> It creates an
3081 extra level within the PDF-documents . Use this function for your final documents.
3082  
3083 See "Using the template" in the tutorial for an example.
3084  
3085 This function works for pages created with prPage, but mot with prDoc and prSinglePage,
3086 So it is more or less deprecated as these function have developed.
3087  
3088 (To encrypt your documents: use the batch utility within Acrobat)
3089  
3090  
3091 =item prVers - check version of log and program
3092  
3093 prVers ( $versionNo )
3094  
3095 To check version of this module in case a document has to be
3096 restored.
3097  
3098 =back
3099  
3100 =head1 SEE ALSO
3101  
3102 PDF::Reuse::Tutorial
3103 PDF::Reuse::Barcode
3104 PDF::Reuse::OverlayChart
3105  
3106 To program with PDF-operators, look at "The PDF-reference Manual" which probably
3107 is possible to download from http://partners.adobe.com/asn/tech/pdf/specifications.jsp
3108 Look especially at chapter 4 and 5, Graphics and Text, and the Operator summary.
3109  
3110 Technical Note # 5186 contains the "Acrobat JavaScript Object Specification". I
3111 downloaded it from http://partners.adobe.com/asn/developer/technotes/acrobatpdf.html
3112  
3113 If you are serious about producing PDF-files, you probably need Adobe Acrobat sooner
3114 or later. It has a price tag. Other good programs are GhostScript and GSview.
3115 I got them via http://www.cs.wisc.edu/~ghost/index.html Sometimes they can replace Acrobat.
3116 A nice little detail is e.g. that GSview shows the x- and y-coordinates better then Acrobat. If you need to convert HTML-files to PDF, HTMLDOC is a possible tool. Download it from
3117 http://www.easysw.com . A simple tool for vector graphics is Mayura Draw 2.04, download
3118 it from http://www.mayura.com. It is free. I have used it to produce the graphic
3119 OO-code in the tutorial. It produces postscript which the Acrobat Distiller (you get it together with Acrobat)
3120 or Ghostscript can convert to PDF.(The commercial product, Mayura Draw 4.01 or something
3121 higher can produce PDF-files straight away)
3122  
3123 If you want to import jpeg-images, you might need
3124  
3125 Image::Info
3126  
3127 To get definitions for e.g. colors, take them from
3128  
3129 PDF::API2::Util
3130  
3131 =head1 LIMITATIONS
3132  
3133 Meta data, info and many other features of the PDF-format have not been
3134 implemented in this module.
3135  
3136 Many things can be added afterwards, after creating the files. If you e.g. need
3137 files to be encrypted, you can use a standard batch routine within Adobe Acrobat.
3138  
3139 =head1 THANKS TO
3140  
3141 Martin Langhoff, Matisse Enzer, Yunliang Yu and others who have contributed with code, suggestions and error
3142 reports.
3143  
3144 Grant McLean has implemented font embedding by grafting Font::TTF and
3145 Text::PDF::TTFont0 onto the PDF::Reuse API. He has written the embedded packages PDF::Reuse::DocProxy
3146 and PDF::Reuse::TTFont.
3147  
3148 The functionality of prDoc and prSinglePage to include new contents was developed for a
3149 specific task with support from the Electoral Enrolment Centre, Wellington, New Zealand
3150  
3151 =head1 MAILING LIST
3152  
3153 http://groups.google.com/group/PDF-Reuse
3154  
3155 =head1 AUTHOR
3156  
3157 Lars Lundberg larslund@cpan.org
3158 Chris Nighswonger cnighs@cpan.org
3159  
3160 =head1 COPYRIGHT
3161  
3162 Copyright (C) 2003 - 2004 Lars Lundberg, Solidez HB.
3163 Copyright (C) 2005 Karin Lundberg.
3164 Copyright (C) 2006 - 2010 Lars Lundberg, Solidez HB.
3165 Copyright (C) 2010 - 2019 Chris Nighswonger
3166 This program is free software; you can redistribute it and/or
3167 modify it under the same terms as Perl itself.
3168  
3169 =head1 DISCLAIMER
3170  
3171 You get this module free as it is, but nothing is guaranteed to work, whatever
3172 implicitly or explicitly stated in this document, and everything you do,
3173 you do at your own risk - I will not take responsibility
3174 for any damage, loss of money and/or health that may arise from the use of this module.
3175  
3176 =cut
3177  
3178 sub prSinglePage
3179 0 ▶{ my $infil = shift;
Subroutine prSinglePage: not called CC=9 SCAR=45.0
Pod documented
3180 0 my $pageNumber = shift;
3181  
3182 0 ▶ if (! defined $pageNumber)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pageNumber) 0 0 0
3183 { $behandlad{$infil}->{pageNumber} = 0
3184 0 ▶ unless (defined $behandlad{$infil}->{pageNumber});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"pageNumber"} 0 0 0
3185 0 $pageNumber = $behandlad{$infil}->{pageNumber} + 1;
3186 }
3187  
3188 0 my ($sida, $Names, $AARoot, $AcroForm) = analysera($infil, $pageNumber, $pageNumber, 1);
3189 0 ▶ if (($Names) || ($AARoot) || ($AcroForm))
Branch: 1 branch
BranchTrueFalseTotal
if ($Names or $AARoot or $AcroForm) 0 0 0
Condition0%0/6
$Names or $AARoot or $AcroForm
l!l&&r!l&&!r
000
$Names or $AARoot
l!l&&r!l&&!r
000
MC/DC0%0/3
$Names or $AARoot or $AcroForm
$Names $AARoot $AcroForm
Truth table0%0/4
A or B or C
A= $NamesB= $AARootC= $AcroForm
ABCresult
1XX1
01X1
0011
0000
3190 0 { $NamesSaved = $Names;
3191 0 $AARootSaved = $AARoot;
3192 0 $AcroFormSaved = $AcroForm;
3193 0 $interActive = 1;
3194 }
3195 0 ▶ if (defined $sida)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sida) 0 0 0
3196 0 { $behandlad{$infil}->{pageNumber} = $pageNumber;
3197 }
3198 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3199 0 { $infil = prep($infil);
3200 0 $log .= "prSinglePage~$infil~$pageNumber\n";
3201 }
3202 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3203 0 { errLog("No output file, you have to call prFile first");
3204 }
3205 0 return $sida;
3206  
3207 }
3208  
3209  
3210  
3211 sub prLink
3212 0 ▶{ my %link;
Subroutine prLink: not called CC=17 SCAR=57.2
Pod documented
3213 0 my $param = shift;
3214 0 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 0 0
3215 0 ▶ { $link{page} = $param->{'page'} || -1;
Condition0%0/2
$param->{'page'} || -1
l!l
00
MC/DC0%0/1
$param->{'page'} || -1
$param->{'page'}
Truth table0%0/2
A
A= $param->{'page'}
Aresult
11
00
3216 0 ▶ $link{x} = $param->{'x'} || 100;
Condition0%0/2
$param->{'x'} || 100
l!l
00
MC/DC0%0/1
$param->{'x'} || 100
$param->{'x'}
Truth table0%0/2
A
A= $param->{'x'}
Aresult
11
00
3217 0 ▶ $link{y} = $param->{'y'} || 100;
Condition0%0/2
$param->{'y'} || 100
l!l
00
MC/DC0%0/1
$param->{'y'} || 100
$param->{'y'}
Truth table0%0/2
A
A= $param->{'y'}
Aresult
11
00
3218 0 ▶ $link{width} = $param->{width} || 75;
Condition0%0/2
$param->{'width'} || 75
l!l
00
MC/DC0%0/1
$param->{'width'} || 75
$param->{'width'}
Truth table0%0/2
A
A= $param->{'width'}
Aresult
11
00
3219 0 ▶ $link{height} = $param->{height} || 15;
Condition0%0/2
$param->{'height'} || 15
l!l
00
MC/DC0%0/1
$param->{'height'} || 15
$param->{'height'}
Truth table0%0/2
A
A= $param->{'height'}
Aresult
11
00
3220 0 $link{v} = $param->{URI};
3221 0 ▶ $link{s} = $param->{s} || "URI";
Condition0%0/2
$param->{'s'} || 'URI'
l!l
00
MC/DC0%0/1
$param->{'s'} || 'URI'
$param->{'s'}
Truth table0%0/2
A
A= $param->{'s'}
Aresult
11
00
3222 }
3223 else
3224 0 ▶ { $link{page} = $param || -1;
Condition0%0/2
$param || -1
l!l
00
MC/DC0%0/1
$param || -1
$param
Truth table0%0/2
A
A= $param
Aresult
11
00
3225 0 ▶ $link{x} = shift || 100;
Condition0%0/2
shift() || 100
l!l
00
MC/DC0%0/1
shift() || 100
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3226 0 ▶ $link{y} = shift || 100;
Condition0%0/2
shift() || 100
l!l
00
MC/DC0%0/1
shift() || 100
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3227 0 ▶ $link{width} = shift || 75;
Condition0%0/2
shift() || 75
l!l
00
MC/DC0%0/1
shift() || 75
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3228 0 ▶ $link{height} = shift || 15;
Condition0%0/2
shift() || 15
l!l
00
MC/DC0%0/1
shift() || 15
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3229 0 $link{v} = shift;
3230 0 ▶ $link{s} = shift || "URI";
Condition0%0/2
shift() || 'URI'
l!l
00
MC/DC0%0/1
shift() || 'URI'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3231 }
3232  
3233 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3234 0 { errLog("No output file, you have to call prFile first");
3235 }
3236  
3237 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3238 0 { $log .= "Link~$link{page}~$link{x}~$link{y}~$link{width}~"
3239 . "$link{height}~$link{v}~$link{s}\n";
3240 }
3241  
3242 0 ▶ if ($link{v})
Branch: 1 branch
BranchTrueFalseTotal
if ($link{"v"}) 0 0 0
3243 0 { push @{$links{$link{page}}}, \%link;
3244 }
3245 0 1;
3246 }
3247  
3248 sub mergeLinks
3249 0 ▶{ my $tSida = $sida + 1;
Subroutine mergeLinks: not called CC=11 SCAR=48.8
Pod undocumented
3250 0 my $rad;
3251 0 my ($linkObject, $linkObjectNo);
3252 0 for my $link (@{$links{'-1'}}, @{$links{$tSida}} )
3253 0 { my $x2 = $link->{x} + $link->{width};
3254 0 my $y2 = $link->{y} + $link->{height};
3255 0 ▶ if (exists $links{$link->{v}})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::links{$link->{'v'}}) { } 0 0 0
3256 0 { $linkObjectNo = $links{$link->{v}};
3257 }
3258 else
3259 0 { $objNr++;
3260 0 $objekt[$objNr] = $pos;
3261 0 my $v_n;
3262 0 my $v_v = '('.$link->{v}.')';
3263 0 ▶ if ($link->{s} eq 'GoTo')
Branch: 6 branches
BranchTrueFalseTotal
if ($link->{'s'} eq 'GoTo') { } 0 0 0
elsif ($link->{'s'} eq 'GoToA') { } 0 0 0
elsif ($link->{'s'} eq 'Launch') { } 0 0 0
elsif ($link->{'s'} eq 'SubmitForm') { } 0 0 0
elsif ($link->{'s'} eq 'Named') { } 0 0 0
elsif ($link->{'s'} eq 'JavaScript') { } 0 0 0
3264 0 { $v_n = "D";
3265 }
3266 elsif ($link->{s} eq 'GoToA')
3267 0 { $link->{s} = 'GoTo';
3268 0 $v_n = 'D';
3269 0 $v_v = $link->{v};
3270 }
3271 0 elsif ($link->{s} eq 'Launch') {$v_n = 'F';}
3272 0 elsif ($link->{s} eq 'SubmitForm') {$v_n = 'F';}
3273 elsif ($link->{s} eq 'Named')
3274 0 { $v_n = 'N';
3275 0 $v_v = $link->{v};
3276 }
3277 0 elsif ($link->{s} eq 'JavaScript') {$v_n = "JS";}
3278 else
3279 0 { $v_n = $link->{s};
3280 }
3281 0 $rad = "$objNr 0 obj<</S/$link->{s}/$v_n$v_v>>endobj\n";
3282 0 $linkObjectNo = $objNr;
3283 0 $links{$link->{v}} = $objNr;
3284 0 $pos += syswrite UTFIL, $rad;
3285 }
3286 0 $rad = "/Subtype/Link/Rect[$link->{x} $link->{y} "
3287 . "$x2 $y2]/A $linkObjectNo 0 R/Border[0 0 0]";
3288 0 ▶ if (exists $links{$rad})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::links{$rad}) { } 0 0 0
3289 0 { push @annots, $links{$rad};
3290 }
3291 else
3292 0 { $objNr++;
3293 0 $objekt[$objNr] = $pos;
3294 0 $links{$rad} = $objNr;
3295 0 $rad = "$objNr 0 obj<<$rad>>endobj\n";
3296 0 $pos += syswrite UTFIL, $rad;
3297 0 push @annots, $objNr;
3298 }
3299 }
3300 0 @{$links{'-1'}} = ();
3301 0 @{$links{$tSida}} = ();
3302 0 $objNr++;
3303 0 $objekt[$objNr] = $pos;
3304 0 $rad = "$objNr 0 obj[\n";
3305 0 for (@annots)
3306 0 { $rad .= "$_ 0 R\n";
3307 }
3308 0 $rad .= "]endobj\n";
3309 0 $pos += syswrite UTFIL, $rad;
3310 0 @annots = ();
3311 0 return $objNr;
3312 }
3313  
3314  
3315 sub prBookmark
3316 0 ▶{ my $param = shift;
Subroutine prBookmark: not called CC=6 SCAR=37.4
Pod documented
3317 0 ▶ if (! ref($param))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param) 0 0 0
3318 0 { $param = eval ($param);
3319 }
3320 0 ▶ if (! ref($param))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param) 0 0 0
3321 0 { return undef;
3322 }
3323 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3324 0 { errLog("No output file, you have to call prFile first");
3325 }
3326 0 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 0 0
3327 0 { push @bookmarks, $param;
3328 }
3329 else
3330 0 { push @bookmarks, (@$param);
3331 }
3332 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3333 0 { local $Data::Dumper::Indent = 0;
3334 0 $param = Dumper($param);
3335 0 $param =~ s/^\$VAR1 = //;
3336 0 $param = prep($param);
3337 0 $log .= "Bookmark~$param\n";
3338 }
3339 0 return 1;
3340 }
3341  
3342 sub ordnaBookmarks
3343 0 ▶{ my ($first, $last, $me, $entry, $rad);
Subroutine ordnaBookmarks: not called CC=10 SCAR=47.0
Pod undocumented
3344 0 $totalCount = 0;
3345 0 ▶ if (defined $objekt[$objNr])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::objekt[$PDF::Reuse::objNr]) 0 0 0
3346 0 { $objNr++;
3347 }
3348 0 $me = $objNr;
3349  
3350 0 my $number = $#bookmarks;
3351 0 ▶ for (my $i = 0; $i <= $number ; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $number) 0 0 0
3352 0 { my %hash = %{$bookmarks[$i]};
3353 0 $objNr++;
3354 0 $hash{'this'} = $objNr;
3355 0 ▶ if ($i == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 0 0 0
3356 0 { $first = $objNr;
3357 }
3358 0 ▶ if ($i == $number)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $number) 0 0 0
3359 0 { $last = $objNr;
3360 }
3361 0 ▶ if ($i < $number)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $number) 0 0 0
3362 0 { $hash{'next'} = $objNr + 1;
3363 }
3364 0 ▶ if ($i > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
3365 0 { $hash{'previous'} = $objNr - 1;
3366 }
3367 0 $bookmarks[$i] = \%hash;
3368 }
3369  
3370 0 for $entry (@bookmarks)
3371 0 { my %hash = %{$entry};
3372 0 descend ($me, %hash);
3373 }
3374  
3375 0 $objekt[$me] = $pos;
3376  
3377 0 $rad = "$me 0 obj<<";
3378 0 $rad .= "/Type/Outlines";
3379 0 $rad .= "/Count $totalCount";
3380 0 ▶ if (defined $first)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first) 0 0 0
3381 0 { $rad .= "/First $first 0 R";
3382 }
3383 0 ▶ if (defined $last)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last) 0 0 0
3384 0 { $rad .= "/Last $last 0 R";
3385 }
3386 0 $rad .= ">>endobj\n";
3387 0 $pos += syswrite UTFIL, $rad;
3388  
3389 0 return $me;
3390  
3391 }
3392  
3393 sub descend
3394 0 ▶{ my ($parent, %entry) = @_;
Subroutine descend: not called CC=22 SCAR=62.3
Pod undocumented
3395 0 my ($first, $last, $count, $me, $rad, $jsObj);
3396 0 ▶ if (! exists $entry{'close'})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $entry{"close"}) 0 0 0
3397 0 { $totalCount++; }
3398 0 $count = $totalCount;
3399 0 $me = $entry{'this'};
3400 0 ▶ if (exists $entry{'kids'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"kids"}) 0 0 0
3401 0 ▶ { if (ref($entry{'kids'}) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $entry{'kids'} eq 'ARRAY') { } 0 0 0
3402 0 { my @array = @{$entry{'kids'}};
3403 0 my $number = $#array;
3404 0 ▶ for (my $i = 0; $i <= $number ; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $number) 0 0 0
3405 0 { $objNr++;
3406 0 $array[$i]->{'this'} = $objNr;
3407 0 ▶ if ($i == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 0 0 0
3408 0 { $first = $objNr;
3409 }
3410 0 ▶ if ($i == $number)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $number) 0 0 0
3411 0 { $last = $objNr;
3412 }
3413  
3414 0 ▶ if ($i < $number)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $number) 0 0 0
3415 0 { $array[$i]->{'next'} = $objNr + 1;
3416 }
3417 0 ▶ if ($i > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
3418 0 { $array[$i]->{'previous'} = $objNr - 1;
3419 }
3420 0 ▶ if (exists $entry{'close'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"close"}) 0 0 0
3421 0 { $array[$i]->{'close'} = 1;
3422 }
3423 }
3424  
3425 0 for my $element (@array)
3426 0 { descend($me, %{$element})
3427 }
3428 }
3429 else # a hash
3430 0 { my %hash = %{$entry{'kids'}};
3431 0 $objNr++;
3432 0 $hash{'this'} = $objNr;
3433 0 $first = $objNr;
3434 0 $last = $objNr;
3435 0 descend($me, %hash)
3436 }
3437 }
3438  
3439  
3440 0 $objekt[$me] = $pos;
3441 0 $rad = "$me 0 obj<<";
3442 0 ▶ if (exists $entry{'text'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"text"}) 0 0 0
3443 0 { $rad .= "/Title ($entry{'text'})";
3444 }
3445 0 $rad .= "/Parent $parent 0 R";
3446 0 ▶ if (defined $jsObj)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $jsObj) 0 0 0
3447 0 { $rad .= "/A $jsObj 0 R";
3448 }
3449 0 ▶ if (exists $entry{'act'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"act"}) 0 0 0
3450 0 { my $code = $entry{'act'};
3451 0 ▶ if ($code =~ m/(\d+)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /(\d+)/so) 0 0 0
3452 {
3453 0 $code = $1;
3454 }
3455 0 $rad .= "/Dest [$code /XYZ null null null] ";
3456 }
3457 0 ▶ if (exists $entry{'previous'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"previous"}) 0 0 0
3458 0 { $rad .= "/Prev $entry{'previous'} 0 R";
3459 }
3460 0 ▶ if (exists $entry{'next'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"next"}) 0 0 0
3461 0 { $rad .= "/Next $entry{'next'} 0 R";
3462 }
3463 0 ▶ if (defined $first)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first) 0 0 0
3464 0 { $rad .= "/First $first 0 R";
3465 }
3466 0 ▶ if (defined $last)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last) 0 0 0
3467 0 { $rad .= "/Last $last 0 R";
3468 }
3469 0 ▶ if ($count != $totalCount)
Branch: 1 branch
BranchTrueFalseTotal
if ($count != $PDF::Reuse::totalCount) 0 0 0
3470 0 { $count = $totalCount - $count;
3471 0 $rad .= "/Count $count";
3472 }
3473 0 ▶ if (exists $entry{'color'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"color"}) 0 0 0
3474 0 { $rad .= "/C [$entry{'color'}]";
3475 }
3476 0 ▶ if (exists $entry{'style'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $entry{"style"}) 0 0 0
3477 0 { $rad .= "/F $entry{'style'}";
3478 }
3479  
3480 0 $rad .= ">>endobj\n";
3481 0 $pos += syswrite UTFIL, $rad;
3482 }
3483  
3484 sub prInitVars
3485 0 ▶{ my $exit = shift;
Subroutine prInitVars: not called CC=6 SCAR=37.4
Pod documented
3486 0 $genLowerX = 0;
3487 0 $genLowerY = 0;
3488 0 $genUpperX = 595,
3489 $genUpperY = 842;
3490 0 $fontSize = 12;
3491 0 ($utfil, $slutNod, $formCont, $imSeq,
3492 $page, $sidObjNr, $interActive, $NamesSaved, $AARootSaved, $AAPageSaved,
3493 $root, $AcroFormSaved, $id, $ldir, $checkId, $formNr, $imageNr,
3494 $filnamn, $interAktivSida, $taInterAkt, $type, $runfil, $checkCs,
3495 $confuseObj, $compress,$pos, $fontNr, $objNr,
3496 $defGState, $gSNr, $pattern, $shading, $colorSpace) = '';
3497  
3498 0 ▶ if ($docProxy)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::docProxy) 0 0 0
3499 0 { for my $obj (values %{ $docProxy->{' objcache'} })
3500 0 ▶ { if ($obj->isa('Text::PDF::TTFont0'))
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Text::PDF::TTFont0")) 0 0 0
3501 0 ▶ { if (my $font = delete $obj->{' font'})
Branch: 1 branch
BranchTrueFalseTotal
if (my $font = delete $obj->{" font"}) 0 0 0
3502 0 { $font->release();
3503 }
3504 0 $obj->release();
3505 }
3506 }
3507 0 undef $docProxy;
3508 }
3509  
3510 0 (@kids, @counts, @formBox, @objekt, @parents, @aktuellFont, @skapa,
3511 @jsfiler, @inits, @bookmarks, @annots) = ();
3512  
3513 0 ( %resurser, %objRef, %nyaFunk,%oldObject, %unZipped,
3514 %sidFont, %sidXObject, %sidExtGState, %font, %fields, %script,
3515 %initScript, %sidPattern, %sidShading, %sidColorSpace, %knownToFile,
3516 %processed, %dummy) = ();
3517  
3518 0 $stream = '';
3519 0 $idTyp = '';
3520 0 $ddir = '';
3521 0 $log = '';
3522  
3523 0 ▶ if ($exit)
Branch: 1 branch
BranchTrueFalseTotal
if ($exit) 0 0 0
3524 0 { return 1;
3525 }
3526  
3527 0 ( %form, %image, %fontSource, %intAct) = ();
3528  
3529 0 return 1;
3530 }
3531  
3532 ####################
3533 # Behandla en bild
3534 ####################
3535  
3536 sub prImage
3537 0 ▶{ my $param = shift;
Subroutine prImage: not called CC=36 SCAR=71.9
Pod documented
3538 0 my ($infil, $sidnr, $bildnr, $effect, $adjust, $x, $y, $size, $xsize,
3539 $ysize, $rotate);
3540  
3541 0 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 0 0
3542 0 { $infil = $param->{'file'};
3543 0 ▶ $sidnr = $param->{'page'} || 1;
Condition0%0/2
$param->{'page'} || 1
l!l
00
MC/DC0%0/1
$param->{'page'} || 1
$param->{'page'}
Truth table0%0/2
A
A= $param->{'page'}
Aresult
11
00
3544 0 ▶ $bildnr = $param->{'imageNo'} || 1;
Condition0%0/2
$param->{'imageNo'} || 1
l!l
00
MC/DC0%0/1
$param->{'imageNo'} || 1
$param->{'imageNo'}
Truth table0%0/2
A
A= $param->{'imageNo'}
Aresult
11
00
3545 0 ▶ $effect = $param->{'effect'} || 'print';
Condition0%0/2
$param->{'effect'} || 'print'
l!l
00
MC/DC0%0/1
$param->{'effect'} || 'print'
$param->{'effect'}
Truth table0%0/2
A
A= $param->{'effect'}
Aresult
11
00
3546 0 ▶ $adjust = $param->{'adjust'} || '';
Condition0%0/2
$param->{'adjust'} || ''
l!l
00
MC/DC0%0/1
$param->{'adjust'} || ''
$param->{'adjust'}
Truth table0%0/2
A
A= $param->{'adjust'}
Aresult
11
00
3547 0 ▶ $x = $param->{'x'} || 0;
Condition0%0/2
$param->{'x'} || 0
l!l
00
MC/DC0%0/1
$param->{'x'} || 0
$param->{'x'}
Truth table0%0/2
A
A= $param->{'x'}
Aresult
11
00
3548 0 ▶ $y = $param->{'y'} || 0;
Condition0%0/2
$param->{'y'} || 0
l!l
00
MC/DC0%0/1
$param->{'y'} || 0
$param->{'y'}
Truth table0%0/2
A
A= $param->{'y'}
Aresult
11
00
3549 0 ▶ $rotate = $param->{'rotate'} || 0;
Condition0%0/2
$param->{'rotate'} || 0
l!l
00
MC/DC0%0/1
$param->{'rotate'} || 0
$param->{'rotate'}
Truth table0%0/2
A
A= $param->{'rotate'}
Aresult
11
00
3550 0 ▶ $size = $param->{'size'} || 1;
Condition0%0/2
$param->{'size'} || 1
l!l
00
MC/DC0%0/1
$param->{'size'} || 1
$param->{'size'}
Truth table0%0/2
A
A= $param->{'size'}
Aresult
11
00
3551 0 ▶ $xsize = $param->{'xsize'} || 1;
Condition0%0/2
$param->{'xsize'} || 1
l!l
00
MC/DC0%0/1
$param->{'xsize'} || 1
$param->{'xsize'}
Truth table0%0/2
A
A= $param->{'xsize'}
Aresult
11
00
3552 0 ▶ $ysize = $param->{'ysize'} || 1;
Condition0%0/2
$param->{'ysize'} || 1
l!l
00
MC/DC0%0/1
$param->{'ysize'} || 1
$param->{'ysize'}
Truth table0%0/2
A
A= $param->{'ysize'}
Aresult
11
00
3553 }
3554 else
3555 0 { $infil = $param;
3556 0 ▶ $sidnr = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3557 0 ▶ $bildnr = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3558 0 ▶ $effect = shift || 'print';
Condition0%0/2
shift() || 'print'
l!l
00
MC/DC0%0/1
shift() || 'print'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3559 0 ▶ $adjust = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3560 0 ▶ $x = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3561 0 ▶ $y = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3562 0 ▶ $rotate = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3563 0 ▶ $size = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3564 0 ▶ $xsize = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3565 0 ▶ $ysize = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3566 }
3567  
3568 0 my ($refNr, $inamn, $bildIndex, $xc, $yc, $xs, $ys);
3569 0 $type = 'image';
3570  
3571 0 $bildIndex = $bildnr - 1;
3572 0 my $fSource = $infil . '_' . $sidnr;
3573 0 my $iSource = $fSource . '_' . $bildnr;
3574 0 ▶ if (! exists $image{$iSource})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::image{$iSource}) 0 0 0
3575 0 { $imageNr++;
3576 0 $inamn = 'Ig' . $imageNr;
3577 0 $knownToFile{'Ig:' . $iSource} = $inamn;
3578 0 $image{$iSource}[imXPOS] = 0;
3579 0 $image{$iSource}[imYPOS] = 0;
3580 0 $image{$iSource}[imXSCALE] = 1;
3581 0 $image{$iSource}[imYSCALE] = 1;
3582 0 ▶ if (! exists $form{$fSource} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::form{$fSource}) 0 0 0
3583 0 { $refNr = getPage($infil, $sidnr, '');
3584 0 ▶ if ($refNr)
Branch: 2 branches
BranchTrueFalseTotal
if ($refNr) { } 0 0 0
elsif (defined $refNr and $refNr eq '0') { } 0 0 0
3585 0 { $formNr++;
3586 0 my $namn = 'Fm' . $formNr;
3587 0 $knownToFile{$fSource} = $namn;
3588 }
3589 ▶ elsif ((defined $refNr) && ($refNr eq '0'))
Condition0%0/3
defined $refNr and $refNr eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $refNr and $refNr eq 0
defined $refNr $refNr eq 0
Truth table0%0/3
A and B
A= defined $refNrB= $refNr eq 0
ABresult
0X0
100
111
3590 0 { errLog("File: $infil Page: $sidnr can't be found");
3591 }
3592 }
3593 0 my $in = $form{$fSource}[fIMAGES][$bildIndex];
3594 0 $image{$iSource}[imWIDTH] = $form{$fSource}->[fOBJ]->{$in}->[oWIDTH];
3595 0 $image{$iSource}[imHEIGHT] = $form{$fSource}->[fOBJ]->{$in}->[oHEIGHT];
3596 0 $image{$iSource}[imIMAGENO] = $form{$fSource}[fIMAGES][$bildIndex];
3597 }
3598 0 ▶ if (exists $knownToFile{'Ig:' . $iSource})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::knownToFile{'Ig:' . $iSource}) { } 0 0 0
3599 0 { $inamn = $knownToFile{'Ig:' . $iSource};
3600 }
3601 else
3602 0 { $imageNr++;
3603 0 $inamn = 'Ig' . $imageNr;
3604 0 $knownToFile{'Ig:' . $iSource} = $inamn;
3605 }
3606 0 ▶ if (! exists $objRef{$inamn})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::objRef{$inamn}) { } 0 0 0
3607 { $refNr = getImage($infil, $sidnr,
3608 0 $bildnr, $image{$iSource}[imIMAGENO]);
3609 0 $objRef{$inamn} = $refNr;
3610 }
3611 else
3612 0 { $refNr = $objRef{$inamn};
3613 }
3614  
3615 0 my @iData = @{$image{$iSource}};
3616  
3617 0 ▶ if (($effect eq 'print') && ($refNr))
Branch: 1 branch
BranchTrueFalseTotal
if ($effect eq "print" and $refNr) 0 0 0
Condition0%0/3
$effect eq "print" and $refNr
!ll&&!rl&&r
000
MC/DC0%0/2
$effect eq "print" and $refNr
$effect eq "print" $refNr
Truth table0%0/3
A and B
A= $effect eq "print"B= $refNr
ABresult
0X0
100
111
3618 0 ▶ { if (! defined $defGState)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::defGState) 0 0 0
3619 0 { prDefaultGrState();}
3620 0 $stream .= "\n/Gs0 gs\n";
3621 0 $stream .= "q\n";
3622  
3623 0 ▶ if ($adjust)
Branch: 1 branch
BranchTrueFalseTotal
if ($adjust) { } 0 0 0
3624 0 { $stream .= fillTheForm(0, 0, $iData[imWIDTH], $iData[imHEIGHT],$adjust);
3625 }
3626 else
3627 0 { my $tX = ($x + $iData[imXPOS]);
3628 0 my $tY = ($y + $iData[imYPOS]);
3629 0 $stream .= calcMatrix($tX, $tY, $rotate, $size,
3630 $xsize, $ysize, $iData[imWIDTH], $iData[imHEIGHT]);
3631 }
3632 0 $stream .= "$iData[imWIDTH] 0 0 $iData[imHEIGHT] 0 0 cm\n";
3633 0 $stream .= "/$inamn Do\n";
3634 0 $sidXObject{$inamn} = $refNr;
3635 0 $stream .= "Q\n";
3636 0 $sidExtGState{'Gs0'} = $defGState;
3637 }
3638 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3639 0 { $infil = prep($infil);
3640 0 $log .= "Image~$infil~$sidnr~$bildnr~$effect~$adjust";
3641 0 $log .= "$x~$y~$size~$xsize~$ysize~$rotate\n";
3642 }
3643 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3644 0 { errLog("No output file, you have to call prFile first");
3645 }
3646  
3647 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
3648 0 { return ($inamn, $iData[imWIDTH], $iData[imHEIGHT]);
3649 }
3650 else
3651 0 { return $inamn;
3652 }
3653 }
3654  
3655  
3656  
3657 sub prMbox
3658 0 ▶{ my $lx = defined($_[0]) ? shift : 0;
Subroutine prMbox: not called CC=15 SCAR=54.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
3659 0 ▶ my $ly = defined($_[0]) ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
3660 0 ▶ my $ux = defined($_[0]) ? shift : 595;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
3661 0 ▶ my $uy = defined($_[0]) ? shift : 842;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
3662  
3663 0 ▶ if ((defined $lx) && ($lx =~ m'^[\d\-\.]+$'o))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lx and $lx =~ /^[\d\-\.]+$/o) 0 0 0
Condition0%0/3
defined $lx and $lx =~ /^[\d\-\.]+$/o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $lx and $lx =~ /^[\d\-\.]+$/o
defined $lx $lx =~ /^[\d\-\.]+$/o
Truth table0%0/3
A and B
A= defined $lxB= $lx =~ /^[\d\-\.]+$/o
ABresult
0X0
100
111
3664 0 { $genLowerX = $lx; }
3665 0 ▶ if ((defined $ly) && ($ly =~ m'^[\d\-\.]+$'o))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ly and $ly =~ /^[\d\-\.]+$/o) 0 0 0
Condition0%0/3
defined $ly and $ly =~ /^[\d\-\.]+$/o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ly and $ly =~ /^[\d\-\.]+$/o
defined $ly $ly =~ /^[\d\-\.]+$/o
Truth table0%0/3
A and B
A= defined $lyB= $ly =~ /^[\d\-\.]+$/o
ABresult
0X0
100
111
3666 0 { $genLowerY = $ly; }
3667 0 ▶ if ((defined $ux) && ($ux =~ m'^[\d\-\.]+$'o))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ux and $ux =~ /^[\d\-\.]+$/o) 0 0 0
Condition0%0/3
defined $ux and $ux =~ /^[\d\-\.]+$/o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ux and $ux =~ /^[\d\-\.]+$/o
defined $ux $ux =~ /^[\d\-\.]+$/o
Truth table0%0/3
A and B
A= defined $uxB= $ux =~ /^[\d\-\.]+$/o
ABresult
0X0
100
111
3668 0 { $genUpperX = $ux; }
3669 0 ▶ if ((defined $uy) && ($uy =~ m'^[\d\-\.]+$'o))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uy and $uy =~ /^[\d\-\.]+$/o) 0 0 0
Condition0%0/3
defined $uy and $uy =~ /^[\d\-\.]+$/o
!ll&&!rl&&r
000
MC/DC0%0/2
defined $uy and $uy =~ /^[\d\-\.]+$/o
defined $uy $uy =~ /^[\d\-\.]+$/o
Truth table0%0/3
A and B
A= defined $uyB= $uy =~ /^[\d\-\.]+$/o
ABresult
0X0
100
111
3670 0 { $genUpperY = $uy; }
3671 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3672 0 { $log .= "Mbox~$lx~$ly~$ux~$uy\n";
3673 }
3674 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3675 0 { errLog("No output file, you have to call prFile first");
3676 }
3677 0 1;
3678 }
3679  
3680 sub prField
3681 0 ▶{ my ($fieldName, $fieldValue) = @_;
Subroutine prField: not called CC=8 SCAR=42.8
Pod documented
3682 0 ▶ if (($interAktivSida) || ($interActive))
Branch: 2 branches
BranchTrueFalseTotal
if ($PDF::Reuse::interAktivSida or $PDF::Reuse::interActive) { } 0 0 0
elsif (not $PDF::Reuse::pos) { } 0 0 0
Condition0%0/3
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
$PDF::Reuse::interAktivSida $PDF::Reuse::interActive
Truth table0%0/3
A or B
A= $PDF::Reuse::interAktivSidaB= $PDF::Reuse::interActive
ABresult
1X1
011
000
3683 0 { errLog("Too late, has already tried to INITIATE FIELDS within an interactive page");
3684 }
3685 elsif (! $pos)
3686 0 { errLog("Too early INITIATE FIELDS, create a file first");
3687 }
3688 0 $fields{$fieldName} = $fieldValue;
3689 0 ▶ if ($fieldValue =~ m'^\s*js\s*\:(.*)'oi)
Branch: 1 branch
BranchTrueFalseTotal
if ($fieldValue =~ /^\s*js\s*\:(.*)/io) 0 0 0
3690 0 { my $code = $1;
3691 0 my @fall = ($code =~ m'([\w\d\_\$]+)\s*\(.*?\)'gs);
3692 0 for (@fall)
3693 0 ▶ { if (! exists $initScript{$_})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::initScript{$_}) 0 0 0
3694 0 { $initScript{$_} = 0;
3695 }
3696 }
3697 }
3698 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3699 0 { $fieldName = prep($fieldName);
3700 0 $fieldValue = prep($fieldValue);
3701 0 $log .= "Field~$fieldName~$fieldValue\n";
3702 }
3703 0 1;
3704 }
3705 ############################################################
3706 sub prBar
3707 0 ▶{ my ($xPos, $yPos, $TxT) = @_;
Subroutine prBar: not called CC=5 SCAR=34.0
Pod documented
3708  
3709 0 $TxT =~ tr/G/2/;
3710  
3711 0 my @fontSpar = @aktuellFont;
3712  
3713 0 findBarFont();
3714  
3715 0 my $Font = $aktuellFont[foINTNAMN]; # Namn i strömmen
3716  
3717 0 ▶ if (($xPos) && ($yPos))
Branch: 1 branch
BranchTrueFalseTotal
if ($xPos and $yPos) 0 0 0
Condition0%0/3
$xPos and $yPos
!ll&&!rl&&r
000
MC/DC0%0/2
$xPos and $yPos
$xPos $yPos
Truth table0%0/3
A and B
A= $xPosB= $yPos
ABresult
0X0
100
111
3718 0 { $stream .= "\nBT /$Font $fontSize Tf ";
3719 0 $stream .= "$xPos $yPos Td \($TxT\) Tj ET\n";
3720 }
3721 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3722 0 { $log .= "Bar~$xPos~$yPos~$TxT\n";
3723 }
3724 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3725 0 { errLog("No output file, you have to call prFile first");
3726 }
3727 0 @aktuellFont = @fontSpar;
3728 0 return $Font;
3729  
3730 }
3731  
3732  
3733 sub prExtract
3734 0 ▶{ my $name = shift;
Subroutine prExtract: not called CC=8 SCAR=42.8
Pod documented
3735 0 my $form = shift;
3736 0 ▶ my $page = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3737 0 ▶ if ($name =~ m'^/(\w+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ m[^/(\w+)]o) 0 0 0
3738 0 { $name = $1;
3739 }
3740 0 my $fullName = "$name~$form~$page";
3741 0 ▶ if (exists $knownToFile{$fullName})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::knownToFile{$fullName}) { } 0 0 0
3742 0 { return $knownToFile{$fullName};
3743 }
3744 else
3745 0 ▶ { if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
3746 0 { $log = "Extract~$fullName\n";
3747 }
3748 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
3749 0 { errLog("No output file, you have to call prFile first");
3750 }
3751  
3752 0 ▶ if (! exists $form{$form . '_' . $page})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::form{$form . '_' . $page}) 0 0 0
3753 0 { prForm($form, $page, undef, 'load', 1);
3754 }
3755 0 $name = extractName($form, $page, $name);
3756 0 ▶ if ($name)
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 0 0 0
3757 0 { $knownToFile{$fullName} = $name;
3758 }
3759 0 return $name;
3760 }
3761 }
3762  
3763  
3764 ########## Extrahera ett dokument ####################
3765 sub prDoc
3766 5 ▶{ my ($infil, $first, $last);
Subroutine prDoc: called CC=11 SCAR=34.7
Pod documented
3767 5 my $param = shift;
3768 5 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 5 5
3769 0 { $infil = $param->{'file'};
3770 0 ▶ $first = $param->{'first'} || 1;
Condition0%0/2
$param->{'first'} || 1
l!l
00
MC/DC0%0/1
$param->{'first'} || 1
$param->{'first'}
Truth table0%0/2
A
A= $param->{'first'}
Aresult
11
00
3771 0 ▶ $last = $param->{'last'} || '';
Condition0%0/2
$param->{'last'} || ''
l!l
00
MC/DC0%0/1
$param->{'last'} || ''
$param->{'last'}
Truth table0%0/2
A
A= $param->{'last'}
Aresult
11
00
3772 }
3773 else
3774 5 { $infil = $param;
3775 5 ▶ $first = shift || 1;
Condition50%1/2
shift() || 1
l!l
05
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3776 5 ▶ $last = shift || '';
Condition50%1/2
shift() || ''
l!l
05
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3777 }
3778  
3779  
3780 5 my ($sidor, $Names, $AARoot, $AcroForm) = analysera($infil, $first, $last);
3781 5 ▶ if (($Names) || ($AARoot) || ($AcroForm))
Branch: 1 branch
BranchTrueFalseTotal
if ($Names or $AARoot or $AcroForm) 0 5 5
Condition33%2/6
$Names or $AARoot or $AcroForm
l!l&&r!l&&!r
005
$Names or $AARoot
l!l&&r!l&&!r
005
MC/DC0%0/3
$Names or $AARoot or $AcroForm
$Names $AARoot $AcroForm
Truth table25%1/4
A or B or C
A= $NamesB= $AARootC= $AcroForm
ABCresult
1XX1
01X1
0011
0000
3782 0 { $NamesSaved = $Names;
3783 0 $AARootSaved = $AARoot;
3784 0 $AcroFormSaved = $AcroForm;
3785 0 $interActive = 1;
3786 }
3787 5 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 5 5
3788 0 { $infil = prep($infil);
3789 0 $log .= "Doc~$infil~$first~$last\n";
3790 }
3791 5 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 5 5
3792 0 { errLog("No output file, you have to call prFile first");
3793 }
3794 5 return $sidor;
3795 }
3796  
3797 ############# Ett interaktivt + grafiskt "formulär" ##########
3798  
3799 sub prDocForm
3800 1 ▶{my ($sidnr, $adjust, $effect, $tolerant, $infil, $x, $y, $size, $xsize,
Subroutine prDocForm: called CC=55 SCAR=67.6
Pod documented
3801 $ysize, $rotate);
3802 1 my $param = shift;
3803 1 ▶ if (ref($param) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq 'HASH') { } 0 1 1
3804 0 { $infil = $param->{'file'};
3805 0 ▶ $sidnr = $param->{'page'} || 1;
Condition0%0/2
$param->{'page'} || 1
l!l
00
MC/DC0%0/1
$param->{'page'} || 1
$param->{'page'}
Truth table0%0/2
A
A= $param->{'page'}
Aresult
11
00
3806 0 ▶ $adjust = $param->{'adjust'} || '';
Condition0%0/2
$param->{'adjust'} || ''
l!l
00
MC/DC0%0/1
$param->{'adjust'} || ''
$param->{'adjust'}
Truth table0%0/2
A
A= $param->{'adjust'}
Aresult
11
00
3807 0 ▶ $effect = $param->{'effect'} || 'print';
Condition0%0/2
$param->{'effect'} || 'print'
l!l
00
MC/DC0%0/1
$param->{'effect'} || 'print'
$param->{'effect'}
Truth table0%0/2
A
A= $param->{'effect'}
Aresult
11
00
3808 0 ▶ $tolerant = $param->{'tolerant'} || '';
Condition0%0/2
$param->{'tolerant'} || ''
l!l
00
MC/DC0%0/1
$param->{'tolerant'} || ''
$param->{'tolerant'}
Truth table0%0/2
A
A= $param->{'tolerant'}
Aresult
11
00
3809 0 ▶ $x = $param->{'x'} || 0;
Condition0%0/2
$param->{'x'} || 0
l!l
00
MC/DC0%0/1
$param->{'x'} || 0
$param->{'x'}
Truth table0%0/2
A
A= $param->{'x'}
Aresult
11
00
3810 0 ▶ $y = $param->{'y'} || 0;
Condition0%0/2
$param->{'y'} || 0
l!l
00
MC/DC0%0/1
$param->{'y'} || 0
$param->{'y'}
Truth table0%0/2
A
A= $param->{'y'}
Aresult
11
00
3811 0 ▶ $rotate = $param->{'rotate'} || 0;
Condition0%0/2
$param->{'rotate'} || 0
l!l
00
MC/DC0%0/1
$param->{'rotate'} || 0
$param->{'rotate'}
Truth table0%0/2
A
A= $param->{'rotate'}
Aresult
11
00
3812 0 ▶ $size = $param->{'size'} || 1;
Condition0%0/2
$param->{'size'} || 1
l!l
00
MC/DC0%0/1
$param->{'size'} || 1
$param->{'size'}
Truth table0%0/2
A
A= $param->{'size'}
Aresult
11
00
3813 0 ▶ $xsize = $param->{'xsize'} || 1;
Condition0%0/2
$param->{'xsize'} || 1
l!l
00
MC/DC0%0/1
$param->{'xsize'} || 1
$param->{'xsize'}
Truth table0%0/2
A
A= $param->{'xsize'}
Aresult
11
00
3814 0 ▶ $ysize = $param->{'ysize'} || 1;
Condition0%0/2
$param->{'ysize'} || 1
l!l
00
MC/DC0%0/1
$param->{'ysize'} || 1
$param->{'ysize'}
Truth table0%0/2
A
A= $param->{'ysize'}
Aresult
11
00
3815 }
3816 else
3817 1 { $infil = $param;
3818 1 ▶ $sidnr = shift || 1;
Condition50%1/2
shift() || 1
l!l
01
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3819 1 ▶ $adjust = shift || '';
Condition50%1/2
shift() || ''
l!l
01
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3820 1 ▶ $effect = shift || 'print';
Condition50%1/2
shift() || 'print'
l!l
01
MC/DC0%0/1
shift() || 'print'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3821 1 ▶ $tolerant = shift || '';
Condition50%1/2
shift() || ''
l!l
01
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3822 1 ▶ $x = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3823 1 ▶ $y = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3824 1 ▶ $rotate = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3825 1 ▶ $size = shift || 1;
Condition50%1/2
shift() || 1
l!l
01
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3826 1 ▶ $xsize = shift || 1;
Condition50%1/2
shift() || 1
l!l
01
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3827 1 ▶ $ysize = shift || 1;
Condition50%1/2
shift() || 1
l!l
01
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3828 }
3829 1 my $namn;
3830 my $refNr;
3831 1 $type = 'docform';
3832 1 my $fSource = $infil . '_' . $sidnr;
3833 1 my $action;
3834 1 ▶ if (! exists $form{$fSource})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::form{$fSource}) { } 1 0 1
3835 1 { $formNr++;
3836 1 $namn = 'Fm' . $formNr;
3837 1 $knownToFile{$fSource} = $namn;
3838 1 ▶ if ($effect eq 'load')
Branch: 1 branch
BranchTrueFalseTotal
if ($effect eq 'load') { } 0 1 1
3839 0 { $action = 'load'
3840 }
3841 else
3842 1 { $action = 'print'
3843 }
3844 1 $refNr = getPage($infil, $sidnr, $action);
3845 1 ▶ if ($refNr)
Branch: 1 branch
BranchTrueFalseTotal
if ($refNr) { } 1 0 1
3846 1 { $objRef{$namn} = $refNr;
3847 }
3848 else
3849 0 ▶ { if ($tolerant)
Branch: 2 branches
BranchTrueFalseTotal
if ($tolerant) { } 0 0 0
elsif (not defined $refNr) { } 0 0 0
3850 0 ▶ { if ((defined $refNr) && ($refNr eq '0')) # Sidnumret existerar inte, men ok
Branch: 1 branch
BranchTrueFalseTotal
if (defined $refNr and $refNr eq '0') { } 0 0 0
Condition0%0/3
defined $refNr and $refNr eq 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $refNr and $refNr eq 0
defined $refNr $refNr eq 0
Truth table0%0/3
A and B
A= defined $refNrB= $refNr eq 0
ABresult
0X0
100
111
3851 0 { $namn = '0';
3852 }
3853 else
3854 0 { undef $namn; # Sidan kan inte användas som form
3855 }
3856 }
3857 elsif (! defined $refNr)
3858 0 { my $mess = "$fSource can't be used as a form. See the documentation\n"
3859 . "under prForm how to concatenate streams\n";
3860 0 errLog($mess);
3861 }
3862 else
3863 0 { errLog("File : $infil Page: $sidnr doesn't exist");
3864 }
3865 }
3866 }
3867 else
3868 0 ▶ { if (exists $knownToFile{$fSource})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::knownToFile{$fSource}) { } 0 0 0
3869 0 { $namn = $knownToFile{$fSource};
3870 }
3871 else
3872 0 { $formNr++;
3873 0 $namn = 'Fm' . $formNr;
3874 0 $knownToFile{$fSource} = $namn;
3875 }
3876 0 ▶ if (exists $objRef{$namn})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::objRef{$namn}) { } 0 0 0
3877 0 { $refNr = $objRef{$namn};
3878 }
3879 else
3880 0 ▶ { if (! $form{$fSource}[fVALID])
Branch: 2 branches
BranchTrueFalseTotal
if (not $PDF::Reuse::form{$fSource}[8]) { } 0 0 0
elsif ($effect ne 'load') { } 0 0 0
3881 0 { my $mess = "$fSource can't be used as a form. See the documentation\n"
3882 . "under prForm how to concatenate streams\n";
3883 0 ▶ if ($tolerant)
Branch: 1 branch
BranchTrueFalseTotal
if ($tolerant) { } 0 0 0
3884 0 { cluck $mess;
3885 0 undef $namn;
3886 }
3887 else
3888 0 { errLog($mess);
3889 }
3890 }
3891 elsif ($effect ne 'load')
3892 0 { $refNr = byggForm($infil, $sidnr);
3893 0 $objRef{$namn} = $refNr;
3894 }
3895 }
3896 }
3897 1 ▶ my @BBox = @{$form{$fSource}[fBBOX]} if ($refNr);
Branch: 1 branch
BranchTrueFalseTotal
if $refNr 1 0 1
3898 1 ▶ if (($effect eq 'print') && ($form{$fSource}[fVALID]) && ($refNr))
Branch: 1 branch
BranchTrueFalseTotal
if ($effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr) 1 0 1
Condition33%2/6
$effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr
!ll&&!rl&&r
001
$effect eq "print" and $PDF::Reuse::form{$fSource}[8]
!ll&&!rl&&r
001
MC/DC0%0/3
$effect eq "print" and $PDF::Reuse::form{$fSource}[8] and $refNr
$effect eq "print" $PDF::Reuse::form{$fSource}[8] $refNr
Truth table25%1/4
A and B and C
A= $effect eq "print"B= $PDF::Reuse::form{$fSource}[8]C= $refNr
ABCresult
0XX0
10X0
1100
1111
3899 1 ▶ { if ((! defined $interActive)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $PDF::Reuse::interActive and $sidnr == 1 and %{$PDF::Reuse::intAct{$fSource}[0];}) 0 1 1
Condition33%2/6
not defined $PDF::Reuse::interActive and $sidnr == 1 and %{$PDF::Reuse::intAct{$fSource}[0];}
!ll&&!rl&&r
010
not defined $PDF::Reuse::interActive and $sidnr == 1
!ll&&!rl&&r
001
MC/DC0%0/3
not defined $PDF::Reuse::interActive and $sidnr == 1 and %{$PDF::Reuse::intAct{$fSource}[0];}
not defined $PDF::Reuse::interActive $sidnr == 1 %{$PDF::Reuse::intAct{$fSource}[0];}
Truth table25%1/4
not(A) and B and C
A= not defined $PDF::Reuse::interActiveB= $sidnr == 1C= %{$PDF::Reuse::intAct{$fSource}[0];}
ABCresult
0XX0
10X0
1100
1111
3900 && ($sidnr == 1)
3901 1 && (%{$intAct{$fSource}[0]}) )
3902 0 { $interActive = $infil . ' ' . $sidnr;
3903 0 $interAktivSida = 1;
3904 }
3905 1 ▶ if (! defined $defGState)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::defGState) 1 0 1
3906 1 { prDefaultGrState();
3907 }
3908 1 ▶ if ($adjust)
Branch: 2 branches
BranchTrueFalseTotal
if ($adjust) { } 0 1 1
elsif ($x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1) { } 0 1 1
3909 0 { $stream .= "q\n";
3910 0 $stream .= fillTheForm(@BBox, $adjust);
3911 0 $stream .= "\n/Gs0 gs\n";
3912 0 $stream .= "/$namn Do\n";
3913 0 $stream .= "Q\n";
3914 }
3915 ▶ elsif (($x) || ($y) || ($rotate) || ($size != 1)
Condition33%5/15
$x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1
l!l&&r!l&&!r
001
$x or $y or $rotate or $size != 1 or $xsize != 1
l!l&&r!l&&!r
001
$x or $y or $rotate or $size != 1
l!l&&r!l&&!r
001
$x or $y or $rotate
l!l&&r!l&&!r
001
$x or $y
l!l&&r!l&&!r
001
MC/DC0%0/6
$x or $y or $rotate or $size != 1 or $xsize != 1 or $ysize != 1
$x $y $rotate $size != 1 $xsize != 1 $ysize != 1
Truth table14%1/7
A or B or C or D or E or F
A= $xB= $yC= $rotateD= $size != 1E= $xsize != 1F= $ysize != 1
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
3916 || ($xsize != 1) || ($ysize != 1))
3917 0 { $stream .= "q\n";
3918 0 $stream .= calcMatrix($x, $y, $rotate, $size,
3919 $xsize, $ysize, $BBox[2], $BBox[3]);
3920 0 $stream .= "\n/Gs0 gs\n";
3921 0 $stream .= "/$namn Do\n";
3922 0 $stream .= "Q\n";
3923 }
3924 else
3925 1 { $stream .= "\n/Gs0 gs\n";
3926 1 $stream .= "/$namn Do\n";
3927 }
3928 1 $sidXObject{$namn} = $refNr;
3929 1 $sidExtGState{'Gs0'} = $defGState;
3930 }
3931 1 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 1 1
3932 0 { $infil = prep($infil);
3933 0 $log .= "Form~$infil~$sidnr~$adjust~$effect~$tolerant";
3934 0 $log .= "~$x~$y~$rotate~$size~$xsize~$ysize\n";
3935 }
3936 1 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 1 1
3937 0 { errLog("No output file, you have to call prFile first");
3938 }
3939 1 ▶ if (($effect ne 'print') && ($effect ne 'add'))
Branch: 1 branch
BranchTrueFalseTotal
if ($effect ne "print" and $effect ne "add") 0 1 1
Condition33%1/3
$effect ne "print" and $effect ne "add"
!ll&&!rl&&r
100
MC/DC0%0/2
$effect ne "print" and $effect ne "add"
$effect ne "print" $effect ne "add"
Truth table33%1/3
A and B
A= $effect ne "print"B= $effect ne "add"
ABresult
0X0
100
111
3940 0 { undef $namn;
3941 }
3942 1 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
3943 0 { my $images = 0;
3944 0 ▶ if (exists $form{$fSource}[fIMAGES])
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::form{$fSource}[3]) 0 0 0
3945 0 { $images = scalar(@{$form{$fSource}[fIMAGES]});
3946 }
3947 0 return ($namn, $BBox[0], $BBox[1], $BBox[2],
3948 $BBox[3], $images);
3949 }
3950 else
3951 1 { return $namn;
3952 }
3953 }
3954  
3955 sub calcMatrix
3956 0 ▶{ my ($x, $y, $rotate, $size, $xsize, $ysize, $upperX, $upperY) = @_;
Subroutine calcMatrix: not called CC=8 SCAR=42.8
Pod undocumented
3957 0 my ($str, $xSize, $ySize);
3958 0 ▶ $size = 1 if ($size == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $size == 0 0 0 0
3959 0 ▶ $xsize = 1 if ($xsize == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $xsize == 0 0 0 0
3960 0 ▶ $ysize = 1 if ($ysize == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $ysize == 0 0 0 0
3961 0 $xSize = $xsize * $size;
3962 0 $ySize = $ysize * $size;
3963 0 $str = "$xSize 0 0 $ySize $x $y cm\n";
3964 0 ▶ if ($rotate)
Branch: 1 branch
BranchTrueFalseTotal
if ($rotate) 0 0 0
3965 0 ▶ { if ($rotate =~ m'q(\d)'oi)
Branch: 1 branch
BranchTrueFalseTotal
if ($rotate =~ /q(\d)/io) { } 0 0 0
3966 0 { my $tal = $1;
3967 0 ▶ if ($tal == 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($tal == 1) { } 0 0 0
elsif ($tal == 2) { } 0 0 0
3968 0 { $upperY = $upperX;
3969 0 $upperX = 0;
3970 0 $rotate = 270;
3971 }
3972 elsif ($tal == 2)
3973 0 { $rotate = 180;
3974 }
3975 else
3976 0 { $rotate = 90;
3977 0 $upperX = $upperY;
3978 0 $upperY = 0;
3979 }
3980 }
3981 else
3982 0 { $upperX = 0;
3983 0 $upperY = 0;
3984 }
3985 0 my $radian = sprintf("%.6f", $rotate / 57.2957795); # approx.
3986 0 my $Cos = sprintf("%.6f", cos($radian));
3987 0 my $Sin = sprintf("%.6f", sin($radian));
3988 0 my $negSin = $Sin * -1;
3989 0 $str .= "$Cos $Sin $negSin $Cos $upperX $upperY cm\n";
3990 }
3991 0 return $str;
3992 }
3993  
3994 sub fillTheForm
3995 0 ▶{ my $left = shift || 0;
Subroutine fillTheForm: not called CC=8 SCAR=42.8
Pod undocumented
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3996 0 ▶ my $bottom = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3997 0 ▶ my $right = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3998 0 ▶ my $top = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
3999 0 ▶ my $how = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
4000 0 my $image = shift;
4001 0 my $str;
4002 0 my $scaleX = 1;
4003 0 my $scaleY = 1;
4004  
4005 0 my $xDim = $genUpperX - $genLowerX;
4006 0 my $yDim = $genUpperY - $genLowerY;
4007 0 my $xNy = $right - $left;
4008 0 my $yNy = $top - $bottom;
4009 0 $scaleX = $xDim / $xNy;
4010 0 $scaleY = $yDim / $yNy;
4011 0 ▶ if ($how == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($how == 1) 0 0 0
4012 0 ▶ { if ($scaleX < $scaleY)
Branch: 1 branch
BranchTrueFalseTotal
if ($scaleX < $scaleY) { } 0 0 0
4013 0 { $scaleY = $scaleX;
4014 }
4015 else
4016 0 { $scaleX = $scaleY;
4017 }
4018 }
4019 0 $str = "$scaleX 0 0 $scaleY $left $bottom cm\n";
4020 0 return $str;
4021 }
4022  
4023 sub prAltJpeg
4024 0 ▶{ my ($iData, $iWidth, $iHeight, $iFormat,$aiData, $aiWidth, $aiHeight, $aiFormat) = @_;
Subroutine prAltJpeg: not called CC=4 SCAR=30.0
Pod documented
4025 0 ▶ if (! $pos) # If no output is active, it is no use to continue
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4026 0 { return undef;
4027 }
4028 0 prJpeg($aiData, $aiWidth, $aiHeight, $aiFormat);
4029 0 my $altObjNr = $objNr;
4030 0 $imageNr++;
4031 0 $objNr++;
4032 0 $objekt[$objNr] = $pos;
4033 0 my $utrad = "$objNr 0 obj\n" .
4034 "[ << /Image $altObjNr 0 R\n" .
4035 "/DefaultForPrinting true\n" .
4036 ">>\n" .
4037 "]\n" .
4038 "endobj\n";
4039 0 $pos += syswrite UTFIL, $utrad;
4040 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4041 0 { $log .= "Jpeg~AltImage\n";
4042 }
4043 0 my $namnet = prJpeg($iData, $iWidth, $iHeight, $iFormat, $objNr);
4044 0 $objRef{$namnet} = $objNr;
4045 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4046 0 { errLog("No output file, you have to call prFile first");
4047 }
4048 0 return $namnet;
4049 }
4050  
4051 sub prJpeg
4052 0 ▶{ my ($iData, $iWidth, $iHeight, $iFormat, $iColorType, $altArrayObjNr) = @_;
Subroutine prJpeg: not called CC=14 SCAR=53.5
Pod documented
4053 0 ▶ if ($iColorType =~ /Gray/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($iColorType =~ /Gray/i) { } 0 0 0
4054 0 { $iColorType = 'DeviceGray';
4055 }
4056 else
4057 0 { $iColorType = 'DeviceRGB';
4058 }
4059 0 my ($iLangd, $namnet, $utrad, $iFile);
4060 0 ▶ if (! $pos) # If no output is active, it is no use to continue
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4061 0 { return undef;
4062 }
4063 0 my $checkidOld = $checkId;
4064 0 ▶ if (!$iFormat)
Branch: 2 branches
BranchTrueFalseTotal
if (not $iFormat) { } 0 0 0
elsif ($iFormat == 1) { } 0 0 0
4065 0 { ($iFile, $checkId) = findGet($iData, $checkidOld);
4066 0 ▶ if ($iFile)
Branch: 1 branch
BranchTrueFalseTotal
if ($iFile) 0 0 0
4067 0 { $iLangd = (stat($iFile))[7];
4068 0 $imageNr++;
4069 0 $namnet = 'Ig' . $imageNr;
4070 0 $objNr++;
4071 0 $objekt[$objNr] = $pos;
4072 0 ▶ open (BILDFIL, "<$iFile") || errLog("Couldn't open $iFile, $!, aborts");
Branch: 1 branch
BranchTrueFalseTotal
open BILDFIL, "<$iFile" or errLog("Couldn't open $iFile, $!, aborts") 0 0 0
4073 0 binmode BILDFIL;
4074 0 my $iStream;
4075 0 sysread BILDFIL, $iStream, $iLangd;
4076 0 ▶ $utrad = "$objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
Branch: 1 branch
BranchTrueFalseTotal
$altArrayObjNr ? : 0 0 0
4077 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
4078 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
4079 "/Filter/DCTDecode/ColorSpace/$iColorType"
4080 . "/Length $iLangd >>stream\n$iStream\nendstream\nendobj\n";
4081 0 close BILDFIL;
4082 0 $pos += syswrite UTFIL, $utrad;
4083 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4084 0 { $log .= "Cid~$checkId\n";
4085 0 $log .= "Jpeg~$iFile~$iWidth~$iHeight\n";
4086 }
4087 0 $objRef{$namnet} = $objNr;
4088 }
4089 }
4090 elsif ($iFormat == 1)
4091 0 { my $iBlob = $iData;
4092 0 $iLangd = length($iBlob);
4093 0 $imageNr++;
4094 0 $namnet = 'Ig' . $imageNr;
4095 0 $objNr++;
4096 0 $objekt[$objNr] = $pos;
4097 0 ▶ $utrad = "$objNr 0 obj\n<</Type/XObject/Subtype/Image/Name/$namnet" .
Branch: 1 branch
BranchTrueFalseTotal
$altArrayObjNr ? : 0 0 0
4098 "/Width $iWidth /Height $iHeight /BitsPerComponent 8 " .
4099 ($altArrayObjNr ? "/Alternates $altArrayObjNr 0 R " : "") .
4100 "/Filter/DCTDecode/ColorSpace/$iColorType"
4101 . "/Length $iLangd >>stream\n$iBlob\nendstream\nendobj\n";
4102 0 $pos += syswrite UTFIL, $utrad;
4103 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4104 0 { $log .= "Cid~$checkId\n";
4105 0 ▶ $log .= "Jpeg~$iFile~$iWidth~$iHeight\n" if !$iFormat;
Branch: 1 branch
BranchTrueFalseTotal
unless $iFormat 0 0 0
4106 0 ▶ $log .= "Jpeg~Blob~$iWidth~$iHeight\n" if $iFormat == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $iFormat == 1 0 0 0
4107 }
4108 0 $objRef{$namnet} = $objNr;
4109 }
4110 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4111 0 { errLog("No output file, you have to call prFile first");
4112 }
4113 0 undef $checkId;
4114 0 return $namnet;
4115 }
4116  
4117 sub checkContentStream
4118 0 ▶{ for (@_)
Subroutine checkContentStream: not called CC=10 SCAR=47.0
Pod undocumented
4119 0 ▶ { if (my $value = $objRef{$_})
Branch: 2 branches
BranchTrueFalseTotal
if (my $value = $PDF::Reuse::objRef{$_}) { } 0 0 0
elsif ($_ eq 'Gs0' and not defined $PDF::Reuse::defGState) { } 0 0 0
4120 0 { my $typ = substr($_, 0, 2);
4121 0 ▶ if ($typ eq 'Ft')
Branch: 5 branches
BranchTrueFalseTotal
if ($typ eq 'Ft') { } 0 0 0
elsif ($typ eq 'Gs') { } 0 0 0
elsif ($typ eq 'Pt') { } 0 0 0
elsif ($typ eq 'Sh') { } 0 0 0
elsif ($typ eq 'Cs') { } 0 0 0
4122 0 { $sidFont{$_} = $value;
4123 }
4124 elsif ($typ eq 'Gs')
4125 0 { $sidExtGState{$_} = $value;
4126 }
4127 elsif ($typ eq 'Pt')
4128 0 { $sidPattern{$_} = $value;
4129 }
4130 elsif ($typ eq 'Sh')
4131 0 { $sidShading{$_} = $value;
4132 }
4133 elsif ($typ eq 'Cs')
4134 0 { $sidColorSpace{$_} = $value;
4135 }
4136 else
4137 0 { $sidXObject{$_} = $value;
4138 }
4139 }
4140 ▶ elsif (($_ eq 'Gs0') && (! defined $defGState))
Condition0%0/3
$_ eq "Gs0" and not defined $PDF::Reuse::defGState
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq "Gs0" and not defined $PDF::Reuse::defGState
$_ eq "Gs0" not defined $PDF::Reuse::defGState
Truth table0%0/3
A and not(B)
A= $_ eq "Gs0"B= not defined $PDF::Reuse::defGState
ABresult
0X0
100
111
4141 0 { my ($dummy, $oNr) = prDefaultGrState();
4142 0 $sidExtGState{'Gs0'} = $oNr;
4143 }
4144 }
4145 }
4146  
4147 sub prGraphState
4148 0 ▶{ my $string = shift;
Subroutine prGraphState: not called CC=3 SCAR=24.8
Pod documented
4149 0 $gSNr++;
4150 0 my $name = 'Gs' . $gSNr ;
4151 0 $objNr++;
4152 0 $objekt[$objNr] = $pos;
4153 0 my $utrad = "$objNr 0 obj\n" . $string . "\nendobj\n";
4154 0 $pos += syswrite UTFIL, $utrad;
4155 0 $objRef{$name} = $objNr;
4156 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4157 0 { $log .= "GraphStat~$string\n";
4158 }
4159 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4160 0 { errLog("No output file, you have to call prFile first");
4161 }
4162 0 return $name;
4163 }
4164  
4165 ##############################################################
4166 # Streckkods fonten lokaliseras och objekten skrivs ev. ut
4167 ##############################################################
4168  
4169 sub findBarFont()
4170 0 ▶{ my $Font = 'Bar';
Subroutine findBarFont: not called CC=3 SCAR=24.8
Pod undocumented
4171  
4172 0 ▶ if (exists $font{$Font}) # Objekt är redan definierat
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::font{$Font}) { } 0 0 0
4173 0 { $aktuellFont[foEXTNAMN] = $Font;
4174 0 $aktuellFont[foREFOBJ] = $font{$Font}[foREFOBJ];
4175 0 $aktuellFont[foINTNAMN] = $font{$Font}[foINTNAMN];
4176 }
4177 else
4178 0 { $objNr++;
4179 0 $objekt[$objNr] = $pos;
4180 0 my $encodObj = $objNr;
4181 0 my $fontObjekt = "$objNr 0 obj\n<< /Type /Encoding\n" .
4182 '/Differences [48 /tomt /streck /lstreck]' . "\n>>\nendobj\n";
4183 0 $pos += syswrite UTFIL, $fontObjekt;
4184 0 my $charProcsObj = createCharProcs();
4185 0 $objNr++;
4186 0 $objekt[$objNr] = $pos;
4187 0 $fontNr++;
4188 0 my $fontAbbr = 'Ft' . $fontNr;
4189 0 $fontObjekt = "$objNr 0 obj\n<</Type/Font/Subtype/Type3\n" .
4190 '/FontBBox [0 -250 75 2000]' . "\n" .
4191 '/FontMatrix [0.001 0 0 0.001 0 0]' . "\n" .
4192 "\/CharProcs $charProcsObj 0 R\n" .
4193 "\/Encoding $encodObj 0 R\n" .
4194 '/FirstChar 48' . "\n" .
4195 '/LastChar 50' . "\n" .
4196 '/Widths [75 75 75]' . "\n>>\nendobj\n";
4197  
4198 0 $font{$Font}[foINTNAMN] = $fontAbbr;
4199 0 $font{$Font}[foREFOBJ] = $objNr;
4200 0 $objRef{$fontAbbr} = $objNr;
4201 0 $objekt[$objNr] = $pos;
4202 0 $aktuellFont[foEXTNAMN] = $Font;
4203 0 $aktuellFont[foREFOBJ] = $objNr;
4204 0 $aktuellFont[foINTNAMN] = $fontAbbr;
4205 0 $pos += syswrite UTFIL, $fontObjekt;
4206 }
4207 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4208 0 { errLog("No output file, you have to call prFile first");
4209 }
4210  
4211 0 $sidFont{$aktuellFont[foINTNAMN]} = $aktuellFont[foREFOBJ];
4212 }
4213  
4214 sub createCharProcs()
4215 0 ▶{ #################################
Subroutine createCharProcs: not called CC=1 SCAR=6.9
Pod undocumented
4216 # Fonten (objektet) för 0 skapas
4217 #################################
4218  
4219 0 $objNr++;
4220 0 $objekt[$objNr] = $pos;
4221 0 my $tomtObj = $objNr;
4222 0 my $str = "\n75 0 d0\n6 0 69 2000 re\n1.0 g\nf\n";
4223 0 my $strLength = length($str);
4224 0 my $obj = "$objNr 0 obj\n<< /Length $strLength >>\nstream" .
4225 $str . "\nendstream\nendobj\n";
4226 0 $pos += syswrite UTFIL, $obj;
4227  
4228 #################################
4229 # Fonten (objektet) för 1 skapas
4230 #################################
4231  
4232 0 $objNr++;
4233 0 $objekt[$objNr] = $pos;
4234 0 my $streckObj = $objNr;
4235 0 $str = "\n75 0 d0\n4 0 71 2000 re\n0.0 g\nf\n";
4236 0 $strLength = length($str);
4237 0 $obj = "$objNr 0 obj\n<< /Length $strLength >>\nstream" .
4238 $str . "\nendstream\nendobj\n";
4239 0 $pos += syswrite UTFIL, $obj;
4240  
4241 ###################################################
4242 # Fonten (objektet) för 2, ett långt streck skapas
4243 ###################################################
4244  
4245 0 $objNr++;
4246 0 $objekt[$objNr] = $pos;
4247 0 my $lStreckObj = $objNr;
4248 0 $str = "\n75 0 d0\n4 -250 71 2250 re\n0.0 g\nf\n";
4249 0 $strLength = length($str);
4250 0 $obj = "$objNr 0 obj\n<< /Length $strLength >>\nstream" .
4251 $str . "\nendstream\nendobj\n";
4252 0 $pos += syswrite UTFIL, $obj;
4253  
4254 #####################################################
4255 # Objektet för "CharProcs" skapas
4256 #####################################################
4257  
4258 0 $objNr++;
4259 0 $objekt[$objNr] = $pos;
4260 0 my $charProcsObj = $objNr;
4261 0 $obj = "$objNr 0 obj\n<</tomt $tomtObj 0 R\n/streck $streckObj 0 R\n" .
4262 "/lstreck $lStreckObj 0 R>>\nendobj\n";
4263 0 $pos += syswrite UTFIL, $obj;
4264 0 return $charProcsObj;
4265 }
4266  
4267  
4268  
4269 sub prCid
4270 0 ▶{ $checkId = shift;
Subroutine prCid: not called CC=2 SCAR=17.9
Pod documented
4271 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4272 0 { $log .= "Cid~$checkId\n";
4273 }
4274 0 1;
4275 }
4276  
4277 sub prIdType
4278 0 ▶{ $idTyp = shift;
Subroutine prIdType: not called CC=2 SCAR=17.9
Pod documented
4279 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4280 0 { $log .= "IdType~rep\n";
4281 }
4282 0 1;
4283 }
4284  
4285  
4286 sub prId
4287 0 ▶{ $id = shift;
Subroutine prId: not called CC=3 SCAR=24.8
Pod documented
4288 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4289 0 { $log .= "Id~$id\n";
4290 }
4291 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4292 0 { errLog("No output file, you have to call prFile first");
4293 }
4294 0 1;
4295 }
4296  
4297 sub prJs
4298 0 ▶{ my $filNamnIn = shift;
Subroutine prJs: not called CC=9 SCAR=45.0
Pod documented
4299 0 my $filNamn;
4300 0 ▶ if ($filNamnIn !~ m'\{'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $filNamnIn =~ /\{/so) { } 0 0 0
4301 0 { my $checkIdOld = $checkId;
4302 0 ($filNamn, $checkId) = findGet($filNamnIn, $checkIdOld);
4303 0 ▶ if (($runfil) && ($checkId) && ($checkId ne $checkIdOld))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld) 0 0 0
Condition0%0/6
$PDF::Reuse::runfil and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld
!ll&&!rl&&r
000
$PDF::Reuse::runfil and $PDF::Reuse::checkId
!ll&&!rl&&r
000
MC/DC0%0/3
$PDF::Reuse::runfil and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld
$PDF::Reuse::runfil $PDF::Reuse::checkId $PDF::Reuse::checkId ne $checkIdOld
Truth table0%0/4
A and B and C
A= $PDF::Reuse::runfilB= $PDF::Reuse::checkIdC= $PDF::Reuse::checkId ne $checkIdOld
ABCresult
0XX0
10X0
1100
1111
4304 0 { $log .= "Cid~$checkId\n";
4305 }
4306 0 $checkId = '';
4307 }
4308 else
4309 0 { $filNamn = $filNamnIn;
4310 }
4311 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4312 0 { my $filnamn = prep($filNamn);
4313 0 $log .= "Js~$filnamn\n";
4314 }
4315 0 ▶ if (($interAktivSida) || ($interActive))
Branch: 2 branches
BranchTrueFalseTotal
if ($PDF::Reuse::interAktivSida or $PDF::Reuse::interActive) { } 0 0 0
elsif (not $PDF::Reuse::pos) { } 0 0 0
Condition0%0/3
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
$PDF::Reuse::interAktivSida $PDF::Reuse::interActive
Truth table0%0/3
A or B
A= $PDF::Reuse::interAktivSidaB= $PDF::Reuse::interActive
ABresult
1X1
011
000
4316 0 { errLog("Too late, has already tried to merge JAVA SCRIPTS within an interactive page");
4317 }
4318 elsif (! $pos)
4319 0 { errLog("Too early for JAVA SCRIPTS, create a file first");
4320 }
4321 0 push @jsfiler, $filNamn;
4322 0 1;
4323 }
4324  
4325 sub prInit
4326 0 ▶{ my $initText = shift;
Subroutine prInit: not called CC=9 SCAR=45.0
Pod documented
4327 0 ▶ my $duplicate = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
4328 0 my @fall = ($initText =~ m'([\w\d\_\$]+)\s*\(.*?\)'gs);
4329 0 for (@fall)
4330 0 ▶ { if (! exists $initScript{$_})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::initScript{$_}) 0 0 0
4331 0 { $initScript{$_} = 0;
4332 }
4333 }
4334 0 ▶ if ($duplicate)
Branch: 1 branch
BranchTrueFalseTotal
if ($duplicate) 0 0 0
4335 0 { $duplicateInits = 1;
4336 }
4337 0 push @inits, $initText;
4338 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4339 0 { $initText = prep($initText);
4340 0 $log .= "Init~$initText~$duplicate\n";
4341 }
4342 0 ▶ if (($interAktivSida) || ($interActive))
Branch: 2 branches
BranchTrueFalseTotal
if ($PDF::Reuse::interAktivSida or $PDF::Reuse::interActive) { } 0 0 0
elsif (not $PDF::Reuse::pos) { } 0 0 0
Condition0%0/3
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
l!l&&r!l&&!r
000
MC/DC0%0/2
$PDF::Reuse::interAktivSida or $PDF::Reuse::interActive
$PDF::Reuse::interAktivSida $PDF::Reuse::interActive
Truth table0%0/3
A or B
A= $PDF::Reuse::interAktivSidaB= $PDF::Reuse::interActive
ABresult
1X1
011
000
4343 0 { errLog("Too late, has already tried to create INITIAL JAVA SCRIPTS within an interactive page");
4344 }
4345 elsif (! $pos)
4346 0 { errLog("Too early for INITIAL JAVA SCRIPTS, create a file first");
4347 }
4348 0 1;
4349  
4350 }
4351  
4352 sub prVers
4353 0 ▶{ my $vers = shift;
Subroutine prVers: not called CC=2 SCAR=17.9
Pod documented
4354 ############################################################
4355 # Om programmet körs om så kontrolleras VERSION
4356 ############################################################
4357 0 ▶ if ($vers ne $VERSION)
Branch: 1 branch
BranchTrueFalseTotal
if ($vers ne $PDF::Reuse::VERSION) { } 0 0 0
4358 0 { warn "$vers \<\> $VERSION might give different results, if comparing two runs \n";
4359 0 return undef;
4360 }
4361 else
4362 0 { return 1;
4363 }
4364 }
4365  
4366 sub prDocDir
4367 0 ▶{ $ddir = findDir(shift);
Subroutine prDocDir: not called CC=1 SCAR=6.9
Pod documented
4368 0 1;
4369 }
4370  
4371 sub prLogDir
4372 0 ▶{ $ldir = findDir(shift);
Subroutine prLogDir: not called CC=1 SCAR=6.9
Pod documented
4373 0 1;
4374 }
4375  
4376 sub prLog
4377 0 ▶{ my $mess = shift;
Subroutine prLog: not called CC=2 SCAR=17.9
Pod documented
4378 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) { } 0 0 0
4379 0 { $mess = prep($mess);
4380 0 $log .= "Log~$mess\n";
4381 0 return 1;
4382 }
4383 else
4384 0 { errLog("You have to give a directory for the logfiles first : prLogDir <dir> , aborts");
4385 }
4386  
4387 }
4388  
4389 sub prGetLogBuffer
4390 0 ▶{
Subroutine prGetLogBuffer: not called CC=1 SCAR=6.9
Pod documented
4391 0 return $log;
4392 }
4393  
4394 sub findDir
4395 0 ▶{ my $dir = shift;
Subroutine findDir: not called CC=7 SCAR=40.3
Pod undocumented
4396 0 ▶ if ($dir eq '.')
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq ".") 0 0 0
4397 0 { return undef; }
4398 0 ▶ if (! -e $dir)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
4399 0 ▶ { mkdir $dir || errLog("Couldn't create directory $dir, $!");
Condition0%0/3
$dir || errLog("Couldn't create directory $dir, $!")
l!l&&r!l&&!r
000
MC/DC0%0/2
$dir || errLog("Couldn't create directory $dir, $!")
$dir errLog("Couldn't create directory $dir, $!")
Truth table0%0/3
A || B
A= $dirB= errLog("Couldn't create directory $dir, $!")
ABresult
1X1
011
000
4400 }
4401  
4402 0 ▶ if ((-e $dir) && (-d $dir))
Branch: 1 branch
BranchTrueFalseTotal
if (-e $dir and -d $dir) { } 0 0 0
Condition0%0/3
-e $dir and -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
-e $dir and -d $dir
-e $dir -d $dir
Truth table0%0/3
A and B
A= -e $dirB= -d $dir
ABresult
0X0
100
111
4403 0 ▶ { if (substr($dir, length($dir), 1) eq '/')
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dir, length $dir, 1) eq '/') { } 0 0 0
4404 0 { return $dir; }
4405 else
4406 0 { return ($dir . '/');
4407 }
4408 }
4409 else
4410 0 { errLog("Error finding/creating directory $dir, $!");
4411 }
4412 }
4413  
4414 sub prTouchUp
4415 0 ▶{ $touchUp = shift;
Subroutine prTouchUp: not called CC=3 SCAR=24.8
Pod documented
4416 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4417 0 { $log .= "TouchUp~$touchUp\n";
4418 }
4419 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4420 0 { errLog("No output file, you have to call prFile first");
4421 }
4422 0 1;
4423 }
4424  
4425 sub prCompress
4426 0 ▶{ $compress = shift;
Subroutine prCompress: not called CC=3 SCAR=24.8
Pod documented
4427 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
4428 0 { $log .= "Compress~$compress\n";
4429 }
4430 0 ▶ if (! $pos)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::pos) 0 0 0
4431 0 { errLog("No output file, you have to call prFile first");
4432 }
4433 0 1;
4434  
4435 }
4436  
4437 sub prep
4438 0 ▶{ my $indata = shift;
Subroutine prep: not called CC=1 SCAR=6.9
Pod undocumented
4439 0 $indata =~ s/[\n\r]+/ /sgo;
4440 0 $indata =~ s/~/<tilde>/sgo;
4441 0 return $indata;
4442 }
4443  
4444  
4445 #
4446 # %processed and %behandlad cache byte offsets into a source file, keyed by
4447 # filename. If the file behind that name is replaced within one session the
4448 # offsets no longer describe it, and analysera() dies "Didn't find pages".
4449 #
4450 # Files written by this module are invalidated exactly, in prFile(), at the
4451 # moment the output file is truncated. This is the best-effort guard for
4452 # files replaced by something else (PDF::API2, another process).
4453 # Same-second rewrites that preserve the byte count are not detectable this
4454 # way -- stat mtime is whole seconds -- so prInitVars() remains the reliable
4455 # reset when an external writer rewrites a source file in place.
4456 #
4457 sub dropChangedCache
4458 7 ▶{ my $infil = shift;
Subroutine dropChangedCache: called CC=5 SCAR=16.8
Pod undocumented
4459 7 ▶ return if ref $infil;
Branch: 1 branch
BranchTrueFalseTotal
if ref $infil 0 7 7
4460 7 my @stati = stat($infil);
4461 7 ▶ return unless @stati;
Branch: 1 branch
BranchTrueFalseTotal
unless @stati 0 7 7
4462 7 my $stamp = "$stati[9]|$stati[7]";
4463 7 my $known = $processed{$infil}->{fileStamp};
4464 7 ▶ if (defined $known)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $known) 1 6 7
4465 1 ▶ { return if $known eq $stamp;
Branch: 1 branch
BranchTrueFalseTotal
if $known eq $stamp 1 0 1
4466 0 delete $processed{$infil};
4467 0 delete $behandlad{$infil};
4468 }
4469 6 $processed{$infil}->{fileStamp} = $stamp;
4470 6 return;
4471 }
4472  
4473 sub xRefs
4474 6 ▶{ my ($bytes, $infil) = @_;
Subroutine xRefs: called CC=13 SCAR=27.3
Pod undocumented
4475 6 my ($j, $nr, $xref, $i, $antal, $inrad, $Root, $tempRoot, $referens);
4476 6 my $buf = '';
4477 6 %embedded =();
4478  
4479 6 my $res = sysseek INFIL, -50, 2;
4480 6 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 6 0 6
4481 6 { sysread INFIL, $buf, 100;
4482 6 ▶ if ($buf =~ m'Encrypt'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /Encrypt/o) 0 6 6
4483 0 { errLog("The file $infil is encrypted, cannot be used, aborts");
4484 }
4485 6 ▶ if ($buf =~ m/\bstartxref$ws+(\d+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /\bstartxref$PDF::Reuse::ws+(\d+)/) 6 0 6
4486 6 { $xref = $1;
4487 6 ▶ if ($xref <= $bytes)
Branch: 1 branch
BranchTrueFalseTotal
if ($xref <= $bytes) { } 6 0 6
4488 {
4489 6 ▶ while ($xref)
Branch: 1 branch
BranchTrueFalseTotal
if ($xref) 6 6 12
4490 6 { $res = sysseek INFIL, $xref, 0;
4491 6 $res = sysread INFIL, $buf, 200;
4492 6 ▶ if ($buf =~ m /^\d+$ws+\d+$ws+obj/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj/so) { } 0 6 6
4493 0 { ($xref, $tempRoot, $nr) = crossrefObj($nr, $xref);
4494 }
4495 else
4496 6 { ($xref, $tempRoot, $nr) = xrefSection($nr, $xref, $infil);
4497 }
4498 6 ▶ if (($tempRoot) && (! $Root))
Branch: 1 branch
BranchTrueFalseTotal
if ($tempRoot and not $Root) 6 0 6
Condition33%1/3
$tempRoot and not $Root
!ll&&!rl&&r
006
MC/DC0%0/2
$tempRoot and not $Root
$tempRoot not $Root
Truth table33%1/3
A and not(B)
A= $tempRootB= not $Root
ABresult
0X0
100
111
4499 6 { $Root = $tempRoot;
4500 }
4501 }
4502 }
4503 else
4504 0 { errLog("Invalid XREF, aborting");
4505 }
4506 }
4507 }
4508  
4509 6 ▶ ($Root) || errLog("The Root object in $infil couldn't be found, aborting");
Branch: 1 branch
BranchTrueFalseTotal
$Root or errLog("The Root object in $infil couldn't be found, aborting") 6 0 6
4510  
4511 ##############################################################
4512 # Objekten sorteras i fallande ordning (efter offset i filen)
4513 ##############################################################
4514  
4515 6 my @offset = sort { $oldObject{$b} <=> $oldObject{$a} } keys %oldObject;
4516  
4517 6 my $saved;
4518  
4519 6 for (@offset)
4520 75 { $saved = $oldObject{$_};
4521 75 $bytes -= $saved;
4522  
4523 75 ▶ if ($_ !~ m'^xref'o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^xref/o) 69 6 75
4524 69 ▶ { if ($saved == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($saved == 0) { } 0 69 69
4525 0 { $oldObject{$_} = [ 0, 0, $embedded{$_}];
4526 }
4527 else
4528 69 { $oldObject{$_} = [ $saved, $bytes];
4529 }
4530 }
4531 75 $bytes = $saved;
4532 }
4533 6 %embedded = ();
4534 6 return $Root;
4535 }
4536  
4537 sub crossrefObj
4538 0 ▶{ my ($nr, $xref) = @_;
Subroutine crossrefObj: not called CC=28 SCAR=67.0
Pod undocumented
4539 0 my ($buf, %param, $len, $tempRoot);
4540 0 my $from = $xref;
4541 0 sysseek INFIL, $xref, 0;
4542 0 sysread INFIL, $buf, 400;
4543 0 my $str;
4544 0 ▶ if ($buf =~ m/^(.+>>$ws*)stream/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^(.+>>$PDF::Reuse::ws*)stream/so) 0 0 0
4545 0 { $str = $1;
4546 0 $from = length($str) + 7;
4547 0 ▶ if (substr($buf, $from, 1) eq "\n")
Branch: 1 branch
BranchTrueFalseTotal
if (substr($buf, $from, 1) eq "\n") 0 0 0
4548 0 { $from++;
4549 }
4550 0 $from += $xref;
4551 }
4552  
4553 0 for (split('/',$str))
4554 0 ▶ { if ($_ =~ m'^(\w+)(.*)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^(\w+)(.*)/o) 0 0 0
4555 0 ▶ { $param{$1} = $2 || ' ';
Condition0%0/2
$2 || ' '
l!l
00
MC/DC0%0/1
$2 || ' '
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
4556 }
4557 }
4558 0 ▶ if (!exists $param{'Index'})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $param{"Index"}) 0 0 0
4559 0 { $param{'Index'} = "[0 $param{'Size'}]";
4560 }
4561 0 ▶ if ((exists $param{'Root'}) && ($param{'Root'} =~ m/^$ws*(\d+)/o))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"Root"} and $param{"Root"} =~ /^$PDF::Reuse::ws*(\d+)/o) 0 0 0
Condition0%0/3
exists $param{"Root"} and $param{"Root"} =~ /^$PDF::Reuse::ws*(\d+)/o
!ll&&!rl&&r
000
MC/DC0%0/2
exists $param{"Root"} and $param{"Root"} =~ /^$PDF::Reuse::ws*(\d+)/o
exists $param{"Root"} $param{"Root"} =~ /^$PDF::Reuse::ws*(\d+)/o
Truth table0%0/3
A and B
A= exists $param{"Root"}B= $param{"Root"} =~ /^$PDF::Reuse::ws*(\d+)/o
ABresult
0X0
100
111
4562 0 { $tempRoot = $1;
4563 }
4564 0 my @keys = ($param{'W'} =~ m'(\d+)'og);
4565 0 my $keyLength = 0;
4566 0 for (@keys)
4567 0 { $keyLength += $_;
4568 }
4569 0 my $recLength = $keyLength + 1;
4570 0 my $upTo = 1 + $keys[0] + $keys[1];
4571 0 ▶ if ((exists $param{'Length'}) && ($param{'Length'} =~ m'(\d+)'o))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"Length"} and $param{"Length"} =~ /(\d+)/o) 0 0 0
Condition0%0/3
exists $param{"Length"} and $param{"Length"} =~ /(\d+)/o
!ll&&!rl&&r
000
MC/DC0%0/2
exists $param{"Length"} and $param{"Length"} =~ /(\d+)/o
exists $param{"Length"} $param{"Length"} =~ /(\d+)/o
Truth table0%0/3
A and B
A= exists $param{"Length"}B= $param{"Length"} =~ /(\d+)/o
ABresult
0X0
100
111
4572 0 { $len = $1;
4573 0 sysseek INFIL, $from, 0;
4574 0 sysread INFIL, $buf, $len;
4575 0 ▶ my $x = inflateInit()
Condition0%0/2
&inflateInit() || die("Cannot create an inflation stream\n")
l!l
00
MC/DC0%0/1
&inflateInit() || die("Cannot create an inflation stream\n")
&inflateInit()
Truth table0%0/2
A
A= &inflateInit()
Aresult
11
00
4576 || die "Cannot create an inflation stream\n" ;
4577 0 my ($output, $status) = $x->inflate(\$buf) ;
4578 0 ▶ die "inflation failed\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 1 0 0 0
4579 unless $status == 1;
4580  
4581 0 my $i = 0;
4582 0 my @last = (0, 0, 0, 0, 0, 0, 0);
4583 0 my @word = ('0', '0', '0', '0', '0', '0', '0');
4584 0 my $recTyp;
4585 0 my @intervall = ($param{'Index'} =~ m'(\d+)\D'osg);
4586 0 my $m = 0;
4587 0 my $currObj = $intervall[$m];
4588 0 $m++;
4589 0 my $max = $currObj + $intervall[$m];
4590  
4591 0 for (unpack ("C*", $output))
4592 0 ▶ { if (($_ != 0) && ($i > 0) && ($i < $upTo))
Branch: 1 branch
BranchTrueFalseTotal
if ($_ != 0 and $i > 0 and $i < $upTo) 0 0 0
Condition0%0/6
$_ != 0 and $i > 0 and $i < $upTo
!ll&&!rl&&r
000
$_ != 0 and $i > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$_ != 0 and $i > 0 and $i < $upTo
$_ != 0 $i > 0 $i < $upTo
Truth table0%0/4
A and B and C
A= $_ != 0B= $i > 0C= $i < $upTo
ABCresult
0XX0
10X0
1100
1111
4593 0 { my $tal = $_ + $last[$i] ;
4594 0 ▶ if ($tal > 255)
Branch: 1 branch
BranchTrueFalseTotal
if ($tal > 255) 0 0 0
4595 0 {$tal -= 256;
4596 }
4597  
4598 0 $last[$i] = $tal;
4599 0 $word[$i] = sprintf("%x", $tal);
4600 0 ▶ if (length($word[$i]) == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (length $word[$i] == 1) 0 0 0
4601 0 { $word[$i] = '0' . $word[$i];
4602 }
4603 }
4604 0 $i++;
4605 0 ▶ if ($i == $recLength)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $recLength) 0 0 0
4606 0 { $i = 0;
4607 0 my $j = 0;
4608 0 my $offsObj; # offset or object
4609 0 ▶ if ($keys[0] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($keys[0] == 0) { } 0 0 0
4610 0 { $recTyp = 1;
4611 0 $j = 1;
4612 }
4613 else
4614 0 { $recTyp = hex($word[1]);
4615 0 $j = 2;
4616 }
4617 0 my $k = 0;
4618 0 ▶ while ($k < $keys[1])
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $keys[1]) 0 0 0
4619 0 { $offsObj .= $word[$j];
4620 0 $k++;
4621 0 $j++;
4622 }
4623  
4624 0 ▶ if ($recTyp == 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($recTyp == 1) { } 0 0 0
elsif ($recTyp == 2) { } 0 0 0
4625 0 ▶ { if (! (exists $oldObject{$currObj}))
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::oldObject{$currObj}) { } 0 0 0
4626 0 { $oldObject{$currObj} = hex($offsObj); }
4627 else
4628 0 { $nr++;
4629 0 $oldObject{'xref' . "$nr"} = hex($offsObj);
4630 }
4631 }
4632 elsif ($recTyp == 2)
4633 0 ▶ { if (! (exists $oldObject{$currObj}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::oldObject{$currObj}) 0 0 0
4634 0 { $oldObject{$currObj} = 0;
4635 }
4636 0 $embedded{$currObj} = hex($offsObj);
4637 }
4638 0 ▶ if ($currObj < $max)
Branch: 1 branch
BranchTrueFalseTotal
if ($currObj < $max) { } 0 0 0
4639 0 { $currObj++;
4640 }
4641 else
4642 0 { $m++;
4643 0 $currObj = $intervall[$m];
4644 0 $m++;
4645 0 $max = $currObj + $intervall[$m];
4646 }
4647 }
4648 }
4649 }
4650 0 return ($param{'Prev'}, $tempRoot, $nr);
4651 }
4652  
4653 sub xrefSection
4654 6 ▶{ my ($nr, $xref, $infil) = @_;
Subroutine xrefSection: called CC=30 SCAR=40.0
Pod undocumented
4655 6 my ($i, $root, $antal);
4656 6 $nr++;
4657 6 $oldObject{('xref' . "$nr")} = $xref; # Offset för xref sparas
4658 6 sysseek INFIL, $xref, 0;
4659 6 sysread INFIL, my $buf, 30;
4660 6 ▶ if ($buf =~ /xref/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /xref/) { } 6 0 6
4661 6 sysseek INFIL, $xref+$-[0]+5, 0;
4662 }
4663 else {
4664 # If the regexp fails (it shouldn't), fall back to the previous
4665 # behaviour.
4666 0 sysseek INFIL, $xref + 5, 0;
4667 }
4668 6 $xref = 0;
4669 6 my $inrad = '';
4670 6 $buf = '';
4671 6 my $c;
4672 6 sysread INFIL, $c, 1;
4673 6 ▶ while ($c =~ m!\s!s)
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /\s/s) 0 6 6
4674 0 { sysread INFIL, $c, 1; }
4675  
4676 6 ▶ while ( (defined $c)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c ne "\n" and $c ne "\r") 22 6 28
Condition66%4/6
defined $c and $c ne "\n" and $c ne "\r"
!ll&&!rl&&r
6022
defined $c and $c ne "\n"
!ll&&!rl&&r
0622
MC/DC33%1/3
defined $c and $c ne "\n" and $c ne "\r"
defined $c $c ne "\n" $c ne "\r"
Truth table50%2/4
A and B and C
A= defined $cB= $c ne "\n"C= $c ne "\r"
ABCresult
0XX0
10X0
1100
1111
4677 && ($c ne "\n")
4678 && ($c ne "\r") )
4679 22 { $inrad .= $c;
4680 22 sysread INFIL, $c, 1;
4681 }
4682  
4683 6 ▶ if ($inrad =~ m'^(\d+)\s+(\d+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($inrad =~ /^(\d+)\s+(\d+)/o) 6 0 6
4684 6 { $i = $1;
4685 6 $antal = $2;
4686 }
4687  
4688 6 ▶ while ($antal)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal) 6 6 12
4689 6 ▶ { for (my $l = 1; $l <= $antal; $l++)
Branch: 1 branch
BranchTrueFalseTotal
if ($l <= $antal) 75 6 81
4690 75 { sysread INFIL, $inrad, 20;
4691 75 ▶ if ($inrad =~ m'^\s?(\d+) \d+ (\w)\s*'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($inrad =~ /^\s?(\d+) \d+ (\w)\s*/o) 75 0 75
4692 75 ▶ { if ($2 eq 'n')
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "n") 69 6 75
4693 69 ▶ { if (! (exists $oldObject{$i}))
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::oldObject{$i}) { } 69 0 69
4694 69 { $oldObject{$i} = int($1); }
4695 else
4696 0 { $nr++;
4697 0 $oldObject{'xref' . "$nr"} = int($1);
4698 }
4699 }
4700 }
4701 75 $i++;
4702 }
4703 6 undef $antal;
4704 6 undef $inrad;
4705 6 sysread INFIL, $c, 1;
4706 6 ▶ while ($c =~ m!\s!s)
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /\s/s) 0 6 6
4707 0 { sysread INFIL, $c, 1; }
4708  
4709 6 ▶ while ( (defined $c)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c ne "\n" and $c ne "\r") 42 6 48
Condition66%4/6
defined $c and $c ne "\n" and $c ne "\r"
!ll&&!rl&&r
6042
defined $c and $c ne "\n"
!ll&&!rl&&r
0642
MC/DC33%1/3
defined $c and $c ne "\n" and $c ne "\r"
defined $c $c ne "\n" $c ne "\r"
Truth table50%2/4
A and B and C
A= defined $cB= $c ne "\n"C= $c ne "\r"
ABCresult
0XX0
10X0
1100
1111
4710 && ($c ne "\n")
4711 && ($c ne "\r") )
4712 42 { $inrad .= $c;
4713 42 sysread INFIL, $c, 1;
4714 }
4715 6 ▶ if ($inrad =~ m'^(\d+)\s+(\d+)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($inrad =~ /^(\d+)\s+(\d+)/o) 0 6 6
4716 0 { $i = $1;
4717 0 $antal = $2;
4718 }
4719  
4720 }
4721  
4722 6 ▶ while ($inrad)
Branch: 1 branch
BranchTrueFalseTotal
if ($inrad) 30 0 30
4723 30 { $buf .= $inrad;
4724 30 ▶ if ($buf =~ m'Encrypt'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /Encrypt/o) 0 30 30
4725 0 { errLog("The file $infil is encrypted, cannot be used, aborts");
4726 }
4727 30 ▶ if ((! $root) && ($buf =~ m|\/Root$ws+(\d+)$ws+\d+$ws+R|so))
Branch: 1 branch
BranchTrueFalseTotal
if (not $root and $buf =~ m[\/Root$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 6 24 30
Condition100%3/3
not $root and $buf =~ m[\/Root$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so
!ll&&!rl&&r
1866
MC/DC100%2/2
not $root and $buf =~ m[\/Root$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so
not $root $buf =~ m[\/Root$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so
Truth table100%3/3
not(A) and B
A= not $rootB= $buf =~ m[\/Root$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so
ABresult
0X0
100
111
4728 6 { $root = $1;
4729 6 ▶ if ($xref)
Branch: 1 branch
BranchTrueFalseTotal
if ($xref) 0 6 6
4730 0 { last; }
4731 }
4732  
4733 30 ▶ if ((! $xref) && ($buf =~ m|\/Prev$ws+(\d+)\D|so))
Branch: 1 branch
BranchTrueFalseTotal
if (not $xref and $buf =~ m[\/Prev$PDF::Reuse::ws+(\d+)\D]so) 0 30 30
Condition33%1/3
not $xref and $buf =~ m[\/Prev$PDF::Reuse::ws+(\d+)\D]so
!ll&&!rl&&r
0300
MC/DC0%0/2
not $xref and $buf =~ m[\/Prev$PDF::Reuse::ws+(\d+)\D]so
not $xref $buf =~ m[\/Prev$PDF::Reuse::ws+(\d+)\D]so
Truth table33%1/3
not(A) and B
A= not $xrefB= $buf =~ m[\/Prev$PDF::Reuse::ws+(\d+)\D]so
ABresult
0X0
100
111
4734 0 { $xref = $1;
4735 0 ▶ if ($root)
Branch: 1 branch
BranchTrueFalseTotal
if ($root) 0 0 0
4736 0 { last; }
4737 }
4738  
4739 30 ▶ if ($buf =~ m'xref'so)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /xref/so) 6 24 30
4740 6 { last; }
4741  
4742 24 ▶ if($inrad=~ m/trailer/o && (! $root) && ($inrad =~ m'\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R'so))
Branch: 1 branch
BranchTrueFalseTotal
if ($inrad =~ /trailer/o and not $root and $inrad =~ m[\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R]so) 0 24 24
Condition66%4/6
$inrad =~ /trailer/o and not $root and $inrad =~ m[\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R]so
!ll&&!rl&&r
1860
$inrad =~ /trailer/o and not $root
!ll&&!rl&&r
1806
MC/DC0%0/3
$inrad =~ /trailer/o and not $root and $inrad =~ m[\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R]so
$inrad =~ /trailer/o not $root $inrad =~ m[\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R]so
Truth table50%2/4
A and not(B) and C
A= $inrad =~ /trailer/oB= not $rootC= $inrad =~ m[\/Root\s+(\d+)\s{1,2}\d+\s{1,2}R]so
ABCresult
0XX0
10X0
1100
1111
4743 0 { $root = $1;
4744 0 ▶ if ($xref)
Branch: 1 branch
BranchTrueFalseTotal
if ($xref) 0 0 0
4745 0 { last; }
4746 }
4747  
4748 24 sysread INFIL, $inrad, 30;
4749 }
4750 6 return ($xref, $root, $nr);
4751 }
4752  
4753 sub getObject
4754 88 ▶{ my ($nr, $noId, $noEnd) = @_;
Subroutine getObject: called CC=15 SCAR=40.4
Pod undocumented
4755  
4756 88 my $buf;
4757 88 my ($offs, $siz, $embedded) = @{$oldObject{$nr}};
4758  
4759 88 ▶ if ($offs)
Branch: 3 branches
BranchTrueFalseTotal
if ($offs) { } 88 0 88
elsif (exists $PDF::Reuse::unZipped{$nr}) { } 0 0 0
elsif ($embedded) { } 0 0 0
4760 88 { sysseek INFIL, $offs, 0;
4761 88 sysread INFIL, $buf, $siz;
4762 88 ▶ if (($noId) && ($noEnd))
Branch: 2 branches
BranchTrueFalseTotal
if ($noId and $noEnd) { } 12 76 88
elsif ($noId) { } 0 76 76
Condition66%2/3
$noId and $noEnd
!ll&&!rl&&r
76012
MC/DC50%1/2
$noId and $noEnd
$noId $noEnd
Truth table66%2/3
A and B
A= $noIdB= $noEnd
ABresult
0X0
100
111
4763 12 ▶ { if ($buf =~ m/^\d+$ws+\d+$ws+obj$ws*(.*)endobj/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*(.*)endobj/so) 12 0 12
4764 12 ▶ { if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 12 12
4765 0 { return ($1, $offs, $siz, $embedded);
4766 }
4767 else
4768 12 { return $1;
4769 }
4770 }
4771 }
4772 elsif ($noId)
4773 0 ▶ { if ($buf =~ m/^\d+$ws+\d+$ws+obj$ws*(.*)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*(.*)/so) 0 0 0
4774 0 ▶ { if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
4775 0 { return ($1, $offs, $siz, $embedded);
4776 }
4777 else
4778 0 { return $1;
4779 }
4780 }
4781 }
4782 76 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 6 70 76
4783 6 { return ($buf, $offs, $siz, $embedded)
4784 }
4785 else
4786 70 { return $buf;
4787 }
4788 }
4789 elsif (exists $unZipped{$nr})
4790 { ;
4791 }
4792 elsif ($embedded)
4793 0 { unZipPrepare($embedded);
4794 }
4795 0 ▶ if ($noEnd)
Branch: 1 branch
BranchTrueFalseTotal
if ($noEnd) { } 0 0 0
4796 0 ▶ { if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
4797 0 { return ($unZipped{$nr}, $offs, $siz, $embedded)
4798 }
4799 else
4800 0 { return $unZipped{$nr};
4801 }
4802 }
4803 else
4804 0 ▶ { if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
4805 0 { return ("$unZipped{$nr}endobj\n", $offs, $siz, $embedded)
4806 }
4807 else
4808 0 { return "$unZipped{$nr}endobj\n";
4809 }
4810 }
4811 }
4812  
4813 sub getKnown
4814 0 ▶{ my ($p, $nr) = @_;
Subroutine getKnown: not called CC=6 SCAR=37.4
Pod undocumented
4815 0 my ($del1, $del2);
4816 0 my @objData = @{$$$p[0]->{$nr}};
4817 0 ▶ if (defined $objData[oSTREAMP])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $objData[2]) { } 0 0 0
4818 0 { sysseek INFIL, ($objData[oNR][0] + $objData[oPOS]), 0;
4819 0 sysread INFIL, $del1, ($objData[oSTREAMP] - $objData[oPOS]);
4820 0 sysread INFIL, $del2, ($objData[oNR][1] - $objData[oSTREAMP]);
4821 }
4822 else
4823 0 { my $buf;
4824 0 my ($offs, $siz, $embedded) = @{$objData[oNR]};
4825 0 ▶ if ($offs)
Branch: 3 branches
BranchTrueFalseTotal
if ($offs) { } 0 0 0
elsif (exists $PDF::Reuse::unZipped{$nr}) { } 0 0 0
elsif ($embedded) { } 0 0 0
4826 0 { sysseek INFIL, $offs, 0;
4827 0 sysread INFIL, $buf, $siz;
4828 0 ▶ if ($buf =~ m/^\d+$ws+\d+$ws+obj$ws*(.*)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*(.*)/so) 0 0 0
4829 0 { $del1 = $1;
4830 }
4831 }
4832 elsif (exists $unZipped{$nr})
4833 0 { $del1 = "$unZipped{$nr} endobj";
4834 }
4835 elsif ($embedded)
4836 0 { @objData = @{$$$p[0]->{$embedded}};
4837 0 unZipPrepare($embedded, $objData[oNR][0], $objData[oNR][1]);
4838 0 $del1 = "$unZipped{$nr} endobj";
4839 }
4840 }
4841 0 return (\$del1, \$del2, $objData[oKIDS], $objData[oTYPE]);
4842 }
4843  
4844  
4845 sub unZipPrepare
4846 0 ▶{ my ($nr, $offs, $size) = @_;
Subroutine unZipPrepare: not called CC=11 SCAR=48.8
Pod undocumented
4847 0 my $buf;
4848 0 ▶ if ($offs)
Branch: 1 branch
BranchTrueFalseTotal
if ($offs) { } 0 0 0
4849 0 { sysseek INFIL, $offs, 0;
4850 0 sysread INFIL, $buf, $size;
4851 }
4852 else
4853 0 { $buf = getObject($nr);
4854 }
4855 0 my (%param, $stream, $str);
4856  
4857 0 ▶ if ($buf =~ m~^(\d+$ws+\d+$ws+obj$ws*<<[\w\d\/\s\[\]<>]+)stream\b~os)
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ m(^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<[\w\d\/\s\[\]<>]+)stream\b)so) 0 0 0
4858 0 { $str = $1;
4859 0 $offs = length($str) + 7;
4860 0 ▶ if (substr($buf, $offs, 1) eq "\n")
Branch: 1 branch
BranchTrueFalseTotal
if (substr($buf, $offs, 1) eq "\n") 0 0 0
4861 0 { $offs++;
4862 }
4863  
4864 0 for (split('/',$str))
4865 0 ▶ { if ($_ =~ m'^(\w+)(.*)'o)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^(\w+)(.*)/o) 0 0 0
4866 0 ▶ { $param{$1} = $2 || ' ';
Condition0%0/2
$2 || ' '
l!l
00
MC/DC0%0/1
$2 || ' '
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
4867 }
4868 }
4869 0 $stream = substr($buf, $offs, $param{'Length'});
4870 0 ▶ my $x = inflateInit()
Condition0%0/2
&inflateInit() || die("Cannot create an inflation stream\n")
l!l
00
MC/DC0%0/1
&inflateInit() || die("Cannot create an inflation stream\n")
&inflateInit()
Truth table0%0/2
A
A= &inflateInit()
Aresult
11
00
4871 || die "Cannot create an inflation stream\n";
4872 0 my ($output, $status) = $x->inflate($stream);
4873 0 ▶ die "inflation failed\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 1 0 0 0
4874 unless $status == 1;
4875  
4876 0 my $first = $param{'First'};
4877 0 my @oOffsets = (substr($output, 0, $first) =~ m'(\d+)\b'osg);
4878 0 my $i = 0;
4879 0 my $j = 1;
4880 0 my $bytes;
4881 0 ▶ while ($oOffsets[$i])
Branch: 1 branch
BranchTrueFalseTotal
if ($oOffsets[$i]) 0 0 0
4882 0 { my $k = $j + 2;
4883 0 ▶ if ($oOffsets[$k])
Branch: 1 branch
BranchTrueFalseTotal
if ($oOffsets[$k]) { } 0 0 0
4884 0 { $bytes = $oOffsets[$k] - $oOffsets[$j];
4885 }
4886 else
4887 0 { $bytes = length($output) - $first - $oOffsets[$j];
4888 }
4889 0 $unZipped{$oOffsets[$i]} = substr($output,($first + $oOffsets[$j]), $bytes);
4890 0 $i += 2;
4891 0 $j += 2;
4892 }
4893 }
4894 }
4895  
4896 ############################################
4897 # En definitionerna för en sida extraheras
4898 ############################################
4899  
4900 sub getPage
4901 2 ▶{ my ($infil, $sidnr, $action) = @_;
Subroutine getPage: called CC=98 SCAR=72.3
Pod undocumented
4902  
4903 2 my ($res, $i, $referens,$objNrSaved,$validStream, $formRes, @objData,
4904 @underObjekt, @sidObj, $strPos, $startSida, $sidor, $filId, $del1, $del2,
4905 $offs, $siz, $embedded, $vektor, $utrad, $robj, $valid, $Annots, $Names,
4906 $AcroForm, $AARoot, $AAPage);
4907  
4908 2 my $sidAcc = 0;
4909 2 my $seq = 0;
4910 2 $imSeq = 0;
4911 2 @skapa = ();
4912 2 undef $formCont;
4913  
4914  
4915 2 $objNrSaved = $objNr;
4916 2 my $fSource = $infil . '_' . $sidnr;
4917 2 my $checkidOld = $checkId;
4918 2 ($infil, $checkId) = findGet($infil, $checkidOld);
4919 2 ▶ if (($ldir) && ($checkId) && ($checkId ne $checkidOld))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkidOld) 0 2 2
Condition33%2/6
$PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkidOld
!ll&&!rl&&r
200
$PDF::Reuse::ldir and $PDF::Reuse::checkId
!ll&&!rl&&r
200
MC/DC0%0/3
$PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkidOld
$PDF::Reuse::ldir $PDF::Reuse::checkId $PDF::Reuse::checkId ne $checkidOld
Truth table25%1/4
A and B and C
A= $PDF::Reuse::ldirB= $PDF::Reuse::checkIdC= $PDF::Reuse::checkId ne $checkidOld
ABCresult
0XX0
10X0
1100
1111
4920 0 { $log .= "Cid~$checkId\n";
4921 }
4922 2 $form{$fSource}[fID] = $checkId;
4923 2 $checkId = '';
4924 2 dropChangedCache($infil);
4925 $behandlad{$infil}->{old} = {}
4926 2 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 2 0 2
4927 $processed{$infil}->{oldObject} = {}
4928 2 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 2 0 2
4929 $processed{$infil}->{unZipped} = {}
4930 2 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 2 0 2
4931  
4932 2 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'print') { } 2 0 2
4933 2 { *old = $behandlad{$infil}->{old};
4934 }
4935 else
4936 0 { $behandlad{$infil}->{dummy} = {};
4937 0 *old = $behandlad{$infil}->{dummy};
4938 }
4939  
4940 2 *oldObject = $processed{$infil}->{oldObject};
4941 2 *unZipped = $processed{$infil}->{unZipped};
4942 $root = (exists $processed{$infil}->{root})
4943 2 ▶ ? $processed{$infil}->{root} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::processed{$infil}{'root'} ? : 0 2 2
4944  
4945  
4946 2 my @stati = stat($infil);
4947 2 ▶ open (INFIL, "<$infil") || errLog("Couldn't open $infil, $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("Couldn't open $infil, $!") 2 0 2
4948 2 binmode INFIL;
4949  
4950 2 ▶ if (! $root)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::root) 2 0 2
4951 2 { $root = xRefs($stati[7], $infil);
4952 }
4953  
4954 #############
4955 # Hitta root
4956 #############
4957  
4958 2 my $objektet = getObject($root);;
4959  
4960 2 ▶ if ($sidnr == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidnr == 1) 2 0 2
4961 2 ▶ { if ($objektet =~ m|/AcroForm($ws+\d+$ws+\d+$ws+R)|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/AcroForm($PDF::Reuse::ws+\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R)]so) 0 2 2
4962 0 { $AcroForm = $1;
4963 }
4964 2 ▶ if ($objektet =~ m|/Names$ws+(\d+)$ws+\d+$ws+R|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Names$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 2 2
4965 0 { $Names = $1;
4966 }
4967 #################################################
4968 # Finns ett dictionary för Additional Actions ?
4969 #################################################
4970 2 ▶ if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/AA$PDF::Reuse::ws*\<\<$PDF::Reuse::ws*[^\>]+[^\>]+]so) 0 2 2
4971 0 { my $k;
4972 0 my ($dummy, $obj) = split /\/AA/, $objektet;
4973 0 $obj =~ s/\<\</\#\<\</gs;
4974 0 $obj =~ s/\>\>/\>\>\#/gs;
4975 0 my @ord = split /\#/, $obj;
4976 0 ▶ for ($i = 0; $i <= $#ord; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#ord) 0 0 0
4977 0 { $AARoot .= $ord[$i];
4978 0 ▶ if ($ord[$i] =~ m'\S+'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /\S+/so) 0 0 0
4979 0 ▶ { if ($ord[$i] =~ m'<<'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /<</so) 0 0 0
4980 0 { $k++; }
4981 0 ▶ if ($ord[$i] =~ m'>>'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ />>/so) 0 0 0
4982 0 { $k--; }
4983 0 ▶ if ($k == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 0) 0 0 0
4984 0 { last; }
4985 }
4986 }
4987 }
4988 }
4989  
4990 #
4991 # Hitta pages
4992 #
4993  
4994 2 ▶ if ($objektet =~ m|/Pages$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Pages$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) { } 2 0 2
4995 2 { $objektet = getObject($1);
4996 2 ▶ if ($objektet =~ m|/Count$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Count$PDF::Reuse::ws+(\d+)]so) 2 0 2
4997 2 { $sidor = $1;
4998 2 ▶ if ($sidnr <= $sidor)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidnr <= $sidor) { } 2 0 2
4999 2 { ($formRes, $valid) = kolla($objektet);
5000 }
5001 else
5002 0 { return 0;
5003 }
5004 2 ▶ if ($sidor > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidor > 1) 0 2 2
5005 0 { undef $AcroForm;
5006 0 undef $Names;
5007 0 undef $AARoot;
5008 0 ▶ if ($type eq 'docform')
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::type eq "docform") 0 0 0
5009 0 { errLog("prDocForm can only be used for single page documents - try prDoc or reformat $infil");
5010 }
5011 }
5012 }
5013 }
5014 else
5015 0 { errLog("Didn't find Pages in $infil - aborting"); }
5016  
5017 2 ▶ if ($objektet =~ m|/Kids$ws*\[([^\]]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m(/Kids$PDF::Reuse::ws*\[([^\]]+))so) 2 0 2
5018 2 { $vektor = $1; }
5019 2 ▶ while ($vektor =~ m|(\d+)$ws+\d+$ws+R|go)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/go) 2 2 4
5020 2 { push @sidObj, $1;
5021 }
5022  
5023 2 my $bryt1 = -20; # Hängslen
5024 2 my $bryt2 = -20; # Svångrem för att undvika oändliga loopar
5025  
5026 2 ▶ while ($sidAcc < $sidnr)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidAcc < $sidnr) 2 2 4
5027 2 { @underObjekt = @sidObj;
5028 2 @sidObj = ();
5029 2 $bryt1++;
5030 2 for my $uO (@underObjekt)
5031 2 { $objektet = getObject($uO);
5032 2 ▶ if ($objektet =~ m|/Count$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Count$PDF::Reuse::ws+(\d+)]so) { } 0 2 2
5033 0 ▶ { if (($sidAcc + $1) < $sidnr)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidAcc + $1 < $sidnr) { } 0 0 0
5034 0 { $sidAcc += $1; }
5035 else
5036 0 { ($formRes, $valid) = kolla($objektet, $formRes);
5037 0 ▶ if ($objektet =~ m|/Kids$ws*\[([^\]]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m(/Kids$PDF::Reuse::ws*\[([^\]]+))so) 0 0 0
5038 0 { $vektor = $1; }
5039 0 ▶ while ($vektor =~ m/(\d+)$ws+\d+$ws+R/gso)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/sog) 0 0 0
5040 0 { push @sidObj, $1; }
5041 0 last;
5042 }
5043 }
5044 else
5045 2 { $sidAcc++; }
5046 2 ▶ if ($sidAcc == $sidnr)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidAcc == $sidnr) 2 0 2
5047 2 { $seq = $uO;
5048 2 last; }
5049 0 $bryt2++;
5050 }
5051 2 ▶ if (($bryt1 > $sidnr) || ($bryt2 > $sidnr)) # Bryt oändliga loopar
Branch: 1 branch
BranchTrueFalseTotal
if ($bryt1 > $sidnr or $bryt2 > $sidnr) 0 2 2
Condition33%1/3
$bryt1 > $sidnr or $bryt2 > $sidnr
l!l&&r!l&&!r
002
MC/DC0%0/2
$bryt1 > $sidnr or $bryt2 > $sidnr
$bryt1 > $sidnr $bryt2 > $sidnr
Truth table33%1/3
A or B
A= $bryt1 > $sidnrB= $bryt2 > $sidnr
ABresult
1X1
011
000
5052 0 { last; }
5053 }
5054  
5055 2 ($formRes, $validStream) = kolla($objektet, $formRes);
5056 2 $startSida = $seq;
5057  
5058 2 ▶ if ($sidor == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidor == 1) 2 0 2
5059 { #################################################
5060 # Kontrollera Page-objektet för annoteringar
5061 #################################################
5062  
5063 2 ▶ if ($objektet =~ m|/Annots$ws*([^\/]+)|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Annots$PDF::Reuse::ws*([^\/]+)]so) 0 2 2
5064 0 { $Annots = $1;
5065 }
5066 #################################################
5067 # Finns ett dictionary för Additional Actions ?
5068 #################################################
5069 2 ▶ if ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary. Hela kopieras
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/AA$PDF::Reuse::ws*\<\<$PDF::Reuse::ws*[^\>]+[^\>]+]so) 0 2 2
5070 0 { my $k;
5071 0 my ($dummy, $obj) = split /\/AA/, $objektet;
5072 0 $obj =~ s/\<\</\#\<\</gs;
5073 0 $obj =~ s/\>\>/\>\>\#/gs;
5074 0 my @ord = split /\#/, $obj;
5075 0 ▶ for ($i = 0; $i <= $#ord; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#ord) 0 0 0
5076 0 { $AAPage .= $ord[$i];
5077 0 ▶ if ($ord[$i] =~ m'\S+'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /\S+/s) 0 0 0
5078 0 ▶ { if ($ord[$i] =~ m'<<'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /<</s) 0 0 0
5079 0 { $k++; }
5080 0 ▶ if ($ord[$i] =~ m'>>'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ />>/s) 0 0 0
5081 0 { $k--; }
5082 0 ▶ if ($k == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 0) 0 0 0
5083 0 { last; }
5084 }
5085 }
5086 }
5087 }
5088  
5089 2 my $rform = \$form{$fSource};
5090 2 @$$rform[fRESOURCE] = $formRes;
5091 2 my @BBox;
5092 2 ▶ if (defined $formBox[0])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::formBox[0]) { } 2 0 2
5093 2 { $BBox[0] = $formBox[0]; }
5094 else
5095 0 { $BBox[0] = $genLowerX; }
5096  
5097 2 ▶ if (defined $formBox[1])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::formBox[1]) { } 2 0 2
5098 2 { $BBox[1] = $formBox[1]; }
5099 else
5100 0 { $BBox[1] = $genLowerY; }
5101  
5102 2 ▶ if (defined $formBox[2])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::formBox[2]) { } 2 0 2
5103 2 { $BBox[2] = $formBox[2]; }
5104 else
5105 0 { $BBox[2] = $genUpperX; }
5106  
5107 2 ▶ if (defined $formBox[3])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::formBox[3]) { } 2 0 2
5108 2 { $BBox[3] = $formBox[3]; }
5109 else
5110 0 { $BBox[3] = $genUpperY; }
5111  
5112 2 @{$form{$fSource}[fBBOX]} = @BBox;
5113  
5114 2 ▶ if ($formCont)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::formCont) { } 2 0 2
5115 2 { $seq = $formCont;
5116 2 ($objektet, $offs, $siz, $embedded) = getObject($seq);
5117  
5118 2 $robj = \$$$rform[fOBJ]->{$seq};
5119 2 @{$$$robj[oNR]} = ($offs, $siz, $embedded);
5120 2 $$$robj[oFORM] = 'Y';
5121 2 $form{$fSource}[fMAIN] = $seq;
5122 2 ▶ if ($objektet =~ m/^(\d+$ws+\d+$ws+obj$ws*<<)(.+)(>>$ws*stream)/so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<)(.+)(>>$PDF::Reuse::ws*stream)/so) { } 2 0 2
5123 2 { $del1 = $2;
5124 2 $strPos = length($1) + length($2) + length($3);
5125 2 $$$robj[oPOS] = length($1);
5126 2 $$$robj[oSTREAMP] = $strPos;
5127 2 my $nyDel1;
5128 2 $nyDel1 = '<</Type/XObject/Subtype/Form/FormType 1';
5129 2 $nyDel1 .= "/Resources $formRes" .
5130 "/BBox \[ $BBox[0] $BBox[1] $BBox[2] $BBox[3]\]" .
5131 # "/Matrix \[ 1 0 0 1 0 0 \]" .
5132 $del1;
5133 2 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 2 0 2
5134 2 { $objNr++;
5135 2 $objekt[$objNr] = $pos;
5136 }
5137 2 $referens = $objNr;
5138  
5139 2 $res = ($nyDel1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs);
5140 2 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 2 0 2
5141 2 { $$$robj[oKIDS] = 1; }
5142 2 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 2 0 2
5143 2 { $utrad = "$referens 0 obj\n" . "$nyDel1" . ">>\nstream";
5144 2 $del2 = substr($objektet, $strPos);
5145 2 $utrad .= $del2;
5146 2 $pos += syswrite UTFIL, $utrad;
5147 }
5148 2 $form{$fSource}[fVALID] = $validStream;
5149 }
5150 else # Endast resurserna kan behandlas
5151 0 { $formRes =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5152 }
5153 }
5154 else # Endast resurserna kan behandlas
5155 0 { $formRes =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5156 }
5157  
5158 2 my $preLength;
5159 2 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 4 2 6
5160 4 { my @process = @skapa;
5161 4 @skapa = ();
5162 4 for (@process)
5163 4 { my $Font;
5164 4 my $gammal = $$_[0];
5165 4 my $ny = $$_[1];
5166 4 ($objektet, $offs, $siz, $embedded) = getObject($gammal);
5167 4 $robj = \$$$rform[fOBJ]->{$gammal};
5168 4 @{$$$robj[oNR]} = ($offs, $siz, $embedded);
5169 4 ▶ if($objektet =~ m/^(\d+$ws+\d+$ws+obj$ws*<<)(.+)(>>$ws*stream)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<)(.+)(>>$PDF::Reuse::ws*stream)/so) { } 0 4 4
5170 0 { $del1 = $2;
5171 0 $strPos = length ($1) + length($2) + length($3);
5172 0 $$$robj[oPOS] = length($1);
5173 0 $$$robj[oSTREAMP] = $strPos;
5174  
5175 ######## En bild ########
5176 0 ▶ if ($del1 =~ m|/Subtype$ws*/Image|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Subtype$PDF::Reuse::ws*/Image]so) 0 0 0
5177 0 { $imSeq++;
5178 0 $$$robj[oIMAGENR] = $imSeq;
5179 0 push @{$$$rform[fIMAGES]}, $gammal;
5180  
5181 0 ▶ if ($del1 =~ m|/Width$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Width$PDF::Reuse::ws+(\d+)]so) 0 0 0
5182 0 { $$$robj[oWIDTH] = $1; }
5183 0 ▶ if ($del1 =~ m|/Height$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Height$PDF::Reuse::ws+(\d+)]so) 0 0 0
5184 0 { $$$robj[oHEIGHT] = $1; }
5185 }
5186 0 $res = ($del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs);
5187 0 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
5188 0 { $$$robj[oKIDS] = 1; }
5189 0 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 0 0 0
5190 0 { $objekt[$ny] = $pos;
5191 0 $utrad = "$ny 0 obj\n<<" . "$del1" . '>>stream';
5192 0 $del2 = substr($objektet, $strPos);
5193 0 $utrad .= $del2;
5194 }
5195 }
5196 else
5197 4 ▶ { if ($objektet =~ m|^(\d+$ws+\d+$ws+obj$ws*)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*)/so) { } 4 0 4
5198 4 { $preLength = length($1);
5199 4 $$$robj[oPOS] = $preLength;
5200 4 $objektet = substr($objektet, $preLength);
5201 }
5202 else
5203 0 { $$$robj[oPOS] = 0;
5204 }
5205 4 $res = ($objektet =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs);
5206 4 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 2 2 4
5207 2 { $$$robj[oKIDS] = 1; }
5208 4 ▶ if ($objektet =~ m|/Subtype$ws*/Image|so)
Branch: 2 branches
BranchTrueFalseTotal
if ($objektet =~ m[/Subtype$PDF::Reuse::ws*/Image]so) { } 0 4 4
elsif ($objektet =~ m[/BaseFont$PDF::Reuse::ws*/([^\s\/]+)]so) { } 2 2 4
5209 0 { $imSeq++;
5210 0 $$$robj[oIMAGENR] = $imSeq;
5211 0 push @{$$$rform[fIMAGES]}, $gammal;
5212 ###################################
5213 # Sparar dimensionerna för bilden
5214 ###################################
5215 0 ▶ if ($del1 =~ m|/Width$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Width$PDF::Reuse::ws+(\d+)]so) 0 0 0
5216 0 { $$$robj[oWIDTH] = $1; }
5217  
5218 0 ▶ if ($del1 =~ m|/Height$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Height$PDF::Reuse::ws+(\d+)]so) 0 0 0
5219 0 { $$$robj[oHEIGHT] = $1; }
5220 }
5221 elsif ($objektet =~ m|/BaseFont$ws*/([^\s\/]+)|os)
5222 2 { $Font = $1;
5223 2 $$$robj[oTYPE] = 'Font';
5224 2 $$$robj[oNAME] = $Font;
5225 2 ▶ if ((! exists $font{$Font})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $PDF::Reuse::font{$Font} and $action) 2 0 2
Condition33%1/3
not exists $PDF::Reuse::font{$Font} and $action
!ll&&!rl&&r
002
MC/DC0%0/2
not exists $PDF::Reuse::font{$Font} and $action
not exists $PDF::Reuse::font{$Font} $action
Truth table33%1/3
not(A) and B
A= not exists $PDF::Reuse::font{$Font}B= $action
ABresult
0X0
100
111
5226 && ($action))
5227 2 { $fontNr++;
5228 2 $font{$Font}[foINTNAMN] = 'Ft' . $fontNr;
5229 2 $font{$Font}[foORIGINALNR] = $gammal;
5230 2 $fontSource{$Font}[foSOURCE] = $fSource;
5231 2 $fontSource{$Font}[foORIGINALNR] = $gammal;
5232 2 ▶ if ($objektet =~ m|/Subtype$ws*/Type0|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Subtype$PDF::Reuse::ws*/Type0]so) 0 2 2
5233 0 { $font{$Font}[foTYP] = 1;
5234 }
5235 2 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 2 0 2
5236 2 { $font{$Font}[foREFOBJ] = $ny;
5237 2 $objRef{'Ft' . $fontNr} = $ny;
5238 }
5239 }
5240 }
5241  
5242 4 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 4 0 4
5243 4 { $objekt[$ny] = $pos;
5244 4 $utrad = "$ny 0 obj $objektet";
5245 }
5246 }
5247 4 ▶ if ($action eq 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "print") 4 0 4
5248 4 { $pos += syswrite UTFIL, $utrad;
5249 }
5250 }
5251 }
5252  
5253 2 my $ref = \$form{$fSource};
5254 2 my @kids;
5255 my @nokids;
5256  
5257 #################################################################
5258 # lägg upp vektorer över vilka objekt som har KIDS eller NOKIDS
5259 #################################################################
5260  
5261 2 for my $key (keys %{$$$ref[fOBJ]})
5262 6 { $robj = \$$$ref[fOBJ]->{$key};
5263 6 ▶ if (! defined $$$robj[oFORM])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$robj->[4]) 4 2 6
5264 4 ▶ { if (defined $$$robj[oKIDS])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$robj->[3]) { } 2 2 4
5265 2 { push @kids, $key; }
5266 else
5267 2 { push @nokids, $key; }
5268 }
5269 6 ▶ if ((defined $$$robj[0]->[2]) && (! exists $$$ref[fOBJ]->{$$$robj[0]->[2]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}) 0 6 6
Condition33%1/3
defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}
!ll&&!rl&&r
600
MC/DC0%0/2
defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}
defined $$robj->[0][2] not exists $$ref->[0]{$$robj->[0][2]}
Truth table33%1/3
A and not(B)
A= defined $$robj->[0][2]B= not exists $$ref->[0]{$$robj->[0][2]}
ABresult
0X0
100
111
5270 0 { $$$ref[fOBJ]->{$$$robj[0]->[2]}->[0] = $oldObject{$$$robj[0]->[2]};
5271 }
5272 }
5273 2 ▶ if (scalar @kids)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @kids) 2 0 2
5274 2 { $form{$fSource}[fKIDS] = \@kids;
5275 }
5276 2 ▶ if (scalar @nokids)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @nokids) 2 0 2
5277 2 { $form{$fSource}[fNOKIDS] = \@nokids;
5278 }
5279  
5280 2 ▶ if ($action ne 'print')
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "print") 0 2 2
5281 0 { $objNr = $objNrSaved; # Restore objNo if nothing was printed
5282 }
5283  
5284 2 $behandlad{$infil}->{dummy} = {};
5285 2 *old = $behandlad{$infil}->{dummy};
5286  
5287 2 $objNrSaved = $objNr; # Save objNo
5288  
5289 2 ▶ if ($sidor == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidor == 1) 2 0 2
5290 2 { @skapa = ();
5291 2 $old{$startSida} = $sidObjNr;
5292 2 my $ref = \$intAct{$fSource};
5293 2 @$$ref[iSTARTSIDA] = $startSida;
5294 2 ▶ if (defined $Names)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Names) 0 2 2
5295 0 { @$$ref[iNAMES] = $Names;
5296 0 quickxform($Names);
5297 }
5298 2 ▶ if (defined $AcroForm)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AcroForm) 0 2 2
5299 0 { @$$ref[iACROFORM] = $AcroForm;
5300 0 $AcroForm =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5301 }
5302 2 ▶ if (defined $AARoot)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AARoot) 0 2 2
5303 0 { @$$ref[iAAROOT] = $AARoot;
5304 0 $AARoot =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5305 }
5306 2 ▶ if (defined $AAPage)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AAPage) 0 2 2
5307 0 { @$$ref[iAAPAGE] = $AAPage;
5308 0 $AAPage =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5309 }
5310 2 ▶ if (defined $Annots)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Annots) 0 2 2
5311 0 { my @array;
5312 0 ▶ if ($Annots =~ m'\[([^\[\]]*)\]'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots =~ /\[([^\[\]]*)\]/so) { } 0 0 0
5313 0 { $Annots = $1;
5314 0 @array = ($Annots =~ m/\b(\d+)$ws+\d+$ws+R\b/ogs);
5315 }
5316 else
5317 0 ▶ { if ($Annots =~ m/\b(\d+)$ws+\d+$ws+R\b/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b/so) 0 0 0
5318 0 { $Annots = getObject($1);
5319 0 @array = ($Annots =~ m/\b(\d+)$ws+\d+$ws+R\b/ogs);
5320 }
5321 }
5322 0 @$$ref[iANNOTS] = \@array;
5323 0 $Annots =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5324 }
5325  
5326 2 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 0 2 2
5327 0 { my @process = @skapa;
5328 0 @skapa = ();
5329 0 for (@process)
5330 0 { my $gammal = $$_[0];
5331 0 my $ny = $$_[1];
5332 0 ($objektet, $offs, $siz, $embedded) = getObject($gammal);
5333 0 $robj = \$$$ref[fOBJ]->{$gammal};
5334 0 @{$$$robj[oNR]} = ($offs, $siz, $embedded);
5335 0 ▶ if ($objektet
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<)(.+)(>>$PDF::Reuse::ws*stream)/so) { } 0 0 0
5336 =~ m/^(\d+$ws+\d+$ws+obj$ws*<<)(.+)(>>$ws*stream)/os)
5337 0 { $del1 = $2;
5338 0 $$$robj[oPOS] = length($1);
5339 0 $$$robj[oSTREAMP] = length($1) + length($2) + length($3);
5340  
5341 0 $res = ($del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs);
5342 0 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
5343 0 { $$$robj[oKIDS] = 1; }
5344 }
5345 else
5346 0 ▶ { if ($objektet =~ m/^(\d+$ws+\d+$ws+obj)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj)/so) 0 0 0
5347 0 { my $preLength = length($1);
5348 0 $$$robj[oPOS] = $preLength;
5349 0 $objektet = substr($objektet, $preLength);
5350  
5351 0 $res = ($objektet =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs);
5352 0 ▶ if ($res)
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
5353 0 { $$$robj[oKIDS] = 1; }
5354 }
5355 }
5356 }
5357 }
5358 2 for my $key (keys %{$$$ref[fOBJ]})
5359 0 { $robj = \$$$ref[fOBJ]->{$key};
5360 0 ▶ if ((defined $$$robj[0]->[2]) && (! exists $$$ref[fOBJ]->{$$$robj[0]->[2]}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}) 0 0 0
Condition0%0/3
defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $$robj->[0][2] and not exists $$ref->[0]{$$robj->[0][2]}
defined $$robj->[0][2] not exists $$ref->[0]{$$robj->[0][2]}
Truth table0%0/3
A and not(B)
A= defined $$robj->[0][2]B= not exists $$ref->[0]{$$robj->[0][2]}
ABresult
0X0
100
111
5361 0 { $$$ref[fOBJ]->{$$$robj[0]->[2]}->[0] = $oldObject{$$$robj[0]->[2]};
5362 }
5363 }
5364 }
5365  
5366 2 $objNr = $objNrSaved;
5367 2 $processed{$infil}->{root} = $root;
5368 2 close INFIL;
5369 2 return $referens;
5370 }
5371  
5372 ##################################################
5373 # Översätter ett gammalt objektnr till ett nytt
5374 # och sparar en tabell med vad som skall skapas
5375 ##################################################
5376  
5377 sub xform
5378 73 ▶{ if (exists $old{$1})
Subroutine xform: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$1}) { } 37 36 73
5379 37 { $old{$1};
5380 }
5381 else
5382 36 { push @skapa, [$1, ++$objNr];
5383 36 $old{$1} = $objNr;
5384 }
5385 }
5386  
5387 sub kolla
5388 4 ▶{ #
Subroutine kolla: called CC=12 SCAR=36.2
Pod undocumented
5389 # Resurser
5390 #
5391 4 my $obj = shift;
5392 4 my $resources = shift;
5393 4 my $valid;
5394  
5395 4 ▶ if ($obj =~ m/MediaBox$ws*\[$ws*([\-\.\d]+)$ws+([\-\.\d]+)$ws+([\-\.\d]+)$ws+([\-\.\d]+)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ /MediaBox$PDF::Reuse::ws*\[$PDF::Reuse::ws*([\-\.\d]+)$PDF::Reuse::ws+([\-\.\d]+)$PDF::Reuse::ws+([\-\.\d]+)$PDF::Reuse::ws+([\-\.\d]+)/so) 2 2 4
5396 2 { $formBox[0] = $1;
5397 2 $formBox[1] = $2;
5398 2 $formBox[2] = $3;
5399 2 $formBox[3] = $4;
5400 }
5401  
5402 4 ▶ if ($obj =~ m|/Contents$ws+(\d+)|so)
Branch: 2 branches
BranchTrueFalseTotal
if ($obj =~ m[/Contents$PDF::Reuse::ws+(\d+)]so) { } 2 2 4
elsif ($obj =~ m(/Contents$PDF::Reuse::ws*\[$PDF::Reuse::ws*(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R$PDF::Reuse::ws*\])so) { } 0 2 2
5403 2 { $formCont = $1;
5404 2 my $cObj = getObject($formCont, 1, 1);
5405 2 ▶ if ($cObj =~ m/^$ws*\[[^\]]+\]$ws*$/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($cObj =~ /^$PDF::Reuse::ws*\[[^\]]+\]$PDF::Reuse::ws*$/so) { } 0 2 2
5406 0 { $valid = 0;
5407 0 undef $formCont;
5408 }
5409 else
5410 2 { $valid = 1;
5411 }
5412 }
5413 elsif ($obj =~ m|/Contents$ws*\[$ws*(\d+)$ws+\d+$ws+R$ws*\]|so)
5414 0 { $formCont = $1;
5415 0 $valid = 1;
5416 }
5417  
5418 4 ▶ if ($obj =~ m'^(.+/Resources)'so)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m[^(.+/Resources)]so) 2 2 4
5419 2 ▶ { if ($obj =~ m/Resources($ws+\d+$ws+\d+$ws+R)/os) # Hänvisning
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ /Resources($PDF::Reuse::ws+\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R)/so) { } 2 0 2
5420 2 { $resources = $1; }
5421 else # Resurserna är ett dictionary. Hela kopieras
5422 0 { my $dummy;
5423 my $i;
5424 0 my $k;
5425 0 undef $resources;
5426 0 ($dummy, $obj) = split /\/Resources/, $obj;
5427 0 $obj =~ s/\<\</\#\<\</gs;
5428 0 $obj =~ s/\>\>/\>\>\#/gs;
5429 0 my @ord = split /\#/, $obj;
5430 0 ▶ for ($i = 0; $i <= $#ord; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#ord) 0 0 0
5431 0 { $resources .= $ord[$i];
5432 0 ▶ if ($ord[$i] =~ m'\S+'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /\S+/s) 0 0 0
5433 0 ▶ { if ($ord[$i] =~ m'<<'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /<</s) 0 0 0
5434 0 { $k++; }
5435 0 ▶ if ($ord[$i] =~ m'>>'s)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ />>/s) 0 0 0
5436 0 { $k--; }
5437 0 ▶ if ($k == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 0) 0 0 0
5438 0 { last; }
5439 }
5440 }
5441 }
5442 }
5443 4 return ($resources, $valid);
5444 }
5445  
5446 ##############################
5447 # Ett formulär (åter)skapas
5448 ##############################
5449  
5450 sub byggForm
5451 3 ▶{ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine byggForm: not called CC=26 SCAR=64.9
Pod undocumented
5452 0 my ($infil, $sidnr) = @_;
5453  
5454 0 my ($res, $corr, $nyDel1, $formRes, $del1, $del2, $kids, $typ, $nr,
5455 $utrad);
5456  
5457 0 my $fSource = $infil . '_' . $sidnr;
5458 0 my @stati = stat($infil);
5459  
5460 0 dropChangedCache($infil);
5461 $behandlad{$infil}->{old} = {}
5462 0 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 0 0 0
5463 $processed{$infil}->{oldObject} = {}
5464 0 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 0 0 0
5465 $processed{$infil}->{unZipped} = {}
5466 0 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 0 0 0
5467  
5468 0 *old = $behandlad{$infil}->{old};
5469 0 *oldObject = $processed{$infil}->{oldObject};
5470 0 *unZipped = $processed{$infil}->{unZipped};
5471  
5472 0 ▶ if ($form{$fSource}[fID] != $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::form{$fSource}[7] != $stati[9]) 0 0 0
5473 0 { errLog("$stati[9] ne $form{$fSource}[fID] aborts");
5474 }
5475 0 ▶ if ($checkId)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId) 0 0 0
5476 0 ▶ { if ($checkId ne $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId ne $stati[9]) 0 0 0
5477 0 { my $mess = "$checkId \<\> $stati[9] \n"
5478 . "The Pdf-file $fSource has not the correct modification time. \n"
5479 . "The program is aborted";
5480 0 errLog($mess);
5481 }
5482 0 undef $checkId;
5483 }
5484 0 ▶ if ($ldir)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::ldir) 0 0 0
5485 0 { $log .= "Cid~$stati[9]\n";
5486 }
5487  
5488 0 ▶ open (INFIL, "<$infil") || errLog("The file $infil couldn't be opened, aborting $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("The file $infil couldn't be opened, aborting $!") 0 0 0
5489 0 binmode INFIL;
5490  
5491 ####################################################
5492 # Objekt utan referenser kopieras och skrivs
5493 ####################################################
5494  
5495 0 for my $key (@{$form{$fSource}->[fNOKIDS]})
5496 0 ▶ { if ((defined $old{$key}) && ($objekt[$old{$key}])) # already processed
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]) 0 0 0
Condition0%0/3
defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
defined $PDF::Reuse::old{$key} $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
Truth table0%0/3
A and B
A= defined $PDF::Reuse::old{$key}B= $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
ABresult
0X0
100
111
5497 0 { next;
5498 }
5499  
5500 0 ▶ if (! defined $old{$key})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::old{$key}) 0 0 0
5501 0 { $old{$key} = ++$objNr;
5502 }
5503 0 $nr = $old{$key};
5504 0 $objekt[$nr] = $pos;
5505  
5506 0 ($del1, $del2, $kids, $typ) = getKnown(\$form{$fSource},$key);
5507  
5508 0 ▶ if ($typ eq 'Font')
Branch: 1 branch
BranchTrueFalseTotal
if ($typ eq "Font") 0 0 0
5509 0 { my $Font = ${$form{$fSource}}[0]->{$key}->[oNAME];
5510 0 ▶ if (! defined $font{$Font}[foINTNAMN])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::font{$Font}[1]) 0 0 0
5511 0 { $fontNr++;
5512 0 $font{$Font}[foINTNAMN] = 'Ft' . $fontNr;
5513 0 $font{$Font}[foREFOBJ] = $nr;
5514 0 $objRef{'Ft' . $fontNr} = $nr;
5515 }
5516 }
5517 0 ▶ if (! defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $$del2) { } 0 0 0
5518 0 { $utrad = "$nr 0 obj " . $$del1;
5519 }
5520 else
5521 0 { $utrad = "$nr 0 obj\n<<" . $$del1 . $$del2;
5522 }
5523 0 $pos += syswrite UTFIL, $utrad;
5524 }
5525  
5526 #######################################################
5527 # Objekt med referenser kopieras, behandlas och skrivs
5528 #######################################################
5529 0 for my $key (@{$form{$fSource}->[fKIDS]})
5530 0 ▶ { if ((defined $old{$key}) && ($objekt[$old{$key}])) # already processed
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]) 0 0 0
Condition0%0/3
defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $PDF::Reuse::old{$key} and $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
defined $PDF::Reuse::old{$key} $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
Truth table0%0/3
A and B
A= defined $PDF::Reuse::old{$key}B= $PDF::Reuse::objekt[$PDF::Reuse::old{$key}]
ABresult
0X0
100
111
5531 0 { next;
5532 }
5533  
5534 0 ▶ if (! defined $old{$key})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::old{$key}) 0 0 0
5535 0 { $old{$key} = ++$objNr;
5536 }
5537 0 $nr = $old{$key};
5538  
5539 0 $objekt[$nr] = $pos;
5540  
5541 0 ($del1, $del2, $kids, $typ) = getKnown(\$form{$fSource},$key);
5542  
5543 0 $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/translate() . ' 0 R'/oegs;
5544  
5545 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
5546 0 { $utrad = "$nr 0 obj\n<<" . $$del1 . $$del2;
5547 }
5548 else
5549 0 { $utrad = "$nr 0 obj " . $$del1;
5550 }
5551  
5552 0 ▶ if (($typ) && ($typ eq 'Font'))
Branch: 1 branch
BranchTrueFalseTotal
if ($typ and $typ eq "Font") 0 0 0
Condition0%0/3
$typ and $typ eq "Font"
!ll&&!rl&&r
000
MC/DC0%0/2
$typ and $typ eq "Font"
$typ $typ eq "Font"
Truth table0%0/3
A and B
A= $typB= $typ eq "Font"
ABresult
0X0
100
111
5553 0 { my $Font = $form{$fSource}[0]->{$key}->[oNAME];
5554 0 ▶ if (! defined $font{$Font}[foINTNAMN])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::font{$Font}[1]) 0 0 0
5555 0 { $fontNr++;
5556 0 $font{$Font}[foINTNAMN] = 'Ft' . $fontNr;
5557 0 $font{$Font}[foREFOBJ] = $nr;
5558 0 $objRef{'Ft' . $fontNr} = $nr;
5559 }
5560 }
5561  
5562 0 $pos += syswrite UTFIL, $utrad;
5563 }
5564  
5565 #################################
5566 # Formulärobjektet behandlas
5567 #################################
5568  
5569 0 my $key = $form{$fSource}->[fMAIN];
5570 0 ▶ if (! defined $key)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
5571 0 { return undef;
5572 }
5573  
5574 0 ▶ if (exists $old{$key}) # already processed
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$key}) 0 0 0
5575 0 { close INFIL;
5576 0 return $old{$key};
5577 }
5578  
5579 0 $nr = ++$objNr;
5580  
5581 0 $objekt[$nr] = $pos;
5582  
5583 0 $formRes = $form{$fSource}->[fRESOURCE];
5584  
5585 0 ($del1, $del2) = getKnown(\$form{$fSource}, $key);
5586  
5587 0 $nyDel1 = '<</Type/XObject/Subtype/Form/FormType 1';
5588 $nyDel1 .= "/Resources $formRes" .
5589 '/BBox [' .
5590 $form{$fSource}->[fBBOX]->[0] . ' ' .
5591 $form{$fSource}->[fBBOX]->[1] . ' ' .
5592 $form{$fSource}->[fBBOX]->[2] . ' ' .
5593 0 $form{$fSource}->[fBBOX]->[3] . ' ]' .
5594 # "\]/Matrix \[ $sX 0 0 $sX $tX $tY \]" .
5595 $$del1;
5596 0 $nyDel1 =~ s/\b(\d+)$ws+\d+$ws+R\b/translate() . ' 0 R'/oegs;
5597  
5598 0 $utrad = "$nr 0 obj" . $nyDel1 . $$del2;
5599  
5600 0 $pos += syswrite UTFIL, $utrad;
5601 0 close INFIL;
5602  
5603 0 return $nr;
5604 }
5605  
5606 ##################
5607 # En bild läses
5608 ##################
5609  
5610 sub getImage
5611 0 ▶{ my ($infil, $sidnr, $bildnr, $key) = @_;
Subroutine getImage: not called CC=12 SCAR=50.5
Pod undocumented
5612 0 ▶ if (! defined $key)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
5613 0 { errLog("Can't find image $bildnr on page $sidnr in file $infil, aborts");
5614 }
5615  
5616 0 @skapa = ();
5617 0 my ($res, $corr, $nyDel1, $del1, $del2, $nr, $utrad);
5618 0 my $fSource = $infil . '_' . $sidnr;
5619 0 my $iSource = $fSource . '_' . $bildnr;
5620  
5621 0 dropChangedCache($infil);
5622 $behandlad{$infil}->{old} = {}
5623 0 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 0 0 0
5624 $processed{$infil}->{oldObject} = {}
5625 0 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 0 0 0
5626 $processed{$infil}->{unZipped} = {}
5627 0 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 0 0 0
5628  
5629 0 *old = $behandlad{$infil}->{old};
5630 0 *oldObject = $processed{$infil}->{oldObject};
5631 0 *unZipped = $processed{$infil}->{unZipped};
5632  
5633 0 my @stati = stat($infil);
5634  
5635 0 ▶ if ($form{$fSource}[fID] != $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::form{$fSource}[7] != $stati[9]) 0 0 0
5636 0 { errLog("$stati[9] ne $form{$fSource}[fID], modification time has changed, aborting");
5637 }
5638  
5639 0 ▶ if (exists $old{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$key}) 0 0 0
5640 0 { return $old{$key};
5641 }
5642  
5643 0 ▶ open (INFIL, "<$infil") || errLog("The file $infil couldn't be opened, $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("The file $infil couldn't be opened, $!") 0 0 0
5644 0 binmode INFIL;
5645  
5646 #########################################################
5647 # En bild med referenser kopieras, behandlas och skrivs
5648 #########################################################
5649  
5650 0 $nr = ++$objNr;
5651 0 $old{$key} = $nr;
5652  
5653 0 $objekt[$nr] = $pos;
5654  
5655 0 ($del1, $del2) = getKnown(\$form{$fSource}, $key);
5656  
5657 0 $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5658 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
5659 0 { $utrad = "$nr 0 obj\n<<" . $$del1 . $$del2;
5660 }
5661 else
5662 0 { $utrad = "$nr 0 obj " . $$del1;
5663 }
5664 0 $pos += syswrite UTFIL, $utrad;
5665 ##################################
5666 # Skriv ut underordnade objekt
5667 ##################################
5668 0 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 0 0 0
5669 0 { my @process = @skapa;
5670 0 @skapa = ();
5671 0 for (@process)
5672 0 { my $gammal = $$_[0];
5673 0 my $ny = $$_[1];
5674  
5675 0 ($del1, $del2) = getKnown(\$form{$fSource}, $gammal);
5676  
5677 0 $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5678 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
5679 0 { $utrad = "$ny 0 obj\n<<" . $$del1 . $$del2;
5680 }
5681 else
5682 0 { $utrad = "$ny 0 obj " . $$del1;
5683 }
5684 0 $objekt[$ny] = $pos;
5685 0 $pos += syswrite UTFIL, $utrad;
5686 }
5687 }
5688  
5689 0 close INFIL;
5690 0 return $nr;
5691  
5692 }
5693  
5694 ##############################################################
5695 # Interaktiva funktioner knutna till ett formulär återskapas
5696 ##############################################################
5697  
5698 sub AcroFormsEtc
5699 0 ▶{ my ($infil, $sidnr) = @_;
Subroutine AcroFormsEtc: not called CC=20 SCAR=60.4
Pod undocumented
5700  
5701 0 my ($Names, $AARoot, $AAPage, $AcroForm);
5702 0 @skapa = ();
5703  
5704 0 my ($res, $corr, $nyDel1, @objData, $del1, $del2, $utrad);
5705 0 my $fSource = $infil . '_' . $sidnr;
5706  
5707 0 dropChangedCache($infil);
5708 $behandlad{$infil}->{old} = {}
5709 0 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 0 0 0
5710 $processed{$infil}->{oldObject} = {}
5711 0 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 0 0 0
5712 $processed{$infil}->{unZipped} = {}
5713 0 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 0 0 0
5714  
5715 0 *old = $behandlad{$infil}->{old};
5716 0 *oldObject = $processed{$infil}->{oldObject};
5717 0 *unZipped = $processed{$infil}->{unZipped};
5718  
5719 0 my @stati = stat($infil);
5720 0 ▶ if ($form{$fSource}[fID] != $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::form{$fSource}[7] != $stati[9]) 0 0 0
5721 0 { print "$stati[9] ne $form{$fSource}[fID]\n";
5722 0 errLog("Modification time for $fSource has changed, aborting");
5723 }
5724  
5725 0 ▶ open (INFIL, "<$infil") || errLog("The file $infil couldn't be opened, aborting $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("The file $infil couldn't be opened, aborting $!") 0 0 0
5726 0 binmode INFIL;
5727  
5728 0 my $fdSidnr = $intAct{$fSource}[iSTARTSIDA];
5729 0 $old{$fdSidnr} = $sidObjNr;
5730  
5731 0 ▶ if (($intAct{$fSource}[iNAMES]) ||(scalar @jsfiler) || (scalar @inits) || (scalar %fields))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::intAct{$fSource}[1] or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields) 0 0 0
Condition0%0/6
$PDF::Reuse::intAct{$fSource}[1] or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields
l!l
00
$PDF::Reuse::intAct{$fSource}[1] or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits
l!l
00
$PDF::Reuse::intAct{$fSource}[1] or scalar @PDF::Reuse::jsfiler
l!l
00
MC/DC0%0/1
$PDF::Reuse::intAct{$fSource}[1] or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits or scalar %PDF::Reuse::fields
$PDF::Reuse::intAct{$fSource}[1]
Truth table0%0/2
A
A= $PDF::Reuse::intAct{$fSource}[1]
Aresult
11
00
5732 0 { $Names = behandlaNames($intAct{$fSource}[iNAMES], $fSource);
5733 }
5734  
5735 ##################################
5736 # Referenser behandlas och skrivs
5737 ##################################
5738  
5739 0 ▶ if (defined $intAct{$fSource}[iACROFORM])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::intAct{$fSource}[2]) 0 0 0
5740 0 { $AcroForm = $intAct{$fSource}[iACROFORM];
5741 0 $AcroForm =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5742 }
5743 0 ▶ if (defined $intAct{$fSource}[iAAROOT])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::intAct{$fSource}[3]) 0 0 0
5744 0 { $AARoot = $intAct{$fSource}[iAAROOT];
5745 0 $AARoot =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5746 }
5747  
5748 0 ▶ if (defined $intAct{$fSource}[iAAPAGE])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::intAct{$fSource}[6]) 0 0 0
5749 0 { $AAPage = $intAct{$fSource}[iAAPAGE];
5750 0 $AAPage =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5751 }
5752 0 ▶ if (defined $intAct{$fSource}[iANNOTS])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::intAct{$fSource}[4]) 0 0 0
5753 0 { for (@{$intAct{$fSource}[iANNOTS]})
5754 0 { push @annots, quickxform($_);
5755 }
5756 }
5757  
5758 ##################################
5759 # Skriv ut underordnade objekt
5760 ##################################
5761 0 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 0 0 0
5762 0 { my @process = @skapa;
5763 0 @skapa = ();
5764 0 for (@process)
5765 0 { my $gammal = $$_[0];
5766 0 my $ny = $$_[1];
5767  
5768 0 my $oD = \@{$intAct{$fSource}[0]->{$gammal}};
5769 0 @objData = @{$$oD[oNR]};
5770  
5771 0 ▶ if (defined $$oD[oSTREAMP])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oD->[2]) { } 0 0 0
5772 0 { $res = sysseek INFIL, ($objData[0] + $$oD[oPOS]), 0;
5773 0 $corr = sysread INFIL, $del1, ($$oD[oSTREAMP] - $$oD[oPOS]) ;
5774 0 ▶ if (defined $$oD[oKIDS])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oD->[3]) 0 0 0
5775 0 { $del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5776 }
5777 0 $res = sysread INFIL, $del2, ($objData[1] - $corr);
5778 0 $utrad = "$ny 0 obj\n<<" . $del1 . $del2;
5779 }
5780 else
5781 0 { $del1 = getObject($gammal);
5782 0 $del1 = substr($del1, $$oD[oPOS]);
5783 0 ▶ if (defined $$oD[oKIDS])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oD->[3]) 0 0 0
5784 0 { $del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5785 }
5786 0 $utrad = "$ny 0 obj " . $del1;
5787 }
5788  
5789 0 $objekt[$ny] = $pos;
5790 0 $pos += syswrite UTFIL, $utrad;
5791 }
5792 }
5793  
5794 0 close INFIL;
5795 0 return ($Names, $AARoot, $AAPage, $AcroForm);
5796 }
5797  
5798 ##############################
5799 # Ett namnobjekt extraheras
5800 ##############################
5801  
5802 sub extractName
5803 0 ▶{ my ($infil, $sidnr, $namn) = @_;
Subroutine extractName: not called CC=33 SCAR=70.2
Pod undocumented
5804  
5805 0 my ($res, $del1, $resType, $key, $corr, $formRes, $kids, $nr, $utrad);
5806 0 my $del2 = '';
5807 0 @skapa = ();
5808  
5809 0 dropChangedCache($infil);
5810 $behandlad{$infil}->{old} = {}
5811 0 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 0 0 0
5812 $processed{$infil}->{oldObject} = {}
5813 0 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 0 0 0
5814 $processed{$infil}->{unZipped} = {}
5815 0 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 0 0 0
5816  
5817 0 *old = $behandlad{$infil}->{old};
5818 0 *oldObject = $processed{$infil}->{oldObject};
5819 0 *unZipped = $processed{$infil}->{unZipped};
5820  
5821 0 my $fSource = $infil . '_' . $sidnr;
5822  
5823 0 my @stati = stat($infil);
5824  
5825 0 ▶ if ($form{$fSource}[fID] != $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::form{$fSource}[7] != $stati[9]) 0 0 0
5826 0 { errLog("$stati[9] ne $form{$fSource}[fID] aborts");
5827 }
5828 0 ▶ if ($checkId)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId) 0 0 0
5829 0 ▶ { if ($checkId ne $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId ne $stati[9]) 0 0 0
5830 0 { my $mess = "$checkId \<\> $stati[9] \n"
5831 . "The Pdf-file $fSource has not the correct modification time. \n"
5832 . "The program is aborted";
5833 0 errLog($mess);
5834 }
5835 0 undef $checkId;
5836 }
5837 0 ▶ if ($ldir)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::ldir) 0 0 0
5838 0 { $log .= "Cid~$stati[9]\n";
5839 }
5840  
5841 0 ▶ open (INFIL, "<$infil") || errLog("The file $infil couldn't be opened, aborting $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("The file $infil couldn't be opened, aborting $!") 0 0 0
5842 0 binmode INFIL;
5843  
5844 #################################
5845 # Resurserna läses
5846 #################################
5847  
5848 0 $formRes = $form{$fSource}->[fRESOURCE];
5849  
5850 0 ▶ if ($formRes !~ m'<<.*>>'os) # If not a directory, get it
Branch: 1 branch
BranchTrueFalseTotal
unless ($formRes =~ /<<.*>>/so) 0 0 0
5851 0 ▶ { if ($formRes =~ m/\b(\d+)$ws+\d+$ws+R/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($formRes =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/o) { } 0 0 0
5852 0 { $key = $1;
5853 0 $formRes = getKnown(\$form{$fSource}, $key);
5854 }
5855 else
5856 0 { return undef;
5857 }
5858 }
5859 0 undef $key;
5860 0 ▶ while ($formRes =~ m|\/(\w+)$ws*\<\<([^>]+)\>\>|osg)
Branch: 1 branch
BranchTrueFalseTotal
if ($formRes =~ m[\/(\w+)$PDF::Reuse::ws*\<\<([^>]+)\>\>]sog) 0 0 0
5861 0 { $resType = $1;
5862 0 my $str = $2;
5863 0 ▶ if ($str =~ m|$namn$ws+(\d+)$ws+\d+$ws+R|s)
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$namn$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/s) 0 0 0
5864 0 { $key = $1;
5865 0 last;
5866 }
5867 }
5868 0 ▶ if (! defined $key) # Try to expand the references
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 0 0 0
5869 0 { my ($str, $del1, $del2);
5870 0 ▶ while ($formRes =~ m|(\/\w+)$ws+(\d+)$ws+\d+$ws+R|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($formRes =~ m[(\/\w+)$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]sog) 0 0 0
5871 0 { $str .= $1 . ' ';
5872 0 ($del1, $del2) = getKnown(\$form{$fSource}, $2);
5873 0 my $string = $$del1;
5874 0 $str .= $string . ' ';
5875 }
5876 0 $formRes = $str;
5877 0 ▶ while ($formRes =~ m|\/(\w+)$ws*\<\<([^>]+)\>\>|osg)
Branch: 1 branch
BranchTrueFalseTotal
if ($formRes =~ m[\/(\w+)$PDF::Reuse::ws*\<\<([^>]+)\>\>]sog) 0 0 0
5878 0 { $resType = $1;
5879 0 my $str = $2;
5880 0 ▶ if ($str =~ m|$namn$ws+(\d+)$ws+\d+$ws+R|s)
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$namn$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/s) 0 0 0
5881 0 { $key = $1;
5882 0 last;
5883 }
5884 }
5885 0 ▶ return undef unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
5886 }
5887  
5888 ########################################
5889 # Read the top object of the hierarchy
5890 ########################################
5891  
5892 0 ($del1, $del2) = getKnown(\$form{$fSource}, $key);
5893  
5894 0 $objNr++;
5895 0 $nr = $objNr;
5896  
5897 0 ▶ if ($resType eq 'Font')
Branch: 6 branches
BranchTrueFalseTotal
if ($resType eq 'Font') { } 0 0 0
elsif ($resType eq 'ColorSpace') { } 0 0 0
elsif ($resType eq 'Pattern') { } 0 0 0
elsif ($resType eq 'Shading') { } 0 0 0
elsif ($resType eq 'ExtGState') { } 0 0 0
elsif ($resType eq 'XObject') { } 0 0 0
5898 0 { my ($Font, $extNamn);
5899 0 ▶ if ($$del1 =~ m|/BaseFont$ws*/([^\s\/]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($$del1 =~ m[/BaseFont$PDF::Reuse::ws*/([^\s\/]+)]so) { } 0 0 0
5900 0 { $extNamn = $1;
5901 0 ▶ if (! exists $font{$extNamn})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $PDF::Reuse::font{$extNamn}) 0 0 0
5902 0 { $fontNr++;
5903 0 $Font = 'Ft' . $fontNr;
5904 0 $font{$extNamn}[foINTNAMN] = $Font;
5905 0 $font{$extNamn}[foORIGINALNR] = $nr;
5906 0 ▶ if ($del1 =~ m|/Subtype$ws*/Type0|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Subtype$PDF::Reuse::ws*/Type0]so) 0 0 0
5907 0 { $font{$extNamn}[foTYP] = 1;
5908 }
5909 0 $fontSource{$Font}[foSOURCE] = $fSource;
5910 0 $fontSource{$Font}[foORIGINALNR] = $nr;
5911 }
5912 0 $font{$extNamn}[foREFOBJ] = $nr;
5913 0 $Font = $font{$extNamn}[foINTNAMN];
5914 0 $namn = $Font;
5915 0 $objRef{$Font} = $nr;
5916 }
5917 else
5918 0 { errLog("Inconsitency in $fSource, font $namn can't be found, aborting");
5919 }
5920 }
5921 elsif ($resType eq 'ColorSpace')
5922 0 { $colorSpace++;
5923 0 $namn = 'Cs' . $colorSpace;
5924 0 $objRef{$namn} = $nr;
5925 }
5926 elsif ($resType eq 'Pattern')
5927 0 { $pattern++;
5928 0 $namn = 'Pt' . $pattern;
5929 0 $objRef{$namn} = $nr;
5930 }
5931 elsif ($resType eq 'Shading')
5932 0 { $shading++;
5933 0 $namn = 'Sh' . $shading;
5934 0 $objRef{$namn} = $nr;
5935 }
5936 elsif ($resType eq 'ExtGState')
5937 0 { $gSNr++;
5938 0 $namn = 'Gs' . $gSNr;
5939 0 $objRef{$namn} = $nr;
5940 }
5941 elsif ($resType eq 'XObject')
5942 0 ▶ { if (defined $form{$fSource}->[0]->{$nr}->[oIMAGENR])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::form{$fSource}[0]{$nr}[5]) { } 0 0 0
5943 0 { $namn = 'Ig' . $form{$fSource}->[0]->{$nr}->[oIMAGENR];
5944 }
5945 else
5946 0 { $formNr++;
5947 0 $namn = 'Fo' . $formNr;
5948 }
5949  
5950 0 $objRef{$namn} = $nr;
5951 }
5952  
5953 0 $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
5954  
5955 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
5956 0 { $utrad = "$nr 0 obj\n<<" . $$del1 . $$del2;
5957 }
5958 else
5959 0 { $utrad = "$nr 0 obj " . $$del1;
5960 }
5961 0 $objekt[$nr] = $pos;
5962 0 $pos += syswrite UTFIL, $utrad;
5963  
5964 ##################################
5965 # Skriv ut underordnade objekt
5966 ##################################
5967  
5968 0 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 0 0 0
5969 0 { my @process = @skapa;
5970 0 @skapa = ();
5971 0 for (@process)
5972 0 { my $gammal = $$_[0];
5973 0 my $ny = $$_[1];
5974  
5975 0 ($del1, $del2, $kids) = getKnown(\$form{$fSource}, $gammal);
5976  
5977 0 ▶ $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs
Branch: 1 branch
BranchTrueFalseTotal
if defined $kids 0 0 0
5978 unless (! defined $kids);
5979 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
5980 0 { $utrad = "$ny 0 obj\n<<" . $$del1 . $$del2;
5981 }
5982 else
5983 0 { $utrad = "$ny 0 obj " . $$del1;
5984 }
5985 0 $objekt[$ny] = $pos;
5986 0 $pos += syswrite UTFIL, $utrad;
5987 }
5988 }
5989 0 close INFIL;
5990  
5991 0 return $namn;
5992  
5993 }
5994  
5995 ########################
5996 # Ett objekt extraheras
5997 ########################
5998  
5999 sub extractObject
6000 3 ▶{ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine extractObject: not called CC=26 SCAR=64.9
Pod undocumented
6001 0 my ($infil, $sidnr, $key, $typ) = @_;
6002  
6003 0 my ($res, $del1, $corr, $namn, $kids, $nr, $utrad);
6004 0 my $del2 = '';
6005 0 @skapa = ();
6006  
6007 0 dropChangedCache($infil);
6008 $behandlad{$infil}->{old} = {}
6009 0 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 0 0 0
6010 $processed{$infil}->{oldObject} = {}
6011 0 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 0 0 0
6012 $processed{$infil}->{unZipped} = {}
6013 0 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 0 0 0
6014  
6015 0 *old = $behandlad{$infil}->{old};
6016 0 *oldObject = $processed{$infil}->{oldObject};
6017 0 *unZipped = $processed{$infil}->{unZipped};
6018  
6019 0 my $fSource = $infil . '_' . $sidnr;
6020 0 my @stati = stat($infil);
6021  
6022 0 ▶ if ($form{$fSource}[fID] != $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::form{$fSource}[7] != $stati[9]) 0 0 0
6023 0 { errLog("$stati[9] ne $form{$fSource}[fID] aborts");
6024 }
6025 0 ▶ if ($checkId)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId) 0 0 0
6026 0 ▶ { if ($checkId ne $stati[9])
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkId ne $stati[9]) 0 0 0
6027 0 { my $mess = "$checkId \<\> $stati[9] \n"
6028 . "The Pdf-file $fSource has not the correct modification time. \n"
6029 . "The program is aborted";
6030 0 errLog($mess);
6031 }
6032 0 undef $checkId;
6033 }
6034 0 ▶ if ($ldir)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::ldir) 0 0 0
6035 0 { $log .= "Cid~$stati[9]\n";
6036 0 my $indata = prep($infil);
6037 0 $log .= "Form~$indata~$sidnr~~load~1\n";
6038 }
6039  
6040 0 ▶ open (INFIL, "<$infil") || errLog("The file $infil couldn't be opened, aborting $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("The file $infil couldn't be opened, aborting $!") 0 0 0
6041 0 binmode INFIL;
6042  
6043 ########################################
6044 # Read the top object of the hierarchy
6045 ########################################
6046  
6047 0 ($del1, $del2, $kids) = getKnown(\$form{$fSource}, $key);
6048  
6049 0 ▶ if (exists $old{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$key}) { } 0 0 0
6050 0 { $nr = $old{$key}; }
6051 else
6052 0 { $old{$key} = ++$objNr;
6053 0 $nr = $objNr;
6054 }
6055  
6056 0 ▶ if ($typ eq 'Font')
Branch: 6 branches
BranchTrueFalseTotal
if ($typ eq 'Font') { } 0 0 0
elsif ($typ eq 'ColorSpace') { } 0 0 0
elsif ($typ eq 'Pattern') { } 0 0 0
elsif ($typ eq 'Shading') { } 0 0 0
elsif ($typ eq 'ExtGState') { } 0 0 0
elsif ($typ eq 'XObject') { } 0 0 0
6057 0 { my ($Font, $extNamn);
6058 0 ▶ if ($$del1 =~ m|/BaseFont$ws*/([^\s\/]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($$del1 =~ m[/BaseFont$PDF::Reuse::ws*/([^\s\/]+)]so) { } 0 0 0
6059 0 { $extNamn = $1;
6060 0 $fontNr++;
6061 0 $Font = 'Ft' . $fontNr;
6062 0 $font{$extNamn}[foINTNAMN] = $Font;
6063 0 $font{$extNamn}[foORIGINALNR] = $key;
6064 0 ▶ if ($del1 =~ m|/Subtype$ws*/Type0|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Subtype$PDF::Reuse::ws*/Type0]so) 0 0 0
6065 0 { $font{$extNamn}[foTYP] = 1;
6066 }
6067 0 ▶ if ( ! defined $fontSource{$extNamn}[foSOURCE])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $PDF::Reuse::fontSource{$extNamn}[4]) 0 0 0
6068 0 { $fontSource{$extNamn}[foSOURCE] = $fSource;
6069 0 $fontSource{$extNamn}[foORIGINALNR] = $key;
6070 }
6071 0 $font{$extNamn}[foREFOBJ] = $nr;
6072 0 $Font = $font{$extNamn}[foINTNAMN];
6073 0 $namn = $Font;
6074 0 $objRef{$Font} = $nr;
6075 }
6076 else
6077 0 { errLog("Error in $fSource, $key is not a font, aborting");
6078 }
6079 }
6080 elsif ($typ eq 'ColorSpace')
6081 0 { $colorSpace++;
6082 0 $namn = 'Cs' . $colorSpace;
6083 0 $objRef{$namn} = $nr;
6084 }
6085 elsif ($typ eq 'Pattern')
6086 0 { $pattern++;
6087 0 $namn = 'Pt' . $pattern;
6088 0 $objRef{$namn} = $nr;
6089 }
6090 elsif ($typ eq 'Shading')
6091 0 { $shading++;
6092 0 $namn = 'Sh' . $shading;
6093 0 $objRef{$namn} = $nr;
6094 }
6095 elsif ($typ eq 'ExtGState')
6096 0 { $gSNr++;
6097 0 $namn = 'Gs' . $gSNr;
6098 0 $objRef{$namn} = $nr;
6099 }
6100 elsif ($typ eq 'XObject')
6101 0 ▶ { if (defined $form{$fSource}->[0]->{$nr}->[oIMAGENR])
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::form{$fSource}[0]{$nr}[5]) { } 0 0 0
6102 0 { $namn = 'Ig' . $form{$fSource}->[0]->{$nr}->[oIMAGENR];
6103 }
6104 else
6105 0 { $formNr++;
6106 0 $namn = 'Fo' . $formNr;
6107 }
6108  
6109 0 $objRef{$namn} = $nr;
6110 }
6111  
6112 0 ▶ $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs
Branch: 1 branch
BranchTrueFalseTotal
if defined $kids 0 0 0
6113 unless (! defined $kids);
6114 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
6115 0 { $utrad = "$nr 0 obj\n<<" . $$del1 . $$del2;
6116 }
6117 else
6118 0 { $utrad = "$nr 0 obj " . $$del1;
6119 }
6120  
6121 0 $objekt[$nr] = $pos;
6122 0 $pos += syswrite UTFIL, $utrad;
6123  
6124 ##################################
6125 # Skriv ut underordnade objekt
6126 ##################################
6127  
6128 0 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 0 0 0
6129 0 { my @process = @skapa;
6130 0 @skapa = ();
6131 0 for (@process)
6132 0 { my $gammal = $$_[0];
6133 0 my $ny = $$_[1];
6134  
6135 0 ($del1, $del2, $kids) = getKnown(\$form{$fSource}, $gammal);
6136  
6137 0 ▶ $$del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs
Branch: 1 branch
BranchTrueFalseTotal
if defined $kids 0 0 0
6138 unless (! defined $kids);
6139  
6140 0 ▶ if (defined $$del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$del2) { } 0 0 0
6141 0 { $utrad = "$ny 0 obj<<" . $$del1 . $$del2;
6142 }
6143 else
6144 0 { $utrad = "$ny 0 obj " . $$del1;
6145 }
6146  
6147 0 $objekt[$ny] = $pos;
6148 0 $pos += syswrite UTFIL, $utrad;
6149 }
6150 }
6151 0 close INFIL;
6152 0 return $namn;
6153 }
6154  
6155  
6156 ##########################################
6157 # En fil analyseras och sidorna kopieras
6158 ##########################################
6159  
6160 sub analysera
6161 5 ▶{ my $infil = shift;
Subroutine analysera: called CC=50 SCAR=54.3
Pod undocumented
6162 5 ▶ my $from = shift || 1;
Condition50%1/2
shift() || 1
l!l
50
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
6163 5 ▶ my $to = shift || 0;
Condition50%1/2
shift() || 0
l!l
05
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
6164 5 my $singlePage = shift;
6165 5 my ($i, $res, @underObjekt, @sidObj, $vektor, $resources, $valid,
6166 $strPos, $sidor, $filId, $Root, $del1, $del2, $utrad);
6167  
6168 5 my $extraherade = 0;
6169 5 my $sidAcc = 0;
6170 5 @skapa = ();
6171  
6172 5 dropChangedCache($infil);
6173 $behandlad{$infil}->{old} = {}
6174 5 ▶ unless (defined $behandlad{$infil}->{old});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::behandlad{$infil}{"old"} 5 0 5
6175 $processed{$infil}->{oldObject} = {}
6176 5 ▶ unless (defined $processed{$infil}->{oldObject});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"oldObject"} 4 1 5
6177 $processed{$infil}->{unZipped} = {}
6178 5 ▶ unless (defined $processed{$infil}->{unZipped});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDF::Reuse::processed{$infil}{"unZipped"} 4 1 5
6179 5 *old = $behandlad{$infil}->{old};
6180 5 *oldObject = $processed{$infil}->{oldObject};
6181 5 *unZipped = $processed{$infil}->{unZipped};
6182  
6183 $root = (exists $processed{$infil}->{root})
6184 5 ▶ ? $processed{$infil}->{root} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $PDF::Reuse::processed{$infil}{'root'} ? : 1 4 5
6185  
6186 5 my ($AcroForm, $Annots, $Names, $AARoot);
6187 5 undef $taInterAkt;
6188 5 undef %script;
6189  
6190 5 my $checkIdOld = $checkId;
6191 5 ($infil, $checkId) = findGet($infil, $checkIdOld);
6192 5 ▶ if (($ldir) && ($checkId) && ($checkId ne $checkIdOld))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld) 0 5 5
Condition33%2/6
$PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld
!ll&&!rl&&r
500
$PDF::Reuse::ldir and $PDF::Reuse::checkId
!ll&&!rl&&r
500
MC/DC0%0/3
$PDF::Reuse::ldir and $PDF::Reuse::checkId and $PDF::Reuse::checkId ne $checkIdOld
$PDF::Reuse::ldir $PDF::Reuse::checkId $PDF::Reuse::checkId ne $checkIdOld
Truth table25%1/4
A and B and C
A= $PDF::Reuse::ldirB= $PDF::Reuse::checkIdC= $PDF::Reuse::checkId ne $checkIdOld
ABCresult
0XX0
10X0
1100
1111
6193 0 { $log .= "Cid~$checkId\n";
6194 }
6195 5 undef $checkId;
6196 5 my @stati = stat($infil);
6197 5 ▶ open (INFIL, "<$infil") || errLog("Couldn't open $infil,aborting. $!");
Branch: 1 branch
BranchTrueFalseTotal
open INFIL, "<$infil" or errLog("Couldn't open $infil,aborting. $!") 5 0 5
6198 5 binmode INFIL;
6199  
6200 5 ▶ if (! $root)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::root) 4 1 5
6201 4 { $root = xRefs($stati[7], $infil);
6202 }
6203 #############
6204 # Hitta root
6205 #############
6206  
6207 5 my $offSet;
6208 my $bytes;
6209 5 my $objektet = getObject($root);
6210  
6211 5 ▶ if ((! $interActive) && ( ! $to) && ($from == 1))
Branch: 1 branch
BranchTrueFalseTotal
if (not $PDF::Reuse::interActive || $to and $from == 1) 5 0 5
Condition33%2/6
not $PDF::Reuse::interActive || $to and $from == 1
!ll&&!rl&&r
005
$PDF::Reuse::interActive || $to
l!l&&r!l&&!r
005
MC/DC0%0/3
not $PDF::Reuse::interActive || $to and $from == 1
$PDF::Reuse::interActive $to $from == 1
Truth table25%1/4
not(A || B) and C
A= $PDF::Reuse::interActiveB= $toC= $from == 1
ABCresult
1XX0
01X0
0000
0011
6212 5 ▶ { if ($objektet =~ m|/AcroForm($ws+\d+$ws+\d+$ws+R)|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/AcroForm($PDF::Reuse::ws+\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R)]so) 0 5 5
6213 0 { $AcroForm = $1;
6214 }
6215 5 ▶ if ($objektet =~ m|/Names$ws+(\d+)$ws+\d+$ws+R|so)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Names$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 5 5
6216 0 { $Names = $1;
6217 }
6218 5 ▶ if ((scalar %fields) || (scalar @jsfiler) || (scalar @inits))
Branch: 2 branches
BranchTrueFalseTotal
if (scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits) { } 0 5 5
elsif ($Names) { } 0 5 5
Condition50%2/4
scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits
l!l
05
scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler
l!l
05
MC/DC0%0/1
scalar %PDF::Reuse::fields or scalar @PDF::Reuse::jsfiler or scalar @PDF::Reuse::inits
scalar %PDF::Reuse::fields
Truth table50%1/2
A
A= scalar %PDF::Reuse::fields
Aresult
11
00
6219 0 { $Names = behandlaNames($Names);
6220 }
6221 elsif ($Names)
6222 0 { $Names = quickxform($Names);
6223 }
6224  
6225 #################################################
6226 # Finns ett dictionary för Additional Actions ?
6227 #################################################
6228 5 ▶ if ($objektet =~ m|/AA($ws+\d+$ws+\d+$ws+R)|os) # Hänvisning
Branch: 2 branches
BranchTrueFalseTotal
if ($objektet =~ m[/AA($PDF::Reuse::ws+\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R)]so) { } 0 5 5
elsif ($objektet =~ m[/AA$PDF::Reuse::ws*\<\<$PDF::Reuse::ws*[^\>]+[^\>]+]so) { } 0 5 5
6229 0 { $AARoot = $1; }
6230 elsif ($objektet =~ m|/AA$ws*\<\<$ws*[^\>]+[^\>]+|so) # AA är ett dictionary
6231 0 { my $k;
6232 0 my ($dummy, $obj) = split /\/AA/, $objektet;
6233 0 $obj =~ s/\<\</\#\<\</gs;
6234 0 $obj =~ s/\>\>/\>\>\#/gs;
6235 0 my @ord = split /\#/, $obj;
6236 0 ▶ for ($i = 0; $i <= $#ord; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#ord) 0 0 0
6237 0 { $AARoot .= $ord[$i];
6238 0 ▶ if ($ord[$i] =~ m'\S+'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /\S+/so) 0 0 0
6239 0 ▶ { if ($ord[$i] =~ m'<<'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ /<</so) 0 0 0
6240 0 { $k++; }
6241 0 ▶ if ($ord[$i] =~ m'>>'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($ord[$i] =~ />>/so) 0 0 0
6242 0 { $k--; }
6243 0 ▶ if ($k == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 0) 0 0 0
6244 0 { last; }
6245 }
6246 }
6247 }
6248 5 $taInterAkt = 1; # Flagga att ta med interaktiva funktioner
6249 }
6250  
6251 #
6252 # Hitta pages
6253 #
6254  
6255 5 ▶ if ($objektet =~ m|/Pages$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Pages$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) { } 5 0 5
6256 5 { $objektet = getObject($1);
6257 5 $resources = checkResources($objektet, $resources);
6258 5 ▶ if ($objektet =~ m|/Count$ws+(\d+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m[/Count$PDF::Reuse::ws+(\d+)]so) 5 0 5
6259 5 { $sidor = $1;
6260 5 $behandlad{$infil}->{sidor} = $sidor;
6261 }
6262 }
6263 else
6264 0 { errLog("Didn't find pages "); }
6265  
6266 5 my @levels; my %kids;
6267 5 my $li = -1;
6268  
6269 5 ▶ if ($objektet =~ m|/Kids$ws*\[([^\]]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m(/Kids$PDF::Reuse::ws*\[([^\]]+))so) 5 0 5
6270 5 { $vektor = $1;
6271 5 ▶ while ($vektor =~ m|(\d+)$ws+\d+$ws+R|go)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/go) 22 5 27
6272 22 { push @sidObj, $1;
6273 }
6274 5 $li++;
6275 5 $levels[$li] = \@sidObj;
6276 }
6277  
6278 5 ▶ while (($li > -1) && ($sidAcc < $sidor))
Branch: 1 branch
BranchTrueFalseTotal
if ($li > -1 and $sidAcc < $sidor) 22 5 27
Condition66%2/3
$li > -1 and $sidAcc < $sidor
!ll&&!rl&&r
0522
MC/DC50%1/2
$li > -1 and $sidAcc < $sidor
$li > -1 $sidAcc < $sidor
Truth table66%2/3
A and B
A= $li > -1B= $sidAcc < $sidor
ABresult
0X0
100
111
6279 22 ▶ { if (scalar @{$levels[$li]})
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$levels[$li];}) { } 22 0 22
6280 22 { my $j = shift @{$levels[$li]};
6281 22 $objektet = getObject($j);
6282 22 ▶ if ($objektet =~ m|/Kids$ws*\[([^\]]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ m(/Kids$PDF::Reuse::ws*\[([^\]]+))so) { } 0 22 22
6283 0 { $resources = checkResources($objektet, $resources);
6284 0 $vektor = $1;
6285 0 my @sObj;
6286 0 ▶ while ($vektor =~ m/(\d+)$ws+\d+$ws+R/go)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/go) 0 0 0
6287 0 ▶ { push @sObj, $1 if !$kids{$1}; $kids{$1}=1;
Branch: 1 branch
BranchTrueFalseTotal
unless $kids{$1} 0 0 0
6288 }
6289 0 ▶ if(@sObj)
Branch: 1 branch
BranchTrueFalseTotal
if (@sObj) 0 0 0
6290 0 { $li++;
6291 0 $levels[$li] = \@sObj;
6292 }
6293 }
6294 else
6295 22 { $sidAcc++;
6296 22 ▶ if ($sidAcc >= $from)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidAcc >= $from) 22 0 22
6297 22 ▶ { if ($to)
Branch: 1 branch
BranchTrueFalseTotal
if ($to) { } 0 22 22
6298 0 ▶ { if ($sidAcc <= $to)
Branch: 1 branch
BranchTrueFalseTotal
if ($sidAcc <= $to) { } 0 0 0
6299 0 { sidAnalys($j, $objektet, $resources);
6300 0 $extraherade++;
6301 0 $sida++;
6302 }
6303 else
6304 0 { $sidAcc = $sidor;
6305 }
6306 }
6307 else
6308 22 { sidAnalys($j, $objektet, $resources);
6309 22 $extraherade++;
6310 22 $sida++;
6311 }
6312 }
6313 }
6314 }
6315 else
6316 0 { $li--;
6317 }
6318 }
6319  
6320 5 ▶ if (defined $AcroForm)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AcroForm) 0 5 5
6321 0 { $AcroForm =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6322 }
6323 5 ▶ if (defined $AARoot)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AARoot) 0 5 5
6324 0 { $AARoot =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6325 }
6326  
6327 5 ▶ while (scalar @skapa)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::skapa) 7 5 12
6328 7 { my @process = @skapa;
6329 7 @skapa = ();
6330 7 for (@process)
6331 32 { my $gammal = $$_[0];
6332 32 my $ny = $$_[1];
6333 32 $objektet = getObject($gammal);
6334  
6335 32 ▶ if($objektet =~ m/^(\d+$ws+\d+$ws+obj$ws*<<)(.+)(>>$ws*stream)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<)(.+)(>>$PDF::Reuse::ws*stream)/so) { } 22 10 32
6336 22 { $del1 = $2;
6337 22 $strPos = length($2) + length($3) + length($1);
6338 0 $del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6339 22 $objekt[$ny] = $pos;
6340 22 $utrad = "$ny 0 obj<<" . "$del1" . '>>stream';
6341 22 $del2 = substr($objektet, $strPos);
6342 22 $utrad .= $del2;
6343  
6344 22 $pos += syswrite UTFIL, $utrad;
6345 }
6346 else
6347 10 ▶ { if ($objektet =~ m/^(\d+$ws+\d+$ws+obj)/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /^(\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj)/so) 10 0 10
6348 10 { my $preLength = length($1);
6349 10 $objektet = substr($objektet, $preLength);
6350 }
6351 10 $objektet =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6352 10 $objekt[$ny] = $pos;
6353 10 $utrad = "$ny 0 obj$objektet";
6354 10 $pos += syswrite UTFIL, $utrad;
6355 }
6356 }
6357 }
6358 5 close INFIL;
6359 5 $processed{$infil}->{root} = $root;
6360  
6361 5 ▶ if (! $singlePage)
Branch: 1 branch
BranchTrueFalseTotal
if (not $singlePage) { } 5 0 5
6362 5 { return ($extraherade, $Names, $AARoot, $AcroForm);
6363 }
6364 else
6365 0 ▶ { if ($extraherade)
Branch: 1 branch
BranchTrueFalseTotal
if ($extraherade) { } 0 0 0
6366 0 { my $kvar = $behandlad{$infil}->{sidor} - $from;
6367 0 return ($kvar, $Names, $AARoot, $AcroForm);
6368 }
6369 else
6370 0 { return (undef, undef, undef, undef);
6371 }
6372 }
6373 }
6374  
6375 sub sidAnalys
6376 22 ▶{ my ($oNr, $obj, $resources) = @_;
Subroutine sidAnalys: called CC=74 SCAR=70.7
Pod undocumented
6377 22 my ($ny, $strPos, $spar, $closeProc, $del1, $del2, $utrad, $Annots,
6378 $resursObjekt, $streamObjekt, @extObj, $langd);
6379  
6380 22 ▶ if ((defined $stream) && (length($stream) > 0))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0) 5 17 22
Condition66%2/3
defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0
!ll&&!rl&&r
0175
MC/DC50%1/2
defined $PDF::Reuse::stream and length $PDF::Reuse::stream > 0
defined $PDF::Reuse::stream length $PDF::Reuse::stream > 0
Truth table66%2/3
A and B
A= defined $PDF::Reuse::streamB= length $PDF::Reuse::stream > 0
ABresult
0X0
100
111
6381 {
6382 5 ▶ if ($checkCs)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::checkCs) 0 5 5
6383 0 { @extObj = ($stream =~ m'/(\S+)\s*'gso);
6384 0 checkContentStream(@extObj);
6385 }
6386  
6387 5 $objNr++;
6388 5 $objekt[$objNr] = $pos;
6389  
6390 5 ▶ if (( $compress ) && ( length($stream) > 99 ))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::compress and length $PDF::Reuse::stream > 99) { } 0 5 5
Condition33%1/3
$PDF::Reuse::compress and length $PDF::Reuse::stream > 99
!ll&&!rl&&r
500
MC/DC0%0/2
$PDF::Reuse::compress and length $PDF::Reuse::stream > 99
$PDF::Reuse::compress length $PDF::Reuse::stream > 99
Truth table33%1/3
A and B
A= $PDF::Reuse::compressB= length $PDF::Reuse::stream > 99
ABresult
0X0
100
111
6391 0 { my $output = compress($stream);
6392 0 ▶ if ((length($output) > 25) && (length($output) < (length($stream))))
Branch: 1 branch
BranchTrueFalseTotal
if (length $output > 25 and length $output < length $PDF::Reuse::stream) 0 0 0
Condition0%0/3
length $output > 25 and length $output < length $PDF::Reuse::stream
!ll&&!rl&&r
000
MC/DC0%0/2
length $output > 25 and length $output < length $PDF::Reuse::stream
length $output > 25 length $output < length $PDF::Reuse::stream
Truth table0%0/3
A and B
A= length $output > 25B= length $output < length $PDF::Reuse::stream
ABresult
0X0
100
111
6393 0 { $stream = $output;
6394 }
6395 0 $langd = length($stream);
6396 0 $stream = "\n" . $stream . "\n";
6397 0 $langd++;
6398 0 $streamObjekt = "$objNr 0 obj<</Filter/FlateDecode"
6399 . "/Length $langd>>stream" . $stream;
6400 0 $streamObjekt .= "endstream\nendobj\n";
6401  
6402 }
6403 else
6404 5 { $langd = length($stream);
6405 5 $streamObjekt = "$objNr 0 obj<</Length $langd>>stream\n" . $stream;
6406 5 $streamObjekt .= "\nendstream\nendobj\n";
6407 }
6408 5 $pos += syswrite UTFIL, $streamObjekt;
6409 5 $streamObjekt = "$objNr 0 R ";
6410  
6411 ########################################################################
6412 # Sometimes the contents reference is a ref to an object which
6413 # contains an array of content streams. Replace the ref with the array
6414 ########################################################################
6415  
6416 5 ▶ if ($obj =~ m|/Contents$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m[/Contents$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 5 0 5
6417 5 { my $cObj = getObject($1, 1, 1);
6418 5 ▶ if ($cObj =~ m/^$ws*\[[^\]]+\]$ws*$/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($cObj =~ /^$PDF::Reuse::ws*\[[^\]]+\]$PDF::Reuse::ws*$/so) 0 5 5
6419 0 { $obj =~ s|/Contents$ws+\d+$ws+\d+$ws+R|'/Contents ' . $cObj|oes;
6420 }
6421 }
6422  
6423 5 my ($from, $to);
6424  
6425 5 ($resources, $from, $to) = checkResources ($obj, $resources);
6426 5 ▶ if ($from && $to)
Branch: 1 branch
BranchTrueFalseTotal
if ($from and $to) 5 0 5
Condition33%1/3
$from and $to
!ll&&!rl&&r
005
MC/DC0%0/2
$from and $to
$from $to
Truth table33%1/3
A and B
A= $fromB= $to
ABresult
0X0
100
111
6427 5 { $obj = substr($obj, 0, $from) . substr($obj, $to);
6428 }
6429  
6430  
6431 ##########################
6432 # Hitta resursdictionary
6433 ##########################
6434 5 my $i = 0;
6435 5 ▶ while (($resources !~ m'\/'os) && ($i < 10))
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/]so and $i < 10) 5 5 10
Condition66%2/3
not $resources =~ m[\/]so and $i < 10
!ll&&!rl&&r
505
MC/DC50%1/2
not $resources =~ m[\/]so and $i < 10
not $resources =~ m[\/]so $i < 10
Truth table66%2/3
not(A) and B
A= not $resources =~ m[\/]soB= $i < 10
ABresult
0X0
100
111
6436 5 { $i++;
6437 5 ▶ if ($resources =~ m/$ws+(\d+)$ws+\d+$ws+R/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ /$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R/so) 5 0 5
6438 5 { $resources = getObject($1, 1, 1);
6439 }
6440 }
6441 5 ▶ if ($i > 7)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 7) 0 5 5
6442 0 { errLog("Couldn't find resources to merge");
6443 }
6444 5 ▶ if ($resources =~ m/$ws*\<\<(.*)\>\>/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ /$PDF::Reuse::ws*\<\<(.*)\>\>/so) 5 0 5
6445 5 { $resources = $1;
6446 }
6447  
6448 5 ▶ if ($resources !~ m'/ProcSet')
Branch: 1 branch
BranchTrueFalseTotal
unless ($resources =~ m[/ProcSet]) 0 5 5
6449 0 { $resources = '/ProcSet[/PDF/Text] ' . $resources;
6450 }
6451  
6452 ###############################################################
6453 # Läsa ev. referenser och skapa ett resursobjekt bestående av
6454 # dictionaries (för utvalda resurser)
6455 ###############################################################
6456  
6457 5 ▶ if (scalar %sidFont)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidFont) 0 5 5
6458 0 ▶ { if ($resources =~ m|/Font$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/Font$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6459 0 { my $dict = getObject($1, 1, 1);
6460 0 $resources =~ s"/Font$ws+\d+$ws+\d+$ws+R"'/Font' . $dict"ose;
6461 }
6462 }
6463  
6464 5 ▶ if (scalar %sidXObject)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidXObject) 0 5 5
6465 0 ▶ { if ($resources =~ m|/XObject$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/XObject$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6466 0 { my $dict = getObject($1, 1, 1);
6467 0 $resources =~ s"/XObject$ws+\d+$ws+\d+$ws+R"'/XObject' . $dict"ose;
6468 }
6469 }
6470  
6471 5 ▶ if (scalar %sidExtGState)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidExtGState) 0 5 5
6472 0 ▶ { if ($resources =~ m|/ExtGState$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/ExtGState$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6473 0 { my $dict = getObject($1, 1, 1);
6474 0 $resources =~ s"/ExtGState$ws+\d+$ws+\d+$ws+R"'/ExtGState' . $dict"ose;
6475 }
6476 }
6477  
6478 5 ▶ if (scalar %sidPattern)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidPattern) 0 5 5
6479 0 ▶ { if ($resources =~ m|/Pattern$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/Pattern$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6480 0 { my $dict = getObject($1, 1, 1);
6481 0 $resources =~ s"/Pattern$ws+\d+$ws+\d+$ws+R"'/Pattern' . $dict"ose;
6482 }
6483 }
6484  
6485 5 ▶ if (scalar %sidShading)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidShading) 0 5 5
6486 0 ▶ { if ($resources =~ m|/Shading$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/Shading$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6487 0 { my $dict = getObject($1, 1, 1);
6488 0 $resources =~ s"/Shading$ws+\d+$ws+\d+$ws+R"'/Shading' . $dict"ose;
6489 }
6490 }
6491  
6492 5 ▶ if (scalar %sidColorSpace)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidColorSpace) 0 5 5
6493 0 ▶ { if ($resources =~ m|/ColorSpace$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($resources =~ m[/ColorSpace$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) 0 0 0
6494 0 { my $dict = getObject($1, 1, 1);
6495 0 $resources =~ s"/ColorSpace$ws+\d+$ws+\d+$ws+R"'/ColorSpace' . $dict"ose;
6496 }
6497 }
6498 ####################################################
6499 # Nu är resurserna "normaliserade" med ursprungliga
6500 # värden. Spara värden för "översättning"
6501 ####################################################
6502  
6503 5 $resources =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6504  
6505 ###############################
6506 # Komplettera med nya resurser
6507 ###############################
6508  
6509 5 ▶ if (scalar %sidFont)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidFont) 0 5 5
6510 0 { my $str = '';
6511 0 for (sort keys %sidFont)
6512 0 { $str .= "/$_ $sidFont{$_} 0 R";
6513 }
6514 0 ▶ if ($resources !~ m'\/Font'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/Font]so) { } 0 0 0
6515 0 { $resources = "/Font << $str >> " . $resources;
6516 }
6517 else
6518 0 { $resources =~ s"/Font$ws*<<"'/Font<<' . $str"oges;
6519 }
6520 }
6521  
6522 5 ▶ if (scalar %sidXObject)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidXObject) 0 5 5
6523 0 { my $str = '';
6524 0 for (sort keys %sidXObject)
6525 0 { $str .= "/$_ $sidXObject{$_} 0 R";
6526 }
6527 0 ▶ if ($resources !~ m'\/XObject'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/XObject]so) { } 0 0 0
6528 0 { $resources = "/XObject << $str >> " . $resources;
6529 }
6530 else
6531 0 { $resources =~ s"/XObject$ws*<<"'/XObject<<' . $str"oges;
6532 }
6533 }
6534  
6535 5 ▶ if (scalar %sidExtGState)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidExtGState) 0 5 5
6536 0 { my $str = '';
6537 0 for (sort keys %sidExtGState)
6538 0 { $str .= "/$_ $sidExtGState{$_} 0 R";
6539 }
6540 0 ▶ if ($resources !~ m'\/ExtGState'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/ExtGState]so) { } 0 0 0
6541 0 { $resources = "/ExtGState << $str >> " . $resources;
6542 }
6543 else
6544 0 { $resources =~ s"/ExtGState$ws*<<"'/ExtGState<<' . $str"oges;
6545 }
6546 }
6547  
6548 5 ▶ if (scalar %sidPattern)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidPattern) 0 5 5
6549 0 { my $str = '';
6550 0 for (sort keys %sidPattern)
6551 0 { $str .= "/$_ $sidPattern{$_} 0 R";
6552 }
6553 0 ▶ if ($resources !~ m'\/Pattern'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/Pattern]so) { } 0 0 0
6554 0 { $resources = "/Pattern << $str >> " . $resources;
6555 }
6556 else
6557 0 { $resources =~ s"/Pattern$ws*<<"'/Pattern<<' . $str"oges;
6558 }
6559 }
6560  
6561 5 ▶ if (scalar %sidShading)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidShading) 0 5 5
6562 0 { my $str = '';
6563 0 for (sort keys %sidShading)
6564 0 { $str .= "/$_ $sidShading{$_} 0 R";
6565 }
6566 0 ▶ if ($resources !~ m'\/Shading'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/Shading]so) { } 0 0 0
6567 0 { $resources = "/Shading << $str >> " . $resources;
6568 }
6569 else
6570 0 { $resources =~ s"/Shading$ws*<<"'/Shading<<' . $str"oges;
6571 }
6572 }
6573  
6574 5 ▶ if (scalar %sidColorSpace)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::sidColorSpace) 0 5 5
6575 0 { my $str = '';
6576 0 for (sort keys %sidColorSpace)
6577 0 { $str .= "/$_ $sidColorSpace{$_} 0 R";
6578 }
6579 0 ▶ if ($resources !~ m'\/ColorSpace'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $resources =~ m[\/ColorSpace]so) { } 0 0 0
6580 0 { $resources = "/ColorSpace << $str >> " . $resources;
6581 }
6582 else
6583 0 { $resources =~ s"/ColorSpace$ws*<<"'/ColorSpace<<'.$str"oges;
6584 }
6585 }
6586  
6587 5 ▶ if (exists $resurser{$resources})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::resurser{$resources}) { } 0 5 5
6588 0 { $resources = "$resurser{$resources} 0 R\n"; # Fanns ett identiskt,
6589 } # använd det
6590 else
6591 5 { $objNr++;
6592 5 ▶ if ( keys(%resurser) < 10)
Branch: 1 branch
BranchTrueFalseTotal
if (keys %PDF::Reuse::resurser < 10) 5 0 5
6593 5 { $resurser{$resources} = $objNr; # Spara 10 första resursobjekten
6594 }
6595 5 $objekt[$objNr] = $pos;
6596 5 $resursObjekt = "$objNr 0 obj<<$resources>>endobj\n";
6597 5 $pos += syswrite UTFIL, $resursObjekt ;
6598 5 $resources = "$objNr 0 R\n";
6599 }
6600  
6601 5 %sidXObject = ();
6602 5 %sidExtGState = ();
6603 5 %sidFont = ();
6604 5 %sidPattern = ();
6605 5 %sidShading = ();
6606 5 %sidColorSpace = ();
6607 5 undef $checkCs;
6608  
6609 5 $stream = '';
6610 }
6611  
6612 22 ▶ if (! $parents[0])
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::parents[0]) 0 22 22
6613 0 { $objNr++;
6614 0 $parents[0] = $objNr;
6615 }
6616 22 my $parent = $parents[0];
6617  
6618 22 ▶ if (($sidObjNr) && (! defined $objekt[$sidObjNr]))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::sidObjNr and not defined $PDF::Reuse::objekt[$PDF::Reuse::sidObjNr]) { } 5 17 22
Condition66%2/3
$PDF::Reuse::sidObjNr and not defined $PDF::Reuse::objekt[$PDF::Reuse::sidObjNr]
!ll&&!rl&&r
0175
MC/DC50%1/2
$PDF::Reuse::sidObjNr and not defined $PDF::Reuse::objekt[$PDF::Reuse::sidObjNr]
$PDF::Reuse::sidObjNr not defined $PDF::Reuse::objekt[$PDF::Reuse::sidObjNr]
Truth table66%2/3
A and not(B)
A= $PDF::Reuse::sidObjNrB= not defined $PDF::Reuse::objekt[$PDF::Reuse::sidObjNr]
ABresult
0X0
100
111
6619 5 { $ny = $sidObjNr;
6620 }
6621 else
6622 17 { $objNr++;
6623 17 $ny = $objNr;
6624 }
6625  
6626 22 $old{$oNr} = $ny;
6627  
6628 22 ▶ if ($obj =~ m|/Parent$ws+(\d+)$ws+\d+$ws+R\b|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m[/Parent$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b]so) 22 0 22
6629 22 { $old{$1} = $parent;
6630 }
6631  
6632 22 ▶ if ($obj =~ m/^\d+$ws+\d+$ws+obj$ws*<<(.+)>>$ws*endobj/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ /^\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+obj$PDF::Reuse::ws*<<(.+)>>$PDF::Reuse::ws*endobj/so) 22 0 22
6633 22 { $del1 = $1;
6634 }
6635  
6636 22 ▶ if (%links)
Branch: 1 branch
BranchTrueFalseTotal
if (%PDF::Reuse::links) 0 22 22
6637 0 { my $tSida = $sida + 1;
6638 0 ▶ if ((%links && $links{'-1'} && @{$links{'-1'}}) || (%links && $links{$tSida} && @{$links{$tSida}}))
Branch: 1 branch
BranchTrueFalseTotal
if (%PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}) 0 0 0
Condition0%0/15
%PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
l!l&&r!l&&!r
000
%PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};}
!ll&&!rl&&r
000
%PDF::Reuse::links and $PDF::Reuse::links{-1}
!ll&&!rl&&r
000
%PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
!ll&&!rl&&r
000
%PDF::Reuse::links and $PDF::Reuse::links{$tSida}
!ll&&!rl&&r
000
MC/DC0%0/6
%PDF::Reuse::links and $PDF::Reuse::links{-1} and @{$PDF::Reuse::links{-1};} or %PDF::Reuse::links and $PDF::Reuse::links{$tSida} and @{$PDF::Reuse::links{$tSida};}
%PDF::Reuse::links $PDF::Reuse::links{-1} @{$PDF::Reuse::links{-1};} %PDF::Reuse::links $PDF::Reuse::links{$tSida} @{$PDF::Reuse::links{$tSida};}
Truth table0%0/13
A and B and C or D and E and F
A= %PDF::Reuse::linksB= $PDF::Reuse::links{-1}C= @{$PDF::Reuse::links{-1};}D= %PDF::Reuse::linksE= $PDF::Reuse::links{$tSida}F= @{$PDF::Reuse::links{$tSida};}
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
6639 0 ▶ { if ($del1 =~ m|/Annots$ws*([^\/\<\>]+)|os)
Branch: 1 branch
BranchTrueFalseTotal
if ($del1 =~ m[/Annots$PDF::Reuse::ws*([^\/\<\>]+)]so) 0 0 0
6640 0 { $Annots = $1;
6641 0 @annots = ();
6642 0 ▶ if ($Annots =~ m'\[([^\[\]]*)\]'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots =~ /\[([^\[\]]*)\]/so) { } 0 0 0
6643 { ; }
6644 else
6645 0 ▶ { if ($Annots =~ m/\b(\d+)$ws+\d+$ws+R\b/os)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b/so) 0 0 0
6646 0 { $Annots = getObject($1);
6647 }
6648 }
6649 0 ▶ while ($Annots =~ m/\b(\d+)$ws+\d+$ws+R\b/ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b/sog) 0 0 0
6650 0 { push @annots, xform();
6651 }
6652 0 $del1 =~ s?/Annots$ws*([^\/\<\>]+)??os;
6653 }
6654 0 $Annots = '/Annots ' . mergeLinks() . ' 0 R';
6655 }
6656 }
6657  
6658 22 ▶ if (! $taInterAkt)
Branch: 1 branch
BranchTrueFalseTotal
unless ($PDF::Reuse::taInterAkt) 0 22 22
6659 0 { $del1 =~ s?$ws*/AA$ws*<<[^>]*>>??os;
6660 }
6661  
6662 22 $del1 =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6663  
6664 22 ▶ if ($del1 !~ m'/Resources'o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($del1 =~ m[/Resources]o) 5 17 22
6665 5 { $del1 .= "/Resources $resources";
6666 }
6667  
6668 22 ▶ if (defined $streamObjekt) # En ny ström ska läggas till
Branch: 1 branch
BranchTrueFalseTotal
if (defined $streamObjekt) 5 17 22
6669 5 ▶ { if ($del1 =~ m|/Contents$ws+(\d+)$ws+\d+$ws+R|os)
Branch: 2 branches
BranchTrueFalseTotal
if ($del1 =~ m[/Contents$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R]so) { } 5 0 5
elsif ($del1 =~ m(/Contents$PDF::Reuse::ws*\[)so) { } 0 0 0
6670 5 { my $oldCont = $1;
6671 5 $del1 =~ s|/Contents$ws+(\d+)$ws+\d+$ws+R|'/Contents [' . "$oldCont 0 R $streamObjekt" . ']'|oes;
6672 }
6673 elsif ($del1 =~ m|/Contents$ws*\[|os)
6674 0 { $del1 =~ s|/Contents$ws*\[([^\]]+)|'/Contents [' . $1 ." $streamObjekt"|oes;
6675 }
6676 else
6677 0 { $del1 .= "/Contents $streamObjekt\n";
6678 }
6679 }
6680  
6681 22 ▶ if ($Annots)
Branch: 1 branch
BranchTrueFalseTotal
if ($Annots) 0 22 22
6682 0 { $del1 .= $Annots;
6683 }
6684  
6685 22 $utrad = "$ny 0 obj<<$del1>>";
6686 22 ▶ if (defined $del2)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $del2) { } 0 22 22
6687 0 { $utrad .= "stream\n$del2";
6688 }
6689 else
6690 22 { $utrad .= "endobj\n";
6691 }
6692  
6693 22 $objekt[$ny] = $pos;
6694 22 $pos += syswrite UTFIL, $utrad;
6695  
6696 22 push @{$kids[0]}, $ny;
6697 22 $counts[0]++;
6698 22 ▶ if ($counts[0] > 9)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::counts[0] > 9) 0 22 22
6699 0 { ordnaNoder(8);
6700 }
6701 }
6702  
6703  
6704 sub checkResources
6705 10 ▶{ my $pObj = shift;
Subroutine checkResources: called CC=10 SCAR=37.0
Pod undocumented
6706 10 my $reStr = shift;
6707 10 my $to;
6708  
6709 10 my $p = index($pObj, '/Resources');
6710 10 ▶ if ( $p < 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($p < 0) { } 5 5 10
elsif ($pObj =~ m[/Resources($PDF::Reuse::ws+\d+$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R)]so) { } 5 0 5
6711 { ;
6712 }
6713 elsif ($pObj =~ m|/Resources($ws+\d+$ws+\d+$ws+R)|os)
6714 5 { $reStr = $1;
6715 5 $to = $p + 10 + length($reStr);
6716 }
6717 else
6718 0 { my $t = length($pObj);
6719 0 my $i = $p + 10;
6720 0 my $j = $i;
6721 0 my $k = 0;
6722 0 my $c;
6723 0 ▶ while ($i < $t)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $t) 0 0 0
6724 0 { $c = substr($pObj,$i,1);
6725 0 ▶ if (($c eq '<' )
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "<" or $c eq ">") 0 0 0
Condition0%0/3
$c eq "<" or $c eq ">"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "<" or $c eq ">"
$c eq "<" $c eq ">"
Truth table0%0/3
A or B
A= $c eq "<"B= $c eq ">"
ABresult
1X1
011
000
6726 || ($c eq '>'))
6727 0 ▶ { if ($c eq '<' )
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq '<') { } 0 0 0
6728 0 { $k++;
6729 }
6730 else
6731 0 { $k--;
6732 }
6733 0 ▶ last if ($k == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $k == 0 0 0 0
6734 }
6735 0 $i++;
6736 }
6737 0 ▶ if ($i != $t)
Branch: 1 branch
BranchTrueFalseTotal
if ($i != $t) 0 0 0
6738 0 { $i++;
6739 0 $reStr = substr($pObj, $j, ($i - $j));
6740 0 $to = $i;
6741 }
6742 }
6743  
6744 10 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 5 5 10
6745 5 { return ($reStr, $p, $to);
6746 }
6747 else
6748 5 { return $reStr;
6749 }
6750 }
6751  
6752  
6753 sub translate
6754 0 ▶{ if (exists $old{$1})
Subroutine translate: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$1}) { } 0 0 0
6755 0 { $old{$1}; }
6756 else
6757 0 { $old{$1} = ++$objNr;
6758 }
6759 }
6760  
6761 sub behandlaNames
6762 0 ▶{ my ($namnObj, $iForm) = @_;
Subroutine behandlaNames: not called CC=45 SCAR=76.4
Pod undocumented
6763  
6764 0 my ($low, $high, $antNod0, $entry, $nyttNr, $ny, $obj,
6765 $fObjnr, $offSet, $bytes, $res, $key, $func, $corr, @objData);
6766 0 my (@nod0, @nodUpp, @kid, @soek, %nytt);
6767  
6768 0 my $objektet = '';
6769 0 my $vektor = '';
6770 0 my $antal = 0;
6771 0 my $antNodUpp = 0;
6772 0 ▶ if ($namnObj)
Branch: 1 branch
BranchTrueFalseTotal
if ($namnObj) 0 0 0
6773 0 ▶ { if ($iForm) # Läsning via interntabell
Branch: 1 branch
BranchTrueFalseTotal
if ($iForm) { } 0 0 0
6774 0 { $objektet = getObject($namnObj, 1);
6775  
6776 0 ▶ if ($objektet =~ m'<<(.+)>>'ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /<<(.+)>>/sog) 0 0 0
6777 0 { $objektet = $1; }
6778 0 ▶ if ($objektet =~ s|/JavaScript$ws+(\d+)$ws+\d+$ws+R||os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ s[/JavaScript$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R][]os) 0 0 0
6779 0 { my $byt = $1;
6780 0 push @kid, $1;
6781 0 ▶ while (scalar @kid)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @kid) 0 0 0
6782 0 { @soek = @kid;
6783 0 @kid = ();
6784 0 for my $sObj (@soek)
6785 0 { $obj = getObject($sObj, 1);
6786 0 ▶ if ($obj =~ m|/Kids$ws*\[([^]]+)|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m(/Kids$PDF::Reuse::ws*\[([^]]+))sog) 0 0 0
6787 0 { $vektor = $1;
6788 }
6789 0 ▶ while ($vektor =~ m/\b(\d+)$ws+\d+$ws+R\b/ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b/sog) 0 0 0
6790 0 { push @kid, $1;
6791 }
6792 0 $vektor = '';
6793 0 ▶ if ($obj =~ m|/Names$ws*\[([^]]+)|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m(/Names$PDF::Reuse::ws*\[([^]]+))sog) 0 0 0
6794 0 { $vektor = $1;
6795 }
6796 0 ▶ while ($vektor=~m|\(([^\)]+)\)$ws*(\d+)$ws+\d$ws+R|gos)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /\(([^\)]+)\)$PDF::Reuse::ws*(\d+)$PDF::Reuse::ws+\d$PDF::Reuse::ws+R/sog) 0 0 0
6797 0 { $script{$1} = $2;
6798 }
6799 }
6800 }
6801 }
6802 }
6803 else # Läsning av ett "doc"
6804 0 { $objektet = getObject($namnObj);
6805 0 ▶ if ($objektet =~ m'<<(.+)>>'ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ /<<(.+)>>/sog) 0 0 0
6806 0 { $objektet = $1; }
6807 0 ▶ if ($objektet =~ s|/JavaScript$ws+(\d+)$ws+\d+$ws+R||os)
Branch: 1 branch
BranchTrueFalseTotal
if ($objektet =~ s[/JavaScript$PDF::Reuse::ws+(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R][]os) 0 0 0
6808 0 { my $byt = $1;
6809 0 push @kid, $1;
6810 0 ▶ while (scalar @kid)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @kid) 0 0 0
6811 0 { @soek = @kid;
6812 0 @kid = ();
6813 0 for my $sObj (@soek)
6814 0 { $obj = getObject($sObj);
6815 0 ▶ if ($obj =~ m|/Kids$ws*\[([^]]+)|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m(/Kids$PDF::Reuse::ws*\[([^]]+))sog) 0 0 0
6816 0 { $vektor = $1;
6817 }
6818 0 ▶ while ($vektor =~ m|\b(\d+)$ws+\d+$ws+R\b|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /\b(\d+)$PDF::Reuse::ws+\d+$PDF::Reuse::ws+R\b/sog) 0 0 0
6819 0 { push @kid, $1;
6820 }
6821 0 undef $vektor;
6822 0 ▶ if ($obj =~ m|/Names$ws*\[([^]]+)|ogs)
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ m(/Names$PDF::Reuse::ws*\[([^]]+))sog) 0 0 0
6823 0 { $vektor = $1;
6824 }
6825 0 ▶ while($vektor =~ m/\(([^\)]+)\)$ws*(\d+)$ws+\d\$ws+R/gos)
Branch: 1 branch
BranchTrueFalseTotal
if ($vektor =~ /\(([^\)]+)\)$PDF::Reuse::ws*(\d+)$PDF::Reuse::ws+\d\$ws+R/sog) 0 0 0
6826 0 { $script{$1} = $2;
6827 }
6828 }
6829 }
6830 }
6831 }
6832 }
6833 0 for my $filnamn (@jsfiler)
6834 0 { inkludera($filnamn);
6835 }
6836 0 my @nya = (keys %nyaFunk);
6837 0 ▶ while (scalar @nya)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @nya) 0 0 0
6838 0 { my @behandla = @nya;
6839 0 @nya = ();
6840 0 for $key (@behandla)
6841 0 ▶ { if (exists $initScript{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::initScript{$key}) 0 0 0
6842 0 ▶ { if (exists $nyaFunk{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::nyaFunk{$key}) 0 0 0
6843 0 { $initScript{$key} = $nyaFunk{$key};
6844 }
6845 0 ▶ if (exists $script{$key}) # företräde för nya funktioner !
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::script{$key}) 0 0 0
6846 0 { delete $script{$key}; # gammalt script m samma namn plockas bort
6847 }
6848 0 my @fall = ($initScript{$key} =~ m'([\w\d\_\$]+)\s*\('ogs);
6849 0 for (@fall)
6850 0 ▶ { if (($_ ne $key) && (exists $nyaFunk{$_}))
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne $key and exists $PDF::Reuse::nyaFunk{$_}) 0 0 0
Condition0%0/3
$_ ne $key and exists $PDF::Reuse::nyaFunk{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne $key and exists $PDF::Reuse::nyaFunk{$_}
$_ ne $key exists $PDF::Reuse::nyaFunk{$_}
Truth table0%0/3
A and B
A= $_ ne $keyB= exists $PDF::Reuse::nyaFunk{$_}
ABresult
0X0
100
111
6851 0 { $initScript{$_} = $nyaFunk{$_};
6852 0 push @nya, $_;
6853 }
6854 }
6855 }
6856 }
6857 }
6858 0 ▶ while (($key, $func) = each %nyaFunk)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %PDF::Reuse::nyaFunk) 0 0 0
6859 0 { $fObjnr = skrivJS($func);
6860 0 $script{$key} = $fObjnr;
6861 0 $nytt{$key} = $fObjnr;
6862 }
6863  
6864 0 ▶ if (scalar %fields)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::fields) 0 0 0
6865 0 { push @inits, 'Ladda();';
6866 0 $fObjnr = defLadda();
6867 0 ▶ if ($duplicateInits)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::duplicateInits) 0 0 0
6868 0 { $script{'Ladda'} = $fObjnr;
6869 0 $nytt{'Ladda'} = $fObjnr;
6870 }
6871 }
6872  
6873 0 ▶ if ((scalar @inits) && ($duplicateInits))
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @PDF::Reuse::inits and $PDF::Reuse::duplicateInits) 0 0 0
Condition0%0/3
scalar @PDF::Reuse::inits and $PDF::Reuse::duplicateInits
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @PDF::Reuse::inits and $PDF::Reuse::duplicateInits
scalar @PDF::Reuse::inits $PDF::Reuse::duplicateInits
Truth table0%0/3
A and B
A= scalar @PDF::Reuse::initsB= $PDF::Reuse::duplicateInits
ABresult
0X0
100
111
6874 0 { $fObjnr = defInit();
6875 0 $script{'Init'} = $fObjnr;
6876 0 $nytt{'Init'} = $fObjnr;
6877 }
6878 0 undef @jsfiler;
6879  
6880 0 for my $key (sort (keys %script))
6881 0 ▶ { if (! defined $low)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $low) 0 0 0
6882 0 { $objNr++;
6883 0 $ny = $objNr;
6884 0 $objekt[$ny] = $pos;
6885 0 $obj = "$ny 0 obj\n";
6886 0 $low = $key;
6887 0 $obj .= '<< /Names [';
6888 }
6889 0 $high = $key;
6890 0 $obj .= '(' . "$key" . ')';
6891 0 ▶ if (! exists $nytt{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $nytt{$key}) { } 0 0 0
6892 0 { $nyttNr = quickxform($script{$key});
6893 }
6894 else
6895 0 { $nyttNr = $script{$key};
6896 }
6897 0 $obj .= "$nyttNr 0 R\n";
6898 0 $antal++;
6899 0 ▶ if ($antal > 9)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal > 9) 0 0 0
6900 0 { $obj .= ' ]/Limits [(' . "$low" . ')(' . "$high" . ')] >>' . "endobj\n";
6901 0 $pos += syswrite UTFIL, $obj;
6902 0 push @nod0, \[$ny, $low, $high];
6903 0 $antNod0++;
6904 0 undef $low;
6905 0 $antal = 0;
6906 }
6907 }
6908 0 ▶ if ($antal)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal) 0 0 0
6909 0 { $obj .= ']/Limits [(' . $low . ')(' . $high . ')]>>' . "endobj\n";
6910 0 $pos += syswrite UTFIL, $obj;
6911 0 push @nod0, \[$ny, $low, $high];
6912 0 $antNod0++;
6913 }
6914 0 $antal = 0;
6915  
6916 0 ▶ while (scalar @nod0)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @nod0) 0 0 0
6917 0 { for $entry (@nod0)
6918 0 ▶ { if ($antal == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal == 0) 0 0 0
6919 0 { $objNr++;
6920 0 $objekt[$objNr] = $pos;
6921 0 $obj = "$objNr 0 obj\n";
6922 0 $low = $$entry->[1];
6923 0 $obj .= '<</Kids [';
6924 }
6925 0 $high = $$entry->[2];
6926 0 $obj .= " $$entry->[0] 0 R";
6927 0 $antal++;
6928 0 ▶ if ($antal > 9)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal > 9) 0 0 0
6929 0 { $obj .= ']/Limits [(' . $low . ')(' . $high . ')]>>' . "endobj\n";
6930 0 $pos += syswrite UTFIL, $obj;
6931 0 push @nodUpp, \[$objNr, $low, $high];
6932 0 $antNodUpp++;
6933 0 undef $low;
6934 0 $antal = 0;
6935 }
6936 }
6937 0 ▶ if ($antal > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($antal > 0) 0 0 0
6938 0 ▶ { if ($antNodUpp == 0) # inget i noderna över
Branch: 1 branch
BranchTrueFalseTotal
if ($antNodUpp == 0) { } 0 0 0
6939 0 { $obj .= ']>>' . "endobj\n";
6940 0 $pos += syswrite UTFIL, $obj;
6941 }
6942 else
6943 0 { $obj .= ']/Limits [(' . "$low" . ')(' . "$high" . ')]>>' . "endobj\n";
6944 0 $pos += syswrite UTFIL, $obj;
6945 0 push @nodUpp, \[$objNr, $low, $high];
6946 0 $antNodUpp++;
6947 0 undef $low;
6948 0 $antal = 0;
6949 }
6950 }
6951 0 @nod0 = @nodUpp;
6952 0 $antNod0 = $antNodUpp;
6953 0 undef @nodUpp;
6954 0 $antNodUpp = 0;
6955 }
6956  
6957  
6958 0 $ny = $objNr;
6959 0 $objektet =~ s|$ws*/JavaScript$ws*\d+$ws+\d+$ws+R||os;
6960 0 $objektet =~ s/\b(\d+)$ws+\d+$ws+R\b/xform() . ' 0 R'/oegs;
6961 0 ▶ if (scalar %script)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar %PDF::Reuse::script) 0 0 0
6962 0 { $objektet .= "\n/JavaScript $ny 0 R\n";
6963 }
6964 0 $objNr++;
6965 0 $ny = $objNr;
6966 0 $objekt[$ny] = $pos;
6967 0 $objektet = "$ny 0 obj<<" . $objektet . ">>endobj\n";
6968 0 $pos += syswrite UTFIL, $objektet;
6969 0 return $ny;
6970 }
6971  
6972  
6973 sub quickxform
6974 0 ▶{ my $inNr = shift;
Subroutine quickxform: not called CC=2 SCAR=17.9
Pod undocumented
6975 0 ▶ if (exists $old{$inNr})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PDF::Reuse::old{$inNr}) { } 0 0 0
6976 0 { $old{$inNr}; }
6977 else
6978 0 { push @skapa, [$inNr, ++$objNr];
6979 0 $old{$inNr} = $objNr;
6980 }
6981 }
6982  
6983  
6984 sub skrivKedja
6985 0 ▶{ my $code = ' ';
Subroutine skrivKedja: not called CC=3 SCAR=24.8
Pod undocumented
6986  
6987 0 for (values %initScript)
6988 0 { $code .= $_ . "\n";
6989 }
6990 0 $code .= "function Init() { ";
6991 0 $code .= 'if (typeof this.info.ModDate == "object")' . " { return true; }";
6992 0 for (@inits)
6993 0 { $code .= $_ . "\n";
6994 }
6995 0 $code .= "} Init(); ";
6996  
6997 0 my $spar = skrivJS($code);
6998 0 undef @inits;
6999 0 undef %initScript;
7000 0 return $spar;
7001 }
7002  
7003  
7004  
7005 sub skrivJS
7006 0 ▶{ my $kod = shift;
Subroutine skrivJS: not called CC=3 SCAR=24.8
Pod undocumented
7007 0 my $obj;
7008 0 ▶ if (($compress) && (length($kod) > 99))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::compress and length $kod > 99) { } 0 0 0
Condition0%0/3
$PDF::Reuse::compress and length $kod > 99
!ll&&!rl&&r
000
MC/DC0%0/2
$PDF::Reuse::compress and length $kod > 99
$PDF::Reuse::compress length $kod > 99
Truth table0%0/3
A and B
A= $PDF::Reuse::compressB= length $kod > 99
ABresult
0X0
100
111
7009 0 { $objNr++;
7010 0 $objekt[$objNr] = $pos;
7011 0 my $spar = $objNr;
7012 0 $kod = compress($kod);
7013 0 my $langd = length($kod);
7014 0 $obj = "$objNr 0 obj<</Filter/FlateDecode"
7015 . "/Length $langd>>stream\n" . $kod
7016 . "\nendstream\nendobj\n";
7017 0 $pos += syswrite UTFIL, $obj;
7018 0 $objNr++;
7019 0 $objekt[$objNr] = $pos;
7020 0 $obj = "$objNr 0 obj<</S/JavaScript/JS $spar 0 R >>endobj\n";
7021 }
7022 else
7023 0 { $kod =~ s'\('\\('gso;
7024 0 $kod =~ s'\)'\\)'gso;
7025 0 $objNr++;
7026 0 $objekt[$objNr] = $pos;
7027 0 $obj = "$objNr 0 obj<</S/JavaScript/JS " . '(' . $kod . ')';
7028 0 $obj .= ">>endobj\n";
7029 }
7030 0 $pos += syswrite UTFIL, $obj;
7031 0 return $objNr;
7032 }
7033  
7034 sub inkludera
7035 0 ▶{ my $jsfil = shift;
Subroutine inkludera: not called CC=6 SCAR=37.4
Pod undocumented
7036 0 my $fil;
7037 0 ▶ if ($jsfil !~ m'\{'os)
Branch: 1 branch
BranchTrueFalseTotal
if (not $jsfil =~ /\{/so) { } 0 0 0
7038 0 ▶ { open (JSFIL, "<$jsfil") || return;
Branch: 1 branch
BranchTrueFalseTotal
open JSFIL, "<$jsfil" or return 0 0 0
7039 0 ▶ while (<JSFIL>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline JSFIL)) 0 0 0
7040 0 { $fil .= $_;}
7041  
7042 0 close JSFIL;
7043 }
7044 else
7045 0 { $fil = $jsfil;
7046 }
7047 0 $fil =~ s|function\s+([\w\_\d\$]+)\s*\(|"zXyZcUt function $1 ("|sge;
7048 0 my @funcs = split/zXyZcUt /, $fil;
7049 0 for my $kod (@funcs)
7050 0 ▶ { if ($kod =~ m'^function ([\w\_\d\$]+)'os)
Branch: 1 branch
BranchTrueFalseTotal
if ($kod =~ /^function ([\w\_\d\$]+)/so) 0 0 0
7051 0 { $nyaFunk{$1} = $kod;
7052 }
7053 }
7054 }
7055  
7056  
7057 sub defLadda
7058 0 ▶{ my $code = "function Ladda() {";
Subroutine defLadda: not called CC=4 SCAR=30.0
Pod undocumented
7059 0 for (keys %fields)
7060 0 { my $val = $fields{$_};
7061 0 ▶ if ($val =~ m'\s*js\s*\:(.+)'oi)
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\s*js\s*\:(.+)/io) { } 0 0 0
7062 0 { $val = $1;
7063 0 $code .= "if (this.getField('$_')) this.getField('$_').value = $val; ";
7064 }
7065 else
7066 0 { $val =~ s/([^A-Za-z0-9\-_.!* ])/sprintf("%%%02X", ord($1))/ge;
7067 0 $code .= "if (this.getField('$_')) this.getField('$_').value = unescape('$val'); ";
7068 }
7069  
7070 }
7071 0 $code .= " 1;} ";
7072  
7073  
7074 0 $initScript{'Ladda'} = $code;
7075 0 ▶ if ($duplicateInits)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::duplicateInits) { } 0 0 0
7076 0 { my $ny = skrivJS($code);
7077 0 return $ny;
7078 }
7079 else
7080 0 { return 1;
7081 }
7082 }
7083  
7084 sub defInit
7085 0 ▶{ my $code = "function Init() { ";
Subroutine defInit: not called CC=2 SCAR=17.9
Pod undocumented
7086 0 $code .= 'if (typeof this.info.ModDate == "object")' . " { return true; } ";
7087 0 for (@inits)
7088 0 { $code .= $_ . "\n";
7089 }
7090 0 $code .= '}';
7091  
7092 0 my $ny = skrivJS($code);
7093 0 return $ny;
7094  
7095 }
7096  
7097  
7098  
7099 sub errLog
7100 3 ▶{ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine errLog: not called CC=11 SCAR=47.3
Pod undocumented
7101 0 my $mess = shift;
7102 0 my $endMess = " $mess \n More information might be found in";
7103 0 ▶ if ($runfil)
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::runfil) 0 0 0
7104 0 { $log .= "Log~Err: $mess\n";
7105 0 $endMess .= "\n $runfil";
7106 0 ▶ if (! $pos)
Branch: 2 branches
BranchTrueFalseTotal
if (not $PDF::Reuse::pos) { } 0 0 0
elsif ($PDF::Reuse::pos > 15000000) { } 0 0 0
7107 0 { $log .= "Log~Err: No pdf-file has been initiated\n";
7108 }
7109 elsif ($pos > 15000000)
7110 0 { $log .= "Log~Err: Current pdf-file is very big: $pos bytes, will not try to finish it\n";
7111 }
7112 else
7113 0 { $log .= "Log~Err: Will try to finish current pdf-file\n";
7114 0 $endMess .= "\n $utfil";
7115 }
7116 }
7117 0 my $errLog = 'error.log';
7118 0 my $now = localtime();
7119 0 ▶ my $lpos = $pos || 'undef';
Condition0%0/2
$PDF::Reuse::pos || 'undef'
l!l
00
MC/DC0%0/1
$PDF::Reuse::pos || 'undef'
$PDF::Reuse::pos
Truth table0%0/2
A
A= $PDF::Reuse::pos
Aresult
11
00
7120 0 ▶ my $lobjNr = $objNr || 'undef';
Condition0%0/2
$PDF::Reuse::objNr || 'undef'
l!l
00
MC/DC0%0/1
$PDF::Reuse::objNr || 'undef'
$PDF::Reuse::objNr
Truth table0%0/2
A
A= $PDF::Reuse::objNr
Aresult
11
00
7121 0 ▶ my $lutfil = $utfil || 'undef';
Condition0%0/2
$PDF::Reuse::utfil || 'undef'
l!l
00
MC/DC0%0/1
$PDF::Reuse::utfil || 'undef'
$PDF::Reuse::utfil
Truth table0%0/2
A
A= $PDF::Reuse::utfil
Aresult
11
00
7122  
7123 0 ▶ my $lrunfil = $runfil || 'undef';
Condition0%0/2
$PDF::Reuse::runfil || 'undef'
l!l
00
MC/DC0%0/1
$PDF::Reuse::runfil || 'undef'
$PDF::Reuse::runfil
Truth table0%0/2
A
A= $PDF::Reuse::runfil
Aresult
11
00
7124 0 ▶ open (ERRLOG, ">$errLog") || croak "$mess can't open an error log, $!";
Branch: 1 branch
BranchTrueFalseTotal
open ERRLOG, ">$errLog" or croak("$mess can't open an error log, $!") 0 0 0
7125 0 print ERRLOG "\n$mess\n\n";
7126 0 print ERRLOG Carp::longmess("The error occurred when executing:\n");
7127 0 print ERRLOG "\nSituation when the error occurred\n\n";
7128 0 print ERRLOG " Bytes written to the current pdf-file, pos = $lpos\n";
7129 0 print ERRLOG " Object processed, not necessarily written objNr = $lobjNr\n";
7130 0 print ERRLOG " Current pdf-file, utfil = $lutfil\n";
7131 0 print ERRLOG " File logging the run, runfil = $lrunfil\n";
7132 0 print ERRLOG " Local time = $now\n";
7133 0 print ERRLOG "\n\n";
7134 0 close ERRLOG;
7135 0 $endMess .= "\n $errLog";
7136 0 ▶ if (($pos) && ($pos < 15000000))
Branch: 1 branch
BranchTrueFalseTotal
if ($PDF::Reuse::pos and $PDF::Reuse::pos < 15000000) 0 0 0
Condition0%0/3
$PDF::Reuse::pos and $PDF::Reuse::pos < 15000000
!ll&&!rl&&r
000
MC/DC0%0/2
$PDF::Reuse::pos and $PDF::Reuse::pos < 15000000
$PDF::Reuse::pos $PDF::Reuse::pos < 15000000
Truth table0%0/3
A and B
A= $PDF::Reuse::posB= $PDF::Reuse::pos < 15000000
ABresult
0X0
100
111
7137 0 { prEnd();
7138 }
7139 0 print STDERR Carp::shortmess("An error occurred \n");
7140 0 croak "$endMess\n";
7141 }
↑ Summary Reuse/Util.pm »