Added msvcrt/eh.h.
[wine] / dlls / wineps / clipping.c
1 /*
2  *      PostScript clipping functions
3  *
4  *      Copyright 1999  Luc Tourangau 
5  *
6  */
7
8 #include "gdi.h"
9 #include "psdrv.h"
10 #include "debugtools.h"
11 #include "winbase.h"
12
13 DEFAULT_DEBUG_CHANNEL(psdrv);
14
15 /***********************************************************************
16  *           PSDRV_SetDeviceClipping
17  */
18 VOID PSDRV_SetDeviceClipping( DC *dc )
19 {
20     CHAR szArrayName[] = "clippath";
21     DWORD size;
22     RGNDATA *rgndata;
23
24     TRACE("hdc=%04x\n", dc->hSelf);
25
26     if (dc->hGCClipRgn == 0) {
27         ERR("Rgn is 0. Please report this.\n");
28         return;
29     }
30
31     size = GetRegionData(dc->hGCClipRgn, 0, NULL);
32     if(!size) {
33         ERR("Invalid region\n");
34         return;
35     }
36
37     rgndata = HeapAlloc( GetProcessHeap(), 0, size );
38     if(!rgndata) {
39         ERR("Can't allocate buffer\n");
40         return;
41     }
42
43     GetRegionData(dc->hGCClipRgn, size, rgndata);
44
45     PSDRV_WriteInitClip(dc);
46
47     /* check for NULL region */
48     if (rgndata->rdh.nCount == 0)
49     {
50         /* set an empty clip path. */
51         PSDRV_WriteRectClip(dc, 0, 0, 0, 0);
52     }
53     /* optimize when it is a simple region */
54     else if (rgndata->rdh.nCount == 1)
55     {
56         RECT *pRect = (RECT *)rgndata->Buffer;
57
58         PSDRV_WriteRectClip(dc, pRect->left, pRect->top, 
59                             pRect->right - pRect->left, 
60                             pRect->bottom - pRect->top);        
61     }
62     else
63     {
64         INT i;
65         RECT *pRect = (RECT *)rgndata->Buffer;
66
67         PSDRV_WriteArrayDef(dc, szArrayName, rgndata->rdh.nCount * 4);
68
69         for (i = 0; i < rgndata->rdh.nCount; i++, pRect++)
70         {
71             PSDRV_WriteArrayPut(dc, szArrayName, i * 4,
72                                 pRect->left);
73             PSDRV_WriteArrayPut(dc, szArrayName, i * 4 + 1,
74                                 pRect->top);
75             PSDRV_WriteArrayPut(dc, szArrayName, i * 4 + 2, 
76                                 pRect->right - pRect->left);
77             PSDRV_WriteArrayPut(dc, szArrayName, i * 4 + 3, 
78                                 pRect->bottom - pRect->top);
79         }
80
81         PSDRV_WriteRectClip2(dc, szArrayName);
82     }
83     
84     HeapFree( GetProcessHeap(), 0, rgndata );
85     return;
86 }