comparison echo.pl @ 51:95fa4bcc5d67 laserkard

[svn r52] implemented SVG backend
author rlm
date Wed, 03 Feb 2010 03:14:09 -0500
parents 1ac1409ea68c
children 375225442677
comparison
equal deleted inserted replaced
50:1b5417799713 51:95fa4bcc5d67
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 use SVG; 16 use SVG;
17 use Laserkard;
18
17 19
18 my $q = new CGI; 20 my $q = new CGI;
19 21
20 22
21 23
22 my %hash = 24 my %hash =
23 ( 25 (
26 'material' => \&Laserkard::material,
27 'template' => \&Laserkard::template,
28 'inputbox' => \&Laserkard::inputbox,
29 'display' => \&Laserkard::display,
30 'change_rules' => \&Laserkard::change_rules,
31 'vanish' => \&Laserkard::vanish,
32 'updateForm' => \&Laserkard::updateForm,
33 'cardType' => \&Laserkard::cardType,
24 'echo' => \&echo 34 'echo' => \&echo
25 ); 35 );
26 36
27 37
28 38
34 44
35 45
36 46
37 sub gen 47 sub gen
38 { 48 {
39 { 49
40 local( $/, *FH ) ; 50
41 open( FH, "<./echo.html" ) or die "sudden flaming death\n"; 51
42 $a = <FH>; 52
43 } 53
44 54 $a = Laserkard::genEcho();
45 { 55
46 local( $/, *FH ) ;
47 open( FH, "<./top_menu.include" ) or die "sudden flaming death\n";
48 $b = <FH>;
49 }
50
51
52
53 $a =~ s/PERL-REPLACE::TOP_MENU/$b/; #equivalent to <?php include("top_menu.html"); ?>, but in perl and with more memory problems :)
54 56
55 57
56 58
57 return $a 59 return $a
58 60
62 64
63 65
64 sub echo 66 sub echo
65 { 67 {
66 68
67 69
68 my $svg = $_[0]; 70
69 71 my $svg = shift;
70 my $destination = 'rlm@mit.edu'; 72
71 73
72 74
73 75 #my $destination = 'rlm@mit.edu';
74 76
75 $svg = &impose($svg); 77
76 78
77 79
78 80
79 81
80 82
81 &mail($svg, $destination); 83 my @cards = split (/S3ntinEL/, $svg);
82 84 my $emmmm = shift;
83 85 #return $emmmm;
84 86
85 87 $cardsPerMail = 30;
86 return "done."; 88 ##### ok, now we have this awesome array with all the cards we need to print.
89 # the numbers are right, so now we really just have to impose them.
90 for $mails(0..int(($#cards) / $cardsPerMail))
91 {
92
93
94 my $start = $mails * $cardsPerMail;
95
96 my $end = ($#cards >($start + $cardsPerMail)) ? ($start + $cardsPerMail) : $#cards;
97
98 $svg = &impose(@cards[$start..$end]);
99 #$svg = &impose($cards[$end]);
100
101 &mail($svg, $emmmm);
102 }
103
104
105
106 return "done";
107
108 return $svg;
109
110
87 111
88 } 112 }
89 113
90 114
91 115
94 118
95 #here $svg is a string which contains the properly formatted svg data for one card 119 #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 120 #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. 121 #so that our supplier can simply import the file and print.
98 122
99 $sss = $_[0]; 123 my $xml = new XML::Simple;
100 $sss =~ s/^/\n\n\n/; 124 my @cards = @_;
101 $sss =~ s/$/\n\n\n/; 125
126
127 for (0..$#cards)
128 {
129
130 $cards[$_] =~ s/^/\n\n\n/;
131 $cards[$_] =~ s/$/\n\n\n/;
102 # you fucking bitch! 132 # you fucking bitch!
103 $sss =~ s/Created wit........//; 133 $cards[$_] =~ s/Created wit........//;
104 134 }
105 135
106 # read XML file 136 # read XML file
107 my $xml = new XML::Simple; 137
108 my $data = $xml->XMLin($sss, ForceArray => 1); 138
139
140
141 #print Dumper(%juzz);
142
143
144 my $svg= SVG->new(width=>"18in",height=>"14in");
145
146 #print Dumper($juzz{'path'}[2]);
147 #print "\n***************************\n";
148 #print Dumper($pathData);
149
150
151
152
153 my $base = "scale(0.6057),matrix(1 0 0 -1 0 317), rotate(180),translate(-514,-317)";
154
155
156 my @cardCollection;
157
158 for $name(0..$#cards) #22 letters for 22 cards
159 {
160
161 #calcuate the thing's place in the grid:
162
163 $cardsToARow = 5;
164 $cardsToAColumn = 5;
165
166 my $row = int($name/$cardsToARow); # cards to a row
167 my $column = int($name % $cardsToAColumn);
168
169 $margin = 25;
170 $cardWidth = 514*0.6057;
171 $cardHeight = 317*0.6057;
172
173
174 $transX = 40 + ($margin + $cardWidth ) * $column;
175 $transY = 40 + ($margin + $cardHeight) * $row;
176
177
178
179 ${"group_".$name} =
180 $svg->group(
181 id => "group_".$name,
182 transform => "translate($transX,$transY),"."$base"
183 );
184
185 push @cardCollection, ${"group_".$name};
186 }
187
188
189
190
191
192
193
194
195
196 for ($i = 0; $i <= $#cardCollection; $i++)
197 {
198
199
200 my $data = $xml->XMLin($cards[$i], ForceArray => 1);
109 201
110 202
111 my %data = %$data; 203 my %data = %$data;
112 204
113 my %juzz = 205 my %juzz =
120 version =>"1.1", 212 version =>"1.1",
121 xmlns =>"http://www.w3.org/2000/svg" 213 xmlns =>"http://www.w3.org/2000/svg"
122 214
123 ); 215 );
124 216
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 217
185 for $pathData(@{$juzz{'path'}}) 218 for $pathData(@{$juzz{'path'}})
186 { 219 {
187 $cardCollection[$i]->tag('path', %{$pathData}); 220 $cardCollection[$i]->tag('path', %{$pathData});
188 } 221 }
317 Content-Transfer-Encoding: base64 350 Content-Transfer-Encoding: base64
318 Content-Disposition: attachment; filename="test.svg" 351 Content-Disposition: attachment; filename="test.svg"
319 352
320 $attach1 353 $attach1
321 354
322 $boundary 355
323 Content-Type: application/octet-stream; name="huh.txt"
324 Content-Transfer-Encoding: base64
325 Content-Disposition: attachment; filename="huh.txt"
326
327 $attach2
328 $boundary-- 356 $boundary--
329 357
330 END_OF_BODY 358 END_OF_BODY
331 359
332 sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; 360 sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";