1 /* This file is part of the GNU libxmi package.
2 
3    Copyright (C) 1985, 1986, 1987, 1988, 1989, X Consortium.  For an
4    associated permission notice, see the accompanying file README-X.
5 
6    GNU enhancements Copyright (C) 1998, 1999, 2000, 2005, Free Software
7    Foundation, Inc.
8 
9    The GNU libxmi package is free software.  You may redistribute it
10    and/or modify it under the terms of the GNU General Public License as
11    published by the Free Software foundation; either version 2, or (at your
12    option) any later version.
13 
14    The GNU libxmi package is distributed in the hope that it will be
15    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License along
20    with the GNU plotutils package; see the file COPYING.  If not, write to
21    the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
22    Boston, MA 02110-1301, USA. */
23 
24 #include "sys-defines.h"
25 #include "extern.h"
26 
27 #include "xmi.h"
28 #include "mi_spans.h"
29 #include "mi_gc.h"
30 #include "mi_api.h"
31 
32 /* mi rectangles
33    written by Todd Newman, with debts to all and sundry
34    */
35 
36 /* Very straightforward.  We let the low-level paint function invoked by
37  * MI_PAINT_SPANS() worry about clipping to the destination.
38  *
39  * Note libxmi's convention: right edges and bottom edges of filled
40  * polygons (including rectangles) are unpainted, so that adjacent polygons
41  * will abut with no overlaps or gaps. */
42 
43 void
miFillRectangles_internal(miPaintedSet * paintedSet,const miGC * pGC,int nrects,const miRectangle * prectInit)44 miFillRectangles_internal (miPaintedSet *paintedSet, const miGC *pGC, int nrects, const miRectangle *prectInit)
45 {
46   const miRectangle *prect;
47 
48   /* ensure we have >=1 rects to fill */
49   if (nrects <= 0)
50     return;
51 
52   prect = prectInit;
53   while (nrects--)
54     {
55       miPoint *ppt;
56       miPoint *pptFirst;
57       int xorg, yorg;
58       unsigned int *pw, *pwFirst;
59       unsigned int height, width, countdown;
60 
61       height = prect->height;
62       width = prect->width;
63       pptFirst = (miPoint *)mi_xmalloc (height * sizeof(miPoint));
64       pwFirst = (unsigned int *)mi_xmalloc (height * sizeof(unsigned int));
65       ppt = pptFirst;
66       pw = pwFirst;
67 
68       xorg = prect->x;
69       yorg = prect->y;
70       countdown = height;
71       while (countdown--)
72 	{
73 	  *pw++ = width;
74 	  ppt->x = xorg;
75 	  ppt->y = yorg;
76 	  ppt++;
77 	  yorg++;
78 	}
79 
80       /* paint to paintedSet, or if that's NULL, to canvas */
81       MI_PAINT_SPANS(paintedSet, pGC->pixels[1], (int)height, pptFirst, pwFirst)
82 
83       prect++;
84     }
85 }
86