mipolyrect.c revision 05b261ec
1/***********************************************************
2
3Copyright 1987, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25
26Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28                        All Rights Reserved
29
30Permission to use, copy, modify, and distribute this software and its
31documentation for any purpose and without fee is hereby granted,
32provided that the above copyright notice appear in all copies and that
33both that copyright notice and this permission notice appear in
34supporting documentation, and that the name of Digital not be
35used in advertising or publicity pertaining to distribution of the
36software without specific, written prior permission.
37
38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44SOFTWARE.
45
46******************************************************************/
47#ifdef HAVE_DIX_CONFIG_H
48#include <dix-config.h>
49#endif
50
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"
57
58_X_EXPORT void
59miPolyRectangle(pDraw, pGC, nrects, pRects)
60    DrawablePtr	pDraw;
61    GCPtr	pGC;
62    int		nrects;
63    xRectangle	*pRects;
64{
65    int i;
66    xRectangle *pR = pRects;
67    DDXPointRec rect[5];
68    int	    bound_tmp;
69
70#define MINBOUND(dst,eqn)	bound_tmp = eqn; \
71				if (bound_tmp < -32768) \
72				    bound_tmp = -32768; \
73				dst = bound_tmp;
74
75#define MAXBOUND(dst,eqn)	bound_tmp = eqn; \
76				if (bound_tmp > 32767) \
77				    bound_tmp = 32767; \
78				dst = bound_tmp;
79
80#define MAXUBOUND(dst,eqn)	bound_tmp = eqn; \
81				if (bound_tmp > 65535) \
82				    bound_tmp = 65535; \
83				dst = bound_tmp;
84
85    if (pGC->lineStyle == LineSolid && pGC->joinStyle == JoinMiter &&
86	pGC->lineWidth != 0)
87    {
88	xRectangle  *tmp, *t;
89	int	    ntmp;
90	int	    offset1, offset2, offset3;
91	int	    x, y, width, height;
92
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++)
102	{
103	    x = pR->x;
104	    y = pR->y;
105	    width = pR->width;
106	    height = pR->height;
107	    pR++;
108	    if (width == 0 && height == 0)
109	    {
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);
115	    }
116	    else if (height < offset2 || width < offset1)
117	    {
118		if (height == 0)
119		{
120		    t->x = x;
121		    t->width = width;
122		}
123		else
124		{
125		    MINBOUND (t->x, x - offset1)
126		    MAXUBOUND (t->width, width + offset2)
127		}
128		if (width == 0)
129		{
130		    t->y = y;
131		    t->height = height;
132		}
133		else
134		{
135		    MINBOUND (t->y, y - offset1)
136		    MAXUBOUND (t->height, height + offset2)
137		}
138		t++;
139	    }
140	    else
141	    {
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++;
162	    }
163	}
164	(*pGC->ops->PolyFillRect) (pDraw, pGC, t - tmp, tmp);
165	DEALLOCATE_LOCAL ((pointer) tmp);
166    }
167    else
168    {
169
170    	for (i=0; i<nrects; i++)
171    	{
172	    rect[0].x = pR->x;
173	    rect[0].y = pR->y;
174
175	    MAXBOUND(rect[1].x, pR->x + (int) pR->width)
176	    rect[1].y = rect[0].y;
177
178	    rect[2].x = rect[1].x;
179	    MAXBOUND(rect[2].y, pR->y + (int) pR->height);
180
181	    rect[3].x = rect[0].x;
182	    rect[3].y = rect[2].y;
183
184	    rect[4].x = rect[0].x;
185	    rect[4].y = rect[0].y;
186
187            (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 5, rect);
188	    pR++;
189    	}
190    }
191}
192