home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / print / ascii2ps / nenscrib / postscri.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  20.1 KB  |  669 lines

  1. /*
  2.  *   $Id: postscri.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  3.  *
  4.  *   This code was written by Craig Southeren whilst under contract
  5.  *   to Computer Sciences of Australia, Systems Engineering Division.
  6.  *   It has been kindly released by CSA into the public domain.
  7.  *
  8.  *   Neither CSA or me guarantee that this source code is fit for anything,
  9.  *   so use it at your peril. I don't even work for CSA any more, so
  10.  *   don't bother them about it. If you have any suggestions or comments
  11.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  12.  *   care of geoffw@extro.ucc.oz.au
  13.  *
  14.  */
  15.  
  16. #include "machdep.h"
  17. #include "defs.h"
  18.  
  19.  
  20. #include "paper.h"
  21. #include "postscri.h"
  22. #include "fontwidt.h"
  23. #include "font_lis.h"
  24.  
  25. /********************************
  26.   defines
  27.  ********************************/
  28.  
  29. #define    TAB     0x9
  30.  
  31. /********************************
  32.   imports
  33.  ********************************/
  34.  
  35. #include "main.h"
  36.  
  37. /********************************
  38.   exports
  39.  ********************************/
  40.  
  41.  
  42. /********************************
  43.   globals
  44.  ********************************/
  45.  
  46. static int  touched_page = False;
  47. static char *CurrentFilename;
  48. static int  WrapFlag;
  49. static int  GaudyFlag;
  50. static int  TabStop;
  51.  
  52. static long Columns;            /* number of columns */
  53. static long X;
  54. static long Y;
  55. static long BFH;                /* body font height */
  56. static long BFW;                /* body font width */
  57. static long TFH;                /* title font height */
  58. static long PageNum;            /* page number within each documenr printed */
  59. static long PageCount;            /* total number of pages printed */
  60. static int  TitleEnabled;        /* True if title to be displayed */
  61.  
  62. static long PW;                /* page width transformed for landscape mode */
  63. static long PH;                /* page height transformed for landscape mode */
  64. static long LM;                /* left margin */
  65. static long RM;                /* right margin */
  66. static long TM;                /* top */
  67. static long BM;                /* bottom margin */
  68. static long WW;                /* width of current print window */
  69. static unsigned int CPL;    /* characters per line */
  70. static long CC;                /* current column */
  71. static long LineNumber;            /* number of line on page (1 top n) */
  72. static long LinesPerPage;        /* number of lines per page, or 0 if to use default */
  73. static char *Classification;        /* points to string to use for classification */
  74. static long ColumnSep;      /* width between columns */
  75.  
  76. static long ClassY;            /* Y location to print classification at */
  77. static long TitleY;            /* Y location to print title at */
  78. static long StartY;            /* Y location to print text from */
  79. static long EndY;            /* Y location to print text down to */
  80. static long ClassBottomY;        /* Y location to print bottom classification at */
  81.  
  82.  
  83.  
  84. /*
  85.  * forward declarations if in ANSI mode
  86.  */
  87.  
  88. #ifdef __STDC__
  89. void          PrintPSString   (FILE *, char *, long);
  90. void          EndPage         (FILE *);
  91. void          StartPage       (FILE *);
  92. void          PrintLine       (FILE *, char *, long, int);
  93. static char * ExtractFontSize (char *, long *);
  94.  
  95. char *font;
  96.  
  97. #endif
  98.  
  99.  
  100. /********************************
  101.   PrintPSString
  102.     Print a string of ASCII characters of length "len" as a
  103.     PostScript string, i.e. enclosed in brackets and with appropriate
  104.     escape characters.
  105.  ********************************/
  106.  
  107. void PrintPSString (stream, line, len)
  108.  
  109. FILE *stream;
  110. char *line;
  111. long len;
  112.  
  113. {
  114.   register long i;
  115.   register char * str = line;
  116.  
  117.   fprintf (stream, "(");
  118.   for (i = 0; i < len ; i++)
  119.     fprintf (stream, "%s%c", str[i] == ')'  ||
  120.                              str[i] == '('  ||
  121.                  str[i] == '\\' ? "\\" : "", str[i]);
  122.   fprintf (stream, ")");
  123. }
  124.  
  125. /********************************
  126.   ExtractFontSize
  127.     Extracts the fontsize from a font type description like "Courier10".
  128.     Also, copy the font name to the fontname ptr
  129.  ********************************/
  130.  
  131. static char * ExtractFontSize (font, fontsize)
  132.  
  133. char *font;
  134. long *fontsize;
  135.  
  136. {
  137.   char *p, *s, *t;
  138.   int i;
  139.  
  140.   /* get ptr to end of string */
  141.   p = &font[strlen(font)-1];
  142.  
  143.   /* move backwards until we find a character that is not a digit */
  144.   while (p > font && isdigit (*p))
  145.     p--;
  146.  
  147.   /* extract the font size */
  148.   *fontsize = atol (++p) * SCALE;
  149.  
  150.   /* now duplicate and copy the font name */
  151.   t = s = (char *)malloc (p - font + 1);
  152.   for (i = p - font; i> 0;i--)
  153.     *t++ = *font++;
  154.   *t = '\0';
  155.  
  156.   return s;
  157. }
  158.  
  159.  
  160.  
  161.  
  162. /********************************
  163.   StartPage
  164.     Called to start a new page
  165.  ********************************/
  166.  
  167. void StartPage (stream)
  168.  
  169. FILE *stream;
  170.  
  171. {
  172.   /* insert a page marker as per the Structuring conventions */
  173.   fprintf (stream, "%%%%Page: %li %li\n", PageNum, PageCount);
  174.  
  175.   /* call the StartPage procedure with the appropriate arguments */
  176.   fprintf (stream, "(%li) ", PageNum);
  177.   PrintPSString (stream, CurrentFilename, strlen (CurrentFilename));
  178.   fprintf (stream, " StartPage\n", PageNum);
  179.  
  180.   /* set X and Y location */
  181.   X = LM;
  182.   Y = StartY;
  183.  
  184.   /* set the column back to column 0 */
  185.   CC = 0;
  186.  
  187.   /* set the line number to line # 1 */
  188.   LineNumber = 1;
  189.  
  190.   /* we have now touched the page */
  191.   touched_page = True;
  192. }
  193.  
  194.  
  195. /********************************
  196.   EndPage
  197.     Called to complete a page
  198.  ********************************/
  199.  
  200. void EndPage (stream)
  201.  
  202. FILE *stream;
  203.  
  204. {
  205.   /* call the end page procedure */
  206.   fprintf (stream, "EndPage\n");
  207.  
  208.   /* increment both the job and document page counters */
  209.   PageNum++;
  210.   PageCount++;
  211.  
  212.   /* now we haven't touched the page */
  213.   touched_page = False;
  214. }
  215.  
  216.  
  217. /*******************************
  218.  
  219.   EndColumn
  220.  
  221.  *******************************/
  222.  
  223. void EndColumn (stream)
  224.  
  225. FILE *stream;
  226.  
  227. {
  228.   LineNumber = 1;
  229.   CC++;
  230.   if (CC == Columns)
  231.     EndPage (stream);
  232.   else {
  233.     X += (ColumnSep * SCALE) + WW;
  234.     Y = StartY;
  235.   }
  236. }
  237.  
  238.  
  239. /********************************
  240.   PrintLine
  241.     Called to print a line which has been chopped to
  242.     the correct length already. The "first" flag indicates
  243.     whether the line is a normal line or a continuation line.
  244.     This routine performs the skipping for indents.
  245.  ********************************/
  246.  
  247. void PrintLine (stream, line, count, first)
  248.  
  249. FILE *stream;
  250. char *line;
  251. long  count;
  252. int  first;
  253.  
  254. {
  255.   char *p;
  256.   long i;
  257.  
  258.   if (!touched_page)
  259.     StartPage (stream);
  260.  
  261.   /* make i point to the first non-blank character on the line */
  262.   for (i = 0; i < count && line[i] == ' ';i++)
  263.     ;
  264.  
  265.   if (i < count) {
  266.     if (!first)
  267.       fprintf (stream, "%li %li K ", Y, X);
  268.     PrintPSString (stream, &line[i], count - i);
  269.     if (i > 0)
  270.       fprintf (stream, " %li %li %i L\n", Y, X, i);
  271.     else
  272.       fprintf (stream, " %li %li T\n", Y, X);
  273.   }
  274.  
  275.   Y -= BFH * 11 / 10;        /* put a little bit of extra spacing between the characters */
  276.   LineNumber++;
  277.  
  278.   if (Y < EndY || (LinesPerPage > 0 && LineNumber > LinesPerPage))
  279.     EndColumn (stream);
  280. }
  281.  
  282. /********************************
  283.   WriteLine
  284.     Writes a line to the output. This routine performs the wrapping and tab expansion
  285.  ********************************/
  286.  
  287. void WriteLine (stream, line)
  288.  
  289. FILE *stream;
  290. char *line;
  291.  
  292. {
  293.   int l;
  294.   int first = True;
  295.   char *p;
  296.   char *q;
  297.   int col;
  298.   int i;
  299.  
  300.   char full_line[8192];
  301.  
  302.   /* expand tabs if we have to */
  303.   if (strchr (line, TAB) != NULL) {
  304.     col = 0;
  305.     q = full_line;
  306.     for (p = line; *p ; p++)
  307.       if (*p != TAB) {
  308.         *q++ = *p;
  309.         col = (col + 1) % TabStop;
  310.       } else {
  311.         for (i = TabStop - col; i > 0; i--)
  312.           *q++ = ' ';
  313.         col = 0;
  314.       }
  315.     *q = 0;
  316.     line = full_line;
  317.   }
  318.  
  319.   if (WrapFlag) {
  320.     while (strlen(line) > CPL) {
  321.       PrintLine (stream, line, CPL, first);
  322.       first = False;
  323.       line += CPL;
  324.     }
  325.     PrintLine (stream, line, strlen(line), first);
  326.   } else
  327.     PrintLine (stream, line, MIN(strlen(line), CPL), True);
  328. }
  329.  
  330.  
  331. /********************************
  332.   StartDocument
  333.     Called when a new document is to be printed. Not to be confused with
  334.     starting the job.
  335.  ********************************/
  336.  
  337. void StartDocument (stream, filename)
  338.  
  339. FILE *stream;
  340. char *filename;
  341.  
  342. {
  343.   /* restart the internal page number */
  344.   PageNum = 1;
  345.  
  346.   /* indicate that the first page has not yet been touched */
  347.   touched_page = False;
  348.  
  349.   /* and set the current filename */
  350.   CurrentFilename = filename;
  351. }
  352.  
  353.  
  354. /********************************
  355.   EndDocument
  356.     Called when a document has been completed.
  357.  ********************************/
  358.  
  359. void EndDocument (stream)
  360.  
  361. FILE *stream;
  362.  
  363. {
  364.   /* if we have drawn a partial page, finish it off properly */
  365.   if (touched_page)
  366.     EndPage (stream);
  367. }
  368.  
  369. /********************************
  370.   StartJob
  371.     Called when a new job is to be started. This performs all of the
  372.     PostScript initialisation
  373.  ********************************/
  374.  
  375. void StartJob (stream, filename, landscape, columns, BodyFont,
  376.                TitleFont, wrap, enabletitle, title, copies, gaudy, force_lines, classification, papermetrics, tabstop)
  377.  
  378.  
  379. FILE * stream;
  380. int  landscape;
  381. int  columns;
  382. char *BodyFont;
  383. char *TitleFont;
  384. int  wrap;
  385. int  enabletitle;
  386. char *title;
  387. int  copies;
  388. int  gaudy;
  389. int  force_lines;
  390. char *filename;
  391. char *classification;
  392. struct PaperMetrics *papermetrics;
  393. int  tabstop;
  394.  
  395. {
  396.   char *bodyfont;
  397.   char *titlefont;
  398.   char *gaudyPNfont;
  399.   char *gaudytitlefont;
  400.   char *gaudydatefont;
  401.   char *classfont;
  402.   long  gaudyPNfontsize;
  403.   long  gaudytitlefontsize;
  404.   long  gaudydatefontsize;
  405.   long  classfontsize;
  406.  
  407.   time_t thetime = time(NULL);
  408.   char  * timestring = strtok(ctime (&thetime), "\n");  /* a simple time string */
  409.   struct tm *tm      = localtime (&thetime);
  410.   char tm_string[15];
  411.   char dt_string[15];
  412.  
  413.   /* get the time and date strings */
  414.   GETDATE (tm, dt_string);
  415.   GETTIME (tm, tm_string);
  416.  
  417.   /* make local copies of various flags */
  418.   WrapFlag       = wrap;
  419.   GaudyFlag      = gaudy && enabletitle;
  420.   TitleEnabled   = enabletitle;
  421.   Columns        = columns;
  422.   LinesPerPage   = force_lines;
  423.   Classification = classification;
  424.   ColumnSep      = papermetrics->ColumnSep;
  425.   TabStop        = tabstop;
  426.  
  427.   /* get the size and width of the font used for the body of the text */
  428.   bodyfont = ExtractFontSize (BodyFont, &BFH);
  429.   BFW      = GetFontWidth    (bodyfont, BFH);
  430.  
  431.   /* extract various font sizes */
  432.   gaudyPNfont    = ExtractFontSize (papermetrics->GaudyPNFont,    &gaudyPNfontsize);
  433.   gaudytitlefont = ExtractFontSize (papermetrics->GaudyTitleFont, &gaudytitlefontsize);
  434.   gaudydatefont  = ExtractFontSize (papermetrics->GaudyDateFont,  &gaudydatefontsize);
  435.  
  436.   /* get the size of the font used for the title */
  437.   titlefont = ExtractFontSize (TitleFont, &TFH);
  438.  
  439.   /* now the classification font, if there is one */
  440.   if (Classification != NULL)
  441.     classfont = ExtractFontSize (papermetrics->ClassificationFont, &classfontsize);
  442.  
  443.   /* output obligatory Postscript header */
  444.   fprintf (stream, "%%!PS-Adobe-1.0\n");
  445.  
  446.   /* output the filename of the first file as the title */
  447.   fprintf (stream, "%%%%Title: %s\n", filename);
  448.  
  449.   /* put version of program in as creator */
  450.   fprintf (stream, "%%%%Creator: %s\n", version_string);
  451.  
  452.   /* extract the users full name and put in as the creator */
  453.   fprintf (stream, "%%%%For: %s\n", USERNAME);
  454.  
  455.   /* put in the time as a string */
  456.   fprintf (stream, "%%%%CreationDate: %s\n", timestring);
  457.  
  458.   /* output the font list */
  459.   add_font_to_list (titlefont);
  460.   add_font_to_list (bodyfont);
  461.   if (GaudyFlag) {
  462.     add_font_to_list (gaudyPNfont);
  463.     add_font_to_list (gaudydatefont);
  464.     add_font_to_list (gaudytitlefont);
  465.   }
  466.   if (Classification != NULL)
  467.     add_font_to_list (classfont);
  468.  
  469.   fprintf (stream, "%%%%DocumentFonts: ");
  470.   enumerate_fonts (stream);
  471.   fprintf (stream, "\n");
  472.  
  473.   /* initialise the document page counter and indicate that the page count info
  474.      can be found at the end of the document. This copout means we don't have
  475.      to store the output data in a temporary file (like enscript) just so we can
  476.      find out how many pages there are */
  477.   PageCount = 1;
  478.   fprintf (stream, "%%%%Pages: (atend)\n");
  479.  
  480.   /* End of header marker */
  481.   fprintf (stream, "%%%%EndComments\n");
  482.  
  483.   /* scale the coordinate system by SCALE so we can use integer arithmetic
  484.      without losing accuracy */
  485.   fprintf (stream, "1 %li div dup scale\n", SCALE);
  486.  
  487.   /* use the Postscript mechanism for duplicating pages, rather than using a flag to lpr.
  488.      This mechanism means less data (I think!!) but it requires you to edit the file
  489.      if you want to print a different number of copies later. It is so rarely used that
  490.      it isn't really an issue anyway!! */
  491.   fprintf (stream, "/#copies %i def\n", copies);
  492.  
  493.   /* rotate the page if using landscape mode, and set PW and PH to the page width and height
  494.      as determined by the SCALE factor */
  495.   if (landscape) {
  496.     PW = papermetrics->PaperHeight * SCALE;
  497.     PH = papermetrics->PaperWidth * SCALE;
  498.  
  499.     LM = PAGE_BOT_MARGIN * SCALE;
  500.     RM = PAGE_TOP_MARGIN * SCALE;
  501.  
  502.     TM = PAGE_LEFT_MARGIN * SCALE;
  503.     BM = PAGE_RIGHT_MARGIN * SCALE;
  504.  
  505.     fprintf (stream, "90 rotate %li %li translate\n",PAGE_LANDSCAPE_XOFFS, PAGE_LANDSCAPE_YOFFS - PH);
  506.   } else {
  507.     PH = papermetrics->PaperHeight * SCALE;
  508.     PW = papermetrics->PaperWidth * SCALE;
  509.  
  510.     LM = PAGE_LEFT_MARGIN * SCALE;
  511.     RM = PAGE_RIGHT_MARGIN * SCALE;
  512.  
  513.     TM = PAGE_TOP_MARGIN * SCALE;
  514.     BM = PAGE_BOT_MARGIN * SCALE;
  515.   }
  516.  
  517.    /* calculate the width of the "window" in which we draw text, and from that calculate the
  518.      number of characters per line (CPL) */
  519.   WW = (PW - (LM + RM) - ((columns - 1) * papermetrics->ColumnSep * SCALE)) / columns;
  520.   CPL = (unsigned int)(WW / BFW);
  521.  
  522.   /* calculate the top position at which we start drawing text */
  523.   StartY = PH - TM;
  524.  
  525.   /* adjust starting position if we are printing security classification */
  526.   if (Classification != NULL) {
  527.     StartY -= classfontsize;
  528.     ClassY = StartY;
  529.   }
  530.  
  531.   /* adjust starting position if we are printing title */
  532.   if (TitleEnabled) {
  533.     if (GaudyFlag)  {
  534.       TitleY = StartY;
  535.       StartY -= (papermetrics->GaudyBoxHeight * SCALE) + BFH; /* StartY -= BH + BFH; */
  536.     } else {
  537.       StartY -= TFH;
  538.       TitleY = StartY;
  539.       StartY -= BFH;
  540.     }
  541.   }
  542.  
  543.   /* move down one line below for start of text */
  544.   StartY -= BFH;
  545.  
  546.   /* calculate the last location on the page to be printing text */
  547.   EndY = BM;
  548.   if (Classification != NULL) {
  549.     ClassBottomY = BM;
  550.     EndY += classfontsize;
  551.   }
  552.  
  553.   /* define a variable for our body font, and calculate the character width for later use */
  554.   fprintf (stream, "/BodyF /%s findfont %li scalefont def\n", bodyfont, BFH);
  555.   fprintf (stream, "/CW BodyF setfont ( ) stringwidth pop def\n");
  556.  
  557.   /* define variables for various other font used - title, gaudy page number, gaudy date, gaudy title */
  558.   fprintf (stream, "/Titlef  /%s findfont %li scalefont def\n", titlefont, TFH);
  559.   if (GaudyFlag) {
  560.     fprintf (stream, "/Gpnf    /%s findfont %li scalefont def\n", gaudyPNfont,    gaudyPNfontsize);
  561.     fprintf (stream, "/Gdatef  /%s findfont %li scalefont def\n", gaudydatefont,  gaudydatefontsize);
  562.     fprintf (stream, "/Gtitlef /%s findfont %li scalefont def\n", gaudytitlefont, gaudytitlefontsize);
  563.   }
  564.  
  565.   /* define procedures for drawing continuation line markers, continuation lines, normal lines, and performing indents */
  566.   fprintf (stream, "/K         { -2 CW mul add exch moveto (+) show } def\n");
  567.   fprintf (stream, "/L         { CW mul add exch moveto show } def\n");
  568.   fprintf (stream, "/T         { exch moveto show } def\n");
  569.   fprintf (stream, "/M         { CW mul 0 rmoveto } def\n");
  570.   fprintf (stream, "/Centre    { dup stringwidth pop 2 div neg 0 rmoveto } def\n");
  571.  
  572.   /* define procedures for drawing gaudy page numbers, gaudy boxes, gaudy bars and gaudy titles */
  573.   if (GaudyFlag) {
  574.     fprintf (stream, "/Gb        { newpath moveto %li 0 rlineto 0 %li rlineto -%li 0 rlineto fill } def\n",
  575.                                       papermetrics->GaudyBoxWidth  * SCALE,   /* BW */
  576.                                       papermetrics->GaudyBoxHeight * SCALE,   /* BH */
  577.                                       papermetrics->GaudyBoxWidth  * SCALE);  /* BW */
  578.     fprintf (stream, "/Gr        { newpath moveto %li 0 rlineto 0 %li rlineto -%li 0 rlineto fill } def\n",
  579.                                        PW - (LM + RM) - (2 * papermetrics->GaudyBoxWidth  * SCALE), papermetrics->GaudyBarHeight  * SCALE,
  580.                                        PW - (LM + RM) - (2 * papermetrics->GaudyBoxWidth  * SCALE));
  581.     fprintf (stream, "/G         { %s setgray %li %li Gb %li %li Gb %s setgray %li %li Gr } def\n",
  582.                     BOXGRAY,
  583.                     LM, TitleY - (papermetrics->GaudyBoxHeight * SCALE),                          /* pos of left box */
  584.                       PW - RM - (papermetrics->GaudyBoxWidth * SCALE), TitleY - (papermetrics->GaudyBoxHeight * SCALE),                /* pos of right box */
  585.                     BARGRAY,
  586.                     LM + (papermetrics->GaudyBoxWidth * SCALE), TitleY - (papermetrics->GaudyBoxHeight * SCALE));               /* pos of bar */
  587.   }
  588.  
  589.   /* define stuff for security strings */
  590.   if (Classification != NULL) {
  591.     fprintf (stream, "/Classf  /%s findfont %li scalefont def\n", classfont, classfontsize);
  592.     fprintf (stream, "/ClassString ");
  593.     PrintPSString (stream, Classification, strlen(classification));
  594.     fprintf (stream, " def\n");
  595.   }
  596.  
  597.   /* if we have titles enabled, define an appropriate procedure for drawing it */
  598.   /* define the start page procedure used to start every page */
  599.   fprintf (stream, "/StartPage { /SavedPage save def\n");
  600.   if (Classification != NULL)
  601.       fprintf (stream, "  Classf setfont %li %li moveto ClassString Centre 0 setgray show\n", PW / 2, ClassY);
  602.  
  603.   if (TitleEnabled) {
  604.     if (GaudyFlag) {
  605.       fprintf (stream, "  G\n");                                                   /* draw boxes */
  606.       fprintf (stream, "  Gtitlef setfont %li %li moveto Centre 0 setgray show\n",   /* title */
  607.                                          ((LM + (papermetrics->GaudyBoxWidth  * SCALE)) +
  608.                                            (PW - RM - (papermetrics->GaudyBoxWidth  * SCALE))) / 2L,
  609.                                          TitleY - (papermetrics->GaudyBoxHeight * SCALE) +
  610.                                          (((papermetrics->GaudyBarHeight  * SCALE) * 7L / 10L) / 2L));
  611.       if (title != NULL) {
  612.         fprintf (stream, "%li %li moveto ",
  613.                                          ((LM + (papermetrics->GaudyBoxWidth * SCALE)) + (PW - RM - (papermetrics->GaudyBoxWidth * SCALE))) / 2L,
  614.                                          TitleY - (((papermetrics->GaudyBarHeight * SCALE) * 7L / 10L) / 2L));
  615.         PrintPSString (stream, title, strlen(title));
  616.         fprintf (stream, " Centre show\n");
  617.       }
  618.       fprintf (stream, "  Gpnf    setfont %li %li moveto Centre 1 setgray show\n",   /* page number */
  619.                                          PW - RM - ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  620.                                          TitleY - ((papermetrics->GaudyBoxHeight * SCALE) / 2L) - gaudyPNfontsize * 7L / 20L);
  621.       fprintf (stream, "  Gdatef  setfont %li %li moveto (%s) Centre 0 setgray show\n",
  622.                      LM + ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  623.                      TitleY - ((papermetrics->GaudyBoxHeight * SCALE) * 3L / 5L) - gaudydatefontsize * 7L / 10L, tm_string);
  624.       fprintf (stream, "                  %li %li moveto (%s) Centre show\n",
  625.                      LM + ((papermetrics->GaudyBoxWidth * SCALE) / 2L),
  626.                      TitleY - ((papermetrics->GaudyBoxHeight * SCALE) * 3L / 5L) + gaudydatefontsize * 7L / 10L, dt_string);
  627.     } else {
  628.       fprintf (stream, "  0 setgray Titlef setfont %li %li moveto ", LM, TitleY);
  629.       if (title != NULL) {
  630.         fprintf (stream, "pop pop ");
  631.         PrintPSString (stream, title, strlen(title));
  632.         fprintf (stream, " show\n");
  633.       } else {
  634.         fprintf (stream, "show 8 M ");
  635.         PrintPSString (stream, timestring, strlen (timestring));
  636.         fprintf (stream, " show 8 M show\n");
  637.       }
  638.     }
  639.   }
  640.   fprintf (stream, "  BodyF setfont 0 setgray } def\n");
  641.  
  642.   /* define end page procedure */
  643.   fprintf (stream, "/EndPage   {");
  644.   if (GaudyFlag && Columns == 2)
  645.     fprintf (stream, " %li %li moveto %li -%li rlineto stroke ", LM + WW + (papermetrics->ColumnSep * SCALE / 2), StartY, 0L, StartY - EndY);
  646.   if (Classification != NULL)
  647.       fprintf (stream, "  Classf setfont %li %li moveto ClassString Centre 0 setgray show\n", PW / 2, ClassBottomY);
  648.   fprintf (stream, "showpage SavedPage restore } def\n");
  649.  
  650.   /* end of the header */
  651.   fprintf (stream, "%%%%EndProlog\n");
  652. }
  653.  
  654. /********************************
  655.    EndJob
  656.  ********************************/
  657.  
  658. void EndJob (stream)
  659.  
  660. FILE *stream;
  661.  
  662. {
  663.   /* indicate this is the end of the file */
  664.   fprintf (stream, "%%%%Trailer\n");
  665.  
  666.   /* now we know how many pages there are!! */
  667.   fprintf (stream, "%%%%Pages: %li\n", PageCount - 1);
  668. }
  669.