1
/* $Xorg: PclPolygon.c,v 1.3 2000/08/17 19:48:08 cpqbld Exp $ */
2
/*******************************************************************
4
** *********************************************************
6
** * File: PclPolygon.c
9
** * Draws Polygons and Rectangles for the PCL DDX
11
** * Created: 10/23/95
13
** *********************************************************
15
********************************************************************/
17
(c) Copyright 1996 Hewlett-Packard Company
18
(c) Copyright 1996 International Business Machines Corp.
19
(c) Copyright 1996 Sun Microsystems, Inc.
20
(c) Copyright 1996 Novell, Inc.
21
(c) Copyright 1996 Digital Equipment Corp.
22
(c) Copyright 1996 Fujitsu Limited
23
(c) Copyright 1996 Hitachi, Ltd.
25
Permission is hereby granted, free of charge, to any person obtaining a copy
26
of this software and associated documentation files (the "Software"), to deal
27
in the Software without restriction, including without limitation the rights
28
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
copies of the Software, and to permit persons to whom the Software is
30
furnished to do so, subject to the following conditions:
32
The above copyright notice and this permission notice shall be included in
33
all copies or substantial portions of the Software.
35
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42
Except as contained in this notice, the names of the copyright holders shall
43
not be used in advertising or otherwise to promote the sale, use or other
44
dealings in this Software without prior written authorization from said
47
/* $XFree86: xc/programs/Xserver/Xprint/pcl/PclPolygon.c,v 1.6 1999/12/13 02:12:56 robin Exp $ */
50
#ifdef HAVE_DIX_CONFIG_H
51
#include <dix-config.h>
56
#include "windowstr.h"
60
DrawablePtr pDrawable,
69
xRectangle *drawRects, *r;
70
RegionPtr drawRegion, region;
74
PclContextPrivPtr pConPriv;
76
if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
79
pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
80
pConPriv = (PclContextPrivPtr)
81
pCon->devPrivates[PclContextPrivateIndex].ptr;
84
* Allocate the storage required to deal with the clipping
87
region = REGION_CREATE( pGC->pScreen, NULL, 0 );
88
drawRects = (xRectangle *)xalloc( nRects * sizeof( xRectangle ) );
90
fudge = 3 * pGC->lineWidth + 1;
93
* Generate the PCL code to draw the rectangles, by defining them
94
* as a macro which uses the HP-GL/2 rectangle drawing function.
96
MACRO_START( outFile, pConPriv );
97
SAVE_PCL( outFile, pConPriv, "\033%0B" );
99
xoffset = pDrawable->x;
100
yoffset = pDrawable->y;
102
for( i = 0, r = drawRects; i < nRects; i++, r++ )
104
xRectangle rect = pRects[i];
106
/* Draw the rectangle */
107
sprintf( t, "PU%d,%d;ER%d,%d;", rect.x + xoffset,
108
rect.y + yoffset, rect.width, rect.height );
109
SAVE_PCL( outFile, pConPriv, t );
111
/* Build the bounding box */
112
r->x = MIN( rect.x, rect.x + rect.width ) + xoffset -
114
r->y = MIN( rect.y, rect.y + rect.height ) + yoffset -
116
r->width = rect.width + 2 * fudge;
117
r->height = rect.height + 2 * fudge;
119
SAVE_PCL( outFile, pConPriv, ";\033%0A" ); /* End the macro */
120
MACRO_END( outFile );
123
* Convert the collection of rectangles to a proper region, then
124
* intersect it with the clip region.
126
drawRegion = RECTS_TO_REGION( pGC->pScreen, nRects,
127
drawRects, CT_UNSORTED );
129
REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
132
* For each rectangle in the clip region, set the HP-GL/2 "input
133
* window" and render the set of rectangles to it.
135
pbox = REGION_RECTS( region );
136
nbox = REGION_NUM_RECTS( region );
138
PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
141
* Clean up the temporary regions
143
REGION_DESTROY( pGC->pScreen, drawRegion );
144
REGION_DESTROY( pGC->pScreen, region );
150
DrawablePtr pDrawable,
162
RegionPtr drawRegion, region;
163
int xoffset, yoffset;
164
int xtop, xbottom, yleft, yright;
167
PclContextPrivPtr pConPriv;
170
if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
173
pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
174
pConPriv = (PclContextPrivPtr)
175
pCon->devPrivates[PclContextPrivateIndex].ptr;
178
* Generate the PCL code to draw the filled polygon, by defining
179
* it as a macro which uses the HP-GL/2 polygon drawing function.
181
MACRO_START( outFile, pConPriv );
182
SAVE_PCL( outFile, pConPriv, "\033%0B" );
184
if( mode == CoordModeOrigin )
186
xoffset = pDrawable->x;
187
yoffset = pDrawable->y;
192
xoffset = yoffset = 0;
196
/* Begin the polygon */
197
sprintf( t, "PU%d,%d;PM0;%s", pPoints[0].x + xoffset, pPoints[0].y
198
+ yoffset, command );
199
SAVE_PCL( outFile, pConPriv, t );
201
/* Seed the bounding box */
202
xtop = xbottom = pPoints[0].x + xoffset;
203
yleft = yright = pPoints[0].y + yoffset;
205
/* Add the rest of the points to the polygon */
206
for( i = 1; i < nPoints; i++ )
209
SAVE_PCL( outFile, pConPriv, "," );
211
sprintf( t, "%d,%d", pPoints[i].x + xoffset, pPoints[i].y +
213
SAVE_PCL( outFile, pConPriv, t );
215
/* Update the bounding box */
216
xtop = MIN( xtop, pPoints[i].x + xoffset );
217
xbottom = MAX( xbottom, pPoints[i].x + xoffset );
218
yleft = MIN( yleft, pPoints[i].y + yoffset );
219
yright = MAX( yright, pPoints[i].y + yoffset );
222
/* Close the polygon and the macro */
224
if( pGC->fillRule == EvenOddRule )
229
sprintf( t, ";PM2;FP%d;\033%%0A", fillRule );
230
SAVE_PCL( outFile, pConPriv, t );
231
MACRO_END ( outFile );
234
* Build the bounding region from the bounding box of the polygon
240
drawRegion = REGION_CREATE( pGC->pScreen, &box, 0 );
242
if( mode == CoordModePrevious )
243
REGION_TRANSLATE( pGC->pScreen, drawRegion, pPoints[0].x, pPoints[0].y );
245
region = REGION_CREATE( pGC->pScreen, NULL, 0 );
247
REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
250
* For each rectangle in the clip region, set the HP-GL/2 "input
251
* window" and render the polygon to it.
253
pbox = REGION_RECTS( region );
254
nbox = REGION_NUM_RECTS( region );
256
PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
259
* Clean up the temporary regions
261
REGION_DESTROY( pGC->pScreen, drawRegion );
262
REGION_DESTROY( pGC->pScreen, region );
267
DrawablePtr pDrawable,
276
xRectangle *drawRects, *r;
277
RegionPtr drawRegion, region;
278
int xoffset, yoffset;
281
PclContextPrivPtr pConPriv;
283
if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
286
pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
287
pConPriv = (PclContextPrivPtr)
288
pCon->devPrivates[PclContextPrivateIndex].ptr;
291
* Allocate the storage required to deal with the clipping
294
region = REGION_CREATE( pGC->pScreen, NULL, 0 );
295
drawRects = (xRectangle *)xalloc( nRects * sizeof( xRectangle ) );
298
fudge = 3 * pGC->lineWidth + 1;
301
* Generate the PCL code to draw the filled rectangles, by
302
* defining them as a macro which uses the HP-GL/2 rectangle
305
MACRO_START( outFile, pConPriv );
306
SAVE_PCL( outFile, pConPriv, "\033%0B" );
308
xoffset = pDrawable->x;
309
yoffset = pDrawable->y;
311
for( i = 0, r = drawRects; i < nRects; i++, r++ )
313
xRectangle rect = pRects[i];
315
/* Draw the rectangle */
316
sprintf( t, "PU%d,%d;RR%d,%d;", rect.x + xoffset, rect.y +
317
yoffset, rect.width, rect.height );
318
SAVE_PCL( outFile, pConPriv, t );
320
/* Build the bounding box */
321
r->x = MIN( rect.x, rect.x + rect.width ) + xoffset - fudge;
322
r->y = MIN( rect.y, rect.y + rect.height ) + yoffset -
324
r->width = rect.width + 2 * fudge;
325
r->height = rect.height + 2 * fudge;
327
SAVE_PCL( outFile, pConPriv, ";\033%0A" ); /* End the macro */
328
MACRO_END( outFile );
331
* Convert the collection of rectangles to a proper region, then
332
* intersect it with the clip region.
334
drawRegion = RECTS_TO_REGION( pGC->pScreen, nRects,
335
drawRects, CT_UNSORTED );
336
REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
339
* For each rectangle in the clip region, set the HP-GL/2 "input
340
* window" and render the set of rectangles to it.
342
pbox = REGION_RECTS( region );
343
nbox = REGION_NUM_RECTS( region );
345
PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
348
* Clean up the temporary regions
350
REGION_DESTROY( pGC->pScreen, drawRegion );
351
REGION_DESTROY( pGC->pScreen, region );