summaryrefslogtreecommitdiff
path: root/oox/source/drawingml/customshapes/generatePresetsCXX.pl
blob: e5a509d394160248ea6ad9b28e82d113769025e6 (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
#!/usr/bin/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/.
#

sub loadSourceCode()
{
	open (IN, "<custom-shapes.log");

	my %sources;

	while (<IN>)
	{
		if (/==cscode== /)
		{
			if (/shape name: '/)
			{
				chop;
				s/.*shape name: '([^']+)'.*/$1/;
				$name = $_;
			}
			else
			{
				if (/==cscode== begin/)
				{
					$inside = true;
					@code = ();
				}
				else
				{
					if (/==cscode== end/)
					{
						s/^  <\/([^>]+)>/$1/;
						undef $inside;
						$sources{$name} = [ @code ];
						#print "added ", $name, "\n";
					}
				}
			}
		}
		else
		{
			if ($inside)
			{
				push @code, $_;
			}
		}
	}

	close (IN);

	return \%sources;
}

sub startSource
{
	my $count = shift;

	open (OUT, ">customshapepresets" . $count . ".cxx");
	print OUT << "EOS"
//
// This file was generated by: $0
//
// Please, DO NOT EDIT.
//
// We mean it.

#include <oox/drawingml/customshapeproperties.hxx>
#include <oox/token/tokenmap.hxx>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/awt/Size.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>

using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::uno;

namespace oox { namespace drawingml {

namespace
{
EOS
;

}

sub endSource
{
    my $count = shift;
    my $classes = shift;
    $endBrace > 0 && print OUT "}\n\n";

    print OUT "} // anonymous namespace\n";
    print OUT "void CustomShapeProperties::initializePresetsMap" . $count . "()\n";
    print OUT "{\n";
    for my $class (@{$classes})
    {
        print OUT "    maPresetsMap [ StaticTokenMap::get().getTokenFromUnicode( \"", $class, "\" ) ] = new ShapeC".$class."();\n";
    }
    print OUT "}

} } // oox // drawingml

";
}

sub generateSource
{
    my $sources = shift;
    my $count = 0;
    my $shCount = 0;

    startSource (++$count);

    my @classes = ();
    foreach $shape (keys %$sources)
    {
	push @classes, $shape;
	print OUT "class ShapeC".$shape." : public CustomShapeProvider\n";
	print OUT "{\n";
	print OUT "  virtual PropertyMap getProperties()\n";
	print OUT "  {\n";
	print OUT "    PropertyMap aPropertyMap;\n\n";
	print OUT @{$sources->{$shape}};
	print OUT "    aPropertyMap [ PROP_Type ] <<= OUString(\"ooxml-", $shape, "\");\n\n";
	print OUT "    return aPropertyMap;\n";
	print OUT "  }\n";
	print OUT "};\n";
        print OUT "\n";
        print OUT "// This is a generated source file. DO NOT EDIT.\n";
        print OUT "\n";

        $shCount++;

        if ($shCount >= 35) {
            $shCount = 0;

	    endSource ($count, \@classes);
	    close OUT;
	    startSource (++$count);
	    @classes = ();
        }
    }

    endSource ($count, \@classes);

    print OUT << "EOS"

void ::oox::drawingml::CustomShapeProperties::initializePresetsMap()
{
EOS
    ;

    for ($i=1; $i <= $count; $i++) {
         print OUT "initializePresetsMap" . $i . "();\n";
    }

    print OUT "}\n";

    close OUT;
}

generateSource (loadSourceCode ());