| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: OOXML.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: Read Office Open XML+ZIP files | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 2009/10/31 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | package Image::ExifTool::OOXML; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Image::ExifTool qw(:DataAccess :Utils); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Image::ExifTool::XMP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Image::ExifTool::ZIP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # test for recognized OOXML document extensions | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my %isOOXML = ( | |||||||||||||||||||||||||||||||||||||||||
| 21 | DOCX => 1, DOCM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | DOTX => 1, DOTM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | POTX => 1, POTM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | PPAX => 1, PPAM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | PPSX => 1, PPSM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | PPTX => 1, PPTM => 1, THMX => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | XLAM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | XLSX => 1, XLSM => 1, XLSB => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | XLTX => 1, XLTM => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | VSDX => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # generate reverse lookup for file type based on MIME | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my %fileType; | |||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $type; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | foreach $type (keys %isOOXML) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 20 | $fileType{$Image::ExifTool::mimeType{$type}} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # XML attributes to queue | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my %queuedAttrs; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my %queueAttrs = ( | |||||||||||||||||||||||||||||||||||||||||
| 45 | fmtid => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | pid => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | name => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # keep track of items in a vector (to accumulate as a list) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my $vectorCount; | |||||||||||||||||||||||||||||||||||||||||
| 52 | my @vectorVals; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # Office Open XML tags | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | %Image::ExifTool::OOXML::Main = ( | |||||||||||||||||||||||||||||||||||||||||
| 56 | GROUPS => { 0 => 'XML', 1 => 'XML', 2 => 'Document' }, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | PROCESS_PROC => \&Image::ExifTool::XMP::ProcessXMP, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | VARS => { ID_FMT => 'none' }, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | NOTES => q{ | ||||||||||||||||||||||||||||||||||||||||||
| 60 | The Office Open XML (OOXML) format was introduced with Microsoft Office 2007 | ||||||||||||||||||||||||||||||||||||||||||
| 61 | and is used by file types such as DOCX, PPTX, XLSX and VSDX. These are | ||||||||||||||||||||||||||||||||||||||||||
| 62 | essentially ZIP archives containing XML files. The table below lists some | ||||||||||||||||||||||||||||||||||||||||||
| 63 | tags which have been observed in OOXML documents, but ExifTool will extract | ||||||||||||||||||||||||||||||||||||||||||
| 64 | any tags found from XML files of the OOXML document properties ("docProps") | ||||||||||||||||||||||||||||||||||||||||||
| 65 | directory. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | B<Tips:> | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1) Structural ZIP tags may be ignored (if desired) with C<--ZIP:all> on the | ||||||||||||||||||||||||||||||||||||||||||
| 70 | command line. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2) Tags may be grouped by their document number in the ZIP archive with the | ||||||||||||||||||||||||||||||||||||||||||
| 73 | C<-g3> or C<-G3> option. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # These tags all have 1:1 correspondence with FlashPix tags except for: | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # OOXML FlashPix | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # --------------- ------------- | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # DocSecurity Security | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # Application Software | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # dc:Description Comments | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # dc:Creator Author | ||||||||||||||||||||||||||||||||||||||||||
| 82 | Application => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | AppVersion => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | category => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | Characters => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | CharactersWithSpaces => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | CheckedBy => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | Client => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | Company => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | created => { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | Name => 'CreateDate', | ||||||||||||||||||||||||||||||||||||||||||
| 92 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | Format => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | createdType => { Hidden => 1, RawConv => 'undef' }, # ignore this XML type name | ||||||||||||||||||||||||||||||||||||||||||
| 97 | DateCompleted => { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | Format => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | Department => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | Destination => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | Disposition => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | Division => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | DocSecurity => { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # (http://msdn.microsoft.com/en-us/library/documentformat.openxml.extendedproperties.documentsecurity.aspx) | ||||||||||||||||||||||||||||||||||||||||||
| 108 | PrintConv => { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 => 'None', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 => 'Password protected', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 => 'Read-only recommended', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 => 'Read-only enforced', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 8 => 'Locked for annotations', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | DocumentNumber=> { }, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | Editor => { Groups => { 2 => 'Author'} }, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | ForwardTo => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Group => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | HeadingPairs=> { }, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | HiddenSlides=> { }, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | HyperlinkBase=>{ }, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | HyperlinksChanged => { PrintConv => { 'false' => 'No', 'true' => 'Yes' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | keywords => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | Language => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | lastModifiedBy => { Groups => { 2 => 'Author'} }, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | lastPrinted => { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | Format => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | Lines => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | LinksUpToDate=>{ PrintConv => { 'false' => 'No', 'true' => 'Yes' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | Mailstop => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | Manager => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | Matter => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | MMClips => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | modified => { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | Name => 'ModifyDate', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | Format => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | modifiedType=> { Hidden => 1, RawConv => 'undef' }, # ignore this XML type name | ||||||||||||||||||||||||||||||||||||||||||
| 145 | Notes => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | Office => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | Owner => { Groups => { 2 => 'Author'} }, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | Pages => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 149 | Paragraphs => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | PresentationFormat => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 151 | Project => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 152 | Publisher => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 153 | Purpose => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ReceivedFrom=> { }, | ||||||||||||||||||||||||||||||||||||||||||
| 155 | RecordedBy => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 156 | RecordedDate=> { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | Groups => { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | Format => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | PrintConv => '$self->ConvertDateTime($val)', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 161 | Reference => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | revision => { Name => 'RevisionNumber' }, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ScaleCrop => { PrintConv => { 'false' => 'No', 'true' => 'Yes' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | SharedDoc => { PrintConv => { 'false' => 'No', 'true' => 'Yes' } }, | ||||||||||||||||||||||||||||||||||||||||||
| 165 | Slides => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 166 | Source => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | Status => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | TelephoneNumber => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | Template => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | TitlesOfParts=>{ }, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | TotalTime => { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | Name => 'TotalEditTime', | ||||||||||||||||||||||||||||||||||||||||||
| 173 | PrintConv => 'ConvertTimeSpan($val, 60)', | ||||||||||||||||||||||||||||||||||||||||||
| 174 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | Typist => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | Words => { }, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # Generate a tag ID for this XML tag | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # Inputs: 0) tag property name list ref | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # Returns: tagID and outtermost interesting namespace (or '' if no namespace) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | sub GetTagID($) | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 67 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetTagID: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 67 | my $props = shift; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 67 | my ($tag, $prop, $namespace); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 67 | foreach $prop (@$props) { | |||||||||||||||||||||||||||||||||||||||||
| 188 | # split name into namespace and property name | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # (Note: namespace can be '' for property qualifiers) | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 180 | ▶ | my ($ns, $nm) = ($prop =~ /(.*?):(.*)/) ? ($1, $2) : ('', $prop); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 180 | ▶ | next if $ns eq 'vt'; # ignore 'vt' properties | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 136 | ▶ | if (defined $tag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | $tag .= ucfirst($nm); # add to tag name | |||||||||||||||||||||||||||||||||||||||||
| 194 | ▶ | } elsif ($prop ne 'Properties' and $prop ne 'cp:coreProperties' and | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$prop ne "Properties" and $prop ne "cp:coreProperties" and $prop ne "property"
$prop ne "Properties" and $prop ne "cp:coreProperties"
MC/DC100%3/3
$prop ne "Properties" and $prop ne "cp:coreProperties" and $prop ne "property"
$prop ne "Properties"
$prop ne "cp:coreProperties"
$prop ne "property"
Truth table100%4/4
A and B and C
A= $prop ne "Properties"B= $prop ne "cp:coreProperties"C= $prop ne "property"
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | $prop ne 'property') | ||||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 39 | $tag = $nm; | |||||||||||||||||||||||||||||||||||||||||
| 198 | # save namespace of first property to contribute to tag name | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 39 | ▶ | $namespace = $ns unless $namespace; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 67 | ▶ | return ($tag, $namespace || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$namespace || ''
MC/DC100%1/1
$namespace || ''
$namespace
Truth table100%2/2
A
A= $namespace
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # We found an XMP property name/value | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # Inputs: 0) ExifTool object ref, 1) tag table ref | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # 2) reference to array of XMP property names (last is current property) | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # 3) property value, 4) attribute hash ref (not used here) | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # Returns: 1 if valid tag was found | ||||||||||||||||||||||||||||||||||||||||||
| 211 | sub FoundTag($$$$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 151 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FoundTag: called CC=28 SCAR=34.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 151 | my ($et, $tagTablePtr, $props, $val, $attrs) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 151 | ▶ | return 0 unless @$props; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 151 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 151 | my $tag = $$props[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 151 | ▶ | $et->VPrint(0, " | - Tag '", join('/',@$props), "'\n") if $verbose > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | # un-escape XML character entities | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 151 | $val = Image::ExifTool::XMP::UnescapeXML($val); | |||||||||||||||||||||||||||||||||||||||||
| 222 | # convert OOXML-escaped characters (eg. "_x0000d_" is a newline) | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $val =~ s/_x([0-9a-f]{4})_/Image::ExifTool::PackUTF8(hex($1))/gie; | |||||||||||||||||||||||||||||||||||||||||
| 224 | # convert from UTF8 to ExifTool Charset | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 151 | $val = $et->Decode($val, 'UTF8'); | |||||||||||||||||||||||||||||||||||||||||
| 226 | # queue this attribute for later if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 151 | ▶ | if ($queueAttrs{$tag}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 84 | $queuedAttrs{$tag} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 84 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 67 | my $ns; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 67 | ($tag, $ns) = GetTagID($props); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 67 | ▶ | if (not $tag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | # all properties are in ignored namespaces | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # so 'name' from our queued attributes for the tag | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 28 | ▶ | my $name = $queuedAttrs{name} or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 28 | $name =~ s/(^| )([a-z])/$1\U$2/g; # start words with uppercase | |||||||||||||||||||||||||||||||||||||||||
| 238 | 28 | ($tag = $name) =~ tr/-_a-zA-Z0-9//dc; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 28 | ▶ | return 0 unless length $tag; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 28 | ▶ | unless ($$tagTablePtr{$tag}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | my %tagInfo = ( | |||||||||||||||||||||||||||||||||||||||||
| 242 | Name => $tag, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | Description => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # format as a date/time value if type is 'vt:filetime' | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | if ($$props[-1] eq 'vt:filetime') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | $tagInfo{Groups} = { 2 => 'Time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | $tagInfo{Format} = 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $tagInfo{PrintConv} = '$self->ConvertDateTime($val)'; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | $et->VPrint(0, " | [adding $tag]\n") if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | AddTagToTable($tagTablePtr, $tag, \%tagInfo); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } elsif ($tag eq 'xmlns') { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # ignore namespaces (for now) | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 257 | ▶ | } elsif (ref $Image::ExifTool::XMP::Main{$ns} eq 'HASH' and | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $Image::ExifTool::XMP::Main{$ns} eq "HASH" and $Image::ExifTool::XMP::Main{$ns}{"SubDirectory"}
MC/DC50%1/2
ref $Image::ExifTool::XMP::Main{$ns} eq "HASH" and $Image::ExifTool::XMP::Main{$ns}{"SubDirectory"}
ref $Image::ExifTool::XMP::Main{$ns} eq "HASH"
$Image::ExifTool::XMP::Main{$ns}{"SubDirectory"}
Truth table66%2/3
A and B
A= ref $Image::ExifTool::XMP::Main{$ns} eq "HASH"B= $Image::ExifTool::XMP::Main{$ns}{"SubDirectory"}
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | $Image::ExifTool::XMP::Main{$ns}{SubDirectory}) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # use standard XMP table if it exists | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | my $table = $Image::ExifTool::XMP::Main{$ns}{SubDirectory}{TagTable}; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | if ($table and %$table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$table and %$table
MC/DC0%0/2
$table and %$table
$table
%$table
Truth table33%1/3
A and B
A= $tableB= %$table
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | $tagTablePtr = Image::ExifTool::GetTagTable($table); | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | ▶ | } elsif (@$props > 2 and grep /^vt:vector$/, @$props) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@$props > 2 and grep /^vt:vector$/, @$props
MC/DC100%2/2
@$props > 2 and grep /^vt:vector$/, @$props
@$props > 2
grep /^vt:vector$/, @$props
Truth table100%3/3
A and B
A= @$props > 2B= grep /^vt:vector$/, @$props
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | # handle vector properties (accumulate as lists) | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 7 | ▶ | if ($$props[-1] eq 'vt:size') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | $vectorCount = $val; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | undef @vectorVals; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } elsif ($$props[-1] eq 'vt:baseType') { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | return 0; # ignore baseType | |||||||||||||||||||||||||||||||||||||||||
| 274 | } elsif ($vectorCount) { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | --$vectorCount; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | if ($vectorCount) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | push @vectorVals, $val; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | $val = [ @vectorVals, $val ] if @vectorVals; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | # Note: we will lose any improper-sized vector elements here | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | # add any unknown tags to table | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 60 | ▶ | if ($$tagTablePtr{$tag}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 60 | my $tagInfo = $$tagTablePtr{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 60 | ▶ | if (ref $tagInfo eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | # reformat date/time values | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 60 | ▶ | my $fmt = $$tagInfo{Format} || $$tagInfo{Writable} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || ''
$tagInfo->{"Format"} or $tagInfo->{"Writable"}
MC/DC100%2/2
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || ''
$tagInfo->{"Format"}
$tagInfo->{"Writable"}
Truth table100%3/3
A or B
A= $tagInfo->{"Format"}B= $tagInfo->{"Writable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 60 | ▶ | $val = Image::ExifTool::XMP::ConvertXMPDate($val) if $fmt eq 'date'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | $et->VPrint(0, " [adding $tag]\n") if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | AddTagToTable($tagTablePtr, $tag, { Name => ucfirst $tag }); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # save the tag | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 60 | $et->HandleTag($tagTablePtr, $tag, $val); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # start fresh for next tag | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 60 | undef $vectorCount; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 60 | undef %queuedAttrs; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 60 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # Extract information from an OOXML file | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # Inputs: 0) ExifTool object reference, 1) dirInfo reference | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # Returns: 1 | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # Notes: Upon entry to this routine, the file type has already been verified | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # and the dirInfo hash contains 2 elements unique to this process proc: | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # MIME - mime type of main document from "[Content_Types].xml" | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # ZIP - reference to Archive::Zip object for this file | ||||||||||||||||||||||||||||||||||||||||||
| 314 | sub ProcessDOCX($$) | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ProcessDOCX: called CC=15 SCAR=31.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | my $zip = $$dirInfo{ZIP}; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | my $tagTablePtr = GetTagTable('Image::ExifTool::OOXML::Main'); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | my $mime = $$dirInfo{MIME} || $Image::ExifTool::mimeType{DOCX}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$dirInfo->{'MIME'} || $Image::ExifTool::mimeType{'DOCX'}
MC/DC0%0/2
$dirInfo->{'MIME'} || $Image::ExifTool::mimeType{'DOCX'}
$dirInfo->{'MIME'}
$Image::ExifTool::mimeType{'DOCX'}
Truth table33%1/3
A || B
A= $dirInfo->{'MIME'}B= $Image::ExifTool::mimeType{'DOCX'}
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # set the file type ('DOCX' by default) | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my $fileType = $fileType{$mime}; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | if ($fileType) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | # THMX is a special case because its contents.main MIME types is PPTX | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | ▶ | if ($fileType eq 'PPTX' and $$et{FILE_EXT} and $$et{FILE_EXT} eq 'THMX') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$fileType eq "PPTX" and $et->{"FILE_EXT"} and $et->{"FILE_EXT"} eq "THMX"
$fileType eq "PPTX" and $et->{"FILE_EXT"}
MC/DC0%0/3
$fileType eq "PPTX" and $et->{"FILE_EXT"} and $et->{"FILE_EXT"} eq "THMX"
$fileType eq "PPTX"
$et->{"FILE_EXT"}
$et->{"FILE_EXT"} eq "THMX"
Truth table25%1/4
A and B and C
A= $fileType eq "PPTX"B= $et->{"FILE_EXT"}C= $et->{"FILE_EXT"} eq "THMX"
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $fileType = 'THMX'; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $et->VPrint(0, "Unrecognized MIME type: $mime\n"); | |||||||||||||||||||||||||||||||||||||||||
| 330 | # get MIME type according to file extension | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $fileType = $$et{FILE_EXT}; | |||||||||||||||||||||||||||||||||||||||||
| 332 | # default to 'DOCX' if this isn't a known OOXML extension | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | $fileType = 'DOCX' unless $fileType and $isOOXML{$fileType}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fileType and $isOOXML{$fileType}
MC/DC0%0/2
$fileType and $isOOXML{$fileType}
$fileType
$isOOXML{$fileType}
Truth table0%0/3
A and B
A= $fileTypeB= $isOOXML{$fileType}
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | $et->SetFileType($fileType); | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | # must catch all Archive::Zip warnings | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | local $SIG{'__WARN__'} = \&Image::ExifTool::ZIP::WarnProc; | |||||||||||||||||||||||||||||||||||||||||
| 339 | # extract meta information from all files in ZIP "docProps" directory | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | my $docNum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | my @members = $zip->members(); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | my $member; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | foreach $member (@members) { | |||||||||||||||||||||||||||||||||||||||||
| 344 | # get filename of this ZIP member | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 18 | my $file = $member->fileName(); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 18 | ▶ | next unless defined $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 18 | $et->VPrint(0, "File: $file\n"); | |||||||||||||||||||||||||||||||||||||||||
| 348 | # set the document number and extract ZIP tags | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 18 | $$et{DOC_NUM} = ++$docNum; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 18 | Image::ExifTool::ZIP::HandleMember($et, $member); | |||||||||||||||||||||||||||||||||||||||||
| 351 | # process only XML and JPEG/WMF thumbnail images in "docProps" directory | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 18 | ▶ | next unless $file =~ m{^docProps/(.*\.xml|(thumbnail\.(jpe?g|wmf)))$}i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | # get the file contents (CAREFUL! $buff MUST be local since we hand off a value ref) | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 4 | my ($buff, $status) = $zip->contents($member); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | ▶ | $status and $et->Warn("Error extracting $file"), next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | # extract docProps/thumbnail.(jpg|mwf) as PreviewImage|PreviewMWF | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | ▶ | if ($file =~ /\.(jpe?g|wmf)$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | ▶ | my $tag = $file =~ /\.wmf$/i ? 'PreviewWMF' : 'PreviewImage'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | $et->FoundTag($tag, \$buff); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | # process XML files (docProps/app.xml, docProps/core.xml, docProps/custom.xml) | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 3 | ▶ | my %dirInfo = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | DataPt => \$buff, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | DirLen => length $buff, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # (skip over XML header if it exists) | ||||||||||||||||||||||||||||||||||||||||||
| 367 | DirStart => ($buff =~ /<\?xml\s+.*?\?>/g ? pos($buff) : 0), | ||||||||||||||||||||||||||||||||||||||||||
| 368 | DataLen => length $buff, | ||||||||||||||||||||||||||||||||||||||||||
| 369 | XMPParseOpts => { FoundProc => \&FoundTag }, | ||||||||||||||||||||||||||||||||||||||||||
| 370 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | $et->ProcessDirectory(\%dirInfo, $tagTablePtr); | |||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | undef $buff; # (free memory now) | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | delete $$et{DOC_NUM}; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | 1; # end | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | __END__ | ||||||||||||||||||||||||||||||||||||||||||