% 
% Enscript styled header.
% Copyright (c) 1995 Markku Rossi.
% Author: Markku Rossi <mtr@iki.fi>
%

%
% This file is part of GNU Enscript.
% 
% Enscript is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Enscript is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
%

% -- code follows this line --
%%DocumentNeededResources: font Times-Bold Times-Roman
%Format: moddatestr	$W
%Format: modtimestr	$C
%Format: pagenumstr	$%

% Fonts.
/Times-Bold /HeaderFont-Bold MF
/HeaderDateF /HeaderFont-Bold findfont 12 scalefont def

/Times-Roman /HeaderFont-Times MF
/HeaderHDRF /HeaderFont-Times findfont 14 scalefont def

/HeaderPageNumF /Helvetica-Bold findfont 28.8 scalefont def

/do_header {	% print enscript header
  gsave
    d_header_x d_header_y translate

    % light bar
    0 0 d_header_w d_header_h 2 div Box
    .95 setgray fill

    % dark gray boxes
    /dbw d_header_h 2 mul def	% dark box width
    /dbc .7 def			% dark box color

    % left dark box.
    0 0 dbw d_header_h Box
    dbc setgray fill

    0 setgray 
    HeaderDateF setfont
    moddatestr dup stringwidth pop dbw exch sub 2 div 
    d_header_h 2 div 2 add moveto show
    modtimestr dup stringwidth pop dbw exch sub 2 div 
    d_header_h 5 div moveto show

    % right dark box
    d_header_w dbw sub 0 dbw d_header_h Box
    dbc setgray fill

    HeaderPageNumF setfont
    1 setgray
    pagenumstr dup
    stringwidth pop dbw exch sub 2 div d_header_w dbw sub add
    d_header_h .2 mul moveto show

    % filename
    0 setgray 
    HeaderHDRF setfont
    d_header_w fname stringwidth pop sub 2 div d_header_h 8 div moveto
    fname show

    % user supplied header string.
    user_header_p {
      /h d_header_h 8 div 5 mul def

      % Implement strict enscript compatibility.
      user_header_center_str () eq user_header_right_str () eq and {
        d_header_w user_header_left_str stringwidth pop sub 2 div 
        h moveto user_header_left_str show
      } {
        dbw 5 add h moveto user_header_left_str show

        d_header_w user_header_center_str stringwidth pop sub 2 div 
        h moveto user_header_center_str show

	d_header_w dbw sub 5 sub user_header_right_str stringwidth pop
	sub h moveto user_header_right_str show
      } ifelse
    } if

  grestore
} def
