#!/usr/bin/perl
#####################################
# This is a language translation file
#
# This is a good example of using a subroutine to handle translations.
#
# Program:                   album
# Created:                   Thu Dec  7 04:36:18 2006
# Language code:             banner
# Language:                  banner ASCII text
# Charset:                   iso-8859-1
# Language: (English)        banner ASCII text
#####################################

sub language_info {
	my ($opt) = @_;
	$opt->{hashes} = 0;	# Doesn't work with banner
	$opt->{save_screen_width} = $opt->{screen_width};
	$opt->{screen_width} = 0;	# We'll handle the wrapping

	return {
		language_code => 'banner',
		language => 'banner ASCII text',
		language_english => 'banner ASCII text',
		album_version	=> "4.00",
		language_version => 1,
		charset => "iso-8859-1",
		translators => [		# List of:  ["name","email/url"],
			[ "David Ljung Madison", "http://GetDave.com/" ],
			[ "Thanks: Glenn Chappell", "http://www.figlet.org/" ],
		],
	};
}

# Translations go here
sub language {
	return {
		'_post' => \&banner,	# Catch-all for all translations
	};
}

#########################
# Font data (see 'generation' below)
#########################
# Based on font: drpepper
my %font = (
	' ' => [' ',' ',' ',' ',' '],
	'!' => [' _ ','| |','|_/','<_>','   '],
	'"' => [' _ _','|/|/','    ','    ','    '],
	'#' => ['       ',' _|_|_ ',' _|_|_ ','  | |  ','       '],
	'$' => ['    ',' ||_','<_-<','/__/',' || '],
	'%' => ['   __','<>/ /',' / / ','/_/<>','     '],
	'&' => [' _   ','< >  ','/.\\/ ','\\_/\\ ','     '],
	"'" => [' _','|/','  ','  ','  '],
	'(' => ['  __',' / /','| | ','| | ',' \\_\\'],
	')' => ['__  ','\\ \\ ',' | |',' | |','/_/ '],
	'*' => ['    ','_/\\_','>  <',' \\/ ','    '],
	'+' => ['   _   ',' _| |_ ','|_   _|','  |_|  ','       '],
	',' => ['  ','  ',' _','|/','  '],
	'-' => ['     ',' ___ ','|___|','     ','     '],
	'.' => ['   ','   ',' _ ','<_>','   '],
	'/' => ['   __','  / /',' / / ','/_/  ','     '],
	'0' => [' ___ ','|   |','| / |','`___\'','     '],
	'1' => [' _ ','/ |','| |','|_|','   '],
	'2' => [' ___ ','<_  >',' / / ','<___>','     '],
	'3' => [' ____','<__ /',' <_ \\','<___/','     '],
	'4' => ['  __  ',' /. | ','/_  .|','  |_| ','      '],
	'5' => [' ___ ','| __|','`__ \\','|___/','     '],
	'6' => [' ___ ','| __>','| . \\','`___/','     '],
	'7' => [' ___ ','|_  |',' / / ','/_/  ','     '],
	'8' => [' ___ ','< . >','/ . \\','\\___/','     '],
	'9' => [' ___ ','| . |','`_  /',' /_/ ','     '],
	':' => [' _ ','<_>',' _ ','<_>','   '],
	';' => [' _ ','<_>',' _ ','|/ ','   '],
	'<' => ['  __',' / /','< < ',' \\_\\','    '],
	'=' => [' ___ ','|___|',' ___ ','|___|','     '],
	'>' => ['__  ','\\ \\ ',' > >','/_/ ','    '],
	'?' => [' ___ ','<_. >',' /_/ ',' <_> ','     '],
	'@' => [' ___ ','|  "|','| \\_|','`___/','     '],
	'A' => [' ___ ','| . |','|   |','|_|_|','     '],
	'B' => [' ___ ','| . >','| . \\','|___/','     '],
	'C' => [' ___ ','|  _>','| <__','`___/','     '],
	'D' => [' ___ ','| . \\','| | |','|___/','     '],
	'E' => [' ___ ','| __>','| _> ','|___>','     '],
	'F' => [' ___ ','| __>','| _> ','|_|  ','     '],
	'G' => [' ___  ','/  _> ','| <_/\\','`____/','      '],
	'H' => [' _ _ ','| | |','|   |','|_|_|','     '],
	'I' => [' _ ','| |','| |','|_|','   '],
	'J' => ['  _ ',' | |','_| |','\\__/','    '],
	'K' => [' _ __','| / /','|  \\ ','|_\\_\\','     '],
	'L' => [' _   ','| |  ','| |_ ','|___|','     '],
	'M' => [' __ __ ','|  \\  \\','|     |','|_|_|_|','       '],
	'N' => [' _ _ ','| \\ |','|   |','|_\\_|','     '],
	'O' => [' ___ ','| . |','| | |','`___\'','     '],
	'P' => [' ___ ','| . \\','|  _/','|_|  ','     '],
	'Q' => [' ___ ','| . |','| | |','`___\\','     '],
	'R' => [' ___ ','| . \\','|   /','|_\\_\\','     '],
	'S' => [' ___ ','/ __>','\\__ \\','<___/','     '],
	'T' => [' ___ ','|_ _|',' | | ',' |_| ','     '],
	'U' => [' _ _ ','| | |','| \' |','`___\'','     '],
	'V' => [' _ _ ','| | |','| \' |','|__/ ','     '],
	'W' => [' _ _ _ ','| | | |','| | | |','|__/_/ ','       '],
	'X' => ['__  _ ','\\ \\/  ',' \\ \\  ','_/\\_\\ ','      '],
	'Y' => [' _ _ ','| | |','\\   /',' |_| ','     '],
	'Z' => [' ____','|_  /',' / / ','/___|','     '],
	'[' => [' ___ ','|  _|','| |  ','| |_ ','|___|'],
	'\\' => ['__ __   ','\\ \\\\ \\  ',' \\ \\\\ \\ ','  \\_\\\\_\\','        '],
	']' => [' ___ ','|_  |','  | |',' _| |','|___|'],
	'^' => [' /\\ ','</\\>','    ','    ','    '],
	'_' => ['     ','     ',' ___ ','|___|','     '],
	'`' => ['_ ','\\|','  ','  ','  '],
	'a' => ['     ',' ___ ','<_> |','<___|','     '],
	'b' => [' _   ','| |_ ','| . \\','|___/','     '],
	'c' => ['     ',' ___ ','/ | \'','\\_|_.','     '],
	'd' => ['   _ ',' _| |','/ . |','\\___|','     '],
	'e' => ['     ',' ___ ','/ ._>','\\___.','     '],
	'f' => [' ___ ','| | \'','| |- ','|_|  ','     '],
	'g' => ['     ',' ___ ','/ . |','\\_. |','<___\''],
	'h' => [' _   ','| |_ ','| . |','|_|_|','     '],
	'i' => [' _ ','<_>','| |','|_|','   '],
	'j' => ['  _ ',' <_>',' | |',' | |','<__\''],
	'k' => [' _   ','| |__','| / /','|_\\_\\','     '],
	'l' => [' _ ','| |','| |','|_|','   '],
	'm' => ['       ','._ _ _ ','| \' \' |','|_|_|_|','       '],
	'n' => ['     ','._ _ ','| \' |','|_|_|','     '],
	'o' => ['     ',' ___ ','/ . \\','\\___/','     '],
	'p' => ['     ',' ___ ','| . \\','|  _/','|_|  '],
	'q' => ['     ',' ___ ','/ . |','\\_  |','  |_|'],
	'r' => ['     ',' _ _ ','| \'_>','|_|  ','     '],
	's' => ['    ',' ___','<_-<','/__/','    '],
	't' => ['   _   ',' _| |_ ','  | |  ','  |_|  ','       '],
	'u' => ['     ',' _ _ ','| | |','`___|','     '],
	'v' => ['     ',' _ _ ','| | |','|__/ ','     '],
	'w' => ['       ',' _ _ _ ','| | | |','|__/_/ ','       '],
	'x' => ['    ','__  ','\\ \\/','/\\_\\','    '],
	'y' => ['     ',' _ _ ','| | |','`_. |','<___\''],
	'z' => ['    ','.___',' / /','/___','    '],
	'{' => ['  __',' / /','/ | ','\\ | ',' \\_\\'],
	'|' => ['||','||','||','||','  '],
	'}' => ['__  ','\\ \\ ',' | \\',' | /','/_/ '],
	'~' => ['     ',' /\\/|','|/\\/ ','     ','     '],
	);

