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