don't chomp line all over
[Printer-EVOLIS.git] / inkscape-render.pl
index df7c73e..9df63e4 100755 (executable)
@@ -4,6 +4,10 @@ use warnings;
 use strict;
 use autodie;
 
+my $card_svg = 'card/ffzg-2010.svg';
+
+warn "# card template: $card_svg\n";
+
 my ($nr,$ime,$prezime) = ( qw/
 200900000042
 Dobrica
@@ -28,33 +32,52 @@ foreach my $existing ( glob $out . '*' ) {
        unlink $existing;
 }
 
-open(my $in,     '<', 'template.svg');
-open(my $print,  '>', "$out.print.svg");
-open(my $screen, '>', "$out.screen.svg");
+open(my $svg_template, '<', $card_svg);
+open(my $svg,          '>', "$out.svg");
 
-while(<$in>) {
+while(<$svg_template>) {
 
        if ( m{($re)} ) {
                warn "mapping $1\n";
                s{($1)}{mapping($1)}e;
        }
 
-       if ( s{##print##}{none} ) {
-               warn "print layer: $_\n";
-               print $print $_;
-               s{none}{inline};
-               print $screen $_;
+       print $svg $_;
 
-       } else {
-               print $print  $_;
-               print $screen $_;
-       }
+}
+
+close($svg_template);
+close($svg);
+
+open(my $inkscape, '|-', 'inkscape --shell --without-gui');
+
+sub inkscape_export {
+       my $part = shift;
 
+       my $shell = "$out.svg --export-area-page --export-id $part";
+
+       print $inkscape "$shell --export-pdf $out.$part.pdf\n";
+       print $inkscape "$shell --export-png $out.$part.png --export-dpi 150\n";
 }
 
-close($in);
-close($print);
-close($screen);
+inkscape_export 'print-front';
+inkscape_export 'print-back';
+
+# export visible
+print $inkscape "$out.svg --export-png $out.png --export-dpi 300\n";
+
+close($inkscape);
+
+foreach my $pdf ( glob "$out*.pdf" ) {
+       my $pbm = $pdf;
+       $pbm =~ s/pdf$/pbm/;
+       warn "# rendering $pdf => $pbm using ghostscript\n";
+       system "gs -dNOPAUSE -dBATCH -q -r300x300 -dDEVICEWIDTHPOINTS=243 -dDEVICEHEIGHTPOINTS=155 -sDEVICE=pbmraw -sOutputFile=$pbm -f $pdf";
+}
+
+system "pdftk $out.print-front.pdf $out.print-back.pdf cat output $out.print-duplex.pdf";
+
+__END__
 
 #system "inkscape --file $out.print.svg  --export-pdf $out.pdf";