home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / graphics / gl.pak / G_PRINT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  6.7 KB  |  222 lines

  1. #ifndef lint
  2. static char sccsid[] = "@(#) g_print.c 5.1 89/02/20";
  3. #endif
  4. /*
  5.  *    Copyright (c) David T. Lewis 1987, 1988, 1989
  6.  *    All rights reserved.
  7.  *
  8.  *    Permission is granted to use this for any personal noncommercial use.
  9.  *    You may not distribute source or executable code for profit, nor
  10.  *    may you distribute it with a commercial product without the written
  11.  *    consent of the author.  Please send modifications to the author for
  12.  *    inclusion in updates to the program.  Thanks.
  13.  */
  14. /* Sat Feb 18 15:54:14 EST 1989                        */
  15. /* Printer specific code.                        */
  16. #include <stdio.h>
  17. #include "config.h"
  18. #if MS_DOS
  19. #include <stdlib.h>
  20. #endif /* MS_DOS */
  21. #if XENIX_286
  22. #include <sys/fcntl.h>
  23. #include <sys/machdep.h>
  24. #include <sys/sysmacros.h>
  25. #endif /* XENIX_286 */
  26. #include "bitmaps.h"
  27. #include "gf_types.h"
  28. #include "graphics.h"
  29. #include "modes.h"
  30. /* Use BIOS output for printer on MS-DOS.    */
  31. #if MS_DOS
  32. extern int bios_print();
  33. #define FWRITE(a,b,c,d) bios_print(a,b,c)
  34. #else
  35. #define FWRITE(a,b,c,d) fwrite(a,b,c,d)
  36. #endif /* MS_DOS */
  37. extern struct GL_graphics graphics;
  38. #define FORM_FEED (014)
  39. #define EPSON_START_GRAPHICS 033, 'A', 07, 033, 02
  40. #define IBM_START_GRAPHICS 033, '1'
  41. #define IBM_PAGE_END 033, 'A', 014, 033, 02
  42. #define IBM_LINE_START 033, 'L', 0300, 03
  43. #define IBM_LINE_END 015, 012
  44. static char IBM_pg_top[] = {EPSON_START_GRAPHICS, IBM_START_GRAPHICS};
  45. static char IBM_pg_end[] = {IBM_PAGE_END};
  46. static char IBM_pg_ff_end[] = {IBM_PAGE_END, FORM_FEED};
  47. static char IBM_ln_start[] = {IBM_LINE_START};
  48. static char IBM_ln_end[] = {IBM_LINE_END};
  49. #define LJ_RESET 033, 'E'
  50. #define LJ_150_DPI 033, '*', 't', '1', '5', '0', 'R'    /* 150 dpi graphics */
  51. #define LJ_CUR_HOME 033, '&', 'a', '3', 'C'          /* Cursor to column 3 */
  52. #define LJ_START_GRAPHICS 033, '*', 'r', '1', 'A'
  53. #define LJ_XFER_GRAPHICS 033, '*', 'b', '1', '4', '0', 'W'     /* 140 bytes */
  54. #define LJ_END_GRAPHICS 033, '*', 'r', 'B'
  55. static char LJ_pg_top[]={LJ_RESET, LJ_150_DPI, LJ_CUR_HOME, LJ_START_GRAPHICS};
  56. static char LJ_pg_end[] = {LJ_END_GRAPHICS, LJ_RESET};
  57. static char LJ_pg_ff_end[] = {LJ_END_GRAPHICS, LJ_RESET};
  58. static char LJ_ln_start[] = {LJ_XFER_GRAPHICS};
  59. static char LJ_ln_end[] = {0};    /* No line end needed */
  60. /* A do-nothing function.  The printer function pointers will initially    */
  61. /* point to this, just to avoid core dumps later on.            */
  62. static int null_function(fp)
  63. FILE *fp;
  64. {
  65.     return(0);
  66. }
  67. /* For printers, the following four functions send data required to    */
  68. /* start the print, end the print, start each line, and end each line.    */
  69. /* These function pointers are defined globally here, and are used to    */
  70. /* send data to printers in g_finish().  These are initialized to a    */
  71. /* safe value now, and set to the appropriate values for the current    */
  72. /* graphics mode later in g_init().                    */
  73. int (*pr_head)() = null_function;
  74. int (*pr_tail)() = null_function;
  75. int (*pr_lnst)() = null_function;
  76. int (*pr_lnend)() = null_function;
  77. /* Following is the device specific code for each printer (sorry, there    */
  78. /* is only one working so far, but I like to plan ahead).        */
  79. /* Start of IBM or Epson compatible dot matrix printer code.        */
  80. int IBM_head(fp)
  81. FILE *fp;
  82. {
  83.     /* Begin graphics mode; set line spacing    */
  84.     if((FWRITE(IBM_pg_top,sizeof(char),sizeof(IBM_pg_top),fp)) <
  85.         sizeof(IBM_pg_top)) return(1);
  86.     else return(0);
  87. }
  88. int IBM_tail(fp)
  89. FILE *fp;
  90. {
  91.     /* End of page, begin text mode                    */
  92. #if HAS_PIPES
  93.     if((FWRITE(IBM_pg_end,sizeof(char),sizeof(IBM_pg_end),fp)) <
  94.         sizeof(IBM_pg_end)) return(1);
  95.     else return(0);
  96. #else
  97.     /* If we are not piping to a print spooler program, then we    */
  98.     /* need to supply our own form feed command.            */
  99.     if((FWRITE(IBM_pg_ff_end,sizeof(char),sizeof(IBM_pg_ff_end),fp)) <
  100.         sizeof(IBM_pg_ff_end)) return(1);
  101.     else return(0);
  102. #endif /* HAS_PIPES */
  103. }
  104. int IBM_lnst(fp)
  105. FILE *fp;
  106. {
  107.     /* Start a line of graphics data    */
  108.     if((FWRITE(IBM_ln_start,sizeof(char),sizeof(IBM_ln_start),fp)) <
  109.         sizeof(IBM_ln_start)) return(1);
  110.     else return(0);
  111. }
  112. int IBM_lnend(fp)
  113. FILE *fp;
  114. {
  115.     /* End line of graphics data        */
  116.     if((FWRITE(IBM_ln_end,sizeof(char),sizeof(IBM_ln_end),fp)) <
  117.         sizeof(IBM_ln_end)) return(1);
  118.     else return(0);
  119. }
  120. int IBM_send_print(fp)
  121. FILE *fp;
  122. #define MODULE "IBM_send_print"
  123. {
  124.     int idx;
  125.     /* Dump the print image to the file    */
  126.     /* Set line feed pitch for graphics    */
  127.     (*pr_head)(fp);
  128.     /* Write the lines of data (3 buffers full) */
  129.     for (idx=0; idx<PRINTLINES; idx++)  {
  130.         (*pr_lnst)(fp);
  131.         FWRITE(&(graphics.printbuf1->buf[idx][0]),
  132.             sizeof(char), PRINTDENSITY, fp);
  133.         (*pr_lnend)(fp);
  134.     }
  135.     for (idx=0; idx<PRINTLINES; idx++)  {
  136.         (*pr_lnst)(fp);
  137.         FWRITE(&(graphics.printbuf2->buf[idx][0]),
  138.             sizeof(char), PRINTDENSITY, fp);
  139.         (*pr_lnend)(fp);
  140.     }
  141.     for (idx=0; idx<PRINTLINES; idx++)  {
  142.         (*pr_lnst)(fp);
  143.         FWRITE(&(graphics.printbuf3->buf[idx][0]),
  144.             sizeof(char), PRINTDENSITY, fp);
  145.         (*pr_lnend)(fp);
  146.     }
  147.     /* Set line feed pitch back for text    */
  148.     if ((*pr_tail)(fp))  {
  149.         fprintf(stderr,"%s: unable to write to printer\n",MODULE);
  150.         return(1);
  151.     }
  152.     return(0);
  153. }
  154. /* End of IBM or Epson compatible dot matrix printer code.        */
  155. /* Start of Laserjet+ printer code.        */
  156. int LJ_head(fp)
  157. FILE *fp;
  158. {
  159.     /* Begin graphics mode; set line spacing    */
  160.     if((FWRITE(LJ_pg_top,sizeof(char),sizeof(LJ_pg_top),fp)) <
  161.         sizeof(LJ_pg_top)) return(1);
  162.     else return(0);
  163. }
  164. int LJ_tail(fp)
  165. FILE *fp;
  166. {
  167.     /* End of page, reset and eject page    */
  168.     if((FWRITE(LJ_pg_end,sizeof(char),sizeof(LJ_pg_end),fp)) <
  169.         sizeof(LJ_pg_end)) return(1);
  170.     else return(0);
  171. }
  172. int LJ_lnst(fp)
  173. FILE *fp;
  174. {
  175.     /* Start a line of graphics data    */
  176.     if((FWRITE(LJ_ln_start,sizeof(char),sizeof(LJ_ln_start),fp)) <
  177.         sizeof(LJ_ln_start)) return(1);
  178.     else return(0);
  179. }
  180. int LJ_lnend(fp)
  181. FILE *fp;
  182. {
  183.     /* End line of graphics data        */
  184.     return(0);
  185. }
  186. int LJ_send_print(fp)
  187. FILE *fp;
  188. #undef MODULE
  189. #define MODULE "LJ_send_print"
  190. {
  191.     int idx;
  192.     /* Dump the print image to the file    */
  193.     /* Start page of graphics */
  194.     (*pr_head)(fp);
  195.     /* Write the lines of data (3 buffers full) */
  196.     for (idx=0; idx<LJ_LINES; idx++)  {
  197.         (*pr_lnst)(fp);
  198.         FWRITE(&(graphics.lj_buf1->buf[idx][0]),
  199.             sizeof(char), LJ_BYTES_PER_LINE, fp);
  200.         (*pr_lnend)(fp);
  201.     }
  202.     for (idx=0; idx<LJ_LINES; idx++)  {
  203.         (*pr_lnst)(fp);
  204.         FWRITE(&(graphics.lj_buf2->buf[idx][0]),
  205.             sizeof(char), LJ_BYTES_PER_LINE, fp);
  206.         (*pr_lnend)(fp);
  207.     }
  208.     for (idx=0; idx<LJ_LINES; idx++)  {
  209.         (*pr_lnst)(fp);
  210.         FWRITE(&(graphics.lj_buf3->buf[idx][0]),
  211.             sizeof(char), LJ_BYTES_PER_LINE, fp);
  212.         (*pr_lnend)(fp);
  213.     }
  214.     /* End of page */
  215.     if ((*pr_tail)(fp))  {
  216.         fprintf(stderr,"%s: unable to write to printer\n",MODULE);
  217.         return(1);
  218.     }
  219.     return(0);
  220. }
  221. /* End of Laserjet+ printer code.        */
  222.