- 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/iWork.pm
r24107 r34921 15 15 use Image::ExifTool::ZIP; 16 16 17 $VERSION = '1.0 2';18 19 # test for recognized iWork document extensions and out ter XML elements17 $VERSION = '1.06'; 18 19 # test for recognized iWork document extensions and outer XML elements 20 20 my %iWorkType = ( 21 21 # file extensions 22 NUMBERS => ' Apple Numbers',23 PAGES => ' Apple Pages',24 KEY => ' Apple Keynote',25 KTH => ' Apple Keynote Theme',26 NMBTEMPLATE => ' Apple Numbers Template',22 NUMBERS => 'NUMBERS', 23 PAGES => 'PAGES', 24 KEY => 'KEY', 25 KTH => 'KTH', 26 NMBTEMPLATE => 'NMBTEMPLATE', 27 27 # we don't support double extensions -- 28 28 # "PAGES.TEMPLATE" => 'Apple Pages Template', 29 # out ter XML elements30 'ls:document' => ' Apple Numbers',31 'sl:document' => ' Apple Pages',32 'key:presentation' => ' Apple Keynote',29 # outer XML elements 30 'ls:document' => 'NUMBERS', 31 'sl:document' => 'PAGES', 32 'key:presentation' => 'KEY', 33 33 ); 34 34 … … 37 37 # indicates, but I think it refers to the new "flattened" package format) 38 38 my %mimeType = ( 39 ' Apple Numbers'=> 'application/x-iwork-numbers-sffnumbers',40 ' Apple Pages'=> 'application/x-iwork-pages-sffpages',41 ' Apple Keynote'=> 'application/x-iWork-keynote-sffkey',42 ' Apple Numbers Template'=> 'application/x-iwork-numbers-sfftemplate',43 ' Apple Pages Template'=> 'application/x-iwork-pages-sfftemplate',44 ' Apple Keynote Theme'=> 'application/x-iWork-keynote-sffkth',39 'NUMBERS' => 'application/x-iwork-numbers-sffnumbers', 40 'PAGES' => 'application/x-iwork-pages-sffpages', 41 'KEY' => 'application/x-iWork-keynote-sffkey', 42 'NMBTEMPLATE' => 'application/x-iwork-numbers-sfftemplate', 43 'PAGES.TEMPLATE'=> 'application/x-iwork-pages-sfftemplate', 44 'KTH' => 'application/x-iWork-keynote-sffkth', 45 45 ); 46 46 … … 71 71 my $props = shift; 72 72 return 0 if $$props[-1] =~ /^\w+:ID$/; # ignore ID tags 73 return ($$props[0] =~ /.*?:(.*)/)? $1 : $$props[0];73 return $$props[0] =~ /^.*?:(.*)/ ? $1 : $$props[0]; 74 74 } 75 75 … … 82 82 sub FoundTag($$$$;$) 83 83 { 84 my ($e xifTool, $tagTablePtr, $props, $val, $attrs) = @_;84 my ($et, $tagTablePtr, $props, $val, $attrs) = @_; 85 85 return 0 unless @$props; 86 my $verbose = $e xifTool->Options('Verbose');87 88 $e xifTool->VPrint(0, " | - Tag '", join('/',@$props), "'\n") if $verbose > 1;86 my $verbose = $et->Options('Verbose'); 87 88 $et->VPrint(0, " | - Tag '", join('/',@$props), "'\n") if $verbose > 1; 89 89 90 90 # un-escape XML character entities 91 91 $val = Image::ExifTool::XMP::UnescapeXML($val); 92 92 # convert from UTF8 to ExifTool Charset 93 $val = $e xifTool->Decode($val, 'UTF8');93 $val = $et->Decode($val, 'UTF8'); 94 94 my $tag = GetTagID($props) or return 0; 95 95 96 96 # add any unknown tags to table 97 97 unless ($$tagTablePtr{$tag}) { 98 $e xifTool->VPrint(0, " [adding $tag]\n") if $verbose;99 Image::ExifTool::AddTagToTable($tagTablePtr, $tag, { Name => ucfirst $tag });98 $et->VPrint(0, " [adding $tag]\n") if $verbose; 99 AddTagToTable($tagTablePtr, $tag, { Name => ucfirst $tag }); 100 100 } 101 101 # save the tag 102 $e xifTool->HandleTag($tagTablePtr, $tag, $val);102 $et->HandleTag($tagTablePtr, $tag, $val); 103 103 104 104 return 1; … … 113 113 sub Process_iWork($$) 114 114 { 115 my ($e xifTool, $dirInfo) = @_;115 my ($et, $dirInfo) = @_; 116 116 my $zip = $$dirInfo{ZIP}; 117 117 my ($type, $index, $indexFile, $status); … … 120 120 local $SIG{'__WARN__'} = \&Image::ExifTool::ZIP::WarnProc; 121 121 # trust type given by file extension if available 122 $type = $iWorkType{$$e xifTool{FILE_EXT}} if $$exifTool{FILE_EXT};122 $type = $iWorkType{$$et{FILE_EXT}} if $$et{FILE_EXT}; 123 123 unless ($type) { 124 124 # read the index file … … 132 132 } 133 133 } 134 } else { 135 @members = $zip->membersMatching('(?i)^.*\.(pages|numbers|key)/Index.*'); 136 if (@members) { 137 my $tmp = $members[0]->fileName(); 138 $type = $iWorkType{uc $1} if $tmp =~ /\.(pages|numbers|key)/i; 139 } 134 140 } 135 141 $type or $type = 'ZIP'; # assume ZIP by default 136 142 } 137 $e xifTool->SetFileType($type, $mimeType{$type});143 $et->SetFileType($type, $mimeType{$type}); 138 144 139 145 my @members = $zip->members(); … … 144 150 my $file = $member->fileName(); 145 151 next unless defined $file; 146 $e xifTool->VPrint(0, "File: $file\n");152 $et->VPrint(0, "File: $file\n"); 147 153 # set the document number and extract ZIP tags 148 $$e xifTool{DOC_NUM} = ++$docNum;149 Image::ExifTool::ZIP::HandleMember($e xifTool, $member);150 151 # process only the index XML and JPEG thumbnail files152 next unless $file =~ m{^(index\.(xml|apxl)|QuickLook/Thumbnail\.jpg )$}i;154 $$et{DOC_NUM} = ++$docNum; 155 Image::ExifTool::ZIP::HandleMember($et, $member); 156 157 # process only the index XML and JPEG thumbnail/preview files 158 next unless $file =~ m{^(index\.(xml|apxl)|QuickLook/Thumbnail\.jpg|[^/]+/preview(-micro|-web)?.jpg)$}i; 153 159 # get the file contents if necessary 154 160 # (CAREFUL! $buff MUST be local since we hand off a value ref to PreviewImage) … … 159 165 } else { 160 166 ($buff, $status) = $zip->contents($member); 161 $status and $e xifTool->Warn("Error extracting $file"), next;167 $status and $et->Warn("Error extracting $file"), next; 162 168 $buffPt = \$buff; 163 169 } 164 170 # extract JPEG as PreviewImage (should only be QuickLook/Thumbnail.jpg) 165 171 if ($file =~ /\.jpg$/) { 166 $exifTool->FoundTag('PreviewImage', $buffPt); 172 my $type = ($file =~ /preview-(\w+)/) ? ($1 eq 'web' ? 'Other' : 'Thumbnail') : 'Preview'; 173 $et->FoundTag($type . 'Image', $buffPt); 167 174 next; 168 175 } … … 183 190 ); 184 191 my $tagTablePtr = GetTagTable('Image::ExifTool::iWork::Main'); 185 $e xifTool->ProcessDirectory(\%dirInfo, $tagTablePtr);192 $et->ProcessDirectory(\%dirInfo, $tagTablePtr); 186 193 undef $$buffPt; # (free memory now) 187 194 } 188 delete $$e xifTool{DOC_NUM};195 delete $$et{DOC_NUM}; 189 196 return 1; 190 197 } … … 209 216 =head1 AUTHOR 210 217 211 Copyright 2003-20 11, Phil Harvey (phil at owl.phy.queensu.ca)218 Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com) 212 219 213 220 This library is free software; you can redistribute it and/or modify it
Note:
See TracChangeset
for help on using the changeset viewer.