First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xprint / ps / PsMisc.c
blob0df039e0b6c263f7062dfd92985cea0c14cbb40e
1 /*
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
9 documentation.
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 Sun Microsystems, Inc.
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
52 * SOFTWARE.
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 ** *********************************************************
63 ** *
64 ** * File: PsMisc.c
65 ** *
66 ** * Contents: Miscellaneous code for Ps driver.
67 ** *
68 ** * Created By: Roger Helmendach (Liberty Systems)
69 ** *
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
71 ** *
72 ** *********************************************************
73 **
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #endif
80 #include <X11/Xos.h> /* for SIGCLD on pre-POSIX systems */
81 #include <stdio.h>
82 #include "Ps.h"
84 #include "cursor.h"
85 #include "resource.h"
87 #include "windowstr.h"
88 #include "propertyst.h"
91 /*ARGSUSED*/
92 void
93 PsQueryBestSize(
94 int type,
95 short *pwidth,
96 short *pheight,
97 ScreenPtr pScreen)
99 unsigned width, highBit;
101 switch(type)
103 case CursorShape:
104 *pwidth = 0;
105 *pheight = 0;
106 break;
107 case TileShape:
108 case StippleShape:
109 width = *pwidth;
110 if (!width) break;
111 /* Return the nearest power of two >= what they gave us */
112 highBit = 0x80000000;
113 /* Find the highest 1 bit in the given width */
114 while(!(highBit & width))
115 highBit >>= 1;
116 /* If greater than that then return the next power of two */
117 if((highBit - 1) & width)
118 highBit <<= 1;
119 *pwidth = highBit;
120 /* height is a don't-care */
121 break;
126 * PsGetMediumDimensions is installed in the GetMediumDimensions field
127 * of each Ps-initialized context.
130 PsGetMediumDimensions(XpContextPtr pCon, CARD16 *width, CARD16 *height)
132 XpGetMediumDimensions(pCon, width, height);
133 return Success;
137 * PsGetReproducibleArea is installed in the GetReproducibleArea field
138 * of each Ps-initialized context.
141 PsGetReproducibleArea(XpContextPtr pCon, xRectangle *pRect)
143 XpGetReproductionArea(pCon, pRect);
144 return Success;
148 * PsSetImageResolution is installed in the SetImageResolution field
149 * of each Ps-initialized context.
152 PsSetImageResolution(XpContextPtr pCon, int imageRes, Bool *status)
154 pCon->imageRes = imageRes;
155 *status = True;
156 return Success;
160 * GetPropString searches the window heirarchy from pWin up looking for
161 * a property by the name of propName. If found, returns the property's
162 * value. If not, it returns NULL.
165 char *
166 GetPropString(
167 WindowPtr pWin,
168 char *propName)
170 Atom atom;
171 PropertyPtr pProp = (PropertyPtr)NULL;
172 char *retVal;
174 atom = MakeAtom(propName, strlen(propName), FALSE);
175 if(atom != BAD_RESOURCE)
177 WindowPtr pPropWin;
178 int n;
182 * The atom has been defined, but it might only exist as a
183 * property on an unrelated window.
186 for(pPropWin = pWin; pPropWin != (WindowPtr)NULL;
187 pPropWin = pPropWin->parent)
189 for(pProp = (PropertyPtr)(wUserProps(pPropWin));
190 pProp != (PropertyPtr)NULL;
191 pProp = pProp->next)
193 if (pProp->propertyName == atom)
194 break;
196 if(pProp != (PropertyPtr)NULL)
197 break;
199 if(pProp == (PropertyPtr)NULL)
200 return (char *)NULL;
202 n = (pProp->format/8) * pProp->size; *//* size (bytes) of prop */
204 retVal = (char *)xalloc(n + 1);
205 (void)memcpy((void *)retVal, (void *)pProp->data, n);
206 retVal[n] = '\0';
208 return retVal;
211 return (char *)NULL;
214 #include <signal.h>
217 /* ARGSUSED */
219 static void SigchldHndlr (int dummy)
221 int status, w;
222 struct sigaction act;
223 sigfillset(&act.sa_mask);
224 act.sa_flags = 0;
225 act.sa_handler = SigchldHndlr;
227 w = wait (&status);
231 * Is this really necessary?
234 sigaction(SIGCHLD, &act, (struct sigaction *)NULL);
239 * SystemCmd provides a wrapper for the 'system' library call. The call
240 * appears to be sensitive to the handling of SIGCHLD, so this wrapper
241 * sets the status to SIG_DFL, and then resets the established handler
242 * after system returns.
246 SystemCmd(char *cmdStr)
248 int status;
249 struct sigaction newAct, oldAct;
250 sigfillset(&newAct.sa_mask);
251 newAct.sa_flags = 0;
252 newAct.sa_handler = SIG_DFL;
253 sigfillset(&oldAct.sa_mask);
254 oldAct.sa_flags = 0;
255 oldAct.sa_handler = SigchldHndlr;
259 * get the old handler, and set the action to IGN
262 sigaction(SIGCHLD, &newAct, &oldAct);
264 status = system (cmdStr);
266 sigaction(SIGCHLD, &oldAct, (struct sigaction *)NULL);
267 return status;
271 Bool
272 PsCloseScreen(
273 int index,
274 ScreenPtr pScreen)
276 return TRUE;
279 void
280 PsLineAttrs(
281 PsOutPtr psOut,
282 GCPtr pGC,
283 ColormapPtr cMap)
285 int i;
286 int nDsh;
287 int dshOff;
288 int *dsh;
289 PsCapEnum cap;
290 PsJoinEnum join;
292 switch(pGC->capStyle) {
293 case CapButt: cap = PsCButt; break;
294 case CapRound: cap = PsCRound; break;
295 case CapProjecting: cap = PsCSquare; break;
296 default: cap = PsCButt; break; }
297 switch(pGC->joinStyle) {
298 case JoinMiter: join = PsJMiter; break;
299 case JoinRound: join = PsJRound; break;
300 case JoinBevel: join = PsJBevel; break;
301 default: join = PsJBevel; break; }
302 if( pGC->lineStyle==LineSolid ) { nDsh = dshOff = 0; dsh = (int *)0; }
303 else
305 nDsh = pGC->numInDashList;
306 dshOff = pGC->dashOffset;
307 if( !nDsh ) dsh = (int *)0;
308 else
310 dsh = (int *)xalloc(sizeof(int)*nDsh);
311 for( i=0 ; i<nDsh ; i++ ) dsh[i] = (int)pGC->dash[i]&0xFF;
315 if( pGC->lineStyle!=LineDoubleDash )
316 PsOut_LineAttrs(psOut, (int)pGC->lineWidth,
317 cap, join, nDsh, dsh, dshOff, -1);
318 else
319 PsOut_LineAttrs(psOut, (int)pGC->lineWidth,
320 cap, join, nDsh, dsh, dshOff,
321 PsGetPixelColor(cMap, pGC->bgPixel));
322 if( nDsh && dsh ) xfree(dsh);