Faster serial speed cases for non Linux systems.
[wine] / dlls / wineps / clipping.c
1 /*
2  *      PostScript clipping functions
3  *
4  *      Copyright 1999  Luc Tourangau 
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "gdi.h"
22 #include "psdrv.h"
23 #include "wine/debug.h"
24 #include "winbase.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27
28 /***********************************************************************
29  *           PSDRV_SetDeviceClipping
30  */
31 VOID PSDRV_SetDeviceClipping( PSDRV_PDEVICE *physDev )
32 {
33     CHAR szArrayName[] = "clippath";
34     DWORD size;
35     RGNDATA *rgndata;
36     DC *dc = physDev->dc;
37
38     TRACE("hdc=%04x\n", physDev->hdc);
39
40     if (dc->hGCClipRgn == 0) {
41         ERR("Rgn is 0. Please report this.\n");
42         return;
43     }
44
45     size = GetRegionData(dc->hGCClipRgn, 0, NULL);
46     if(!size) {
47         ERR("Invalid region\n");
48         return;
49     }
50
51     rgndata = HeapAlloc( GetProcessHeap(), 0, size );
52     if(!rgndata) {
53         ERR("Can't allocate buffer\n");
54         return;
55     }
56
57     GetRegionData(dc->hGCClipRgn, size, rgndata);
58
59     PSDRV_WriteInitClip(physDev);
60
61     /* check for NULL region */
62     if (rgndata->rdh.nCount == 0)
63     {
64         /* set an empty clip path. */
65         PSDRV_WriteRectClip(physDev, 0, 0, 0, 0);
66     }
67     /* optimize when it is a simple region */
68     else if (rgndata->rdh.nCount == 1)
69     {
70         RECT *pRect = (RECT *)rgndata->Buffer;
71
72         PSDRV_WriteRectClip(physDev, pRect->left, pRect->top, 
73                             pRect->right - pRect->left, 
74                             pRect->bottom - pRect->top);        
75     }
76     else
77     {
78         INT i;
79         RECT *pRect = (RECT *)rgndata->Buffer;
80
81         PSDRV_WriteArrayDef(physDev, szArrayName, rgndata->rdh.nCount * 4);
82
83         for (i = 0; i < rgndata->rdh.nCount; i++, pRect++)
84         {
85             PSDRV_WriteArrayPut(physDev, szArrayName, i * 4,
86                                 pRect->left);
87             PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 1,
88                                 pRect->top);
89             PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 2, 
90                                 pRect->right - pRect->left);
91             PSDRV_WriteArrayPut(physDev, szArrayName, i * 4 + 3, 
92                                 pRect->bottom - pRect->top);
93         }
94
95         PSDRV_WriteRectClip2(physDev, szArrayName);
96     }
97     
98     HeapFree( GetProcessHeap(), 0, rgndata );
99     return;
100 }