CWS-TOOLING: integrate CWS ooo33gsl12
[LibreOffice.git] / basegfx / qa / mkpolygons.pl
blobb465a4f845ab8c35940e0dfe596ff60ad9c7a2fa
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
6 # 2009 Copyright Novell, Inc. & Sun Microsystems, Inc.
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.
13 use IO::File;
14 use Cwd;
15 use File::Spec;
16 use File::Spec::Functions;
17 use File::Temp;
18 use File::Path;
20 $TempDir = "";
23 # all the XML package generation is a blatant rip from AF's
24 # write-calc-doc.pl
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.
34 sub open_file
36 my $filename = pop @_;
38 # Create base directory of temporary directory tree if not alreay
39 # present.
40 if ($TempDir eq "")
42 $TempDir = File::Temp::tempdir (CLEANUP => 1);
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,""));
50 # Open the file and return a file handle to it.
51 return new IO::File ($fullname, "w");
55 ###############################################################################
56 # Zip the files in the directory tree into the given file.
58 sub zip_dirtree
60 my $filename = pop @_;
62 my $cwd = getcwd;
63 my $zip_name = $filename;
65 # We are about to change the directory.
66 # Therefore create an absolute pathname for the zip archive.
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);
76 # Add the current working directory to a relative path.
77 if ( ! file_name_is_absolute ($zip_name))
79 $zip_name = File::Spec->catfile ($cwd, $zip_name);
81 # Try everything to clean up the name.
82 $zip_name = File::Spec->rel2abs ($filename);
83 $zip_name = File::Spec->canonpath ($zip_name);
85 # Remove .. directories from the middle of the path.
86 while ($zip_name =~ /\/[^\/][^\.\/][^\/]*\/\.\.\//)
88 $zip_name = $` . "/" . $';
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)
96 if (unlink ($filename) == 0)
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;
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);
113 sub writeHeader
115 print $OUT qq~<?xml version="1.0" encoding="UTF-8"?>
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>
185 sub writeSlideHeader
187 my $titleText = pop @_;
188 my $slideNum = pop @_;
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";
199 sub writeSlideFooter
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";
210 sub writeFooter
212 print $OUT qq~ <presentation:settings presentation:full-screen="false"/>
213 </office:presentation>
214 </office:body>
215 </office:document-content>
220 sub writePath
222 my $pathAry = pop @_;
223 my $path = $pathAry->[1];
224 my $viewBox = $pathAry->[0];
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";
235 sub writeManifest
237 my $outFile = open_file("META-INF/manifest.xml");
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>
247 $outFile->close;
251 ###############################################################################
252 # Print usage information.
254 sub usage ()
256 print <<END_OF_USAGE;
257 usage: $0 <option>* [<SvgD-values>]
259 output-file-name defaults to polygons.odp.
261 -h Print this usage information.
262 -o output-file-name
263 END_OF_USAGE
266 ###############################################################################
267 # Process the command line.
269 sub process_command_line
271 foreach (@ARGV)
273 if (/^-h/)
275 usage;
276 exit 0;
280 $global_output_name = "polygons.odp";
281 my $j = 0, $noMoreOptions = 0;
282 for (my $i=0; $i<$#ARGV; $i++)
284 if ( !$noMoreOptions and $ARGV[$i] eq "-o")
286 $i++;
287 $global_output_name = $ARGV[$i];
289 elsif ( !$noMoreOptions and $ARGV[$i] eq "--")
291 $noMoreOptions = 1;
293 elsif ( !$noMoreOptions and $ARGV[$i] =~ /^-/)
295 print "Unknown option $ARGV[$i]\n";
296 usage;
297 exit 1;
299 else
301 push(@paths, [$ARGV[$i],$ARGV[$i+1]]);
302 $i++;
306 print "output to $global_output_name\n";
309 ###############################################################################
310 # Main
311 ###############################################################################
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.
316 if ( ! defined $ZipCmd)
318 $ZipCmd = "zip" unless defined $ZipCmd;
319 $ZipFlags = "-r -q" unless defined $ZipFlags;
322 process_command_line();
324 writeManifest();
326 $OUT = open_file( "content.xml" );
328 writeHeader();
330 $pathNum=0;
331 foreach $path (@paths)
333 writeSlideHeader($pathNum, $path->[1]);
334 writePath($path);
335 writeSlideFooter();
336 $pathNum++;
339 writeFooter();
341 $OUT->close;
343 zip_dirtree ($global_output_name);