~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to Xprint/pcl/PclPolygon.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: PclPolygon.c,v 1.3 2000/08/17 19:48:08 cpqbld Exp $ */
 
2
/*******************************************************************
 
3
**
 
4
**    *********************************************************
 
5
**    *
 
6
**    *  File:          PclPolygon.c
 
7
**    *
 
8
**    *  Contents:
 
9
**    *                 Draws Polygons and Rectangles for the PCL DDX
 
10
**    *
 
11
**    *  Created:       10/23/95
 
12
**    *
 
13
**    *********************************************************
 
14
**
 
15
********************************************************************/
 
16
/*
 
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.
 
24
 
 
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:
 
31
 
 
32
The above copyright notice and this permission notice shall be included in
 
33
all copies or substantial portions of the Software.
 
34
 
 
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.
 
41
 
 
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
 
45
copyright holders.
 
46
*/
 
47
/* $XFree86: xc/programs/Xserver/Xprint/pcl/PclPolygon.c,v 1.6 1999/12/13 02:12:56 robin Exp $ */
 
48
 
 
49
 
 
50
#ifdef HAVE_DIX_CONFIG_H
 
51
#include <dix-config.h>
 
52
#endif
 
53
 
 
54
#include "Pcl.h"
 
55
#include "gcstruct.h"
 
56
#include "windowstr.h"
 
57
 
 
58
void
 
59
PclPolyRectangle(
 
60
     DrawablePtr pDrawable,
 
61
     GCPtr pGC,
 
62
     int nRects,
 
63
     xRectangle *pRects)
 
64
{
 
65
    char t[80];
 
66
    FILE *outFile;
 
67
    int nbox, i;
 
68
    BoxPtr pbox;
 
69
    xRectangle *drawRects, *r;
 
70
    RegionPtr drawRegion, region;
 
71
    short fudge;
 
72
    int xoffset, yoffset;
 
73
    XpContextPtr pCon;
 
74
    PclContextPrivPtr pConPriv;
 
75
 
 
76
    if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
 
77
      return;
 
78
 
 
79
    pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
 
80
    pConPriv = (PclContextPrivPtr)
 
81
                        pCon->devPrivates[PclContextPrivateIndex].ptr;
 
82
 
 
83
    /*
 
84
     * Allocate the storage required to deal with the clipping
 
85
     * regions.
 
86
     */
 
87
    region = REGION_CREATE( pGC->pScreen, NULL, 0 );
 
88
    drawRects = (xRectangle *)xalloc( nRects * sizeof( xRectangle ) );
 
89
 
 
90
    fudge = 3 * pGC->lineWidth + 1;
 
91
 
 
92
    /*
 
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.
 
95
     */
 
96
    MACRO_START( outFile, pConPriv );
 
97
    SAVE_PCL( outFile, pConPriv, "\033%0B" );
 
98
 
 
99
    xoffset = pDrawable->x;
 
100
    yoffset = pDrawable->y;
 
101
 
 
102
    for( i = 0, r = drawRects; i < nRects; i++, r++ )
 
103
      {
 
104
          xRectangle rect = pRects[i];
 
105
 
 
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 );
 
110
 
 
111
          /* Build the bounding box */
 
112
          r->x = MIN( rect.x, rect.x + rect.width ) + xoffset -
 
113
            fudge;
 
114
          r->y = MIN( rect.y, rect.y + rect.height ) + yoffset -
 
115
            fudge;
 
116
          r->width = rect.width + 2 * fudge;
 
117
          r->height = rect.height + 2 * fudge;
 
118
      }
 
119
    SAVE_PCL( outFile, pConPriv, ";\033%0A" ); /* End the macro */
 
120
    MACRO_END( outFile );
 
121
 
 
122
    /*
 
123
     * Convert the collection of rectangles to a proper region, then
 
124
     * intersect it with the clip region.
 
125
     */
 
126
    drawRegion = RECTS_TO_REGION( pGC->pScreen, nRects,
 
127
                                  drawRects, CT_UNSORTED );
 
128
 
 
129
    REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
 
