#!/usr/local/bin/perl

# Gosen version 0.02
# Copyright (C) 2001, 2002 Kaname Funakoshi

$version = "Gosen version 0.02. Copyright (C) 2001, 2002 Kaname Funakoshi";

$top_margin	= -1;
$bottom_margin	= 60;
$row_margin	= 60;
$line_width	= .2;
$nb_rows	= 12;
$left_margin	= 60;
$right_margin	= 5;
$line_margin	= 5;
$nb_lines	= 5;	# can print 4, 6, or any number of lines

$paper	= "a4";

# a3        11.7 x 16.5   29.7 x 42.0    842 x 1190
# a4         8.3 x 11.7   21.0 x 29.7    595 x  842
# a5         5.8 x  8.3   14.9 x 21.0    421 x  595
# b5         7.0 x  9.8   17.7 x 25.0    501 x  709
# letter     8.5 x 11.0   21.6 x 27.9    612 x  792
# legal      8.5 x 14.0   21.6 x 35.6    612 x 1008
# 11x17     11.0 x 17.0   27.9 x 43.2    792 x 1224   11x17  portrait
# ledger    17.0 x 11.0   43.2 x 27.9   1224 x  792   11x17 landscape
if ($paper eq "a4"){
	$pheight = 842; $pwidth = 595;
} elsif ($paper eq "letter"){
	$pheight = 792; $pwidth = 612;
} else {
	printf STDERR "unrecognized paper size\n";
	exit;
}

$box_height	= ($nb_lines - 1) * $line_margin;
$box_width	= $pwidth - $left_margin - $right_margin;

if (($top_margin >= 0) && ($bottom_margin >= 0)){
# ignore defined row_margin
	$row_margin = 
		($pheight - $top_margin - $bottom_margin - $box_height)
		/ ($nb_rows -1);

}

print << "__END_OF_FILE__";
%!PS-Adobe-2.0
%%Creator: $version
%%Title: Gosen
%%Pages: 1
%%BoundingBox: 0 0 $pwidth $pheight
%%EndComments
%!

% box_height = $box_height
% top_margin = $top_margin

/hline {$box_width 0 rlineto stroke} def	% strike a $box_width pt holizonal line

/startpoint {0 exch add moveto} def

/nextline {
	newpath
	$left_margin exch startpoint
	hline
} def

$line_width setlinewidth

0 $bottom_margin translate

$nb_rows {
	newpath
	$left_margin 0 startpoint
	hline
	$line_margin $line_margin $box_height {nextline} for
	0 $row_margin translate
} repeat

showpage
__END_OF_FILE__

