1 /*******************************************************************
3 ** *********************************************************
8 ** * Miscellaneous code for Pcl driver.
12 ** *********************************************************
14 ********************************************************************/
16 (c) Copyright 1996 Hewlett-Packard Company
17 (c) Copyright 1996 International Business Machines Corp.
18 (c) Copyright 1996 Sun Microsystems, Inc.
19 (c) Copyright 1996 Novell, Inc.
20 (c) Copyright 1996 Digital Equipment Corp.
21 (c) Copyright 1996 Fujitsu Limited
22 (c) Copyright 1996 Hitachi, Ltd.
24 Permission is hereby granted, free of charge, to any person obtaining a copy
25 of this software and associated documentation files (the "Software"), to deal
26 in the Software without restriction, including without limitation the rights
27 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 copies of the Software, and to permit persons to whom the Software is
29 furnished to do so, subject to the following conditions:
31 The above copyright notice and this permission notice shall be included in
32 all copies or substantial portions of the Software.
34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 Except as contained in this notice, the names of the copyright holders shall
42 not be used in advertising or otherwise to promote the sale, use or other
43 dealings in this Software without prior written authorization from said
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
53 #include <sys/types.h>
55 #include <X11/Xos.h> /* for SIGCLD on pre-POSIX systems */
61 #include "windowstr.h"
62 #include "propertyst.h"
63 #include "attributes.h"
74 unsigned width
, highBit
;
86 /* Return the nearest power of two >= what they gave us */
88 /* Find the highest 1 bit in the given width */
89 while(!(highBit
& width
))
91 /* If greater than that then return the next power of two */
92 if((highBit
- 1) & width
)
95 /* height is a don't-care */
101 * GetPropString searches the window heirarchy from pWin up looking for
102 * a property by the name of propName. If found, returns the property's
103 * value. If not, it returns NULL.
111 PropertyPtr pProp
= (PropertyPtr
)NULL
;
114 atom
= MakeAtom(propName
, strlen(propName
), FALSE
);
115 if(atom
!= BAD_RESOURCE
)
121 * The atom has been defined, but it might only exist as a
122 * property on an unrelated window.
124 for(pPropWin
= pWin
; pPropWin
!= (WindowPtr
)NULL
;
125 pPropWin
= pPropWin
->parent
)
127 for(pProp
= (PropertyPtr
)(wUserProps(pPropWin
));
128 pProp
!= (PropertyPtr
)NULL
;
131 if (pProp
->propertyName
== atom
)
134 if(pProp
!= (PropertyPtr
)NULL
)
137 if(pProp
== (PropertyPtr
)NULL
)
140 n
= (pProp
->format
/8) * pProp
->size
; /* size (bytes) of prop */
141 retVal
= (char *)xalloc(n
+ 1);
142 (void)memcpy((void *)retVal
, (void *)pProp
->data
, n
);
155 static void SigchldHndlr (
159 int olderrno
= errno
;
160 struct sigaction act
;
161 sigfillset(&act
.sa_mask
);
163 act
.sa_handler
= SigchldHndlr
;
165 (void) wait (&status
);
168 * Is this really necessary?
170 sigaction(SIGCHLD
, &act
, (struct sigaction
*)NULL
);
175 * SystemCmd provides a wrapper for the 'system' library call. The call
176 * appears to be sensitive to the handling of SIGCHLD, so this wrapper
177 * sets the status to SIG_DFL, and then resets the established handler
178 * after system returns.
181 SystemCmd(char *cmdStr
)
184 struct sigaction newAct
, oldAct
;
185 sigfillset(&newAct
.sa_mask
);
187 newAct
.sa_handler
= SIG_DFL
;
188 sigfillset(&oldAct
.sa_mask
);
190 oldAct
.sa_handler
= SigchldHndlr
;
193 * get the old handler, and set the action to IGN
195 sigaction(SIGCHLD
, &newAct
, &oldAct
);
197 status
= system (cmdStr
);
199 sigaction(SIGCHLD
, &oldAct
, (struct sigaction
*)NULL
);
205 * PclGetMediumDimensions is installed in the GetMediumDimensions field
206 * of each Pcl-initialized context.
209 PclGetMediumDimensions(XpContextPtr pCon
,
213 XpGetMediumDimensions(pCon
, width
, height
);
218 * PclGetReproducibleArea is installed in the GetReproducibleArea field
219 * of each Pcl-initialized context.
222 PclGetReproducibleArea(XpContextPtr pCon
,
225 XpGetReproductionArea(pCon
, pRect
);
231 * PclSpoolFigs spooled the rendering PCL/HP-GL2 commands into the
232 * temporary buffer pointed by figures pointer in pcl private context.
233 * LaserJet IIIs printers don't support the macro function which
234 * includes some HP-GL/2 commands.
237 PclSpoolFigs(PclContextPrivPtr pConPriv
, char *t
, int n
)
241 ptr
= pConPriv
->figures
;
242 while ( ( pConPriv
->fcount
+ n
) > pConPriv
->fcount_max
) {
243 ptr
= (char *)xrealloc(ptr
, 1024 + pConPriv
->fcount_max
);
246 pConPriv
->figures
= ptr
;
247 pConPriv
->fcount_max
+= 1024;
249 ptr
+= pConPriv
->fcount
;
250 pConPriv
->fcount
+= n
;
253 #endif /* XP_PCL_LJ3 */
257 * For XP-PCL-COLOR/XP-PCL-MONO, it executes the macro stored before
258 * in the clipped area.
259 * For XP-PCL-LJ3, it draws the spooled figures in the clipped area.
264 PclContextPrivPtr pConPriv
,
275 ptr
= pConPriv
->figures
;
276 n
= pConPriv
->fcount
;
280 #endif /* XP_PCL_LJ3 */
285 * Set the HP-GL/2 input window to the current
286 * rectangle in the clip region, then send the code to
287 * execute the macro defined above.
290 sprintf( t
, "\033%%0BIW%d,%d,%d,%d;\033%%0A",
292 pbox
->x2
, pbox
->y2
);
294 sprintf( t
, "\033%%0BIW%g,%d,%g,%d;\033%%0A",
295 ratio
* pbox
->x1
, pbox
->y1
,
296 ratio
* pbox
->x2
, pbox
->y2
);
298 SEND_PCL( outFile
, t
);
299 SEND_PCL_COUNT( outFile
, ptr
, n
);