3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996, 2000 Sun Microsystems, Inc. All rights reserved.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
66 ** * Contents: Print extension code of Ps driver
68 ** * Created By: Roger Helmendach (Liberty Systems)
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
72 ** *********************************************************
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
82 #include <sys/types.h>
87 #include <X11/Xprotostr.h>
90 #include <X11/Xproto.h>
95 #include "windowstr.h"
96 #include "attributes.h"
99 /* static utility function to get document/page attributes */
101 S_GetPageAttributes(XpContextPtr pCon
,int *iorient
,int *icount
, int *iplex
,
102 int *ires
, unsigned short *iwd
, unsigned short *iht
)
107 * Get the orientation
109 orient
= XpGetContentOrientation(pCon
);
111 case xpoid_val_content_orientation_landscape
:
114 case xpoid_val_content_orientation_reverse_portrait
:
117 case xpoid_val_content_orientation_reverse_landscape
:
120 case xpoid_val_content_orientation_portrait
:
129 count
= XpGetOneAttribute(pCon
, XPDocAttr
, "copy-count");
132 int ii
= sscanf(count
, "%d", icount
);
133 if( ii
!=1 ) *icount
= 1;
140 plex
= XpGetPlex(pCon
);
143 case xpoid_val_plex_duplex
:
146 case xpoid_val_plex_tumble
:
155 * Get the resolution and media size
157 *ires
= XpGetResolution(pCon
);
158 XpGetMediumDimensions(pCon
, iwd
, iht
);
168 PsContextPrivPtr pConPriv
=
169 (PsContextPrivPtr
)pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
172 * Create a temporary file to store the printer output.
174 if (!XpOpenTmpFile("w", &pConPriv
->jobFileName
, &pConPriv
->pJobFile
))
182 /* I thought about making this following code into a set of routines
183 or using a goto, or something, but in the end decided not to,
184 because the plain old listing here makes the logic clearer. */
194 PsContextPrivPtr priv
=
195 (PsContextPrivPtr
)pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
197 if (cancel
== True
) {
198 if (priv
->getDocClient
!= (ClientPtr
) NULL
) {
199 (void) XpFinishDocData( priv
->getDocClient
);
201 priv
->getDocClient
= NULL
;
202 priv
->getDocBufSize
= 0;
205 /* job is cancelled - do we really care if we're out of space? */
206 (void) fclose(priv
->pJobFile
);
207 priv
->pJobFile
= NULL
;
209 unlink(priv
->jobFileName
);
210 xfree(priv
->jobFileName
);
211 priv
->jobFileName
= (char *)NULL
;
213 PsFreeFontInfoRecords(priv
);
219 * Append any trailing information here
221 PsOut_EndFile(priv
->pPsOut
, 0);
224 /* this is where we find out if we're out of space */
225 error
= (fclose(priv
->pJobFile
) == EOF
);
226 priv
->pJobFile
= NULL
;
228 /* status to the client if we have ran out of space on the disk or
229 some other resource problem with the temporary file... */
231 if (priv
->getDocClient
!= (ClientPtr
) NULL
) {
232 (void) XpFinishDocData( priv
->getDocClient
);
234 priv
->getDocClient
= NULL
;
235 priv
->getDocBufSize
= 0;
238 unlink(priv
->jobFileName
);
239 xfree(priv
->jobFileName
);
240 priv
->jobFileName
= (char *)NULL
;
242 PsFreeFontInfoRecords(priv
);
247 /* we have finished without incident & no cancel */
249 if (priv
->getDocClient
!= NULL
&& priv
->getDocBufSize
> 0) {
252 file
= fopen(priv
->jobFileName
, "r");
253 if (!file
|| (fstat(fileno(file
), &buffer
) < 0))
256 r
= XpSendDocumentData(priv
->getDocClient
, file
, buffer
.st_size
,
257 priv
->getDocBufSize
);
261 (void) XpFinishDocData(priv
->getDocClient
);
263 priv
->getDocClient
= NULL
;
264 priv
->getDocBufSize
= 0;
267 XpSubmitJob(priv
->jobFileName
, pCon
);
272 unlink(priv
->jobFileName
);
273 xfree(priv
->jobFileName
);
274 priv
->jobFileName
= (char *)NULL
;
276 PsFreeFontInfoRecords(priv
);
279 PsBmClearImageCache();
292 int iorient
, iplex
, icount
, ires
;
293 unsigned short iwd
, iht
;
294 PsContextPrivPtr pConPriv
=
295 (PsContextPrivPtr
)pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
296 PsWindowPrivPtr pWinPriv
=
297 (PsWindowPrivPtr
)pWin
->devPrivates
[PsWindowPrivateIndex
].ptr
;
300 * Put a pointer to the context in the window private structure
302 pWinPriv
->validContext
= 1;
303 pWinPriv
->context
= pCon
;
305 /* get page level attributes */
306 S_GetPageAttributes(pCon
,&iorient
,&icount
,&iplex
,&ires
,&iwd
,&iht
);
310 if (pConPriv
->pPsOut
== NULL
) {
313 /* get job level attributes */
314 title
= XpGetOneAttribute(pCon
, XPJobAttr
, "job-name");
316 pConPriv
->pPsOut
= PsOut_BeginFile(pConPriv
->pJobFile
,
317 title
, iorient
, icount
, iplex
, ires
,
318 (int)iwd
, (int)iht
, False
);
319 pConPriv
->fontInfoRecords
= NULL
;
320 pConPriv
->fontTypeInfoRecords
= NULL
;
322 PsOut_BeginPage(pConPriv
->pPsOut
, iorient
, icount
, iplex
, ires
,
332 * Write page trailer to page file
333 * Write page file to job file
340 PsWindowPrivPtr pWinPriv
=
341 (PsWindowPrivPtr
)pWin
->devPrivates
[PsWindowPrivateIndex
].ptr
;
342 PsContextPrivPtr pConPriv
=
343 (PsContextPrivPtr
)pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
345 PsOut_EndPage(pConPriv
->pPsOut
);
347 pWinPriv
->validContext
= 0;
348 pWinPriv
->context
= NULL
;
350 /* status to the client if we have ran out of space on the disk or
351 some other resource problem with the temporary file... */
352 /* if (ferror(pConPriv->pJobFile)) return BadAlloc; */
358 * The PsStartDoc() and PsEndDoc() functions serve basically as NOOP
359 * placeholders. This driver doesn't deal with the notion of multiple
360 * documents per page.
364 PsStartDoc(XpContextPtr pCon
, XPDocumentType type
)
366 int iorient
, iplex
, icount
, ires
;
367 unsigned short iwd
, iht
;
369 PsContextPrivPtr pConPriv
=
370 (PsContextPrivPtr
)pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
372 /* get job level attributes */
373 title
= XpGetOneAttribute(pCon
, XPJobAttr
, "job-name");
375 /* get document level attributes */
376 S_GetPageAttributes(pCon
,&iorient
,&icount
,&iplex
,&ires
,&iwd
,&iht
);
378 pConPriv
->pPsOut
= PsOut_BeginFile(pConPriv
->pJobFile
,
379 title
, iorient
, icount
, iplex
, ires
,
380 (int)iwd
, (int)iht
, (Bool
)(type
== XPDocRaw
));
382 pConPriv
->fontInfoRecords
= NULL
;
383 pConPriv
->fontTypeInfoRecords
= NULL
;
399 * Hand any pre-generated PDL down to the spool files, formatting it
400 * as necessary to fit the given window.
415 PsContextPrivPtr cPriv
;
419 strncasecmp(pFmt
, "PostScript 2", len_fmt
) != 0 ||
423 cPriv
= pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
424 psOut
= cPriv
->pPsOut
;
427 PsOut_BeginFrame(psOut
, 0, 0, pDraw
->x
, pDraw
->y
,
428 pDraw
->width
, pDraw
->height
);
429 PsOut_RawData(psOut
, pData
, len_data
);
431 PsOut_EndFrame(psOut
);
438 * PsGetDocumentData()
440 * This function allows the driver to send the generated PS back to
450 PsContextPrivPtr pPriv
= (PsContextPrivPtr
)
451 pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
453 pPriv
->getDocClient
= client
;
454 pPriv
->getDocBufSize
= maxBufferSize
;