130
 
 
131
    /*
 
132
     * For each rectangle in the clip region, set the HP-GL/2 "input
 
133
     * window" and render the set of rectangles to it.
 
134
     */
 
135
    pbox = REGION_RECTS( region );
 
136
    nbox = REGION_NUM_RECTS( region );
 
137
 
 
138
    PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
 
139
 
 
140
    /*
 
141
     * Clean up the temporary regions
 
142
     */
 
143
    REGION_DESTROY( pGC->pScreen, drawRegion );
 
144
    REGION_DESTROY( pGC->pScreen, region );
 
145
    xfree( drawRects );
 
146
}
 
147
 
 
148
void
 
149
PclFillPolygon(
 
150
     DrawablePtr pDrawable,
 
151
     GCPtr pGC,
 
152
     int shape,
 
153
     int mode,
 
154
     int nPoints,
 
155
     DDXPointPtr pPoints)
 
156
{
 
157
    char t[80];
 
158
    FILE *outFile;
 
159
    int nbox, i;
 
160
    BoxPtr pbox;
 
161
    BoxRec box;
 
162
    RegionPtr drawRegion, region;
 
163
    int xoffset, yoffset;
 
164
    int xtop, xbottom, yleft, yright;
 
165
    int fillRule;
 
166
    XpContextPtr pCon;
 
167
    PclContextPrivPtr pConPriv;
 
168
    char *command;
 
169
 
 
170
    if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
 
171
      return;
 
172
 
 
173
    pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
 
174
    pConPriv = (PclContextPrivPtr)
 
175
                        pCon->devPrivates[PclContextPrivateIndex].ptr;
 
176
 
 
177
    /*
 
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.
 
180
     */
 
181
    MACRO_START( outFile, pConPriv );
 
182
    SAVE_PCL( outFile, pConPriv, "\033%0B" );
 
183
 
 
184
    if( mode == CoordModeOrigin )
 
185
      {
 
186
          xoffset = pDrawable->x;
 
187
          yoffset = pDrawable->y;
 
188
          command = "PA";
 
189
      }
 
190
    else
 
191
      {
 
192
          xoffset = yoffset = 0;
 
193
          command = "PR";
 
194
      }
 
195
 
 
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 );
 
200
 
 
201
    /* Seed the bounding box */
 
202
    xtop = xbottom = pPoints[0].x + xoffset;
 
203
    yleft = yright = pPoints[0].y + yoffset;
 
204
 
 
205
    /* Add the rest of the points to the polygon */
 
206
    for( i = 1; i < nPoints; i++ )
 
207
      {
 
208
          if( i != 1 )
 
209
            SAVE_PCL( outFile, pConPriv, "," );
 
210
 
 
211
          sprintf( t, "%d,%d", pPoints[i].x + xoffset, pPoints[i].y +
 
212
                  yoffset );
 
213
          SAVE_PCL( outFile, pConPriv, t );
 
214
 
 
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 );
 
220
      }
 
221
 
 
222
    /* Close the polygon and the macro */
 
223
 
 
224
    if( pGC->fillRule == EvenOddRule )
 
225
      fillRule = 0;
 
226
    else
 
227
      fillRule = 1;
 
228
 
 
229
    sprintf( t, ";PM2;FP%d;\033%%0A", fillRule );
 
230
    SAVE_PCL( outFile, pConPriv, t );
 
231
    MACRO_END ( outFile );
 
232
 
 
233
    /*
 
234
     * Build the bounding region from the bounding box of the polygon
 
235
     */
 
236
    box.x1 = xtop;
 
237
    box.y1 = yleft;
 
238
    box.x2 = xbottom;
 
239
    box.y2 = yright;
 
240
    drawRegion = REGION_CREATE( pGC->pScreen, &box, 0 );
 
241
 
 
242
    if( mode == CoordModePrevious )
 
243
      REGION_TRANSLATE( pGC->pScreen, drawRegion, pPoints[0].x, pPoints[0].y );
 
244
 
 
245
    region = REGION_CREATE( pGC->pScreen, NULL, 0 );
 
246
 
 
247
    REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
 
