#!/usr/bin/perl

my ($S) = shift || 50;

my ($h, $w);
my $output = [];
while (<>) {
  chomp;
  $w ||= length();
  $h++;
  push @$output, convert($_);
}       

open STDOUT, "| pnmscale 1 | cjpeg";
print "P1\n", $w * $S, " ", $h * $S, "\n";
print $_, "\n" for @$output;
exit;

sub convert {
  my @result;
  for my $ch (split //, $_[0]) {
    my @rows = convert_ch($ch);
    for my $i (0 .. $#rows) {
      $result[$i] ||= "";
      $result[$i] .= $rows[$i];
    }
  }
  return @result;
}

# 
sub convert_ch {
  my @rows;
  my $ch = shift;
  my $up = $ch =~ /[<|>^'`+]/i;
  my $dn = $ch =~ /[<|>V.,+]/i;
  my $lt = $ch =~ /[-<V^,`+]/i;
  my $rt = $ch =~ /[->V^.'+]/i;
  my $top = int($S * 0.4);
  my $mid = int($S * 0.2);
  my $bot = int($S * 0.4);

  my $v0 = "0" x $S;
  my $v1 = "0" x $top . "1" x $mid . "0" x $bot;
  push @rows, ($up ? $v1 : $v0) x $top;

  my $ls = $lt ? "1" : "0";
  my $ms = ($lt || $rt || $up || $dn) ? "1" : "0";
  my $rs = $rt ? "1" : "0";
  push @rows, ($ls x $top . $ms x $mid . $rs x $bot) x $mid;

  push @rows, ($dn ? $v1 : $v0) x $bot;
 
  return @rows;
}

__DATA__
 .
.<
<'
'-