sub banner {
	my ($opt, $lines) = @_;

	# Wrap to screen width / $CHARWIDTH
	$lines =~ s/\t/  /g;	# Just convert tabs to two spaces
	# Unfortunately this means -screen_width must be specified
	# before the language.  Ah well.
	$lines = wrap($opt, $lines, $opt->{save_screen_width});

	my $at = 0;
	my @texts;
	foreach my $line ( split(/\n/, $lines) ) {
		if ($line =~ /^\s*[\s\|\\\/_\.\'\`\>\<]+?[\|\\\/_\.\'\`\>\<]+?\s*$/) {
			push(@texts,$line);	# Ugly kludge to avoid double translation...
			next;
		}
		my @text;
		foreach my $ch ( split('', $line) ) {
			$ch = '?' unless $font{$ch};
			my @ch = @{$font{$ch}};
			for (my $i=0; $i<=$#ch; $i++) {
				$text[$i] .= $ch[$i];
			}
		}
		push(@texts,@text);
	}
	join("\n",@texts)."\n";
}

# These routines make wrap() work properly for banner.
sub ch_length {
	my ($ch) = @_;
	$ch = '?' unless $font{$ch};
	length($font{$ch}[0]);
}

sub word_split {
	my ($opt, $word, $width) = @_;
	my @word = split('', $word);
	my $pre = shift(@word);
	my $length = ch_length($pre)+ch_length('-');
	while (@word) {
		my $new_length = ch_length($word[0]);
		last if $length+$new_length > $width;
		$length += $new_length;
		$pre .= shift(@word);
	}
	($pre.'-', join('',@word));
}

sub space_length {
	my ($opt, $space) = @_;
	length($space) * ch_length(' ');
}
sub word_length {
	my ($opt, $word) = @_;
	my $length = 0;
	map($length+=ch_length($_), split('', $word));
	$length;
}

#########################
# Font generation (using figlet)
#########################
# Call as an executable with arg: "-gen"
# Output is perl code, put above to replace "my %font"
if (grep($_ eq '-gen', @ARGV)) {
	# Good fonts to use: figlet bulbhead computer contessa mini short
	my $font = "drpepper";
	print "my %font = (\n";
	foreach my $ord ( 32..126 ) {
		my $ch = chr($ord);
		my $qch = $ch eq "'" ? "\"$ch\"" : $ch eq '\\' ? "'\\\\'" : "'$ch'";
		open(FIG,"figlet -f $font $qch |") || die("Can't run figlet\n");
		my @ch = <FIG>;
		close FIG;
		chomp(@ch);
		print "	$qch => [";
		@ch = map { s/\\/\\\\/g; s/'/\\'/g; "'$_'"; } @ch;
		print join(',', @ch);
		print "],\n";
	}
	print "	);\n";
}

# Language file must return:
1;