248
 
 
249
    /*
 
250
     * For each rectangle in the clip region, set the HP-GL/2 "input
 
251
     * window" and render the polygon to it.
 
252
     */
 
253
    pbox = REGION_RECTS( region );
 
254
    nbox = REGION_NUM_RECTS( region );
 
255
 
 
256
    PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
 
257
 
 
258
    /*
 
259
     * Clean up the temporary regions
 
260
     */
 
261
    REGION_DESTROY( pGC->pScreen, drawRegion );
 
262
    REGION_DESTROY( pGC->pScreen, region );
 
263
}
 
264
 
 
265
void
 
266
PclPolyFillRect(
 
267
     DrawablePtr pDrawable,
 
268
     GCPtr pGC,
 
269
     int nRects,
 
270
     xRectangle *pRects)
 
271
{
 
272
    char t[80];
 
273
    FILE *outFile;
 
274
    int nbox, i;
 
275
    BoxPtr pbox;
 
276
    xRectangle *drawRects, *r;
 
277
    RegionPtr drawRegion, region;
 
278
    int xoffset, yoffset;
 
279
    short fudge;
 
280
    XpContextPtr pCon;
 
281
    PclContextPrivPtr pConPriv;
 
282
 
 
283
    if( PclUpdateDrawableGC( pGC, pDrawable, &outFile ) == FALSE )
 
284
      return;
 
285
 
 
286
    pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
 
287
    pConPriv = (PclContextPrivPtr)
 
288
                        pCon->devPrivates[PclContextPrivateIndex].ptr;
 
289
 
 
290
    /*
 
291
     * Allocate the storage required to deal with the clipping
 
292
     * regions.
 
293
     */
 
294
    region = REGION_CREATE( pGC->pScreen, NULL, 0 );
 
295
    drawRects = (xRectangle *)xalloc( nRects * sizeof( xRectangle ) );
 
296
 
 
297
 
 
298
    fudge = 3 * pGC->lineWidth + 1;
 
299
 
 
300
    /*
 
301
     * Generate the PCL code to draw the filled rectangles, by
 
302
     * defining them as a macro which uses the HP-GL/2 rectangle
 
303
     * drawing function.
 
304
     */
 
305
    MACRO_START( outFile, pConPriv );
 
306
    SAVE_PCL( outFile, pConPriv, "\033%0B" );
 
307
 
 
308
    xoffset = pDrawable->x;
 
309
    yoffset = pDrawable->y;
 
310
 
 
311
    for( i = 0, r = drawRects; i < nRects; i++, r++ )
 
312
      {
 
313
          xRectangle rect = pRects[i];
 
314
 
 
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 );
 
319
 
 
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 -
 
323
            fudge;
 
324
          r->width = rect.width + 2 * fudge;
 
325
          r->height = rect.height + 2 * fudge;
 
326
      }
 
327
    SAVE_PCL( outFile, pConPriv, ";\033%0A" ); /* End the macro */
 
328
    MACRO_END( outFile );
 
329
 
 
330
    /*
 
331
     * Convert the collection of rectangles to a proper region, then
 
332
     * intersect it with the clip region.
 
333
     */
 
334
    drawRegion = RECTS_TO_REGION( pGC->pScreen, nRects,
 
335
                                  drawRects, CT_UNSORTED );
 
336
    REGION_INTERSECT( pGC->pScreen, region, drawRegion, pGC->pCompositeClip );
 
337
 
 
338
    /*
 
339
     * For each rectangle in the clip region, set the HP-GL/2 "input
 
340
     * window" and render the set of rectangles to it.
 
341
     */
 
342
    pbox = REGION_RECTS( region );
 
343
    nbox = REGION_NUM_RECTS( region );
 
344
 
 
345
    PclSendData(outFile, pConPriv, pbox, nbox, 1.0);
 
346
 
 
347
    /*
 
348
     * Clean up the temporary regions
 
349
     */
 
350
    REGION_DESTROY( pGC->pScreen, drawRegion );
 
351
    REGION_DESTROY( pGC->pScreen, region );
 
352
    xfree( drawRects );
 
353
}