1: 2eval 'exec perl -wS $0 ${1+"$@"}' 3 if 0; 4 5# 6# 2009 Copyright Novell, Inc. & Sun Microsystems, Inc. 7# 8# OpenOffice.org is free software: you can redistribute it and/or modify 9# it under the terms of the GNU Lesser General Public License version 3 10# only, as published by the Free Software Foundation. 11# 12 13use IO::File; 14use Cwd; 15use File::Spec; 16use File::Spec::Functions; 17use File::Temp; 18use File::Path; 19 20$TempDir = ""; 21 22 23# all the XML package generation is a blatant rip from AF's 24# write-calc-doc.pl 25 26 27############################################################################### 28# Open a file with the given name. 29# First it is checked if the temporary directory, in which all files for 30# the document are gathered, is already present and create it if it is not. 31# Then create the path to the file inside the temporary directory. 32# Finally open the file and return a file handle to it. 33# 34sub open_file 35{ 36 my $filename = pop @_; 37 38 # Create base directory of temporary directory tree if not alreay 39 # present. 40 if ($TempDir eq "") 41 { 42 $TempDir = File::Temp::tempdir (CLEANUP => 1); 43 } 44 45 # Create the path to the file. 46 my $fullname = File::Spec->catfile ($TempDir, $filename); 47 my ($volume,$directories,$file) = File::Spec->splitpath ($fullname); 48 mkpath (File::Spec->catpath ($volume,$directories,"")); 49 50 # Open the file and return a file handle to it. 51 return new IO::File ($fullname, "w"); 52} 53 54 55############################################################################### 56# Zip the files in the directory tree into the given file. 57# 58sub zip_dirtree 59{ 60 my $filename = pop @_; 61 62 my $cwd = getcwd; 63 my $zip_name = $filename; 64 65 # We are about to change the directory. 66 # Therefore create an absolute pathname for the zip archive. 67 68 # First transfer the drive from $cwd to $zip_name. This is a 69 # workaround for a bug in file_name_is_absolute which thinks 70 # the the path \bla is an absolute path under DOS. 71 my ($volume,$directories,$file) = File::Spec->splitpath ($zip_name); 72 my ($volume_cwd,$directories_cwd,$file_cwd) = File::Spec->splitpath ($cwd); 73 $volume = $volume_cwd if ($volume eq ""); 74 $zip_name = File::Spec->catpath ($volume,$directories,$file); 75 76 # Add the current working directory to a relative path. 77 if ( ! file_name_is_absolute ($zip_name)) 78 { 79 $zip_name = File::Spec->catfile ($cwd, $zip_name); 80 81 # Try everything to clean up the name. 82 $zip_name = File::Spec->rel2abs ($filename); 83 $zip_name = File::Spec->canonpath ($zip_name); 84 85 # Remove .. directories from the middle of the path. 86 while ($zip_name =~ /\/[^\/][^\.\/][^\/]*\/\.\.\//) 87 { 88 $zip_name = $` . "/" . $'; 89 } 90 } 91 92 # Just in case the zip program gets confused by an existing file with the 93 # same name as the one to be written that file is removed first. 94 if ( -e $filename) 95 { 96 if (unlink ($filename) == 0) 97 { 98 print "Existing file $filename could not be deleted.\n"; 99 print "Please close the application that uses it, then try again.\n"; 100 return; 101 } 102 } 103 104 # Finally create the zip file. First change into the temporary directory 105 # so that the resulting zip file contains only paths relative to it. 106 print "zipping [$ZipCmd $ZipFlags $zip_name *]\n"; 107 chdir ($TempDir); 108 system ("$ZipCmd $ZipFlags $zip_name *"); 109 chdir ($cwd); 110} 111 112 113sub writeHeader 114{ 115 print $OUT qq~<?xml version="1.0" encoding="UTF-8"?> 116 117<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" office:version="1.0"> 118 <office:scripts/> 119 <office:automatic-styles> 120 <style:style style:name="dp1" style:family="drawing-page"> 121 <style:drawing-page-properties presentation:background-visible="true" presentation:background-objects-visible="true" presentation:display-footer="true" presentation:display-page-number="false" presentation:display-date-time="true"/> 122 </style:style> 123 <style:style style:name="gr1" style:family="graphic" style:parent-style-name="standard"> 124 <style:graphic-properties draw:textarea-horizontal-align="center" draw:fill="none" draw:stroke="none" draw:textarea-vertical-align="middle"/> 125 </style:style> 126 <style:style style:name="gr2" style:family="graphic" style:parent-style-name="standard"> 127 <style:graphic-properties draw:textarea-horizontal-align="center" draw:textarea-vertical-align="middle"/> 128 </style:style> 129 <style:style style:name="pr1" style:family="presentation" style:parent-style-name="Default-title"> 130 <style:graphic-properties draw:fill-color="#ffffff" draw:auto-grow-height="true" fo:min-height="3.508cm"/> 131 </style:style> 132 <style:style style:name="pr2" style:family="presentation" style:parent-style-name="Default-notes"> 133 <style:graphic-properties draw:fill-color="#ffffff" draw:auto-grow-height="true" fo:min-height="13.367cm"/> 134 </style:style> 135 <style:style style:name="P1" style:family="paragraph"> 136 <style:paragraph-properties fo:margin-left="0cm" fo:margin-right="0cm" fo:text-indent="0cm"/> 137 </style:style> 138 <style:style style:name="P2" style:family="paragraph"> 139 <style:paragraph-properties fo:margin-left="0.6cm" fo:margin-right="0cm" fo:text-indent="-0.6cm"/> 140 </style:style> 141 <text:list-style style:name="L1"> 142 <text:list-level-style-bullet text:level="1" text:bullet-char="●"> 143 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 144 </text:list-level-style-bullet> 145 <text:list-level-style-bullet text:level="2" text:bullet-char="●"> 146 <style:list-level-properties text:space-before="0.6cm" text:min-label-width="0.6cm"/> 147 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 148 </text:list-level-style-bullet> 149 <text:list-level-style-bullet text:level="3" text:bullet-char="●"> 150 <style:list-level-properties text:space-before="1.2cm" text:min-label-width="0.6cm"/> 151 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 152 </text:list-level-style-bullet> 153 <text:list-level-style-bullet text:level="4" text:bullet-char="●"> 154 <style:list-level-properties text:space-before="1.8cm" text:min-label-width="0.6cm"/> 155 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 156 </text:list-level-style-bullet> 157 <text:list-level-style-bullet text:level="5" text:bullet-char="●"> 158 <style:list-level-properties text:space-before="2.4cm" text:min-label-width="0.6cm"/> 159 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 160 </text:list-level-style-bullet> 161 <text:list-level-style-bullet text:level="6" text:bullet-char="●"> 162 <style:list-level-properties text:space-before="3cm" text:min-label-width="0.6cm"/> 163 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 164 </text:list-level-style-bullet> 165 <text:list-level-style-bullet text:level="7" text:bullet-char="●"> 166 <style:list-level-properties text:space-before="3.6cm" text:min-label-width="0.6cm"/> 167 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 168 </text:list-level-style-bullet> 169 <text:list-level-style-bullet text:level="8" text:bullet-char="●"> 170 <style:list-level-properties text:space-before="4.2cm" text:min-label-width="0.6cm"/> 171 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 172 </text:list-level-style-bullet> 173 <text:list-level-style-bullet text:level="9" text:bullet-char="●"> 174 <style:list-level-properties text:space-before="4.8cm" text:min-label-width="0.6cm"/> 175 <style:text-properties fo:font-family="StarSymbol" style:use-window-font-color="true" fo:font-size="45%"/> 176 </text:list-level-style-bullet> 177 </text:list-style> 178 </office:automatic-styles> 179 <office:body> 180 <office:presentation> 181~; 182 183} 184 185sub writeSlideHeader 186{ 187 my $titleText = pop @_; 188 my $slideNum = pop @_; 189 190 print $OUT " <draw:page draw:name=\"page1\" draw:style-name=\"dp1\" draw:master-page-name=\"Default\">\n"; 191 print $OUT " <office:forms form:automatic-focus=\"false\" form:apply-design-mode=\"false\"/>\n"; 192 print $OUT " <draw:rect draw:style-name=\"gr1\" draw:text-style-name=\"P1\" draw:id=\"id$slideNum\" draw:layer=\"layout\" svg:width=\"17.5cm\" svg:height=\"6cm\" svg:x=\"5cm\" svg:y=\"4cm\">\n"; 193 print $OUT " <text:p text:style-name=\"P2\">Slide: $slideNum</text:p>\n"; 194 print $OUT " <text:p text:style-name=\"P2\">Path: $titleText</text:p>\n"; 195 print $OUT " </draw:rect>\n"; 196} 197 198 199sub writeSlideFooter 200{ 201 print $OUT " <presentation:notes draw:style-name=\"dp1\">\n"; 202 print $OUT " <draw:page-thumbnail draw:style-name=\"gr1\" draw:layer=\"layout\" svg:width=\"14.851cm\" svg:height=\"11.138cm\" svg:x=\"3.068cm\" svg:y=\"2.257cm\" draw:page-number=\"1\" presentation:class=\"page\"/>\n"; 203 print $OUT " <draw:frame presentation:style-name=\"pr3\" draw:layer=\"layout\" svg:width=\"16.79cm\" svg:height=\"13.116cm\" svg:x=\"2.098cm\" svg:y=\"14.109cm\" presentation:class=\"notes\" presentation:placeholder=\"true\">\n"; 204 print $OUT " <draw:text-box/>\n"; 205 print $OUT " </draw:frame>\n"; 206 print $OUT " </presentation:notes>\n"; 207 print $OUT " </draw:page>\n"; 208} 209 210sub writeFooter 211{ 212 print $OUT qq~ <presentation:settings presentation:full-screen="false"/> 213 </office:presentation> 214 </office:body> 215</office:document-content> 216~; 217 218} 219 220sub writePath 221{ 222 my $pathAry = pop @_; 223 my $path = $pathAry->[1]; 224 my $viewBox = $pathAry->[0]; 225 226 print $OUT " <draw:path draw:style-name=\"gr2\" draw:text-style-name=\"P1\" draw:layer=\"layout\" svg:width=\"10cm\" svg:height=\"10cm\" svg:x=\"5cm\" svg:y=\"5cm\" svg:viewBox=\""; 227 print $OUT $viewBox; 228 print $OUT "\" svg:d=\""; 229 print $OUT $path; 230 print $OUT "\">\n"; 231 print $OUT " <text:p/>\n"; 232 print $OUT " </draw:path>\n"; 233} 234 235sub writeManifest 236{ 237 my $outFile = open_file("META-INF/manifest.xml"); 238 239 print $outFile qq~<?xml version="1.0" encoding="UTF-8"?> 240<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd"> 241<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"> 242 <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.presentation" manifest:full-path="/"/> 243 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/> 244</manifest:manifest> 245~; 246 247 $outFile->close; 248} 249 250 251############################################################################### 252# Print usage information. 253# 254sub usage () 255{ 256 print <<END_OF_USAGE; 257usage: $0 <option>* [<SvgD-values>] 258 259output-file-name defaults to polygons.odp. 260 261 -h Print this usage information. 262 -o output-file-name 263END_OF_USAGE 264} 265 266############################################################################### 267# Process the command line. 268# 269sub process_command_line 270{ 271 foreach (@ARGV) 272 { 273 if (/^-h/) 274 { 275 usage; 276 exit 0; 277 } 278 } 279 280 $global_output_name = "polygons.odp"; 281 my $j = 0, $noMoreOptions = 0; 282 for (my $i=0; $i<$#ARGV; $i++) 283 { 284 if ( !$noMoreOptions and $ARGV[$i] eq "-o") 285 { 286 $i++; 287 $global_output_name = $ARGV[$i]; 288 } 289 elsif ( !$noMoreOptions and $ARGV[$i] eq "--") 290 { 291 $noMoreOptions = 1; 292 } 293 elsif ( !$noMoreOptions and $ARGV[$i] =~ /^-/) 294 { 295 print "Unknown option $ARGV[$i]\n"; 296 usage; 297 exit 1; 298 } 299 else 300 { 301 push(@paths, [$ARGV[$i],$ARGV[$i+1]]); 302 $i++; 303 } 304 } 305 306 print "output to $global_output_name\n"; 307} 308 309############################################################################### 310# Main 311############################################################################### 312 313$ZipCmd = $ENV{LOG_FILE_ZIP_CMD}; 314$ZipFlags = $ENV{LOG_FILE_ZIP_FLAGS}; 315# Provide default values for the zip command and it's flags. 316if ( ! defined $ZipCmd) 317{ 318 $ZipCmd = "zip" unless defined $ZipCmd; 319 $ZipFlags = "-r -q" unless defined $ZipFlags; 320} 321 322process_command_line(); 323 324writeManifest(); 325 326$OUT = open_file( "content.xml" ); 327 328writeHeader(); 329 330$pathNum=0; 331foreach $path (@paths) 332{ 333 writeSlideHeader($pathNum, $path->[1]); 334 writePath($path); 335 writeSlideFooter(); 336 $pathNum++; 337} 338 339writeFooter(); 340 341$OUT->close; 342 343zip_dirtree ($global_output_name); 344 345