mipolyrect.c revision 4642e01f
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(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
60{
61    int i;
62    xRectangle *pR = pRects;
63    DDXPointRec rect[5];
64    int	    bound_tmp;
65
66#define MINBOUND(dst,eqn)	bound_tmp = eqn; \
67				if (bound_tmp < -32768) \
68				    bound_tmp = -32768; \
69				dst = bound_tmp;
70
71#define MAXBOUND(dst,eqn)	bound_tmp = eqn; \
72				if (bound_tmp > 32767) \
73				    bound_tmp = 32767; \
74				dst = bound_tmp;
75
76#define MAXUBOUND(dst,eqn)	bound_tmp = eqn; \
77				if (bound_tmp > 65535) \
78				    bound_tmp = 65535; \
79				dst = bound_tmp;
80
81    if (pGC->lineStyle == LineSolid && pGC->joinStyle == JoinMiter &&
82	pGC->lineWidth != 0)
83    {
84	xRectangle  *tmp, *t;
85	int	    ntmp;
86	int	    offset1, offset2, offset3;
87	int	    x, y, width, height;
88
89	ntmp = (nrects << 2);
90	offset2 = pGC->lineWidth;
91	offset1 = offset2 >> 1;
92	offset3 = offset2 - offset1;
93	tmp = (xRectangle *) xalloc(ntmp * sizeof (xRectangle));
94	if (!tmp)
95	    return;
96	t = tmp;
97	for (i = 0; i < nrects; i++)
98	{
99	    x = pR->x;
100	    y = pR->y;
101	    width = pR->width;
102	    height = pR->height;
103	    pR++;
104	    if (width == 0 && height == 0)
105	    {
106		rect[0].x = x;
107		rect[0].y = y;
108		rect[1].x = x;
109		rect[1].y = y;
110		(*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 2, rect);
111	    }
112	    else if (height < offset2 || width < offset1)
113	    {
114		if (height == 0)
115		{
116		    t->x = x;
117		    t->width = width;
118		}
119		else
120		{
121		    MINBOUND (t->x, x - offset1)
122		    MAXUBOUND (t->width, width + offset2)
123		}
124		if (width == 0)
125		{
126		    t->y = y;
127		    t->height = height;
128		}
129		else
130		{
131		    MINBOUND (t->y, y - offset1)
132		    MAXUBOUND (t->height, height + offset2)
133		}
134		t++;
135	    }
136	    else
137	    {
138		MINBOUND(t->x, x - offset1)
139		MINBOUND(t->y, y - offset1)
140		MAXUBOUND(t->width, width + offset2)
141	    	t->height = offset2;
142	    	t++;
143	    	MINBOUND(t->x, x - offset1)
144	    	MAXBOUND(t->y, y + offset3);
145	    	t->width = offset2;
146	    	t->height = height - offset2;
147	    	t++;
148	    	MAXBOUND(t->x, x + width - offset1);
149	    	MAXBOUND(t->y, y + offset3)
150	    	t->width = offset2;
151	    	t->height = height - offset2;
152	    	t++;
153	    	MINBOUND(t->x, x - offset1)
154	    	MAXBOUND(t->y, y + height - offset1)
155	    	MAXUBOUND(t->width, width + offset2)
156	    	t->height = offset2;
157	    	t++;
158	    }
159	}
160	(*pGC->ops->PolyFillRect) (pDraw, pGC, t - tmp, tmp);
161	xfree ((pointer) tmp);
162    }
163    else
164    {
165
166    	for (i=0; i<nrects; i++)
167    	{
168	    rect[0].x = pR->x;
169	    rect[0].y = pR->y;
170
171	    MAXBOUND(rect[1].x, pR->x + (int) pR->width)
172	    rect[1].y = rect[0].y;
173
174	    rect[2].x = rect[1].x;
175	    MAXBOUND(rect[2].y, pR->y + (int) pR->height);
176
177	    rect[3].x = rect[0].x;
178	    rect[3].y = rect[2].y;
179
180	    rect[4].x = rect[0].x;
181	    rect[4].y = rect[0].y;
182
183            (*pGC->ops->Polylines)(pDraw, pGC, CoordModeOrigin, 5, rect);
184	    pR++;
185    	}
186    }
187}
188