~ubuntu-branches/ubuntu/karmic/libimage-exiftool-perl/karmic

« back to all changes in this revision

Viewing changes to lib/Image/ExifTool/PostScript.pm

  • Committer: Bazaar Package Importer
  • Author(s): Mari Wang
  • Date: 2008-02-04 20:32:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080204203253-mpbal8trlfe1fz5d
Tags: 7.00-1
* Upload of new production release (Closes: #456430)
* Added Recommends: libcompress-zlib-perl (Closes: #435589)
* Package now includes iptc2xmp.args and xmp2iptc.args, they are put
  into /usr/share/libimage-exiftool/ (Closes: #436100)
* Updated standards-version (3.7.2 -> 3.7.3). No changes needed.
* Lots of updates and bugfixes compared to last debian version
  (6.90).  See the Changes file for details
* Upload sponsored by Petter Reinholdtsen

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
use vars qw($VERSION $AUTOLOAD);
17
17
use Image::ExifTool qw(:DataAccess :Utils);
18
18
 
19
 
$VERSION = '1.14';
 
19
$VERSION = '1.19';
20
20
 
21
21
sub WritePS($$);
22
22
sub CheckPS($$$);
72
72
            TagTable => 'Image::ExifTool::XMP::Main',
73
73
        },
74
74
    },
 
75
    TIFFPreview => {
 
76
        Binary => 1,
 
77
        Notes => q{
 
78
            not a real tag ID, but used to represent the TIFF preview extracted from DOS
 
79
            EPS images
 
80
        },
 
81
    },
75
82
);
76
83
 
77
84
# composite tags
205
212
#
206
213
# extract TIFF information from DOS header
207
214
#
 
215
    my $tagTablePtr = GetTagTable('Image::ExifTool::PostScript::Main');
208
216
    if ($dos) {
209
217
        my $base = Get32u(\$dos, 16);
210
218
        if ($base) {
211
219
            my $pos = $raf->Tell();
 
220
            # extract the TIFF preview
 
221
            my $len = Get32u(\$dos, 20);
 
222
            my $val = $exifTool->ExtractBinary($base, $len, 'TIFFPreview');
 
223
            if (defined $val and $val =~ /^(MM\0\x2a|II\x2a\0|Binary)/) {
 
224
                $exifTool->HandleTag($tagTablePtr, 'TIFFPreview', $val);
 
225
            } else {
 
226
                $exifTool->Warn('Bad TIFF preview image');
 
227
            }
212
228
            # extract information from TIFF in DOS header
213
229
            # (set Parent to '' to avoid setting FileType tag again)
214
230
            my %dirInfo = (
225
241
# parse the postscript
226
242
#
227
243
    my ($buff, $mode, $endToken);
228
 
    my $tagTablePtr = GetTagTable('Image::ExifTool::PostScript::Main');
229
244
    my (@lines, $altnl);
230
245
    if ($/ eq "\x0d") {
231
246
        $altnl = "\x0a";
243
258
                # split into separate lines
244
259
                @lines = split /$altnl/, $data, -1;
245
260
                $data = shift @lines;
 
261
                if (@lines == 1 and $lines[0] eq $/) {
 
262
                    # handle case of DOS newline data inside file using Unix newlines
 
263
                    $data .= $lines[0];
 
264
                    undef @lines;
 
265
                }
246
266
            }
247
267
        }
248
268
        if ($mode) {
252
272
            } elsif ($data !~ /^$endToken/i) {
253
273
                if ($mode eq 'XMP') {
254
274
                    $buff .= $data;
 
275
                } elsif ($mode eq 'Document') {
 
276
                    # ignore embedded documents 
255
277
                } else {
256
278
                    # data is ASCII-hex encoded
257
279
                    $data =~ tr/0-9A-Fa-f//dc;  # remove all but hex characters
259
281
                }
260
282
                next;
261
283
            }
262
 
        } elsif ($data =~ /^(%{1,2})(Begin)(_xml_packet|Photoshop|ICCProfile)/i) {
 
284
        } elsif ($data =~ /^(%{1,2})(Begin)(_xml_packet|Photoshop|ICCProfile|Binary)/i) {
263
285
            # the beginning of a data block
264
286
            my %modeLookup = (
265
287
                _xml_packet => 'XMP',
267
289
                photoshop   => 'Photoshop',
268
290
            );
269
291
            $mode = $modeLookup{lc($3)};
 
292
            unless ($mode or @lines) {
 
293
                # skip binary data
 
294
                $raf->Seek($1, 1) or last if $data =~ /^%{1,2}BeginBinary:\s*(\d+)/i;
 
295
                next;
 
296
            }
270
297
            $buff = '';
271
298
            $endToken = $1 . ($2 eq 'begin' ? 'end' : 'End') . $3;
272
299
            next;
 
300
        } elsif ($data =~ /^(%{1,2})(Begin)(Document)/i) {
 
301
            $mode = 'Document';
 
302
            next;
273
303
        } elsif ($data =~ /^<\?xpacket begin=.{7,13}W5M0MpCehiHzreSzNTczkc9d/) {
274
304
            # pick up any stray XMP data
275
305
            $mode = 'XMP';
292
322
            next;
293
323
        }
294
324
        # extract information from buffered data
295
 
        my %dirInfo = (
296
 
            DataPt => \$buff,
297
 
            DataLen => length $buff,
298
 
            DirStart => 0,
299
 
            DirLen => length $buff,
300
 
            Parent => 'PostScript',
301
 
        );
302
 
        my $subTablePtr = GetTagTable("Image::ExifTool::${mode}::Main");
303
 
        unless ($exifTool->ProcessDirectory(\%dirInfo, $subTablePtr)) {
304
 
            $exifTool->Warn("Error processing $mode information in PostScript file");
 
325
        if ($mode ne 'Document'){
 
326
            my %dirInfo = (
 
327
                DataPt => \$buff,
 
328
                DataLen => length $buff,
 
329
                DirStart => 0,
 
330
                DirLen => length $buff,
 
331
                Parent => 'PostScript',
 
332
            );
 
333
            my $subTablePtr = GetTagTable("Image::ExifTool::${mode}::Main");
 
334
            unless ($exifTool->ProcessDirectory(\%dirInfo, $subTablePtr)) {
 
335
                $exifTool->Warn("Error processing $mode information in PostScript file");
 
336
            }
 
337
            undef $buff;
305
338
        }
306
339
        undef $mode;
307
 
        undef $buff;
308
340
    }
309
341
    $/ = $oldsep;   # restore original separator
310
 
    $mode and PSErr($exifTool, "unterminated $mode data");
 
342
    $mode and $mode ne 'Document' and PSErr($exifTool, "unterminated $mode data");
311
343
    return 1;
312
344
}
313
345