#!/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, ") { 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 " "; $id = 16; $col = 0; $row = 0; $size = 500000; foreach $shape (keys %$shapes) { if (defined $type) { if ($shape ne $type) { next; } # # $size *= 10; $col = 0.5; $row = 0.25; } if ($col > 15) { $col = 0; $row ++; } print OUT " "; if ($preset) { print OUT " "; } else { print OUT " "; print OUT @{$shapes->{$shape}}; print OUT " "; } print OUT " "; } print OUT " "; close (OUT); }