summaryrefslogtreecommitdiffstats
path: root/oox/source/drawingml/customshapes/generatePresetsPPTXs.pl
blob: 246bfddcdcfdfba64021fe262456ece110bcf12f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/env perl
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

use IO::Handle;

$shapes = loadShapes ();

generatePPTXs($shapes);
exit;


sub generatePPTXs
{
	$shapes = shift;

	foreach $shape (keys %$shapes)
	{
		generatePPTX ($shapes, $shape);
	}

	generatePPTX ($shapes);
}

sub generatePPTX
{
	$shapes = shift;
	$type = shift;

	mkdir ("cshape");
	mkdir ("pptx");
	system ("unzip -qq -o -d cshape cshape.pptx");

	# custom shape(s) slide with preset definition
	generateSlide ($shapes, $type, ">cshape/ppt/slides/slide1.xml", 0);

	$pptx = "../pptx/cshape-" . (defined $type ? $type : "all") . ".pptx";
	system ("cd cshape\nrm -rf ". $pptx . "\nzip -q -r " . $pptx . " .\ncd ..");

	# preset(s) slide, for testing
	generateSlide ($shapes, $type, ">cshape/ppt/slides/slide1.xml", 1);

	$pptx = "../pptx/preset-cshape-" . (defined $type ? $type : "all") . ".pptx";
	system ("cd cshape\nrm -rf ". $pptx . "\nzip -q -r " . $pptx . " .\ncd ..");
}

sub loadShapes()
{
	open (IN, "<presetShapeDefinitions.xml");

	$inside = false;
	my %shapes;

	while (<IN>)
	{
		if (/^  <[^\/]/)
		{
			$inside = true;
			@definition = ();
		}
		else
		{
			if (/^  <\//)
			{
				chomp;
				s/^  <\/([^>]+)>.*/$1/;
				undef $inside;
				$shapes{$_} = [ @definition ];
				#print "added ", $_, "\n";
			}
			else
			{
				if ($inside)
				{
					push @definition, $_;
				}
			}
		}
	}

	close (IN);

	return \%shapes;
}

sub generateSlide
{
	$shapes = shift;
	$type = shift;
	$file = shift;
	$preset = shift;

	open (OUT, $file);

	print OUT "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<p:sld xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">
  <p:cSld>
    <p:spTree>
      <p:nvGrpSpPr>
        <p:cNvPr id=\"1\" name=\"\"/>
        <p:cNvGrpSpPr/>
        <p:nvPr/>
      </p:nvGrpSpPr>
      <p:grpSpPr>
        <a:xfrm>
          <a:off x=\"0\" y=\"0\"/>
          <a:ext cx=\"0\" cy=\"0\"/>
          <a:chOff x=\"0\" y=\"0\"/>
          <a:chExt cx=\"0\" cy=\"0\"/>
        </a:xfrm>
      </p:grpSpPr>
";

	$id = 16;
	$col = 0;
	$row = 0;
	$size = 500000;
	foreach $shape (keys %$shapes)
	{
		if (defined $type) {
			if ($shape ne $type) { next; }
#            <a:ext cx=\"1050925\" cy=\"457200\"/>
#            <a:ext cx=\"1000000\" cy=\"1000000\"/>
			$size *= 10;
			$col = 0.5;
			$row = 0.25;
		}

		if ($col > 15) {
			$col = 0;
			$row ++;
		}

		print OUT "      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id=\"", $id++, "\" name=\"", $shape, "\"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr bwMode=\"auto\">
          <a:xfrm>
            <a:off x=\"" . (350000 + $col++*$size) . "\" y=\"" . (450000 + $row*$size) . "\"/>
            <a:ext cx=\"" . (4*$size/5) . "\" cy=\"" . (4*$size/5) . "\"/>
          </a:xfrm>
";
		if ($preset) {
		    print OUT "          <a:prstGeom prst=\"" . $shape . "\"><a:avLst/></a:prstGeom>
";
		} else {
		    print OUT "          <a:custGeom>
";
		    print OUT @{$shapes->{$shape}};
		    print OUT "          </a:custGeom>
";
		}
		print OUT "          <a:solidFill>
            <a:srgbClr val=\"FFFF7F\"/>
          </a:solidFill>
          <a:ln w=\"19080\">
            <a:solidFill>
              <a:srgbClr val=\"A0A060\"/>
            </a:solidFill>
            <a:miter lim=\"800000\"/>
            <a:headEnd/>
            <a:tailEnd/>
          </a:ln>
        </p:spPr>
      </p:sp>
";
	}

	print OUT "    </p:spTree>
  </p:cSld>
  <p:clrMapOvr>
    <a:masterClrMapping/>
  </p:clrMapOvr>
  <p:timing>
    <p:tnLst>
      <p:par>
        <p:cTn id=\"1\" dur=\"indefinite\" restart=\"never\" nodeType=\"tmRoot\"/>
      </p:par>
    </p:tnLst>
  </p:timing>
</p:sld>
";

	close (OUT);
}