comparison echo.pl @ 40:1ac1409ea68c laserkard

[svn r41] implemented dynamic text.
author rlm
date Mon, 25 Jan 2010 03:42:08 -0500
parents 07c19a58ba5a
children 95fa4bcc5d67
comparison
equal deleted inserted replaced
39:8b3b5753ad41 40:1ac1409ea68c
11 use Mail::Sendmail 0.75; # doesn't work with v. 0.74! 11 use Mail::Sendmail 0.75; # doesn't work with v. 0.74!
12 use XML::Simple; 12 use XML::Simple;
13 use Data::Dumper; 13 use Data::Dumper;
14 $Data::Dumper::Indent = 1; 14 $Data::Dumper::Indent = 1;
15 use Storable; 15 use Storable;
16 16 use SVG;
17 17
18 my $q = new CGI; 18 my $q = new CGI;
19 19
20 20
21 21
66 66
67 67
68 my $svg = $_[0]; 68 my $svg = $_[0];
69 69
70 my $destination = 'rlm@mit.edu'; 70 my $destination = 'rlm@mit.edu';
71 #~ $svg =~ s/</\&lt\;/g; 71
72 #~ return $svg; 72
73 73
74 74
75 $svg = &repair_file($svg); 75 $svg = &impose($svg);
76
76 77
77 78
78 79
79 80
80 &mail($svg, $destination); 81 &mail($svg, $destination);
85 return "done."; 86 return "done.";
86 87
87 } 88 }
88 89
89 90
90 sub repair_file 91
91 { 92 sub impose
92 93 {
94
95 #here $svg is a string which contains the properly formatted svg data for one card
96 #out purpose here is to take that one card, size it correctly, and make appropiate copies
97 #so that our supplier can simply import the file and print.
93 98
94 $sss = $_[0]; 99 $sss = $_[0];
95
96
97
98 $sss =~ s/^/\n\n\n/; 100 $sss =~ s/^/\n\n\n/;
99 $sss =~ s/$/\n\n\n/; 101 $sss =~ s/$/\n\n\n/;
100 # you fucking bitch. 102 # you fucking bitch!
101 $sss =~ s/Created wit........//; 103 $sss =~ s/Created wit........//;
102 104
103 105
104 store \$sss, 'file';
105
106 # read XML file 106 # read XML file
107 $xml = new XML::Simple; 107 my $xml = new XML::Simple;
108 $data = $xml->XMLin($sss, ForceArray => 1); 108 my $data = $xml->XMLin($sss, ForceArray => 1);
109 109
110 110
111 my %data = %$data; 111 my %data = %$data;
112 112
113 my %juzz = 113 my %juzz =
121 xmlns =>"http://www.w3.org/2000/svg" 121 xmlns =>"http://www.w3.org/2000/svg"
122 122
123 ); 123 );
124 124
125 125
126
127
128 #print Dumper(%juzz);
129
130
131 my $svg= SVG->new(width=>"18in",height=>"12in");
132
133 #print Dumper($juzz{'path'}[2]);
134 #print "\n***************************\n";
135 #print Dumper($pathData);
136
137
138
139
140 my $base = "scale(0.6057),matrix(1 0 0 -1 0 317), rotate(180),translate(-514,-317)";
141
142
143 my @cardCollection;
144
145 for $name(0..21) #22 letters for 22 cards
146 {
147
148 #calcuate the thing's place in the grid:
149
150 $cardsToARow = 5;
151 $cardsToAColumn = 5;
152
153 my $row = int($name/$cardsToARow); # cards to a row
154 my $column = int($name % $cardsToAColumn);
155
156 $margin = 25;
157 $cardWidth = 514*0.6057;
158 $cardHeight = 317*0.6057;
159
160
161 $transX = 40 + ($margin + $cardWidth ) * $column;
162 $transY = 40 + ($margin + $cardHeight) * $row;
163
164
165
166 ${"group_".$name} =
167 $svg->group(
168 id => "group_".$name,
169 transform => "translate($transX,$transY),"."$base"
170 );
171
172 push @cardCollection, ${"group_".$name};
173 }
174
175
176
177
178
179
180
181
182 for ($i = 0; $i <= $#cardCollection; $i++)
183 {
184
185 for $pathData(@{$juzz{'path'}})
186 {
187 $cardCollection[$i]->tag('path', %{$pathData});
188 }
189
190 for $pathData(@{$juzz{'rect'}})
191 {
192 $cardCollection[$i]->tag('rect', %{$pathData});
193 }
194
195
196 }
197
198
199
200 #my $tag = $svg->tag('path', $juzz{'path'});
201
202
203 #$tag = $svg->group(%attributes);
204
205
206 $output = $svg->xmlify;
207
208
209 $killCopyrigt = <<HERE;
210 <!--
211 Generated using the Perl SVG Module V2.49
212 by Ronan Oger
213 Info: http://www.roitsystems.com/
214 -->
215 HERE
216
217 $output =~ s/$killCopyrigt/\n/;
218
219 return $output;
220
221
222
223 }
224
225
226 sub repair_file
227 {
228
229
230 $sss = $_[0];
231
232
233
234 $sss =~ s/^/\n\n\n/;
235 $sss =~ s/$/\n\n\n/;
236 # you fucking bitch.
237 $sss =~ s/Created wit........//;
238
239
240 store \$sss, 'file';
241
242 # read XML file
243 $xml = new XML::Simple;
244 $data = $xml->XMLin($sss, ForceArray => 1);
245
246
247 my %data = %$data;
248
249 my %juzz =
250 (
251
252 path => $data{'path'},
253 rect => $data{'rect'},
254 width =>"16in" ,
255 height =>"12in" ,
256 version =>"1.1",
257 xmlns =>"http://www.w3.org/2000/svg"
258
259 );
260
261
126 $out = $xml->XMLout(\%juzz , RootName=>'svg'); 262 $out = $xml->XMLout(\%juzz , RootName=>'svg');
127 263
128 264
129 my $fixed = <<HERE; 265 my $fixed = <<HERE;
130 <?xml version="1.0" standalone="no"?> 266 <?xml version="1.0" standalone="no"?>