gdevdfax.c 3.1 KB

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