Image/ExifTool/PostScript.pm

filter: Statementstmt 62.5% 202 / 323 Branchbran 52.0% 130 / 250 Conditioncond 33.3% 22 / 66 MC/DCmcdc 13.9% 6 / 43 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 10 totaltotal 52.6% 372 / 706 CC 150 SCAR 62.8
CC
150
Cov
55%
ProcessPS
872.1
DecodeComment
130.4
GetNextLine
14.9
CRAP 536.1
« Image/ExifTool/MPEG.pm ↑ Summary Image/ExifTool/Photoshop.pm »
1 #------------------------------------------------------------------------------
2 # File: PostScript.pm
3 #
4 # Description: Read PostScript meta information
5 #
6 # Revisions: 07/08/2005 - P. Harvey Created
7 #
8 # References: 1) http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
9 # 2) http://partners.adobe.com/public/developer/en/ps/5001.DSC_Spec.pdf
10 # 3) http://partners.adobe.com/public/developer/en/illustrator/sdk/AI7FileFormat.pdf
11 #------------------------------------------------------------------------------
12  
13 package Image::ExifTool::PostScript;
14  
15 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 29 ▶use vars qw($VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 29 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 29 $VERSION = '1.46';
20  
21 sub WritePS($$);
22 sub ProcessPS($$;$);
23  
24 # PostScript tag table
25 29 %Image::ExifTool::PostScript::Main = (
26 PROCESS_PROC => \&ProcessPS,
27 WRITE_PROC => \&WritePS,
28 PREFERRED => 1, # always add these tags when writing
29 GROUPS => { 2 => 'Image' },
30 # Note: Make all of these tags priority 0 since the first one found at
31 # the start of the file should take priority (in case multiples exist)
32 Author => { Priority => 0, Groups => { 2 => 'Author' }, Writable => 'string' },
33 BoundingBox => { Priority => 0 },
34 Copyright => { Priority => 0, Writable => 'string' }, #2
35 CreationDate => {
36 Name => 'CreateDate',
37 Priority => 0,
38 Groups => { 2 => 'Time' },
39 Writable => 'string',
40 PrintConv => '$self->ConvertDateTime($val)',
41 PrintConvInv => '$self->InverseDateTime($val)',
42 },
43 Creator => { Priority => 0, Writable => 'string' },
44 ImageData => { Priority => 0 },
45 For => { Priority => 0, Writable => 'string', Notes => 'for whom the document was prepared'},
46 Keywords => { Priority => 0, Writable => 'string' },
47 ModDate => {
48 Name => 'ModifyDate',
49 Priority => 0,
50 Groups => { 2 => 'Time' },
51 Writable => 'string',
52 PrintConv => '$self->ConvertDateTime($val)',
53 PrintConvInv => '$self->InverseDateTime($val)',
54 },
55 Pages => { Priority => 0 },
56 Routing => { Priority => 0, Writable => 'string' }, #2
57 Subject => { Priority => 0, Writable => 'string' },
58 Title => { Priority => 0, Writable => 'string' },
59 Version => { Priority => 0, Writable => 'string' }, #2
60 # these subdirectories for documentation only
61 BeginPhotoshop => {
62 Name => 'PhotoshopData',
63 SubDirectory => {
64 TagTable => 'Image::ExifTool::Photoshop::Main',
65 },
66 },
67 BeginICCProfile => {
68 Name => 'ICC_Profile',
69 SubDirectory => {
70 TagTable => 'Image::ExifTool::ICC_Profile::Main',
71 },
72 },
73 begin_xml_packet => {
74 Name => 'XMP',
75 SubDirectory => {
76 TagTable => 'Image::ExifTool::XMP::Main',
77 },
78 },
79 TIFFPreview => {
80 Groups => { 2 => 'Preview' },
81 Binary => 1,
82 Notes => q{
83 not a real tag ID, but used to represent the TIFF preview extracted from DOS
84 EPS images
85 },
86 },
87 BeginDocument => {
88 Name => 'EmbeddedFile',
89 SubDirectory => {
90 TagTable => 'Image::ExifTool::PostScript::Main',
91 },
92 Notes => 'extracted with L<ExtractEmbedded|../ExifTool.html#ExtractEmbedded> option',
93 },
94 EmbeddedFileName => {
95 Notes => q{
96 not a real tag ID, but the file name from a BeginDocument statement.
97 Extracted with document metadata when L<ExtractEmbedded|../ExifTool.html#ExtractEmbedded> option is used
98 },
99 },
100 # AI metadata (most with a single leading '%')
101 AI9_ColorModel => {
102 Name => 'AIColorModel',
103 PrintConv => {
104 1 => 'RGB',
105 2 => 'CMYK',
106 },
107 },
108 AI3_ColorUsage => { Name => 'AIColorUsage' },
109 AI5_RulerUnits => {
110 Name => 'AIRulerUnits',
111 PrintConv => {
112 0 => 'Inches',
113 1 => 'Millimeters',
114 2 => 'Points',
115 3 => 'Picas',
116 4 => 'Centimeters',
117 6 => 'Pixels',
118 },
119 },
120 AI5_TargetResolution => { Name => 'AITargetResolution' },
121 AI5_NumLayers => { Name => 'AINumLayers' },
122 AI5_FileFormat => { Name => 'AIFileFormat' },
123 AI8_CreatorVersion => { Name => 'AICreatorVersion' }, # (double leading '%')
124 AI12_BuildNumber => { Name => 'AIBuildNumber' },
125 );
126  
127 # composite tags
128 29 %Image::ExifTool::PostScript::Composite = (
129 GROUPS => { 2 => 'Image' },
130 # BoundingBox is in points, not pixels,
131 # but use it anyway if ImageData is not available
132 ImageWidth => {
133 Desire => {
134 0 => 'Main:PostScript:ImageData',
135 1 => 'PostScript:BoundingBox',
136 },
137 ValueConv => 'Image::ExifTool::PostScript::ImageSize(\@val, 0)',
138 },
139 ImageHeight => {
140 Desire => {
141 0 => 'Main:PostScript:ImageData',
142 1 => 'PostScript:BoundingBox',
143 },
144 ValueConv => 'Image::ExifTool::PostScript::ImageSize(\@val, 1)',
145 },
146 );
147  
148 # add our composite tags
149 29 Image::ExifTool::AddCompositeTags('Image::ExifTool::PostScript');
150  
151 #------------------------------------------------------------------------------
152 # AutoLoad our writer routines when necessary
153 #
154 sub AUTOLOAD
155 19 ▶{
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
156 19 return Image::ExifTool::DoAutoLoad($AUTOLOAD, @_);
157 }
158  
159 #------------------------------------------------------------------------------
160 # Get image width or height
161 # Inputs: 0) value list ref (ImageData, BoundingBox), 1) true to get height
162 sub ImageSize($$)
163 4 ▶{
Subroutine ImageSize: called CC=6 SCAR=23.5
Pod undocumented
164 4 my ($vals, $getHeight) = @_;
165 4 my ($w, $h);
166 4 ▶ if ($$vals[0] and $$vals[0] =~ /^(\d+) (\d+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vals->[0] and $vals->[0] =~ /^(\d+) (\d+)/) { } 4 0 4
elsif ($vals->[1] and $vals->[1] =~ /^(\d+) (\d+) (\d+) (\d+)/) { } 0 0 0
Condition33%1/3
$vals->[0] and $vals->[0] =~ /^(\d+) (\d+)/
!ll&&!rl&&r
004
MC/DC0%0/2
$vals->[0] and $vals->[0] =~ /^(\d+) (\d+)/
$vals->[0] $vals->[0] =~ /^(\d+) (\d+)/
Truth table33%1/3
A and B
A= $vals->[0]B= $vals->[0] =~ /^(\d+) (\d+)/
ABresult
0X0
100
111
167 4 ($w, $h) = ($1, $2);
168 ▶ } elsif ($$vals[1] and $$vals[1] =~ /^(\d+) (\d+) (\d+) (\d+)/) {
Condition0%0/3
$vals->[1] and $vals->[1] =~ /^(\d+) (\d+) (\d+) (\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$vals->[1] and $vals->[1] =~ /^(\d+) (\d+) (\d+) (\d+)/
$vals->[1] $vals->[1] =~ /^(\d+) (\d+) (\d+) (\d+)/
Truth table0%0/3
A and B
A= $vals->[1]B= $vals->[1] =~ /^(\d+) (\d+) (\d+) (\d+)/
ABresult
0X0
100
111
169 0 ($w, $h) = ($3 - $1, $4 - $2);
170 }
171 4 ▶ return $getHeight ? $h : $w;
Branch: 1 branch
BranchTrueFalseTotal
$getHeight ? : 2 2 4
172 }
173  
174 #------------------------------------------------------------------------------
175 # Set PostScript format error warning
176 # Inputs: 0) ExifTool object reference, 1) error string
177 # Returns: 1
178 sub PSErr($$)
179 0 ▶{
Subroutine PSErr: not called CC=3 SCAR=24.8
Pod undocumented
180 0 my ($et, $str) = @_;
181 # set file type if not done already
182 0 my $ext = $$et{FILE_EXT};
183 0 ▶ $et->SetFileType(($ext and $ext eq 'AI') ? 'AI' : 'PS');
Branch: 1 branch
BranchTrueFalseTotal
$ext && $ext eq 'AI' ? : 0 0 0
Condition0%0/3
$ext and $ext eq "AI"
!ll&&!rl&&r
000
MC/DC0%0/2
$ext and $ext eq "AI"
$ext $ext eq "AI"
Truth table0%0/3
A and B
A= $extB= $ext eq "AI"
ABresult
0X0
100
111
184 0 $et->Warn("PostScript format error ($str)");
185 0 return 1;
186 }
187  
188 #------------------------------------------------------------------------------
189 # Return input record separator to use for the specified file
190 # Inputs: 0) RAF reference
191 # Returns: Input record separator or undef on error
192 sub GetInputRecordSeparator($)
193 8 ▶{
Subroutine GetInputRecordSeparator: called CC=8 SCAR=21.2
Pod undocumented
194 8 my $raf = shift;
195 8 my $pos = $raf->Tell(); # save current position
196 8 my ($data, $sep);
197 8 ▶ $raf->Read($data,256) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($data, 256) or return undef 8 0 8
198 8 my ($a, $d) = (999,999);
199 8 ▶ $a = pos($data), pos($data) = 0 if $data =~ /\x0a/g;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /\x0a/g 4 4 8
200 8 ▶ $d = pos($data) if $data =~ /\x0d/g;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /\x0d/g 3 5 8
201 8 my $diff = $a - $d;
202 8 ▶ if ($diff == 1) {
Branch: 4 branches
BranchTrueFalseTotal
if ($diff == 1) { } 0 8 8
elsif ($diff == -1) { } 0 8 8
elsif ($diff > 0) { } 3 5 8
elsif ($diff < 0) { } 4 1 5
203 0 $sep = "\x0d\x0a";
204 } elsif ($diff == -1) {
205 0 $sep = "\x0a\x0d";
206 } elsif ($diff > 0) {
207 3 $sep = "\x0d";
208 } elsif ($diff < 0) {
209 4 $sep = "\x0a";
210 } # else error
211 8 $raf->Seek($pos, 0); # restore original position
212 8 return $sep;
213 }
214  
215 #------------------------------------------------------------------------------
216 # Split into lines ending in any CR, LF or CR+LF combination
217 # (this is annoying, and could be avoided if EPS files didn't mix linefeeds!)
218 # Inputs: 0) data pointer, 1) reference to lines array
219 # Notes: Fills @$lines with lines from splitting $$dataPt
220 sub SplitLine($$)
221 1 ▶{
Subroutine SplitLine: called CC=7 SCAR=20.2
Pod undocumented
222 1 my ($dataPt, $lines) = @_;
223 1 for (;;) {
224 108 my $endl;
225 # find the position of the first LF (\x0a)
226 108 ▶ $endl = pos($$dataPt), pos($$dataPt) = 0 if $$dataPt =~ /\x0a/g;
Branch: 1 branch
BranchTrueFalseTotal
if $$dataPt =~ /\x0a/g 107 1 108
227 108 ▶ if ($$dataPt =~ /\x0d/g) { # find the first CR (\x0d)
Branch: 2 branches
BranchTrueFalseTotal
if ($$dataPt =~ /\x0d/g) { } 108 0 108
elsif (not defined $endl) { } 0 0 0
228 108 ▶ if (defined $endl) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $endl) { } 107 1 108
229 # (remember, CR+LF is a DOS newline...)
230 107 ▶ $endl = pos($$dataPt) if pos($$dataPt) < $endl - 1;
Branch: 1 branch
BranchTrueFalseTotal
if pos $$dataPt < $endl - 1 0 107 107
231 } else {
232 1 $endl = pos($$dataPt);
233 }
234 } elsif (not defined $endl) {
235 0 push @$lines, $$dataPt;
236 0 last;
237 }
238 108 ▶ if (length $$dataPt == $endl) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $$dataPt == $endl) { } 1 107 108
239 1 push @$lines, $$dataPt;
240 1 last;
241 } else {
242 # continue to split into separate lines
243 107 push @$lines, substr($$dataPt, 0, $endl);
244 107 $$dataPt = substr($$dataPt, $endl);
245 }
246 }
247 }
248  
249 #------------------------------------------------------------------------------
250 # check to be sure we haven't read past end of PS data in DOS-style file
251 # Inputs: 0) RAF ref (with PSEnd member), 1) data ref
252 # - modifies data and sets RAF to EOF if end of PS is reached
253 sub CheckPSEnd($$)
254 0 ▶{
Subroutine CheckPSEnd: not called CC=3 SCAR=24.8
Pod undocumented
255 0 my ($raf, $dataPt) = @_;
256 0 my $pos = $raf->Tell();
257 0 ▶ if ($pos >= $$raf{PSEnd}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= $raf->{"PSEnd"}) 0 0 0
258 0 $raf->Seek(0, 2); # seek to end of file so we can't read any more
259 0 ▶ $$dataPt = substr($$dataPt, 0, length($$dataPt) - $pos + $$raf{PSEnd}) if $pos > $$raf{PSEnd};
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $raf->{"PSEnd"} 0 0 0
260 }
261 }
262  
263 #------------------------------------------------------------------------------
264 # Read next line from EPS file
265 # Inputs: 0) RAF ref (with PSEnd member if Postscript ends before end of file)
266 # 1) array of lines from file
267 # Returns: true on success
268 sub GetNextLine($$)
269 114 ▶{
Subroutine GetNextLine: called CC=9 SCAR=27.0
Pod undocumented
270 114 my ($raf, $lines) = @_;
271 114 my ($data, $changedNL);
272 114 ▶ my $altnl = ($/ eq "\x0d") ? "\x0a" : "\x0d";
Branch: 1 branch
BranchTrueFalseTotal
$/ eq "\r" ? : 108 6 114
273 114 for (;;) {
274 114 ▶ $raf->ReadLine($data) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($data) or last 114 0 114
275 114 ▶ $$raf{PSEnd} and CheckPSEnd($raf, \$data);
Branch: 1 branch
BranchTrueFalseTotal
$raf->{"PSEnd"} and &CheckPSEnd($raf, \$data) 0 114 114
276 # split line if it contains other newline sequences
277 114 ▶ if ($data =~ /$altnl/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /$altnl/) { } 1 113 114
278 1 ▶ if (length($data) > 500000 and Image::ExifTool::IsPC()) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data > 500000 and &Image::ExifTool::IsPC()) { } 0 1 1
Condition33%1/3
length $data > 500000 and &Image::ExifTool::IsPC()
!ll&&!rl&&r
100
MC/DC0%0/2
length $data > 500000 and &Image::ExifTool::IsPC()
length $data > 500000 &Image::ExifTool::IsPC()
Truth table33%1/3
A and B
A= length $data > 500000B= &Image::ExifTool::IsPC()
ABresult
0X0
100
111
279 # patch for Windows memory problem
280 0 ▶ unless ($changedNL) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($changedNL) 0 0 0
281 0 $changedNL = $/;
282 0 $/ = $altnl;
283 0 $altnl = $changedNL;
284 0 $raf->Seek(-length($data), 1);
285 0 next;
286 }
287 } else {
288 # split into separate lines
289 # push @$lines, split /$altnl/, $data, -1;
290 # if (@$lines == 2 and $$lines[1] eq $/) {
291 # # handle case of DOS newline data inside file using Unix newlines
292 # $$lines[0] .= pop @$lines;
293 # }
294 # split into separate lines if necessary
295 1 SplitLine(\$data, $lines);
296 }
297 } else {
298 113 push @$lines, $data;
299 }
300 114 ▶ $/ = $changedNL if $changedNL;
Branch: 1 branch
BranchTrueFalseTotal
if $changedNL 0 114 114
301 114 return 1;
302 }
303 0 return 0;
304 }
305  
306 #------------------------------------------------------------------------------
307 # Decode comment from PostScript file
308 # Inputs: 0) comment string, 1) RAF ref, 2) reference to lines array
309 # 3) optional data reference for extra lines read from file
310 # Returns: Decoded comment string (may be an array reference)
311 # - handles multi-line comments and escape sequences
312 sub DecodeComment($$$;$)
313 31 ▶{
Subroutine DecodeComment: called CC=18 SCAR=48.7
Pod undocumented
314 31 my ($val, $raf, $lines, $dataPt) = @_;
315 31 $val =~ s/\x0d*\x0a*$//; # remove trailing CR, LF or CR/LF
316 # check for continuation comments
317 31 for (;;) {
318 31 ▶ @$lines or GetNextLine($raf, $lines) or last;
Branch: 1 branch
BranchTrueFalseTotal
@$lines or &GetNextLine($raf, $lines) or last 31 0 31
Condition33%1/3
@$lines or &GetNextLine($raf, $lines)
l!l&&r!l&&!r
0310
MC/DC0%0/2
@$lines or &GetNextLine($raf, $lines)
@$lines &GetNextLine($raf, $lines)
Truth table33%1/3
A or B
A= @$linesB= &GetNextLine($raf, $lines)
ABresult
1X1
011
000
319 31 ▶ last unless $$lines[0] =~ /^%%\+/; # is the next line a continuation?
Branch: 1 branch
BranchTrueFalseTotal
unless $lines->[0] =~ /^%%\+/ 31 0 31
320 0 ▶ $$dataPt .= $$lines[0] if $dataPt; # add to data if necessary
Branch: 1 branch
BranchTrueFalseTotal
if $dataPt 0 0 0
321 0 $$lines[0] =~ s/\x0d*\x0a*$//; # remove trailing CR, LF or CR/LF
322 0 $val .= substr(shift(@$lines), 3); # add to value (without leading "%%+")
323 }
324 31 my @vals;
325 # handle bracketed string values
326 31 ▶ if ($val =~ s/^\((.*)\)$/$1/) { # remove brackets if necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s/^\((.*)\)$/$1/) 3 28 31
327 # split into an array of strings if necessary
328 3 my $nesting = 1;
329 3 ▶ while ($val =~ /(\(|\))/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /(\(|\))/g) 0 3 3
330 0 my $bra = $1;
331 0 my $pos = pos($val) - 2;
332 0 my $backslashes = 0;
333 0 ▶ while ($pos and substr($val, $pos, 1) eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos and substr($val, $pos, 1) eq "\\") 0 0 0
Condition0%0/3
$pos and substr($val, $pos, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$pos and substr($val, $pos, 1) eq "\\"
$pos substr($val, $pos, 1) eq "\\"
Truth table0%0/3
A and B
A= $posB= substr($val, $pos, 1) eq "\\"
ABresult
0X0
100
111
334 0 --$pos;
335 0 ++$backslashes;
336 }
337 0 ▶ next if $backslashes & 0x01; # escaped if odd number
Branch: 1 branch
BranchTrueFalseTotal
if $backslashes & 1 0 0 0
338 0 ▶ if ($bra eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bra eq '(') { } 0 0 0
339 0 ++$nesting;
340 } else {
341 0 --$nesting;
342 0 ▶ unless ($nesting) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nesting) 0 0 0
343 0 push @vals, substr($val, 0, pos($val)-1);
344 0 $val = substr($val, pos($val));
345 0 ▶ ++$nesting if $val =~ s/\s*\(//;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ s/\s*\(// 0 0 0
346 }
347 }
348 }
349 3 push @vals, $val;
350 3 foreach $val (@vals) {
351 # decode escape sequences in bracketed strings
352 # (similar to code in PDF.pm, but without line continuation)
353 3 ▶ while ($val =~ /\\(.)/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\\(.)/gs) 0 3 3
354 0 my $n = pos($val) - 2;
355 0 my $c = $1;
356 0 my $r;
357 0 ▶ if ($c =~ /[0-7]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /[0-7]/) { } 0 0 0
358 # get up to 2 more octal digits
359 0 ▶ $c .= $1 if $val =~ /\G([0-7]{1,2})/g;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /\G([0-7]{1,2})/g 0 0 0
360 # convert octal escape code
361 0 $r = chr(oct($c) & 0xff);
362 } else {
363 # convert escaped characters
364 0 ($r = $c) =~ tr/nrtbf/\n\r\t\b\f/;
365 }
366 0 substr($val, $n, length($c)+1) = $r;
367 # continue search after this character
368 0 pos($val) = $n + length($r);
369 }
370 }
371 3 ▶ $val = @vals > 1 ? \@vals : $vals[0];
Branch: 1 branch
BranchTrueFalseTotal
@vals > 1 ? : 0 3 3
372 }
373 31 return $val;
374 }
375  
376 #------------------------------------------------------------------------------
377 # Unescape PostScript string
378 # Inputs: 0) string
379 # Returns: unescaped string
380 sub UnescapePostScript($)
381 10 ▶{
Subroutine UnescapePostScript: called CC=7 SCAR=21.1
Pod undocumented
382 10 my $str = shift;
383 # decode escape sequences in literal strings
384 10 ▶ while ($str =~ /\\(.)/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\\(.)/gs) 12 10 22
385 12 my $n = pos($str) - 2;
386 12 my $c = $1;
387 12 my $r;
388 12 ▶ if ($c =~ /[0-7]/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c =~ /[0-7]/) { } 11 1 12
elsif ($c eq "\r") { } 0 1 1
elsif ($c eq "\n") { } 0 1 1
389 # get up to 2 more octal digits
390 11 ▶ $c .= $1 if $str =~ /\G([0-7]{1,2})/g;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G([0-7]{1,2})/g 11 0 11
391 # convert octal escape code
392 11 $r = chr(oct($c) & 0xff);
393 } elsif ($c eq "\x0d") {
394 # the string is continued if the line ends with '\'
395 # (also remove "\x0d\x0a")
396 0 ▶ $c .= $1 if $str =~ /\G(\x0a)/g;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G(\x0a)/g 0 0 0
397 0 $r = '';
398 } elsif ($c eq "\x0a") {
399 0 $r = '';
400 } else {
401 # convert escaped characters
402 1 ($r = $c) =~ tr/nrtbf/\n\r\t\b\f/;
403 }
404 12 substr($str, $n, length($c)+1) = $r;
405 # continue search after this character
406 12 pos($str) = $n + length($r);
407 }
408 10 return $str;
409 }
410  
411 #------------------------------------------------------------------------------
412 # Extract information from EPS, PS or AI file
413 # Inputs: 0) ExifTool object reference, 1) dirInfo reference, 2) optional tag table ref
414 # Returns: 1 if this was a valid PostScript file
415 sub ProcessPS($$;$)
416 4 ▶{
Subroutine ProcessPS: called CC=97 SCAR=67.7
Pod undocumented
417 4 my ($et, $dirInfo, $tagTablePtr) = @_;
418 4 my $raf = $$dirInfo{RAF};
419 4 my $embedded = $et->Options('ExtractEmbedded');
420 4 my ($data, $dos, $endDoc, $fontTable, $comment);
421  
422 # allow read from data
423 4 ▶ unless ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf) 0 4 4
424 0 $raf = File::RandomAccess->new($$dirInfo{DataPt});
425 0 $et->VerboseDir('PostScript');
426 }
427 #
428 # determine if this is a postscript file
429 #
430 4 ▶ $raf->Read($data, 4) == 4 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($data, 4) == 4 or return 0 4 0 4
431 # accept either ASCII or DOS binary postscript file format
432 4 ▶ return 0 unless $data =~ /^(%!PS|%!Ad|%!Fo|\xc5\xd0\xd3\xc6)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /^(%!PS|%!Ad|%!Fo|\xc5\xd0\xd3\xc6)/ 0 4 4
433 4 ▶ if ($data =~ /^%!Ad/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data =~ /^%!Ad/) { } 0 4 4
elsif ($data =~ /^\xc5\xd0\xd3\xc6/) { } 0 4 4
434 # I've seen PS files start with "%!Adobe-PS"...
435 0 ▶ return 0 unless $raf->Read($data, 6) == 6 and $data eq "obe-PS";
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($data, 6) == 6 and $data eq "obe-PS" 0 0 0
Condition0%0/3
$raf->Read($data, 6) == 6 and $data eq "obe-PS"
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Read($data, 6) == 6 and $data eq "obe-PS"
$raf->Read($data, 6) == 6 $data eq "obe-PS"
Truth table0%0/3
A and B
A= $raf->Read($data, 6) == 6B= $data eq "obe-PS"
ABresult
0X0
100
111
436 } elsif ($data =~ /^\xc5\xd0\xd3\xc6/) {
437 # process DOS binary file header
438 # - save DOS header then seek ahead and check PS header
439 0 ▶ $raf->Read($dos, 26) == 26 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($dos, 26) == 26 or return 0 0 0 0
440 0 SetByteOrder('II');
441 0 my $psStart = Get32u(\$dos, 0);
442 0 ▶ unless ($raf->Seek($psStart, 0) and
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Seek($psStart, 0) and $raf->Read($data, 4) == 4 and $data eq "%!PS") 0 0 0
Condition0%0/6
$raf->Seek($psStart, 0) and $raf->Read($data, 4) == 4 and $data eq "%!PS"
!ll&&!rl&&r
000
$raf->Seek($psStart, 0) and $raf->Read($data, 4) == 4
!ll&&!rl&&r
000
MC/DC0%0/3
$raf->Seek($psStart, 0) and $raf->Read($data, 4) == 4 and $data eq "%!PS"
$raf->Seek($psStart, 0) $raf->Read($data, 4) == 4 $data eq "%!PS"
Truth table0%0/4
A and B and C
A= $raf->Seek($psStart, 0)B= $raf->Read($data, 4) == 4C= $data eq "%!PS"
ABCresult
0XX0
10X0
1100
1111
443 $raf->Read($data, 4) == 4 and $data eq '%!PS')
444 {
445 0 return PSErr($et, 'invalid header');
446 }
447 0 $$raf{PSEnd} = $psStart + Get32u(\$dos, 4); # set end of PostScript data in RAF
448 } else {
449 # check for PostScript font file (PFA or PFB)
450 4 my $d2;
451 4 ▶ $data .= $d2 if $raf->Read($d2,12);
Branch: 1 branch
BranchTrueFalseTotal
if $raf->Read($d2, 12) 4 0 4
452 4 ▶ if ($data =~ /^%!(PS-(AdobeFont-|Bitstream )|FontType1-)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /^%!(PS-(AdobeFont-|Bitstream )|FontType1-)/) 2 2 4
453 2 $et->SetFileType('PFA'); # PostScript ASCII font file
454 2 $fontTable = GetTagTable('Image::ExifTool::Font::PSInfo');
455 # PostScript font files may contain an unformatted comments which may
456 # contain useful information, so accumulate these for the Comment tag
457 2 $comment = 1;
458 }
459 4 $raf->Seek(-length($data), 1);
460 }
461 #
462 # set the newline type based on the first newline found in the file
463 #
464 4 local $/ = GetInputRecordSeparator($raf);
465 4 ▶ $/ or return PSErr($et, 'invalid PS data');
Branch: 1 branch
BranchTrueFalseTotal
$/ or return &PSErr($et, "invalid PS data") 4 0 4
466  
467 # set file type (PostScript or EPS)
468 4 ▶ $raf->ReadLine($data) or $data = '';
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($data) or $data = "" 4 0 4
469 4 my $type;
470 4 ▶ if ($data =~ /EPSF/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /EPSF/) { } 2 2 4
471 2 $type = 'EPS';
472 } else {
473 # read next line to see if this is an Illustrator file
474 2 my $line2;
475 2 my $pos = $raf->Tell();
476 2 ▶ if ($raf->ReadLine($line2) and $line2 =~ /^%%Creator: Adobe Illustrator/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->ReadLine($line2) and $line2 =~ /^%%Creator: Adobe Illustrator/) { } 0 2 2
Condition33%1/3
$raf->ReadLine($line2) and $line2 =~ /^%%Creator: Adobe Illustrator/
!ll&&!rl&&r
020
MC/DC0%0/2
$raf->ReadLine($line2) and $line2 =~ /^%%Creator: Adobe Illustrator/
$raf->ReadLine($line2) $line2 =~ /^%%Creator: Adobe Illustrator/
Truth table33%1/3
A and B
A= $raf->ReadLine($line2)B= $line2 =~ /^%%Creator: Adobe Illustrator/
ABresult
0X0
100
111
477 0 $type = 'AI';
478 } else {
479 2 $type = 'PS';
480 }
481 2 $raf->Seek($pos, 0);
482 }
483 4 $et->SetFileType($type);
484 4 ▶ return 1 if $$et{OPTIONS}{FastScan} and $$et{OPTIONS}{FastScan} == 3;
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3 0 4 4
Condition33%1/3
$et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3
!ll&&!rl&&r
400
MC/DC0%0/2
$et->{"OPTIONS"}{"FastScan"} and $et->{"OPTIONS"}{"FastScan"} == 3
$et->{"OPTIONS"}{"FastScan"} $et->{"OPTIONS"}{"FastScan"} == 3
Truth table33%1/3
A and B
A= $et->{"OPTIONS"}{"FastScan"}B= $et->{"OPTIONS"}{"FastScan"} == 3
ABresult
0X0
100
111
485 #
486 # extract TIFF information from DOS header
487 #
488 4 ▶ $tagTablePtr or $tagTablePtr = GetTagTable('Image::ExifTool::PostScript::Main');
Branch: 1 branch
BranchTrueFalseTotal
$tagTablePtr or $tagTablePtr = &GetTagTable("Image::ExifTool::PostScript::Main") 0 4 4
489 4 ▶ if ($dos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dos) 0 4 4
490 0 my $base = Get32u(\$dos, 16);
491 0 ▶ if ($base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base) 0 0 0
492 0 my $pos = $raf->Tell();
493 # extract the TIFF preview
494 0 my $len = Get32u(\$dos, 20);
495 0 my $val = $et->ExtractBinary($base, $len, 'TIFFPreview');
496 0 ▶ if (defined $val and $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/) { } 0 0 0
Condition0%0/3
defined $val and $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/
defined $val $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/
Truth table0%0/3
A and B
A= defined $valB= $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/
ABresult
0X0
100
111
497 0 $et->HandleTag($tagTablePtr, 'TIFFPreview', $val);
498 } else {
499 0 $et->Warn('Bad TIFF preview image');
500 }
501 # extract information from TIFF in DOS header
502 # (set Parent to '' to avoid setting FileType tag again)
503 0 my %dirInfo = (
504 Parent => '',
505 RAF => $raf,
506 Base => $base,
507 );
508 0 ▶ $et->ProcessTIFF(\%dirInfo) or $et->Warn('Bad embedded TIFF');
Branch: 1 branch
BranchTrueFalseTotal
$et->ProcessTIFF(\%dirInfo) or $et->Warn("Bad embedded TIFF") 0 0 0
509 # position file pointer to extract PS information
510 0 $raf->Seek($pos, 0);
511 }
512 }
513 #
514 # parse the postscript
515 #
516 4 my ($buff, $mode, $beginToken, $endToken, $docNum, $subDocNum, $changedNL);
517 4 my (@lines, $altnl);
518 4 ▶ if ($/ eq "\x0d") {
Branch: 1 branch
BranchTrueFalseTotal
if ($/ eq "\r") { } 2 2 4
519 2 $altnl = "\x0a";
520 } else {
521 2 $/ = "\x0a"; # end on any LF (even if DOS CR+LF)
522 2 $altnl = "\x0d";
523 }
524 4 for (;;) {
525 725 ▶ if (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) { } 243 482 725
526 243 $data = shift @lines;
527 } else {
528 482 ▶ $raf->ReadLine($data) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($data) or last 478 4 482
529 # check for alternate newlines as efficiently as possible
530 478 ▶ if ($data =~ /$altnl/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /$altnl/) 2 476 478
531 2 ▶ if (length($data) > 500000 and Image::ExifTool::IsPC()) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data > 500000 and &Image::ExifTool::IsPC()) { } 0 2 2
Condition33%1/3
length $data > 500000 and &Image::ExifTool::IsPC()
!ll&&!rl&&r
200
MC/DC0%0/2
length $data > 500000 and &Image::ExifTool::IsPC()
length $data > 500000 &Image::ExifTool::IsPC()
Truth table33%1/3
A and B
A= length $data > 500000B= &Image::ExifTool::IsPC()
ABresult
0X0
100
111
532 # Windows can't split very long lines due to poor memory handling,
533 # so re-read the file with the other newline character instead
534 # (slower but uses less memory)
535 0 ▶ unless ($changedNL) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($changedNL) 0 0 0
536 0 $changedNL = 1;
537 0 my $t = $/;
538 0 $/ = $altnl;
539 0 $altnl = $t;
540 0 $raf->Seek(-length($data), 1);
541 0 next;
542 }
543 } else {
544 # split into separate lines
545 2 @lines = split /$altnl/, $data, -1;
546 2 $data = shift @lines;
547 2 ▶ if (@lines == 1 and $lines[0] eq $/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines == 1 and $lines[0] eq $/) 0 2 2
Condition33%1/3
@lines == 1 and $lines[0] eq $/
!ll&&!rl&&r
200
MC/DC0%0/2
@lines == 1 and $lines[0] eq $/
@lines == 1 $lines[0] eq $/
Truth table33%1/3
A and B
A= @lines == 1B= $lines[0] eq $/
ABresult
0X0
100
111
548 # handle case of DOS newline data inside file using Unix newlines
549 0 $data .= $lines[0];
550 0 undef @lines;
551 }
552 }
553 }
554 }
555 721 undef $changedNL;
556 721 ▶ if ($mode) {
Branch: 7 branches
BranchTrueFalseTotal
if ($mode) { } 306 415 721
elsif ($endDoc and $data =~ /^$endDoc/i) { } 4 411 415
elsif ($data =~ /^(%{1,2})(Begin)(_xml_packet|Photoshop|ICCProfile|Document|Binary)/i) { } 13 398 411
elsif ($data =~ /^<\?xpacket begin=.{7,13}W5M0MpCehiHzreSzNTczkc9d/) { } 0 398 398
elsif ($data =~ /^%%?(\w+): ?(.*)/s and $tagTablePtr->{$1}) { } 29 369 398
elsif ($embedded and $data =~ /^%AI12_CompressedData/) { } 0 369 369
elsif ($fontTable) { } 58 311 369
557 306 ▶ if (not $endToken) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $endToken) { } 0 306 306
elsif (not $data =~ /^$endToken/i) { } 298 8 306
elsif ($mode eq 'Document') { } 4 4 8
558 0 $buff .= $data;
559 0 ▶ next unless $data =~ m{<\?xpacket end=.(w|r).\?>(\n|\r|$)};
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /<\?xpacket end=.(w|r).\?>(\n|\r|$)/ 0 0 0
560 } elsif ($data !~ /^$endToken/i) {
561 298 ▶ if ($mode eq 'XMP') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'XMP') { } 216 82 298
elsif ($mode eq 'Document') { } 29 53 82
562 216 $buff .= $data;
563 } elsif ($mode eq 'Document') {
564 # ignore embedded documents, but keep track of nesting level
565 29 ▶ $docNum .= '-1' if $data =~ /^$beginToken/;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^$beginToken/ 1 28 29
566 } else {
567 # data is ASCII-hex encoded
568 53 $data =~ tr/0-9A-Fa-f//dc; # remove all but hex characters
569 53 $buff .= pack('H*', $data); # translate from hex
570 }
571 298 next;
572 } elsif ($mode eq 'Document') {
573 4 $docNum =~ s/-?\d+$//; # decrement document nesting level
574 # done with Document mode if we are back at the top level
575 4 ▶ undef $mode unless $docNum;
Branch: 1 branch
BranchTrueFalseTotal
unless $docNum 3 1 4
576 4 next;
577 }
578 ▶ } elsif ($endDoc and $data =~ /^$endDoc/i) {
Condition100%3/3
$endDoc and $data =~ /^$endDoc/i
!ll&&!rl&&r
382294
MC/DC100%2/2
$endDoc and $data =~ /^$endDoc/i
$endDoc $data =~ /^$endDoc/i
Truth table100%3/3
A and B
A= $endDocB= $data =~ /^$endDoc/i
ABresult
0X0
100
111
579 4 $docNum =~ s/-?(\d+)$//; # decrement nesting level
580 4 $subDocNum = $1; # remember our last sub-document number
581 4 $$et{DOC_NUM} = $docNum;
582 4 ▶ undef $endDoc unless $docNum; # done with document if top level
Branch: 1 branch
BranchTrueFalseTotal
unless $docNum 3 1 4
583 4 next;
584 } elsif ($data =~ /^(%{1,2})(Begin)(_xml_packet|Photoshop|ICCProfile|Document|Binary)/i) {
585 # the beginning of a data block
586 13 my %modeLookup = (
587 _xml_packet => 'XMP',
588 photoshop => 'Photoshop',
589 iccprofile => 'ICC_Profile',
590 document => 'Document',
591 binary => undef, # (we will try to skip this)
592 );
593 13 $mode = $modeLookup{lc $3};
594 13 ▶ unless ($mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode) 2 11 13
595 2 ▶ if (not @lines and $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @lines and $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i) 2 0 2
Condition33%1/3
not @lines and $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i
!ll&&!rl&&r
002
MC/DC0%0/2
not @lines and $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i
not @lines $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i
Truth table33%1/3
not(A) and B
A= not @linesB= $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i
ABresult
0X0
100
111
596 2 ▶ $raf->Seek($1, 1) or last; # skip binary data
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($1, 1) or last 2 0 2
597 }
598 2 next;
599 }
600 11 $buff = '';
601 11 $beginToken = $1 . $2 . $3;
602 11 ▶ $endToken = $1 . ($2 eq 'begin' ? 'end' : 'End') . $3;
Branch: 1 branch
BranchTrueFalseTotal
$2 eq 'begin' ? : 2 9 11
603 11 ▶ if ($mode eq 'Document') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "Document") 7 4 11
604 # this is either the 1st sub-document or Nth document
605 7 ▶ if ($docNum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docNum) { } 1 6 7
606 # increase nesting level
607 1 $docNum .= '-' . (++$subDocNum);
608 } else {
609 # this is the Nth document
610 6 $docNum = $$et{DOC_COUNT} + 1;
611 }
612 7 $subDocNum = 0; # new level, so reset subDocNum
613 7 ▶ next unless $embedded; # skip over this document
Branch: 1 branch
BranchTrueFalseTotal
unless $embedded 3 4 7
614 # set document number for family 4-7 group names
615 4 $$et{DOC_NUM} = $docNum;
616 4 $$et{LIST_TAGS} = { }; # don't build lists across different documents
617 4 $$et{PROCESSED} = { }; # re-initialize processed directory lookup too
618 4 $endDoc = $endToken; # parse to EndDocument token
619 # reset mode to allow parsing into sub-directories
620 4 undef $endToken;
621 4 undef $mode;
622 # save document name if available
623 4 ▶ if ($data =~ /^$beginToken:\s+([^\n\r]+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /^$beginToken:\s+([^\n\r]+)/i) 4 0 4
624 4 my $docName = $1;
625 # remove brackets if necessary
626 4 ▶ $docName = $1 if $docName =~ /^\((.*)\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $docName =~ /^\((.*)\)$/ 4 0 4
627 4 $et->HandleTag($tagTablePtr, 'EmbeddedFileName', $docName);
628 }
629 }
630 8 next;
631 } elsif ($data =~ /^<\?xpacket begin=.{7,13}W5M0MpCehiHzreSzNTczkc9d/) {
632 # pick up any stray XMP data
633 0 $mode = 'XMP';
634 0 $buff = $data;
635 0 undef $endToken; # no end token (just look for xpacket end)
636 # XMP could be contained in a single line (if newlines are different)
637 0 ▶ next unless $data =~ m{<\?xpacket end=.(w|r).\?>(\n|\r|$)};
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /<\?xpacket end=.(w|r).\?>(\n|\r|$)/ 0 0 0
638 ▶ } elsif ($data =~ /^%%?(\w+): ?(.*)/s and $$tagTablePtr{$1}) {
Condition100%3/3
$data =~ /^%%?(\w+): ?(.*)/s and $tagTablePtr->{$1}
!ll&&!rl&&r
3561329
MC/DC100%2/2
$data =~ /^%%?(\w+): ?(.*)/s and $tagTablePtr->{$1}
$data =~ /^%%?(\w+): ?(.*)/s $tagTablePtr->{$1}
Truth table100%3/3
A and B
A= $data =~ /^%%?(\w+): ?(.*)/sB= $tagTablePtr->{$1}
ABresult
0X0
100
111
639 29 my ($tag, $val) = ($1, $2);
640 # only allow 'ImageData' and AI tags to have single leading '%'
641 29 ▶ next unless $data =~ /^%(%|AI\d+_)/ or $tag eq 'ImageData';
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /^%(%|AI\d+_)/ or $tag eq "ImageData" 0 29 29
Condition66%2/3
$data =~ /^%(%|AI\d+_)/ or $tag eq "ImageData"
l!l&&r!l&&!r
2720
MC/DC0%0/2
$data =~ /^%(%|AI\d+_)/ or $tag eq "ImageData"
$data =~ /^%(%|AI\d+_)/ $tag eq "ImageData"
Truth table66%2/3
A or B
A= $data =~ /^%(%|AI\d+_)/B= $tag eq "ImageData"
ABresult
1X1
011
000
642 # decode comment string (reading continuation lines if necessary)
643 29 $val = DecodeComment($val, $raf, \@lines);
644 29 $et->HandleTag($tagTablePtr, $tag, $val);
645 29 next;
646 ▶ } elsif ($embedded and $data =~ /^%AI12_CompressedData/) {
Condition66%2/3
$embedded and $data =~ /^%AI12_CompressedData/
!ll&&!rl&&r
2091600
MC/DC0%0/2
$embedded and $data =~ /^%AI12_CompressedData/
$embedded $data =~ /^%AI12_CompressedData/
Truth table66%2/3
A and B
A= $embeddedB= $data =~ /^%AI12_CompressedData/
ABresult
0X0
100
111
647 # the rest of the file is compressed
648 0 ▶ unless (eval { require Compress::Zlib }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Compress::Zlib } }) 0 0 0
649 0 $et->Warn('Install Compress::Zlib to extract compressed embedded data');
650 0 last;
651 }
652 # seek back to find the start of the compressed data in the file
653 0 my $tlen = length($data) + @lines;
654 0 $tlen += length $_ foreach @lines;
655 0 my $backTo = $raf->Tell() - $tlen - 64;
656 0 ▶ $backTo = 0 if $backTo < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $backTo < 0 0 0 0
657 0 ▶ last unless $raf->Seek($backTo, 0) and $raf->Read($data, 2048);
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek($backTo, 0) and $raf->Read($data, 2048) 0 0 0
Condition0%0/3
$raf->Seek($backTo, 0) and $raf->Read($data, 2048)
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Seek($backTo, 0) and $raf->Read($data, 2048)
$raf->Seek($backTo, 0) $raf->Read($data, 2048)
Truth table0%0/3
A and B
A= $raf->Seek($backTo, 0)B= $raf->Read($data, 2048)
ABresult
0X0
100
111
658 0 ▶ last unless $data =~ s/.*?%AI12_CompressedData//;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ s/.*?%AI12_CompressedData// 0 0 0
659 0 my $inflate = Compress::Zlib::inflateInit();
660 0 ▶ $inflate or $et->Warn('Error initializing inflate'), last;
Branch: 1 branch
BranchTrueFalseTotal
$inflate or $et->Warn("Error initializing inflate"), last 0 0 0
661 # generate a PS-like file in memory from the compressed data
662 0 my $verbose = $et->Options('Verbose');
663 0 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
664 0 $et->VerboseDir('AI12_CompressedData (first 4kB)');
665 0 $et->VerboseDump(\$data);
666 }
667 # remove header if it exists (Windows AI files only)
668 0 $data =~ s/^.{0,256}EndData[\x0d\x0a]+//s;
669 0 my $val;
670 0 for (;;) {
671 0 my ($v2, $stat) = $inflate->inflate($data);
672 0 ▶ $stat == Compress::Zlib::Z_STREAM_END() and $val .= $v2, last;
Branch: 1 branch
BranchTrueFalseTotal
$stat == Compress::Zlib::Z_STREAM_END() and $val .= $v2, last 0 0 0
673 0 ▶ $stat != Compress::Zlib::Z_OK() and undef($val), last;
Branch: 1 branch
BranchTrueFalseTotal
$stat != Compress::Zlib::Z_OK() and undef $val, last 0 0 0
674 0 ▶ if (defined $val) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
elsif ($v2 =~ /^%!PS/) { } 0 0 0
675 0 $val .= $v2;
676 } elsif ($v2 =~ /^%!PS/) {
677 0 $val = $v2;
678 } else {
679 # add postscript header (for file recognition) if it doesn't exist
680 0 $val = "%!PS-Adobe-3.0$/" . $v2;
681 }
682 0 ▶ $raf->Read($data, 65536) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($data, 65536) or last 0 0 0
683 }
684 0 ▶ defined $val or $et->Warn('Error inflating AI compressed data'), last;
Branch: 1 branch
BranchTrueFalseTotal
defined $val or $et->Warn("Error inflating AI compressed data"), last 0 0 0
685 0 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
686 0 $et->VerboseDir('Uncompressed AI12 Data');
687 0 $et->VerboseDump(\$val);
688 }
689 # extract information from embedded images in the uncompressed data
690 $val = # add PS header in case it needs one
691 0 ProcessPS($et, { DataPt => \$val });
692 0 last;
693 } elsif ($fontTable) {
694 58 ▶ if (defined $comment) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comment) 10 48 58
695 # extract initial comments from PostScript Font files
696 10 ▶ if ($data =~ /^%\s+(.*?)[\x0d\x0a]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data =~ /^%\s+(.*?)[\x0d\x0a]/) { } 4 6 10
elsif (not $data =~ /^%/) { } 2 4 6
697 4 ▶ $comment .= "\n" if $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 4 0 4
698 4 $comment .= $1;
699 4 next;
700 } elsif ($data !~ /^%/) {
701 # stop extracting comments at the first non-comment line
702 2 ▶ $et->FoundTag('Comment', $comment) if length $comment;
Branch: 1 branch
BranchTrueFalseTotal
if length $comment 2 0 2
703 2 undef $comment;
704 }
705 }
706 54 ▶ if ($data =~ m{^\s*/(\w+)\s*(.*)} and $$fontTable{$1}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data =~ m[^\s*/(\w+)\s*(.*)] and $fontTable->{$1}) { } 24 30 54
elsif ($data =~ /^currentdict end/) { } 2 28 30
Condition100%3/3
$data =~ m[^\s*/(\w+)\s*(.*)] and $fontTable->{$1}
!ll&&!rl&&r
161424
MC/DC100%2/2
$data =~ m[^\s*/(\w+)\s*(.*)] and $fontTable->{$1}
$data =~ m[^\s*/(\w+)\s*(.*)] $fontTable->{$1}
Truth table100%3/3
A and B
A= $data =~ m[^\s*/(\w+)\s*(.*)]B= $fontTable->{$1}
ABresult
0X0
100
111
707 24 my ($tag, $val) = ($1, $2);
708 24 ▶ if ($val =~ /^\((.*)\)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^\((.*)\)/) { } 10 14 24
elsif ($val =~ m[/?(\S+)]) { } 14 0 14
709 10 $val = UnescapePostScript($1);
710 } elsif ($val =~ m{/?(\S+)}) {
711 14 $val = $1;
712 }
713 24 $et->HandleTag($fontTable, $tag, $val);
714 } elsif ($data =~ /^currentdict end/) {
715 # only extract tags from initial FontInfo dict
716 2 undef $fontTable;
717 }
718 54 next;
719 } else {
720 311 next;
721 }
722 # extract information from buffered data
723 4 my %dirInfo = (
724 DataPt => \$buff,
725 DataLen => length $buff,
726 DirStart => 0,
727 DirLen => length $buff,
728 Parent => 'PostScript',
729 );
730 4 my $subTablePtr = GetTagTable("Image::ExifTool::${mode}::Main");
731 4 ▶ unless ($et->ProcessDirectory(\%dirInfo, $subTablePtr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($et->ProcessDirectory(\%dirInfo, $subTablePtr)) 0 4 4
732 0 $et->Warn("Error processing $mode information in PostScript file");
733 }
734 4 undef $buff;
735 4 undef $mode;
736 }
737 4 ▶ $mode = 'Document' if $endDoc and not $mode;
Branch: 1 branch
BranchTrueFalseTotal
if $endDoc and not $mode 0 4 4
Condition33%1/3
$endDoc and not $mode
!ll&&!rl&&r
400
MC/DC0%0/2
$endDoc and not $mode
$endDoc not $mode
Truth table33%1/3
A and not(B)
A= $endDocB= not $mode
ABresult
0X0
100
111
738 4 ▶ $mode and PSErr($et, "unterminated $mode data");
Branch: 1 branch
BranchTrueFalseTotal
$mode and &PSErr($et, "unterminated $mode data") 0 4 4
739 4 return 1;
740 }
741  
742 #------------------------------------------------------------------------------
743 # Extract information from EPS file
744 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
745 # Returns: 1 if this was a valid PostScript file
746 sub ProcessEPS($$)
747 2 ▶{
Subroutine ProcessEPS: called CC=1 SCAR=0.0
Pod undocumented
748 2 return ProcessPS($_[0],$_[1]);
749 }
750  
751 29 1; # end
752  
753  
754 __END__
« Image/ExifTool/MPEG.pm ↑ Summary Image/ExifTool/Photoshop.pm »