home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GDEVDFAX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-30  |  3.5 KB  |  114 lines

  1. /* Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevdfax.c */
  20. /* DigiBoard fax device. */
  21. /***
  22.  *** Note: this driver is maintained by a user: please contact
  23.  ***       Rick Richardson (rick@digibd.com) if you have questions.
  24.  ***/
  25. #include "gdevprn.h"
  26. #include "strimpl.h"
  27. #include "scfx.h"
  28.  
  29. /* Import the key routines from gdevtfax.c. */
  30. const gx_device_paper_info *gdev_fax_paper_size(P1(gx_device *dev));
  31. int gdev_fax_print_page(P3(gx_device_printer *, FILE *, stream_CFE_state *));
  32.  
  33. /* Define the device parameters. */
  34. #define X_DPI 204
  35. #define Y_DPI 196
  36.  
  37. /* The device descriptors */
  38.  
  39. private dev_proc_open_device(dfax_prn_open);
  40. private dev_proc_print_page(dfax_print_page);
  41.  
  42. struct gx_device_dfax_s {
  43.     gx_device_common;
  44.     gx_prn_device_common;
  45.     long pageno;
  46.     uint iwidth;        /* width of image data in pixels */
  47. };
  48. typedef struct gx_device_dfax_s gx_device_dfax;
  49.  
  50. private gx_device_procs dfax_procs =
  51.   prn_procs(dfax_prn_open, gdev_prn_output_page, gdev_prn_close);
  52.  
  53. gx_device_dfax far_data gs_dfaxlow_device =
  54. {   prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxlow",
  55.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  56.     X_DPI, Y_DPI/2,
  57.     0,0,0,0,            /* margins */
  58.     1, dfax_print_page)
  59. };
  60.  
  61. gx_device_dfax far_data gs_dfaxhigh_device =
  62. {   prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxhigh",
  63.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  64.     X_DPI, Y_DPI,
  65.     0,0,0,0,            /* margins */
  66.     1, dfax_print_page)
  67. };
  68.  
  69. #define dfdev ((gx_device_dfax *)dev)
  70.  
  71. /* Open the device, adjusting the paper size. */
  72. private int
  73. dfax_prn_open(gx_device *dev)
  74. {    const gx_device_paper_info *pi = gdev_fax_paper_size(dev);
  75.     dev->width = (int)(pi->width_inches * dev->x_pixels_per_inch);
  76.     dev->height = (int)(pi->height_inches * dev->y_pixels_per_inch);
  77.     dfdev->iwidth = pi->width;
  78.     dfdev->pageno = 0;
  79.     return gdev_prn_open(dev);
  80. }
  81.  
  82. /* Print a DigiFAX page. */
  83. private int
  84. dfax_print_page(gx_device_printer *dev, FILE *prn_stream)
  85. {    stream_CFE_state state;
  86.     static char hdr[64] = "\000PC Research, Inc\000\000\000\000\000\000";
  87.     int code;
  88.  
  89.     state.K = 0;
  90.     state.EndOfBlock = true;
  91.  
  92.     /* Start a page: write the header */
  93.     hdr[24] = 0; hdr[28] = 1;
  94.     hdr[26] = ++dfdev->pageno; hdr[27] = dfdev->pageno >> 8;
  95.     if (dev->y_pixels_per_inch == Y_DPI)
  96.         { hdr[45] = 0x40; hdr[29] = 1; }    /* high res */
  97.     else
  98.         { hdr[45] = hdr[29] = 0; }        /* low res */
  99.     fseek(prn_stream, 0, SEEK_END);
  100.     fwrite(hdr, sizeof(hdr), 1, prn_stream);
  101.  
  102.     /* Write the page */
  103.     code = gdev_fax_print_page(dev, prn_stream, &state);
  104.  
  105.     /* Fixup page count */
  106.     fseek(prn_stream, 24L, SEEK_SET);
  107.     hdr[24] = dfdev->pageno; hdr[25] = dfdev->pageno >> 8;
  108.     fwrite(hdr+24, 2, 1, prn_stream);
  109.  
  110.     return code;
  111. }
  112.  
  113. #undef dfdev
  114.