First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xprint / ps / PsLine.c
blobaca186642a5c0d2f029bf354da608c22bfa6e84e
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: PsLine.c
65 ** *
66 ** * Contents: Line drawing routines for the 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 "Ps.h"
81 #include "gcstruct.h"
82 #include "windowstr.h"
84 void
85 PsPolyLine(
86 DrawablePtr pDrawable,
87 GCPtr pGC,
88 int mode,
89 int nPoints,
90 xPoint *pPoints)
92 if( pDrawable->type==DRAWABLE_PIXMAP )
94 DisplayElmPtr elm;
95 PixmapPtr pix = (PixmapPtr)pDrawable;
96 PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
97 DisplayListPtr disp;
98 GCPtr gc;
100 if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
102 disp = PsGetFreeDisplayBlock(priv);
104 elm = &disp->elms[disp->nelms];
105 elm->type = PolyLineCmd;
106 elm->gc = gc;
107 elm->c.polyPts.mode = mode;
108 elm->c.polyPts.nPoints = nPoints;
109 elm->c.polyPts.pPoints = (xPoint *)xalloc(nPoints*sizeof(xPoint));
110 memcpy(elm->c.polyPts.pPoints, pPoints, nPoints*sizeof(xPoint));
111 disp->nelms += 1;
113 else
115 int i;
116 PsOutPtr psOut;
117 PsPointPtr pts;
118 ColormapPtr cMap;
120 if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
121 PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
122 PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
123 PsLineAttrs(psOut, pGC, cMap);
124 pts = (PsPointPtr)xalloc(sizeof(PsPointRec)*nPoints);
125 if( mode==CoordModeOrigin )
127 for( i=0 ; i<nPoints ; i++ )
128 { pts[i].x = pPoints[i].x; pts[i].y = pPoints[i].y; }
130 else
132 pts[0].x = pPoints[0].x; pts[0].y = pPoints[0].y;
133 for( i=1 ; i<nPoints ; i++ )
135 pts[i].x = pts[i-1].x+pPoints[i].x;
136 pts[i].y = pts[i-1].y+pPoints[i].y;
139 PsOut_Lines(psOut, nPoints, pts);
140 xfree(pts);
144 void
145 PsPolySegment(
146 DrawablePtr pDrawable,
147 GCPtr pGC,
148 int nSegments,
149 xSegment *pSegments)
151 if( pDrawable->type==DRAWABLE_PIXMAP )
153 DisplayElmPtr elm;
154 PixmapPtr pix = (PixmapPtr)pDrawable;
155 PsPixmapPrivPtr priv = (PsPixmapPrivPtr)pix->devPrivate.ptr;
156 DisplayListPtr disp;
157 GCPtr gc;
159 if ((gc = PsCreateAndCopyGC(pDrawable, pGC)) == NULL) return;
161 disp = PsGetFreeDisplayBlock(priv);
163 elm = &disp->elms[disp->nelms];
164 elm->type = PolySegmentCmd;
165 elm->gc = gc;
166 elm->c.segments.nSegments = nSegments;
167 elm->c.segments.pSegments = (xSegment *)xalloc(nSegments*sizeof(xSegment));
168 memcpy(elm->c.segments.pSegments, pSegments, nSegments*sizeof(xSegment));
169 disp->nelms += 1;
171 else
173 int i;
174 PsOutPtr psOut;
175 PsPointRec pts[2];
176 ColormapPtr cMap;
178 if( PsUpdateDrawableGC(pGC, pDrawable, &psOut, &cMap)==FALSE ) return;
179 PsOut_Offset(psOut, pDrawable->x, pDrawable->y);
180 PsOut_Color(psOut, PsGetPixelColor(cMap, pGC->fgPixel));
181 PsLineAttrs(psOut, pGC, cMap);
182 for( i=0 ; i<nSegments ; i++ )
184 pts[0].x = pSegments[i].x1;
185 pts[0].y = pSegments[i].y1;
186 pts[1].x = pSegments[i].x2;
187 pts[1].y = pSegments[i].y2;
188 PsOut_Lines(psOut, 2, pts);