#!/usr/bin/perl
#
# show_url.p: Print filter to overlay page title on output page
# author:   S. Edward Hawkins III  
# date:     1999 October 20
#           
# HISTORY: 20 October 1999. Created seh3.
#          03 January 2000. converted to perl from bash (Richard Mitchell)

$URL="/usr/local/bin/url|";  # use T.Edwards program to grab URL
                              # from active Netscape window
open(URL, $URL) || die("Unable to open $URL\n");
chop($url=<URL>);
close(URL);

while ($label=<STDIN>) {
    SWITCH: for ($label) {
        /%%Title:/
	&& do { $title=$label; chop($title); $title =~ s/%%Title://;};
        /%%Orientation: Portrait/
	&& do { $layout="portrait"; $xpos=576; $ypos=774};
        /%%Orientation: Landscape/
	&& do { $layout="landscape";$xpos=30; $ypos=756};
        /showpage/
	&& do {
            if ( $layout =~ "portrait" ) {
               printf("gsave 0 0 translate\n");
               printf("/Times-Roman findfont 8 scalefont setfont\n");
               printf("36 $ypos moveto \($title\) show\n");
               printf("%%%%%% GET LENGTH OF URL STRING FOR RIGHT JUSTIFICATION\n");
               printf("\($url\) stringwidth pop $xpos exch sub\n");
               printf("$ypos moveto \($url\) show grestore\n");

            } elsif ($layout =~ "landscape" ) {
               printf("gsave 0 0 translate\n");
               printf("/Times-Roman findfont 8 scalefont setfont \n");
               printf("$xpos 36 moveto 90 rotate \($title\) show -90 rotate\n");
               printf("%%%%%% GET LENGTH OF URL STRING FOR RIGHT JUSTIFICATION\n");
               printf("\($url\) stringwidth pop $ypos exch sub $xpos \n");
               printf(" exch moveto  90 rotate \($url\) show grestore\n");
            }
        };
        printf("$label");
    }
}
