- Timestamp:
- 2021-02-26T19:39:51+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cpan/Image/ExifTool/InDesign.pm
r24107 r34921 15 15 use Image::ExifTool qw(:DataAccess :Utils); 16 16 17 $VERSION = '1.0 2';17 $VERSION = '1.06'; 18 18 19 19 # map for writing metadata to InDesign files (currently only write XMP) … … 33 33 sub ProcessIND($$) 34 34 { 35 my ($e xifTool, $dirInfo) = @_;35 my ($et, $dirInfo) = @_; 36 36 my $raf = $$dirInfo{RAF}; 37 37 my $outfile = $$dirInfo{OutFile}; … … 42 42 return 0 unless $hdr eq $masterPageGUID; 43 43 return 0 unless $raf->Read($buff, 8) == 8; 44 $e xifTool->SetFileType($buff eq 'DOCUMENT' ? 'INDD' : 'IND'); # set the FileType tag44 $et->SetFileType($buff eq 'DOCUMENT' ? 'INDD' : 'IND'); # set the FileType tag 45 45 46 46 # read the master pages … … 74 74 $pages < 2 and $err = 'Invalid page count', goto DONE; 75 75 my $pos = $pages * 4096; 76 if ($pos > 0x7fffffff and not $e xifTool->Options('LargeFileSupport')) {76 if ($pos > 0x7fffffff and not $et->Options('LargeFileSupport')) { 77 77 $err = 'InDesign files larger than 2 GB not supported (LargeFileSupport not set)'; 78 78 goto DONE; … … 80 80 if ($outfile) { 81 81 # make XMP the preferred group for writing 82 $e xifTool->InitWriteDirs(\%indMap, 'XMP');82 $et->InitWriteDirs(\%indMap, 'XMP'); 83 83 84 84 Write($outfile, $buff, $buf2) or $err = 1, goto DONE; … … 93 93 } 94 94 # scan through the contiguous objects for XMP 95 my $verbose = $e xifTool->Options('Verbose');96 my $out = $e xifTool->Options('TextOut');95 my $verbose = $et->Options('Verbose'); 96 my $out = $et->Options('TextOut'); 97 97 for (;;) { 98 98 $raf->Read($hdr, 32) or last; … … 106 106 printf $out "Contiguous object at offset 0x%x (%d bytes):\n", $raf->Tell(), $len; 107 107 if ($verbose > 2) { 108 my %parms = (Addr => $raf->Tell()); 109 $parms{MaxLen} = $verbose > 3 ? 1024 : 96 if $verbose < 5; 110 $raf->Seek(-$raf->Read($buff, $len), 1) or $err = 1; 111 Image::ExifTool::HexDump(\$buff, undef, %parms); 108 my $len2 = $len < 1024000 ? $len : 1024000; 109 $raf->Seek(-$raf->Read($buff, $len2), 1) or $err = 1; 110 $et->VerboseDump(\$buff, Addr => $raf->Tell()); 112 111 } 113 112 } … … 119 118 my $lenWord = $1; # save length word for writing later 120 119 $len -= 4; # get length of XMP only 120 $foundXMP = 1; 121 # I have a sample where the XMP is 107 MB, and ActivePerl may run into 122 # memory troubles (with its apparent 1 GB limit) if the XMP is larger 123 # than about 400 MB, so guard against this 124 if ($len > 300 * 1024 * 1024) { 125 my $msg = sprintf('Insanely large XMP (%.0f MB)', $len / (1024 * 1024)); 126 if ($outfile) { 127 $et->Error($msg, 2) and $err = 1, last; 128 } elsif ($et->Options('IgnoreMinorErrors')) { 129 $et->Warn($msg); 130 } else { 131 $et->Warn("$msg. Ignored.", 1); 132 $err = 1; 133 last; 134 } 135 } 121 136 # load and parse the XMP data 122 137 unless ($raf->Seek(-52, 1) and $raf->Read($buff, $len) == $len) { … … 124 139 last; 125 140 } 126 $foundXMP = 1;127 141 my %dirInfo = ( 128 142 DataPt => \$buff, … … 130 144 NoDelete => 1, # do not allow this to be deleted when writing 131 145 ); 146 # validate xmp data length (should be same as length in header - 4) 147 my $xmpLen = unpack($streamInt32u, $lenWord); 148 unless ($xmpLen == $len) { 149 if ($xmpLen < $len) { 150 $dirInfo{DirLen} = $xmpLen; 151 } else { 152 $err = 'Truncated XMP stream (missing ' . ($xmpLen - $len) . ' bytes)'; 153 } 154 } 132 155 my $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main'); 133 156 if ($outfile) { 134 # validate xmp data length (should be same as length in header - 4) 135 my $xmpLen = unpack($streamInt32u, $lenWord); 136 unless ($xmpLen == $len) { 137 $err = "Incorrect XMP stream length ($xmpLen should be $len)"; 138 last; 139 } 157 last if $err; 140 158 # make sure that XMP is writable 141 159 my $classID = Get32u(\$hdr, 20); 142 160 $classID & 0x40000000 or $err = 'XMP stream is not writable', last; 143 my $xmp = $e xifTool->WriteDirectory(\%dirInfo, $tagTablePtr);161 my $xmp = $et->WriteDirectory(\%dirInfo, $tagTablePtr); 144 162 if ($xmp and length $xmp) { 145 163 # write new xmp with leading length word … … 149 167 Set32u(0xffffffff, \$hdr, 28); 150 168 } else { 151 $$e xifTool{CHANGED} = 0; # didn't change anything152 $e xifTool->Warn("Can't delete XMP as a block from InDesign file") if defined $xmp;169 $$et{CHANGED} = 0; # didn't change anything 170 $et->Warn("Can't delete XMP as a block from InDesign file") if defined $xmp; 153 171 # put length word back at start of stream 154 172 $buff = $lenWord . $buff; 155 173 } 156 174 } else { 157 $e xifTool->ProcessDirectory(\%dirInfo, $tagTablePtr);175 $et->ProcessDirectory(\%dirInfo, $tagTablePtr); 158 176 } 159 177 $len = 0; # we got the full stream (nothing left to read) … … 198 216 DONE: 199 217 if (not $err) { 200 $e xifTool->Warn('No XMP stream to edit') if $outfile and not $foundXMP;218 $et->Warn('No XMP stream to edit') if $outfile and not $foundXMP; 201 219 return 1; # success! 202 220 } elsif (not $outfile) { 203 221 # issue warning on read error 204 $e xifTool->Warn($err) unless $err eq '1';222 $et->Warn($err) unless $err eq '1'; 205 223 } elsif ($err ne '1') { 206 224 # set error and return success code 207 $e xifTool->Error($err);225 $et->Error($err); 208 226 } else { 209 227 return -1; # write error … … 236 254 InDesign files which previously contained XMP. 237 255 238 3) File sizes of greater than 2 GB a nd are not currently supported because239 the ability to handle large files like this is system dependent.256 3) File sizes of greater than 2 GB are supported only if the system supports 257 them and the LargeFileSupport option is enabled. 240 258 241 259 =head1 AUTHOR 242 260 243 Copyright 2003-20 11, Phil Harvey (phil at owl.phy.queensu.ca)261 Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com) 244 262 245 263 This library is free software; you can redistribute it and/or modify it
Note:
See TracChangeset
for help on using the changeset viewer.