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