diff options
Diffstat (limited to 'deckcomposer.pl')
| -rwxr-xr-x | deckcomposer.pl | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/deckcomposer.pl b/deckcomposer.pl new file mode 100755 index 0000000..9efd229 --- /dev/null +++ b/deckcomposer.pl @@ -0,0 +1,116 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +package deckcomposer; + +use File::Basename; + +my ($deckfile) = @ARGV; +my($deckname, $deckdir, $suffix) = fileparse($deckfile, ".hs"); + +my $latexpreamble = <<END; + +\\documentclass{article} + +\\usepackage{graphicx} +\\usepackage[top=-.5in, bottom=.1in, left=.3in, right=.1in]{geometry} + + +\\newcommand\\Page[1]{ + \\begin{figure}[p] + \\center + \\includegraphics[height=8in, width=6in]{"#1"} + \\end{figure} + \\pagebreak +} + +END + +open my $deck, $deckfile or die "Could not open $deckfile: $!"; + +sub start_document { + my $begin = <<END; + +\\begin{document} +\\thispagestyle{empty} + +END + return "${latexpreamble}\n${begin}"; +} + +sub end_document { + my ($doc) = @_; + my $end = <<END; + +\\end{document} + +END + return "$doc\n$end"; +} + +my $image_ph = "images/%s.png"; +my $image_magick_command = <<END; +convert \\( \\( "$image_ph" -crop 307x433+0+16\\! \\) \\( "$image_ph" -crop 307x433+0+16\\! \\) -append \\) \\( \\( "$image_ph" -crop 307x433+0+16\\! \\) \\( "$image_ph" -crop 307x433+0+16\\! \\) -append \\) +append "$deckdir/%s" +END + +my $page_nr = 0; +sub add_to_page { + my ($idoc, @list) = @_; + + my $compositefile = "image${page_nr}.png"; + push(@list, $compositefile); + + print @list; + my $imageline = sprintf($image_magick_command, @list); + $page_nr += 1; + + print "$imageline\n"; + system($imageline); + + my ($name, undef, undef) = fileparse($compositefile, ".png"); + my $teximagepath = "$deckdir/$name"; + $idoc = "$idoc\n\\Page{$teximagepath}\n"; + return $idoc; +} + +my $doc = start_document(); +my @list = (); + +while( my $line = <$deck>) { + if ($line =~ m/(\d+)\s*:\s*(.+)\n/) { + my $nr = int($1); + my $name = $2; + + for(my $i=0; $i < $nr; $i++) + { + push(@list, $name); + print "@list\n"; + if( @list == 4 ) { + $doc = add_to_page($doc, @list); + @list = (); + } + } + } +} + +if (@list > 0) { + while (@list < 4) { + push(@list, "Empty"); + } + $doc = add_to_page($doc, @list); +} + +$doc = end_document($doc); + +close $deck; + +my $texfilename = "$deckdir/${deckname}_base.tex"; +open my $texfile, '>', $texfilename or die "Could not open $texfilename for writing: $!"; + +print {$texfile} $doc; + +system("pdflatex -output-directory $deckdir $texfilename"); +system("pdfunite auxilary/auximage.pdf $deckdir/${deckname}_base.pdf $deckdir/$deckname.pdf"); +system("xdg-open $deckdir/$deckname.pdf"); + |
