First import
[xorg_rtime.git] / xorg-server-1.4 / mi / mipolyrect.c
bloba9ab90928713666cd12ff581e4288c093054c908
1 /***********************************************************
3 Copyright 1987, 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.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
49 #endif
51 #include <X11/X.h>
52 #include <X11/Xprotostr.h>
53 #include "regionstr.h"
54 #include "gcstruct.h"
55 #include "pixmap.h"
56 #include "mi.h"
58 _X_EXPORT void
59 miPolyRectangle(pDraw, pGC, nrects, pRects)
60 DrawablePtr pDraw;
61 GCPtr pGC;
62 int nrects;
63 xRectangle *pRects;
65 int i;
66 xRectangle *pR = pRects;
67 DDXPointRec rect[5];
68 int bound_tmp;
70 #define MINBOUND(dst,eqn) bound_tmp = eqn; \
71 if (bound_tmp < -32768) \
72 bound_tmp = -32768; \
73 dst = bound_tmp;
75 #define MAXBOUND(dst,eqn) bound_tmp = eqn; \
76 if (bound_tmp > 32767) \
77 bound_tmp = 32767; \
78 dst = bound_tmp;
80 #define MAXUBOUND(dst,eqn) bound_tmp = eqn; \
81 if (bound_tmp > 65535) \
82 bound_tmp = 65535; \
83 dst = bound_tmp;
85 if (pGC->lineStyle == LineSolid && pGC->joinStyle == JoinMiter &&
86 pGC->lineWidth != 0)
88 xRectangle *tmp, *t;
89 int ntmp;
90 int offset1, offset2, offset3;
91 int x, y, width, height;
93 ntmp = (nrects << 2);
94 offset2 = pGC->lineWidth;
95 offset1 = offset2 >> 1;
96 offset3 = offset2 - offset1;
97 tmp = (xRectangle *) ALLOCATE_LOCAL(ntmp * sizeof (xRectangle));
98 if (!tmp)
99 return;
100 t = tmp;
101 for (i = 0; i < nrects; i++)
103 x = pR->x;
104 y = pR->y;
105 width = pR->width;
106 height = pR->height;
107 pR++;
108 if (width == 0 && height == 0)
110 rect[0].x = x;
111 rect[0].y = y;
112 rect[1].x = x;
113 rect[1].y = y;
114 (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 2, rect);
116 else if (height < offset2 || width < offset1)
118 if (height == 0)
120 t->x = x;
121 t->width = width;
123 else
125 MINBOUND (t->x, x - offset1)
126 MAXUBOUND (t->width, width + offset2)
128 if (width == 0)
130 t->y = y;
131 t->height = height;
133 else
135 MINBOUND (t->y, y - offset1)
136 MAXUBOUND (t->height, height + offset2)
138 t++;
140 else
142 MINBOUND(t->x, x - offset1)
143 MINBOUND(t->y, y - offset1)
144 MAXUBOUND(t->width, width + offset2)
145 t->height = offset2;
146 t++;
147 MINBOUND(t->x, x - offset1)
148 MAXBOUND(t->y, y + offset3);
149 t->width = offset2;
150 t->height = height - offset2;
151 t++;
152 MAXBOUND(t->x, x + width - offset1);
153 MAXBOUND(t->y, y + offset3)
154 t->width = offset2;
155 t->height = height - offset2;
156 t++;
157 MINBOUND(t->x, x - offset1)
158 MAXBOUND(t->y, y + height - offset1)
159 MAXUBOUND(t->width, width + offset2)
160 t->height = offset2;
161 t++;
164 (*pGC->ops->PolyFillRect) (pDraw, pGC, t - tmp, tmp);
165 DEALLOCATE_LOCAL ((pointer) tmp);
167 else
170 for (i=0; i<nrects; i++)
172 rect[0].x = pR->x;
173 rect[0].y = pR->y;
175 MAXBOUND(rect[1].x, pR->x + (int) pR->width)
176 rect[1].y = rect[0].y;
178 rect[2].x = rect[1].x;
179 MAXBOUND(rect[2].y, pR->y + (int) pR->height);
181 rect[3].x = rect[0].x;
182 rect[3].y = rect[2].y;
184 rect[4].x = rect[0].x;
185 rect[4].y = rect[0].y;
187 (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 5, rect);
188 pR++;