comparison sex_again.pl @ 39:8b3b5753ad41 laserkard

[svn r40] created succesuful interface to corel Draw :)
author rlm
date Sun, 24 Jan 2010 15:06:22 -0500
parents
children
comparison
equal deleted inserted replaced
38:07c19a58ba5a 39:8b3b5753ad41
1 #!/usr/bin/perl
2
3
4
5
6
7 use List::Util qw(first max maxstr min minstr reduce shuffle sum);
8 use Storable;
9 use CGI::Ajax;
10 use CGI qw(:standard);
11 use URI::Escape;
12 use MIME::QuotedPrint;
13 use MIME::Base64;
14 use Mail::Sendmail 0.75; # doesn't work with v. 0.74!
15 use XML::Simple;
16 use Data::Dumper;
17 $Data::Dumper::Indent = 1;
18 use Storable;
19 use SVG;
20
21
22 $ref = retrieve('file');
23
24 #print Dumper $$ref;
25 &echo($$ref);
26 #&impose($$ref);
27
28
29
30
31 sub impose
32 {
33
34 #here $svg is a string which contains the properly formatted svg data for one card
35 #out purpose here is to take that one card, size it correctly, and make appropiate copies
36 #so that our supplier can simply import the file and print.
37
38 $sss = $_[0];
39 $sss =~ s/^/\n\n\n/;
40 $sss =~ s/$/\n\n\n/;
41 # you fucking bitch!
42 $sss =~ s/Created wit........//;
43
44
45 # read XML file
46 my $xml = new XML::Simple;
47 my $data = $xml->XMLin($sss, ForceArray => 1);
48
49
50 my %data = %$data;
51
52 my %juzz =
53 (
54
55 path => $data{'path'},
56 rect => $data{'rect'},
57 width =>"16in" ,
58 height =>"12in" ,
59 version =>"1.1",
60 xmlns =>"http://www.w3.org/2000/svg"
61
62 );
63
64
65
66
67 #print Dumper(%juzz);
68
69
70 my $svg= SVG->new(width=>"18in",height=>"12in");
71
72 #print Dumper($juzz{'path'}[2]);
73 print "\n***************************\n";
74 #print Dumper($pathData);
75
76
77
78
79 my $base = "scale(0.6057),matrix(1 0 0 -1 0 317), rotate(180),translate(-514,-317)";
80
81
82 my @cardCollection;
83
84 for $name(0..21) #22 letters for 22 cards
85 {
86
87 #calcuate the thing's place in the grid:
88
89 $cardsToARow = 5;
90 $cardsToAColumn = 5;
91
92 my $row = int($name/$cardsToARow); # cards to a row
93 my $column = int($name % $cardsToAColumn);
94
95 $margin = 25;
96 $cardWidth = 514*0.6057;
97 $cardHeight = 317*0.6057;
98
99
100 $transX = 40 + ($margin + $cardWidth ) * $column;
101 $transY = 40 + ($margin + $cardHeight) * $row;
102
103
104
105 ${"group_".$name} =
106 $svg->group(
107 id => "group_".$name,
108 transform => "translate($transX,$transY),"."$base"
109 );
110
111 push @cardCollection, ${"group_".$name};
112 }
113
114
115
116
117 #my $y=$svg->group(
118 # id => 'group_y' );
119 #
120 #my $f=$svg->group(
121 # id => 'group_f' ,
122 # transform => "$base"
123 #
124 # );
125 #
126 #
127
128
129
130
131
132
133 for ($i = 0; $i <= $#cardCollection; $i++)
134 {
135
136 for $pathData(@{$juzz{'path'}})
137 {
138 $cardCollection[$i]->tag('path', %{$pathData});
139 }
140
141 for $pathData(@{$juzz{'rect'}})
142 {
143 $cardCollection[$i]->tag('rect', %{$pathData});
144 }
145
146
147 }
148
149
150
151 #my $tag = $svg->tag('path', $juzz{'path'});
152
153
154 #$tag = $svg->group(%attributes);
155
156
157 $output = $svg->xmlify;
158
159
160 $killCopyrigt = <<HERE;
161 <!--
162 Generated using the Perl SVG Module V2.49
163 by Ronan Oger
164 Info: http://www.roitsystems.com/
165 -->
166 HERE
167
168 $output =~ s/$killCopyrigt/\n/;
169
170 return $output;
171
172
173
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 sub echo
188 {
189
190
191 my $svg = $_[0];
192
193 my $destination = 'rlm@mit.edu';
194 #~ $svg =~ s/</\&lt\;/g;
195 #~ return $svg;
196
197
198 #$svg = &repair_file($svg);
199
200 $svg = &impose($svg);
201
202
203 #print $svg;
204 open OUT, '>C:/Documents and Settings/Robert McIntyre/Desktop/perlOut.svg';
205 select OUT;
206 print $svg;
207 close OUT;
208
209 #&mail($svg, $destination);
210
211 return "done.";
212
213 }
214
215
216
217
218
219
220 sub repair_file
221 {
222
223
224 $sss = $_[0];
225
226
227
228 $sss =~ s/^/\n\n\n/;
229 $sss =~ s/$/\n\n\n/;
230 # you fucking bitch.
231 $sss =~ s/Created wit........//;
232
233
234 store \$sss, 'file';
235
236 # read XML file
237 my $xml = new XML::Simple;
238 my $data = $xml->XMLin($sss, ForceArray => 1);
239
240
241 my %data = %$data;
242
243 my %juzz =
244 (
245
246 path => $data{'path'},
247 rect => $data{'rect'},
248 width =>"16in" ,
249 height =>"12in" ,
250 version =>"1.1",
251 xmlns =>"http://www.w3.org/2000/svg"
252
253 );
254
255
256 $out = $xml->XMLout(\%juzz , RootName=>'svg');
257
258
259 my $fixed = <<HERE;
260 <?xml version="1.0" standalone="no"?>
261 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
262 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
263 HERE
264
265
266
267 $fixed .= $out;
268
269 #print $fixed;
270 return $fixed;
271
272 }
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291