Mercurial > laserkard
changeset 39:8b3b5753ad41 laserkard
[svn r40] created succesuful interface to corel Draw :)
author | rlm |
---|---|
date | Sun, 24 Jan 2010 15:06:22 -0500 |
parents | 07c19a58ba5a |
children | 1ac1409ea68c |
files | sex_again.pl svgExample.pl |
diffstat | 2 files changed, 350 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sex_again.pl Sun Jan 24 15:06:22 2010 -0500 1.3 @@ -0,0 +1,291 @@ 1.4 +#!/usr/bin/perl 1.5 + 1.6 + 1.7 + 1.8 + 1.9 + 1.10 +use List::Util qw(first max maxstr min minstr reduce shuffle sum); 1.11 +use Storable; 1.12 +use CGI::Ajax; 1.13 +use CGI qw(:standard); 1.14 +use URI::Escape; 1.15 +use MIME::QuotedPrint; 1.16 +use MIME::Base64; 1.17 +use Mail::Sendmail 0.75; # doesn't work with v. 0.74! 1.18 +use XML::Simple; 1.19 +use Data::Dumper; 1.20 +$Data::Dumper::Indent = 1; 1.21 +use Storable; 1.22 +use SVG; 1.23 + 1.24 + 1.25 +$ref = retrieve('file'); 1.26 + 1.27 +#print Dumper $$ref; 1.28 +&echo($$ref); 1.29 +#&impose($$ref); 1.30 + 1.31 + 1.32 + 1.33 + 1.34 +sub impose 1.35 +{ 1.36 + 1.37 +#here $svg is a string which contains the properly formatted svg data for one card 1.38 +#out purpose here is to take that one card, size it correctly, and make appropiate copies 1.39 +#so that our supplier can simply import the file and print. 1.40 + 1.41 +$sss = $_[0]; 1.42 +$sss =~ s/^/\n\n\n/; 1.43 +$sss =~ s/$/\n\n\n/; 1.44 +# you fucking bitch! 1.45 +$sss =~ s/Created wit........//; 1.46 + 1.47 + 1.48 +# read XML file 1.49 +my $xml = new XML::Simple; 1.50 +my $data = $xml->XMLin($sss, ForceArray => 1); 1.51 + 1.52 + 1.53 +my %data = %$data; 1.54 + 1.55 +my %juzz = 1.56 +( 1.57 + 1.58 +path => $data{'path'}, 1.59 +rect => $data{'rect'}, 1.60 +width =>"16in" , 1.61 +height =>"12in" , 1.62 +version =>"1.1", 1.63 +xmlns =>"http://www.w3.org/2000/svg" 1.64 + 1.65 +); 1.66 + 1.67 + 1.68 + 1.69 + 1.70 +#print Dumper(%juzz); 1.71 + 1.72 + 1.73 +my $svg= SVG->new(width=>"18in",height=>"12in"); 1.74 + 1.75 +#print Dumper($juzz{'path'}[2]); 1.76 +print "\n***************************\n"; 1.77 +#print Dumper($pathData); 1.78 + 1.79 + 1.80 + 1.81 + 1.82 +my $base = "scale(0.6057),matrix(1 0 0 -1 0 317), rotate(180),translate(-514,-317)"; 1.83 + 1.84 + 1.85 +my @cardCollection; 1.86 + 1.87 +for $name(0..21) #22 letters for 22 cards 1.88 +{ 1.89 + 1.90 + #calcuate the thing's place in the grid: 1.91 + 1.92 + $cardsToARow = 5; 1.93 + $cardsToAColumn = 5; 1.94 + 1.95 + my $row = int($name/$cardsToARow); # cards to a row 1.96 + my $column = int($name % $cardsToAColumn); 1.97 + 1.98 + $margin = 25; 1.99 + $cardWidth = 514*0.6057; 1.100 + $cardHeight = 317*0.6057; 1.101 + 1.102 + 1.103 + $transX = 40 + ($margin + $cardWidth ) * $column; 1.104 + $transY = 40 + ($margin + $cardHeight) * $row; 1.105 + 1.106 + 1.107 + 1.108 + ${"group_".$name} = 1.109 + $svg->group( 1.110 + id => "group_".$name, 1.111 + transform => "translate($transX,$transY),"."$base" 1.112 + ); 1.113 + 1.114 + push @cardCollection, ${"group_".$name}; 1.115 +} 1.116 + 1.117 + 1.118 + 1.119 + 1.120 +#my $y=$svg->group( 1.121 +# id => 'group_y' ); 1.122 +# 1.123 +#my $f=$svg->group( 1.124 +# id => 'group_f' , 1.125 +# transform => "$base" 1.126 +# 1.127 +# ); 1.128 +# 1.129 +# 1.130 + 1.131 + 1.132 + 1.133 + 1.134 + 1.135 + 1.136 +for ($i = 0; $i <= $#cardCollection; $i++) 1.137 +{ 1.138 + 1.139 +for $pathData(@{$juzz{'path'}}) 1.140 +{ 1.141 +$cardCollection[$i]->tag('path', %{$pathData}); 1.142 +} 1.143 + 1.144 +for $pathData(@{$juzz{'rect'}}) 1.145 +{ 1.146 +$cardCollection[$i]->tag('rect', %{$pathData}); 1.147 +} 1.148 + 1.149 + 1.150 +} 1.151 + 1.152 + 1.153 + 1.154 +#my $tag = $svg->tag('path', $juzz{'path'}); 1.155 + 1.156 + 1.157 +#$tag = $svg->group(%attributes); 1.158 + 1.159 + 1.160 +$output = $svg->xmlify; 1.161 + 1.162 + 1.163 +$killCopyrigt = <<HERE; 1.164 +<!-- 1.165 + Generated using the Perl SVG Module V2.49 1.166 + by Ronan Oger 1.167 + Info: http://www.roitsystems.com/ 1.168 + --> 1.169 +HERE 1.170 + 1.171 +$output =~ s/$killCopyrigt/\n/; 1.172 + 1.173 +return $output; 1.174 + 1.175 + 1.176 + 1.177 +} 1.178 + 1.179 + 1.180 + 1.181 + 1.182 + 1.183 + 1.184 + 1.185 + 1.186 + 1.187 + 1.188 + 1.189 + 1.190 +sub echo 1.191 +{ 1.192 + 1.193 + 1.194 +my $svg = $_[0]; 1.195 + 1.196 +my $destination = 'rlm@mit.edu'; 1.197 +#~ $svg =~ s/</\<\;/g; 1.198 +#~ return $svg; 1.199 + 1.200 + 1.201 +#$svg = &repair_file($svg); 1.202 + 1.203 +$svg = &impose($svg); 1.204 + 1.205 + 1.206 +#print $svg; 1.207 +open OUT, '>C:/Documents and Settings/Robert McIntyre/Desktop/perlOut.svg'; 1.208 +select OUT; 1.209 +print $svg; 1.210 +close OUT; 1.211 + 1.212 +#&mail($svg, $destination); 1.213 + 1.214 +return "done."; 1.215 + 1.216 +} 1.217 + 1.218 + 1.219 + 1.220 + 1.221 + 1.222 + 1.223 +sub repair_file 1.224 +{ 1.225 + 1.226 + 1.227 +$sss = $_[0]; 1.228 + 1.229 + 1.230 + 1.231 +$sss =~ s/^/\n\n\n/; 1.232 +$sss =~ s/$/\n\n\n/; 1.233 +# you fucking bitch. 1.234 +$sss =~ s/Created wit........//; 1.235 + 1.236 + 1.237 +store \$sss, 'file'; 1.238 + 1.239 +# read XML file 1.240 +my $xml = new XML::Simple; 1.241 +my $data = $xml->XMLin($sss, ForceArray => 1); 1.242 + 1.243 + 1.244 +my %data = %$data; 1.245 + 1.246 +my %juzz = 1.247 +( 1.248 + 1.249 +path => $data{'path'}, 1.250 +rect => $data{'rect'}, 1.251 +width =>"16in" , 1.252 +height =>"12in" , 1.253 +version =>"1.1", 1.254 +xmlns =>"http://www.w3.org/2000/svg" 1.255 + 1.256 +); 1.257 + 1.258 + 1.259 +$out = $xml->XMLout(\%juzz , RootName=>'svg'); 1.260 + 1.261 + 1.262 +my $fixed = <<HERE; 1.263 +<?xml version="1.0" standalone="no"?> 1.264 +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 1.265 + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 1.266 +HERE 1.267 + 1.268 + 1.269 + 1.270 +$fixed .= $out; 1.271 + 1.272 +#print $fixed; 1.273 +return $fixed; 1.274 + 1.275 +} 1.276 + 1.277 + 1.278 + 1.279 + 1.280 + 1.281 + 1.282 + 1.283 + 1.284 + 1.285 + 1.286 + 1.287 + 1.288 + 1.289 + 1.290 + 1.291 + 1.292 + 1.293 + 1.294 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/svgExample.pl Sun Jan 24 15:06:22 2010 -0500 2.3 @@ -0,0 +1,59 @@ 2.4 + #!/usr/bin/perl -w 2.5 + use strict; 2.6 + use SVG; 2.7 + 2.8 + # create an SVG object 2.9 + my $svg= SVG->new(width=>200,height=>200); 2.10 + #or 2.11 + my $svg= SVG->new(width=>200,height=>200); 2.12 + 2.13 + # use explicit element constructor to generate a group element 2.14 + my $y=$svg->group( 2.15 + id => 'group_y', 2.16 + style => { stroke=>'red', fill=>'green' } 2.17 + ); 2.18 + 2.19 + # add a circle to the group 2.20 + $y->circle(cx=>100, cy=>100, r=>50, id=>'circle_in_group_y'); 2.21 + 2.22 + # or, use the generic 'tag' method to generate a group element by name 2.23 + my $z=$svg->tag('g', 2.24 + id => 'group_z', 2.25 + style => { 2.26 + stroke => 'rgb(100,200,50)', 2.27 + fill => 'rgb(10,100,150)' 2.28 + } 2.29 + ); 2.30 + 2.31 + # create and add a circle using the generic 'tag' method 2.32 + $z->tag('circle', cx=>50, cy=>50, r=>100, id=>'circle_in_group_z'); 2.33 + 2.34 + # create an anchor on a rectangle within a group within the group z 2.35 + my $k = $z->anchor( 2.36 + id => 'anchor_k', 2.37 + -href => 'http://test.hackmare.com/', 2.38 + target => 'new_window_0' 2.39 + )->rectangle( 2.40 + x => 20, y => 50, 2.41 + width => 20, height => 30, 2.42 + rx => 10, ry => 5, 2.43 + id => 'rect_k_in_anchor_k_in_group_z' 2.44 + ); 2.45 + 2.46 + # now render the SVG object, implicitly use svg namespace 2.47 + print $svg->xmlify; 2.48 + 2.49 + # or render a child node of the SVG object without rendering the entire object 2.50 + print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not 2.51 + #render any of the ancestor nodes of $k 2.52 + 2.53 + 2.54 + # or, explicitly use svg namespace and generate a document with its own DTD 2.55 + print $svg->xmlify(-namespace=>'svg'); 2.56 + 2.57 + # or, explicitly use svg namespace and generate an in-line docunent 2.58 + print $svg->xmlify( 2.59 + -namespace => "svg", 2.60 + -pubid => "-//W3C//DTD SVG 1.0//EN", 2.61 + -inline => 1 2.62 + ); 2.63 \ No newline at end of file