gdevdfax.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (C) 1994, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevdfax.c,v 1.6 2002/02/21 22:24:51 giles Exp $*/
  14. /* DigiBoard fax device. */
  15. /***
  16. *** Note: this driver is maintained by a user: please contact
  17. *** Rick Richardson (rick@digibd.com) if you have questions.
  18. ***/
  19. #include "gdevprn.h"
  20. #include "strimpl.h"
  21. #include "scfx.h"
  22. #include "gdevfax.h"
  23. #include "gdevtfax.h"
  24. /* Define the device parameters. */
  25. #define X_DPI 204
  26. #define Y_DPI 196
  27. /* The device descriptors */
  28. private dev_proc_open_device(dfax_prn_open);
  29. private dev_proc_print_page(dfax_print_page);
  30. struct gx_device_dfax_s {
  31. gx_device_common;
  32. gx_prn_device_common;
  33. long pageno;
  34. uint iwidth; /* width of image data in pixels */
  35. };
  36. typedef struct gx_device_dfax_s gx_device_dfax;
  37. private gx_device_procs dfax_procs =
  38. prn_procs(dfax_prn_open, gdev_prn_output_page, gdev_prn_close);
  39. gx_device_dfax far_data gs_dfaxlow_device =
  40. { prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxlow",
  41. DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  42. X_DPI, Y_DPI/2,
  43. 0,0,0,0, /* margins */
  44. 1, dfax_print_page)
  45. };
  46. gx_device_dfax far_data gs_dfaxhigh_device =
  47. { prn_device_std_body(gx_device_dfax, dfax_procs, "dfaxhigh",
  48. DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  49. X_DPI, Y_DPI,
  50. 0,0,0,0, /* margins */
  51. 1, dfax_print_page)
  52. };
  53. #define dfdev ((gx_device_dfax *)dev)
  54. /* Open the device, adjusting the paper size. */
  55. private int
  56. dfax_prn_open(gx_device *dev)
  57. { dfdev->pageno = 0;
  58. return gdev_fax_open(dev);
  59. }
  60. /* Print a DigiFAX page. */
  61. private int
  62. dfax_print_page(gx_device_printer *dev, FILE *prn_stream)
  63. { stream_CFE_state state;
  64. static char hdr[64] = "\000PC Research, Inc\000\000\000\000\000\000";
  65. int code;
  66. gdev_fax_init_state(&state, (gx_device_fax *)dev);
  67. state.EndOfLine = true;
  68. state.EncodedByteAlign = true;
  69. /* Start a page: write the header */
  70. hdr[24] = 0; hdr[28] = 1;
  71. hdr[26] = ++dfdev->pageno; hdr[27] = dfdev->pageno >> 8;
  72. if (dev->y_pixels_per_inch == Y_DPI)
  73. { hdr[45] = 0x40; hdr[29] = 1; } /* high res */
  74. else
  75. { hdr[45] = hdr[29] = 0; } /* low res */
  76. fseek(prn_stream, 0, SEEK_END);
  77. fwrite(hdr, sizeof(hdr), 1, prn_stream);
  78. /* Write the page */
  79. code = gdev_fax_print_page(dev, prn_stream, &state);
  80. /* Fixup page count */
  81. fseek(prn_stream, 24L, SEEK_SET);
  82. hdr[24] = dfdev->pageno; hdr[25] = dfdev->pageno >> 8;
  83. fwrite(hdr+24, 2, 1, prn_stream);
  84. return code;
  85. }
  86. #undef dfdev